@@ -77,12 +77,7 @@ public function incrementNotificationCounter(SignRequest $signRequest, string $m
7777 public function update (Entity $ entity ): SignRequest {
7878 /** @var SignRequest */
7979 $ signRequest = parent ::update ($ entity );
80- $ filtered = array_filter ($ this ->signers , fn ($ e ) => $ e ->getId () === $ signRequest ->getId ());
81- if (!empty ($ filtered )) {
82- $ this ->signers [key ($ filtered )] = $ signRequest ;
83- } else {
84- $ this ->signers [] = $ signRequest ;
85- }
80+ $ this ->signers [$ signRequest ->getId ()] = $ signRequest ;
8681 return $ signRequest ;
8782 }
8883
@@ -106,8 +101,8 @@ public function getByUuid(string $uuid): SignRequest {
106101 );
107102 /** @var SignRequest */
108103 $ signRequest = $ this ->findEntity ($ qb );
109- if (!array_filter ($ this ->signers , fn ( $ s ) => $ s -> getId () === $ signRequest ->getId ())) {
110- $ this ->signers [] = $ signRequest ;
104+ if (!isset ($ this ->signers [ $ signRequest ->getId ()] )) {
105+ $ this ->signers [$ signRequest -> getId () ] = $ signRequest ;
111106 }
112107 return $ signRequest ;
113108 }
@@ -155,8 +150,8 @@ public function getByFileId(int $fileId): array {
155150 /** @var SignRequest[] */
156151 $ signers = $ this ->findEntities ($ qb );
157152 foreach ($ signers as $ signRequest ) {
158- if (!array_filter ($ this ->signers , fn ( $ s ) => $ s -> getId () === $ signRequest ->getId ())) {
159- $ this ->signers [] = $ signRequest ;
153+ if (!isset ($ this ->signers [ $ signRequest ->getId ()] )) {
154+ $ this ->signers [$ signRequest -> getId () ] = $ signRequest ;
160155 }
161156 }
162157 return $ signers ;
@@ -166,10 +161,8 @@ public function getByFileId(int $fileId): array {
166161 * @throws DoesNotExistException
167162 */
168163 public function getById (int $ signRequestId ): SignRequest {
169- foreach ($ this ->signers as $ signRequest ) {
170- if ($ signRequest ->getId () === $ signRequestId ) {
171- return $ signRequest ;
172- }
164+ if (isset ($ this ->signers [$ signRequestId ])) {
165+ return $ this ->signers [$ signRequestId ];
173166 }
174167 $ qb = $ this ->db ->getQueryBuilder ();
175168
@@ -181,12 +174,76 @@ public function getById(int $signRequestId): SignRequest {
181174
182175 /** @var SignRequest */
183176 $ signRequest = $ this ->findEntity ($ qb );
184- if (!array_filter ($ this ->signers , fn ( $ s ) => $ s -> getId () === $ signRequest ->getId ())) {
185- $ this ->signers [] = $ signRequest ;
177+ if (!isset ($ this ->signers [ $ signRequest ->getId ()] )) {
178+ $ this ->signers [$ signRequest -> getId () ] = $ signRequest ;
186179 }
187180 return $ signRequest ;
188181 }
189182
183+ /**
184+ * @return \Generator<IdentifyMethod>
185+ */
186+ public function findRemindersCandidates (): \Generator {
187+ $ qb = $ this ->db ->getQueryBuilder ();
188+ $ qb ->select (
189+ 'sr.id AS sr_id ' ,
190+ 'sr.file_id AS sr_file_id ' ,
191+ 'sr.uuid AS sr_uuid ' ,
192+ 'sr.display_name AS sr_display_name ' ,
193+ 'sr.description AS sr_description ' ,
194+ 'sr.metadata AS sr_metadata ' ,
195+ 'sr.signed_hash AS sr_signed_hash ' ,
196+ 'sr.created_at AS sr_created_at ' ,
197+ 'sr.signed AS sr_signed ' ,
198+
199+ 'im.id AS im_id ' ,
200+ 'im.mandatory AS im_mandatory ' ,
201+ 'im.code AS im_code ' ,
202+ 'im.identifier_key AS im_identifier_key ' ,
203+ 'im.identifier_value AS im_identifier_value ' ,
204+ 'im.attempts AS im_attempts ' ,
205+ 'im.identified_at_date AS im_identified_at_date ' ,
206+ 'im.last_attempt_date AS im_last_attempt_date ' ,
207+ 'im.sign_request_id AS im_sign_request_id ' ,
208+ 'im.metadata AS im_metadata ' ,
209+ )
210+ ->from ('libresign_sign_request ' , 'sr ' )
211+ ->join ('sr ' , 'libresign_identify_method ' , 'im ' , 'sr.id = im.sign_request_id ' )
212+ ->join ('sr ' , 'libresign_file ' , 'f ' , 'sr.file_id = f.id ' )
213+ ->where ($ qb ->expr ()->isNull ('sr.signed ' ))
214+ ->andWhere ($ qb ->expr ()->neq ('im.identifier_value ' , $ qb ->createNamedParameter ('deleted_users ' )))
215+ ->andWhere ($ qb ->expr ()->in ('f.status ' , $ qb ->createNamedParameter ([
216+ File::STATUS_ABLE_TO_SIGN ,
217+ File::STATUS_PARTIAL_SIGNED
218+ ], IQueryBuilder::PARAM_INT_ARRAY )))
219+ ->setParameter ('st ' , [1 ,2 ], IQueryBuilder::PARAM_INT_ARRAY )
220+ ->orderBy ('sr.id ' , 'ASC ' );
221+
222+ $ result = $ qb ->executeQuery ();
223+ try {
224+ while ($ row = $ result ->fetch ()) {
225+ $ signRequest = new SignRequest ();
226+ $ identifyMethod = new IdentifyMethod ();
227+ foreach ($ row as $ key => $ value ) {
228+ $ prop = $ identifyMethod ->columnToProperty (substr ($ key , 3 ));
229+ if (str_starts_with ($ key , 'sr_ ' )) {
230+ $ signRequest ->{'set ' . lcfirst ($ prop )}($ value );
231+ } else {
232+ $ identifyMethod ->{'set ' . lcfirst ($ prop )}($ value );
233+ }
234+ }
235+ $ signRequest ->resetUpdatedFields ();
236+ $ identifyMethod ->resetUpdatedFields ();
237+ if (!isset ($ this ->signers [$ signRequest ->getId ()])) {
238+ $ this ->signers [$ signRequest ->getId ()] = $ signRequest ;
239+ }
240+ yield $ identifyMethod ;
241+ }
242+ } finally {
243+ $ result ->closeCursor ();
244+ }
245+ }
246+
190247 /**
191248 * Get all signers by multiple fileId
192249 *
@@ -245,8 +302,8 @@ public function getByFileUuid(string $uuid) {
245302 /** @var SignRequest[] */
246303 $ signers = $ this ->findEntities ($ qb );
247304 foreach ($ signers as $ signRequest ) {
248- if (!array_filter ($ this ->signers , fn ( $ s ) => $ s -> getId () === $ signRequest ->getId ())) {
249- $ this ->signers [] = $ signRequest ;
305+ if (!isset ($ this ->signers [ $ signRequest ->getId ()] )) {
306+ $ this ->signers [$ signRequest -> getId () ] = $ signRequest ;
250307 }
251308 }
252309 return $ signers ;
@@ -263,8 +320,8 @@ public function getBySignerUuidAndUserId(string $uuid): SignRequest {
263320
264321 /** @var SignRequest */
265322 $ signRequest = $ this ->findEntity ($ qb );
266- if (!array_filter ($ this ->signers , fn ( $ s ) => $ s -> getId () === $ signRequest ->getId ())) {
267- $ this ->signers [] = $ signRequest ;
323+ if (!isset ($ this ->signers [ $ signRequest ->getId ()] )) {
324+ $ this ->signers [$ signRequest -> getId () ] = $ signRequest ;
268325 }
269326 return $ signRequest ;
270327 }
@@ -301,9 +358,8 @@ public function getByFileIdAndEmail(int $file_id, string $email): SignRequest {
301358 }
302359
303360 public function getByFileIdAndSignRequestId (int $ fileId , int $ signRequestId ): SignRequest {
304- $ filtered = array_filter ($ this ->signers , fn ($ e ) => $ e ->getId () === $ signRequestId );
305- if ($ filtered ) {
306- return current ($ filtered );
361+ if (isset ($ this ->signers [$ signRequestId ])) {
362+ return $ this ->signers [$ signRequestId ];
307363 }
308364 $ qb = $ this ->db ->getQueryBuilder ();
309365
@@ -318,8 +374,8 @@ public function getByFileIdAndSignRequestId(int $fileId, int $signRequestId): Si
318374 );
319375
320376 $ signRequest = $ this ->findEntity ($ qb );
321- if (!array_filter ($ this ->signers , fn ( $ s ) => $ s -> getId () === $ signRequest ->getId ())) {
322- $ this ->signers [] = $ signRequest ;
377+ if (!isset ($ this ->signers [ $ signRequest ->getId ()] )) {
378+ $ this ->signers [$ signRequest -> getId () ] = $ signRequest ;
323379 }
324380 /** @var SignRequest */
325381 return end ($ this ->signers );
0 commit comments