2121namespace PrestaShop \Module \Psgdpr \Repository ;
2222
2323use Doctrine \Bundle \DoctrineBundle \Repository \ServiceEntityRepository ;
24+ use Doctrine \DBAL \FetchMode ;
2425use Doctrine \Persistence \ManagerRegistry ;
2526use PrestaShop \Module \Psgdpr \Entity \PsgdprConsent ;
2627use PrestaShop \Module \Psgdpr \Entity \PsgdprConsentLang ;
2728
2829class ConsentRepository extends ServiceEntityRepository
2930{
31+ /**
32+ * @var Connection
33+ */
34+ private $ connection ;
35+
3036 public function __construct (ManagerRegistry $ registry )
3137 {
3238 parent ::__construct ($ registry , PsgdprConsent::class);
39+ $ this ->connection = $ this ->getEntityManager ()->getConnection ();
3340 }
3441
3542 /**
@@ -87,16 +94,14 @@ public function findConsentByModuleId(int $moduleId)
8794 */
8895 public function findAllRegisteredModules (): array
8996 {
90- $ queryBuilder = $ this ->getEntityManager ()-> getConnection () ->createQueryBuilder ();
97+ $ queryBuilder = $ this ->connection ->createQueryBuilder ();
9198
9299 $ query = $ queryBuilder ->select ('consent.id_gdpr_consent ' , 'consent.id_module ' )
93100 ->from (_DB_PREFIX_ . 'psgdpr_consent ' , 'consent ' )
94101 ->innerJoin ('consent ' , _DB_PREFIX_ . 'module ' , 'module ' , 'module.id_module = consent.id_module ' )
95102 ->orderBy ('consent.id_gdpr_consent ' , 'DESC ' );
96103
97- $ data = $ query ->execute ();
98-
99- return $ data ->fetchAllAssociative ();
104+ return $ this ->connection ->executeQuery ($ query )->fetchAll (FetchMode::ASSOCIATIVE );
100105 }
101106
102107 /**
@@ -109,7 +114,7 @@ public function findAllRegisteredModules(): array
109114 */
110115 public function findModuleConsentMessage (int $ moduleId , int $ langId ): string
111116 {
112- $ queryBuilder = $ this ->getEntityManager ()-> getConnection () ->createQueryBuilder ();
117+ $ queryBuilder = $ this ->connection ->createQueryBuilder ();
113118
114119 $ query = $ queryBuilder ->select ('consent_lang.message ' )
115120 ->from (_DB_PREFIX_ . 'psgdpr_consent ' , 'consent ' )
@@ -119,10 +124,9 @@ public function findModuleConsentMessage(int $moduleId, int $langId): string
119124 ->setParameter ('id_module ' , $ moduleId )
120125 ->setParameter ('id_lang ' , $ langId );
121126
122- $ queryResult = $ query ->execute ();
123- $ data = $ queryResult ->fetchOne ();
127+ $ data = $ this ->connection ->executeQuery ($ query )->fetch (FetchMode::COLUMN );
124128
125- return $ data ? $ data : '' ;
129+ return $ data ?: '' ;
126130 }
127131
128132 /**
@@ -134,15 +138,14 @@ public function findModuleConsentMessage(int $moduleId, int $langId): string
134138 */
135139 public function findModuleConsentIsActive (int $ moduleId ): bool
136140 {
137- $ queryBuilder = $ this ->getEntityManager ()-> getConnection () ->createQueryBuilder ();
141+ $ queryBuilder = $ this ->connection ->createQueryBuilder ();
138142
139143 $ query = $ queryBuilder ->select ('consent.active ' )
140144 ->from (_DB_PREFIX_ . 'psgdpr_consent ' , 'consent ' )
141145 ->where ('consent.id_module = :id_module ' )
142146 ->setParameter ('id_module ' , $ moduleId );
143147
144- $ queryResult = $ query ->execute ();
145- $ data = $ queryResult ->fetchAssociative ();
148+ $ data = $ this ->connection ->executeQuery ($ query )->fetch (FetchMode::COLUMN );
146149
147150 return !empty ($ data ['active ' ]);
148151 }
@@ -156,17 +159,16 @@ public function findModuleConsentIsActive(int $moduleId): bool
156159 */
157160 public function findModuleConsentExist (int $ moduleId ): bool
158161 {
159- $ queryBuilder = $ this ->getEntityManager ()-> getConnection () ->createQueryBuilder ();
162+ $ queryBuilder = $ this ->connection ->createQueryBuilder ();
160163
161164 $ query = $ queryBuilder ->select ('id_module ' )
162165 ->from (_DB_PREFIX_ . 'psgdpr_consent ' , 'consent ' )
163166 ->leftJoin ('consent ' , _DB_PREFIX_ . 'psgdpr_consent_lang ' , 'consent_lang ' , 'consent.id_gdpr_consent = consent_lang.id_gdpr_consent ' )
164167 ->where ('consent.id_module = :id_module ' )
165168 ->setParameter ('id_module ' , $ moduleId );
166169
167- $ queryResult = $ query ->execute ();
168- $ data = $ queryResult ->fetchOne ();
170+ $ data = $ this ->connection ->executeQuery ($ query )->fetch (FetchMode::COLUMN );
169171
170- return $ data ? true : false ;
172+ return ( bool ) $ data ;
171173 }
172174}
0 commit comments