21
21
namespace PrestaShop \Module \Psgdpr \Repository ;
22
22
23
23
use Doctrine \Bundle \DoctrineBundle \Repository \ServiceEntityRepository ;
24
+ use Doctrine \DBAL \FetchMode ;
24
25
use Doctrine \Persistence \ManagerRegistry ;
25
26
use PrestaShop \Module \Psgdpr \Entity \PsgdprConsent ;
26
27
use PrestaShop \Module \Psgdpr \Entity \PsgdprConsentLang ;
27
28
28
29
class ConsentRepository extends ServiceEntityRepository
29
30
{
31
+ /**
32
+ * @var Connection
33
+ */
34
+ private $ connection ;
35
+
30
36
public function __construct (ManagerRegistry $ registry )
31
37
{
32
38
parent ::__construct ($ registry , PsgdprConsent::class);
39
+ $ this ->connection = $ this ->getEntityManager ()->getConnection ();
33
40
}
34
41
35
42
/**
@@ -87,16 +94,14 @@ public function findConsentByModuleId(int $moduleId)
87
94
*/
88
95
public function findAllRegisteredModules (): array
89
96
{
90
- $ queryBuilder = $ this ->getEntityManager ()-> getConnection () ->createQueryBuilder ();
97
+ $ queryBuilder = $ this ->connection ->createQueryBuilder ();
91
98
92
99
$ query = $ queryBuilder ->select ('consent.id_gdpr_consent ' , 'consent.id_module ' )
93
100
->from (_DB_PREFIX_ . 'psgdpr_consent ' , 'consent ' )
94
101
->innerJoin ('consent ' , _DB_PREFIX_ . 'module ' , 'module ' , 'module.id_module = consent.id_module ' )
95
102
->orderBy ('consent.id_gdpr_consent ' , 'DESC ' );
96
103
97
- $ data = $ query ->execute ();
98
-
99
- return $ data ->fetchAllAssociative ();
104
+ return $ this ->connection ->executeQuery ($ query )->fetchAll (FetchMode::ASSOCIATIVE );
100
105
}
101
106
102
107
/**
@@ -109,7 +114,7 @@ public function findAllRegisteredModules(): array
109
114
*/
110
115
public function findModuleConsentMessage (int $ moduleId , int $ langId ): string
111
116
{
112
- $ queryBuilder = $ this ->getEntityManager ()-> getConnection () ->createQueryBuilder ();
117
+ $ queryBuilder = $ this ->connection ->createQueryBuilder ();
113
118
114
119
$ query = $ queryBuilder ->select ('consent_lang.message ' )
115
120
->from (_DB_PREFIX_ . 'psgdpr_consent ' , 'consent ' )
@@ -119,10 +124,9 @@ public function findModuleConsentMessage(int $moduleId, int $langId): string
119
124
->setParameter ('id_module ' , $ moduleId )
120
125
->setParameter ('id_lang ' , $ langId );
121
126
122
- $ queryResult = $ query ->execute ();
123
- $ data = $ queryResult ->fetchOne ();
127
+ $ data = $ this ->connection ->executeQuery ($ query )->fetch (FetchMode::COLUMN );
124
128
125
- return $ data ? $ data : '' ;
129
+ return $ data ?: '' ;
126
130
}
127
131
128
132
/**
@@ -134,15 +138,14 @@ public function findModuleConsentMessage(int $moduleId, int $langId): string
134
138
*/
135
139
public function findModuleConsentIsActive (int $ moduleId ): bool
136
140
{
137
- $ queryBuilder = $ this ->getEntityManager ()-> getConnection () ->createQueryBuilder ();
141
+ $ queryBuilder = $ this ->connection ->createQueryBuilder ();
138
142
139
143
$ query = $ queryBuilder ->select ('consent.active ' )
140
144
->from (_DB_PREFIX_ . 'psgdpr_consent ' , 'consent ' )
141
145
->where ('consent.id_module = :id_module ' )
142
146
->setParameter ('id_module ' , $ moduleId );
143
147
144
- $ queryResult = $ query ->execute ();
145
- $ data = $ queryResult ->fetchAssociative ();
148
+ $ data = $ this ->connection ->executeQuery ($ query )->fetch (FetchMode::COLUMN );
146
149
147
150
return !empty ($ data ['active ' ]);
148
151
}
@@ -156,17 +159,16 @@ public function findModuleConsentIsActive(int $moduleId): bool
156
159
*/
157
160
public function findModuleConsentExist (int $ moduleId ): bool
158
161
{
159
- $ queryBuilder = $ this ->getEntityManager ()-> getConnection () ->createQueryBuilder ();
162
+ $ queryBuilder = $ this ->connection ->createQueryBuilder ();
160
163
161
164
$ query = $ queryBuilder ->select ('id_module ' )
162
165
->from (_DB_PREFIX_ . 'psgdpr_consent ' , 'consent ' )
163
166
->leftJoin ('consent ' , _DB_PREFIX_ . 'psgdpr_consent_lang ' , 'consent_lang ' , 'consent.id_gdpr_consent = consent_lang.id_gdpr_consent ' )
164
167
->where ('consent.id_module = :id_module ' )
165
168
->setParameter ('id_module ' , $ moduleId );
166
169
167
- $ queryResult = $ query ->execute ();
168
- $ data = $ queryResult ->fetchOne ();
170
+ $ data = $ this ->connection ->executeQuery ($ query )->fetch (FetchMode::COLUMN );
169
171
170
- return $ data ? true : false ;
172
+ return ( bool ) $ data ;
171
173
}
172
174
}
0 commit comments