• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LibreSign / libresign / 19881416377

03 Dec 2025 03:33AM UTC coverage: 41.566%. First build
19881416377

Pull #5951

github

web-flow
Merge 5a6b1bb3e into a3b5116b0
Pull Request #5951: fix: remove duplicate extension

7 of 17 new or added lines in 2 files covered. (41.18%)

5128 of 12337 relevant lines covered (41.57%)

4.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

47.7
/lib/Db/SignRequestMapper.php
1
<?php
2

3
declare(strict_types=1);
4
/**
5
 * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
6
 * SPDX-License-Identifier: AGPL-3.0-or-later
7
 */
8

9
namespace OCA\Libresign\Db;
10

11
use DateTimeInterface;
12
use OCA\Libresign\Helper\Pagination;
13
use OCA\Libresign\Service\IdentifyMethod\IIdentifyMethod;
14
use OCA\Libresign\Service\IdentifyMethodService;
15
use OCP\AppFramework\Db\DoesNotExistException;
16
use OCP\AppFramework\Db\Entity;
17
use OCP\AppFramework\Db\QBMapper;
18
use OCP\DB\QueryBuilder\IQueryBuilder;
19
use OCP\IDateTimeFormatter;
20
use OCP\IDBConnection;
21
use OCP\IL10N;
22
use OCP\IURLGenerator;
23
use OCP\IUser;
24
use OCP\IUserManager;
25

26
/**
27
 * Class SignRequestMapper
28
 *
29
 * @package OCA\Libresign\DB
30
 * @template-extends QBMapper<SignRequest>
31
 */
32
class SignRequestMapper extends QBMapper {
33
        /**
34
         * @var SignRequest[]
35
         */
36
        private $signers = [];
37
        private bool $firstNotification = false;
38

39
        public function __construct(
40
                IDBConnection $db,
41
                protected IL10N $l10n,
42
                protected FileMapper $fileMapper,
43
                private IUserManager $userManager,
44
                private IDateTimeFormatter $dateTimeFormatter,
45
                private IURLGenerator $urlGenerator,
46
        ) {
47
                parent::__construct($db, 'libresign_sign_request');
47✔
48
        }
49

50
        /**
51
         * @return boolean true when is the first notification
52
         */
53
        public function incrementNotificationCounter(SignRequest $signRequest, string $method): bool {
54
                $this->db->beginTransaction();
13✔
55
                try {
56
                        $fromDatabase = $this->getById($signRequest->getId());
13✔
57
                        $metadata = $fromDatabase->getMetadata();
13✔
58
                        if (!isset($metadata['notify'])) {
13✔
59
                                $this->firstNotification = true;
13✔
60
                        }
61
                        $metadata['notify'][] = [
13✔
62
                                'method' => $method,
13✔
63
                                'date' => time(),
13✔
64
                        ];
13✔
65
                        $fromDatabase->setMetadata($metadata);
13✔
66
                        $this->update($fromDatabase);
13✔
67
                        $this->db->commit();
13✔
68
                } catch (\Throwable) {
×
69
                        $this->db->rollBack();
×
70
                }
71
                return $this->firstNotification;
13✔
72
        }
73

74
        /**
75
         * @inheritDoc
76
         */
77
        #[\Override]
78
        public function update(Entity $entity): SignRequest {
79
                /** @var SignRequest */
80
                $signRequest = parent::update($entity);
13✔
81
                $this->signers[$signRequest->getId()] = $signRequest;
13✔
82
                return $signRequest;
13✔
83
        }
84

85
        /**
86
         * Get sign request by UUID
87
         *
88
         * @throws DoesNotExistException
89
         */
90
        public function getByUuid(string $uuid): SignRequest {
91
                foreach ($this->signers as $signRequest) {
5✔
92
                        if ($signRequest->getUuid() === $uuid) {
5✔
93
                                return $signRequest;
4✔
94
                        }
95
                }
96
                $qb = $this->db->getQueryBuilder();
1✔
97

98
                $qb->select('*')
1✔
99
                        ->from($this->getTableName())
1✔
100
                        ->where(
1✔
101
                                $qb->expr()->eq('uuid', $qb->createNamedParameter($uuid))
1✔
102
                        );
1✔
103
                /** @var SignRequest */
104
                $signRequest = $this->findEntity($qb);
1✔
105
                if (!isset($this->signers[$signRequest->getId()])) {
×
106
                        $this->signers[$signRequest->getId()] = $signRequest;
×
107
                }
108
                return $signRequest;
×
109
        }
110

111
        public function getByEmailAndFileId(string $email, int $fileId): SignRequest {
112
                $qb = $this->db->getQueryBuilder();
×
113

114
                $qb->select('*')
×
115
                        ->from($this->getTableName())
×
116
                        ->where(
×
117
                                $qb->expr()->eq('email', $qb->createNamedParameter($email))
×
118
                        )
×
119
                        ->andWhere(
×
120
                                $qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))
×
121
                        );
×
122
                /** @var SignRequest */
123
                return $this->findEntity($qb);
×
124
        }
125

126
        public function getByIdentifyMethodAndFileId(IIdentifyMethod $identifyMethod, int $fileId): SignRequest {
127
                $qb = $this->db->getQueryBuilder();
13✔
128
                $qb->select('sr.*')
13✔
129
                        ->from($this->getTableName(), 'sr')
13✔
130
                        ->join('sr', 'libresign_identify_method', 'im', 'sr.id = im.sign_request_id')
13✔
131
                        ->where($qb->expr()->eq('im.identifier_key', $qb->createNamedParameter($identifyMethod->getEntity()->getIdentifierKey())))
13✔
132
                        ->andWhere($qb->expr()->eq('im.identifier_value', $qb->createNamedParameter($identifyMethod->getEntity()->getIdentifierValue())))
13✔
133
                        ->andWhere($qb->expr()->eq('sr.file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
13✔
134
                /** @var SignRequest */
135
                return $this->findEntity($qb);
13✔
136
        }
137

138
        /**
139
         * Get all signers by fileId
140
         *
141
         * @return SignRequest[]
142
         */
143
        public function getByFileId(int $fileId): array {
144
                $qb = $this->db->getQueryBuilder();
14✔
145

146
                $qb->select('*')
14✔
147
                        ->from($this->getTableName())
14✔
148
                        ->where(
14✔
149
                                $qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))
14✔
150
                        );
14✔
151
                /** @var SignRequest[] */
152
                $signers = $this->findEntities($qb);
14✔
153
                foreach ($signers as $signRequest) {
14✔
154
                        if (!isset($this->signers[$signRequest->getId()])) {
11✔
155
                                $this->signers[$signRequest->getId()] = $signRequest;
1✔
156
                        }
157
                }
158
                return $signers;
14✔
159
        }
160

161
        /**
162
         * @throws DoesNotExistException
163
         */
164
        public function getById(int $signRequestId): SignRequest {
165
                if (isset($this->signers[$signRequestId])) {
15✔
166
                        return $this->signers[$signRequestId];
14✔
167
                }
168
                $qb = $this->db->getQueryBuilder();
14✔
169

170
                $qb->select('*')
14✔
171
                        ->from($this->getTableName())
14✔
172
                        ->where(
14✔
173
                                $qb->expr()->eq('id', $qb->createNamedParameter($signRequestId, IQueryBuilder::PARAM_INT))
14✔
174
                        );
14✔
175

176
                /** @var SignRequest */
177
                $signRequest = $this->findEntity($qb);
14✔
178
                if (!isset($this->signers[$signRequest->getId()])) {
14✔
179
                        $this->signers[$signRequest->getId()] = $signRequest;
14✔
180
                }
181
                return $signRequest;
14✔
182
        }
183

184
        /**
185
         * @return \Generator<IdentifyMethod>
186
         */
187
        public function findRemindersCandidates(): \Generator {
188
                $qb = $this->db->getQueryBuilder();
×
189
                $qb->select(
×
190
                        'sr.id AS sr_id',
×
191
                        'sr.file_id AS sr_file_id',
×
192
                        'sr.uuid AS sr_uuid',
×
193
                        'sr.display_name AS sr_display_name',
×
194
                        'sr.description AS sr_description',
×
195
                        'sr.metadata AS sr_metadata',
×
196
                        'sr.signed_hash AS sr_signed_hash',
×
197
                        'sr.created_at AS sr_created_at',
×
198
                        'sr.signed AS sr_signed',
×
199

200
                        'im.id AS im_id',
×
201
                        'im.mandatory AS im_mandatory',
×
202
                        'im.code AS im_code',
×
203
                        'im.identifier_key AS im_identifier_key',
×
204
                        'im.identifier_value AS im_identifier_value',
×
205
                        'im.attempts AS im_attempts',
×
206
                        'im.identified_at_date AS im_identified_at_date',
×
207
                        'im.last_attempt_date AS im_last_attempt_date',
×
208
                        'im.sign_request_id AS im_sign_request_id',
×
209
                        'im.metadata AS im_metadata',
×
210
                )
×
211
                        ->from('libresign_sign_request', 'sr')
×
212
                        ->join('sr', 'libresign_identify_method', 'im', 'sr.id = im.sign_request_id')
×
213
                        ->join('sr', 'libresign_file', 'f', 'sr.file_id = f.id')
×
214
                        ->where($qb->expr()->isNull('sr.signed'))
×
215
                        ->andWhere($qb->expr()->neq('im.identifier_value', $qb->createNamedParameter('deleted_users')))
×
216
                        ->andWhere($qb->expr()->in('f.status', $qb->createNamedParameter([
×
217
                                File::STATUS_ABLE_TO_SIGN,
×
218
                                File::STATUS_PARTIAL_SIGNED
×
219
                        ], IQueryBuilder::PARAM_INT_ARRAY)))
×
220
                        ->setParameter('st', [1,2], IQueryBuilder::PARAM_INT_ARRAY)
×
221
                        ->orderBy('sr.id', 'ASC');
×
222

223
                $result = $qb->executeQuery();
×
224
                try {
225
                        /** @var array<string, mixed> $row */
226
                        while ($row = $result->fetch()) {
×
227
                                $signRequest = new SignRequest();
×
228
                                $identifyMethod = new IdentifyMethod();
×
229
                                foreach ($row as $key => $value) {
×
230
                                        $prop = $identifyMethod->columnToProperty(substr($key, 3));
×
231
                                        if (str_starts_with($key, 'sr_')) {
×
232
                                                $signRequest->{'set' . lcfirst($prop)}($value);
×
233
                                        } else {
234
                                                $identifyMethod->{'set' . lcfirst($prop)}($value);
×
235
                                        }
236
                                }
237
                                $signRequest->resetUpdatedFields();
×
238
                                $identifyMethod->resetUpdatedFields();
×
239
                                if (!isset($this->signers[$signRequest->getId()])) {
×
240
                                        $this->signers[$signRequest->getId()] = $signRequest;
×
241
                                }
242
                                yield $identifyMethod;
×
243
                        }
244
                } finally {
245
                        $result->closeCursor();
×
246
                }
247
        }
248

249
        /**
250
         * Get all signers by multiple fileId
251
         *
252
         * @return SignRequest[]
253
         */
254
        public function getByMultipleFileId(array $fileId) {
255
                $qb = $this->db->getQueryBuilder();
6✔
256

257
                $qb->select('*')
6✔
258
                        ->from($this->getTableName(), 'sr')
6✔
259
                        ->where(
6✔
260
                                $qb->expr()->in('sr.file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT_ARRAY))
6✔
261
                        )
6✔
262
                        ->orderBy('sr.id', 'ASC');
6✔
263

264
                /** @var SignRequest[] */
265
                return $this->findEntities($qb);
6✔
266
        }
267

268
        /**
269
         * Get all signers by fileId
270
         *
271
         * @return SignRequest[]
272
         */
273
        public function getByNodeId(int $nodeId) {
274
                $qb = $this->db->getQueryBuilder();
3✔
275

276
                $qb->select('sr.*')
3✔
277
                        ->from($this->getTableName(), 'sr')
3✔
278
                        ->join('sr', 'libresign_file', 'f', 'sr.file_id = f.id')
3✔
279
                        ->where(
3✔
280
                                $qb->expr()->eq('f.node_id', $qb->createNamedParameter($nodeId, IQueryBuilder::PARAM_INT))
3✔
281
                        );
3✔
282

283
                /** @var SignRequest[] */
284
                $signers = $this->findEntities($qb);
3✔
285
                return $signers;
3✔
286
        }
287

288
        /**
289
         * Get all signers by File Uuid
290
         *
291
         * @param string $nodeId
292
         * @return SignRequest[]
293
         */
294
        public function getByFileUuid(string $uuid) {
295
                $qb = $this->db->getQueryBuilder();
1✔
296

297
                $qb->select('sr.*')
1✔
298
                        ->from($this->getTableName(), 'sr')
1✔
299
                        ->join('sr', 'libresign_file', 'f', 'sr.file_id = f.id')
1✔
300
                        ->where(
1✔
301
                                $qb->expr()->eq('f.uuid', $qb->createNamedParameter($uuid))
1✔
302
                        );
1✔
303

304
                /** @var SignRequest[] */
305
                $signers = $this->findEntities($qb);
1✔
306
                foreach ($signers as $signRequest) {
1✔
307
                        if (!isset($this->signers[$signRequest->getId()])) {
1✔
308
                                $this->signers[$signRequest->getId()] = $signRequest;
×
309
                        }
310
                }
311
                return $signers;
1✔
312
        }
313

314
        public function getBySignerUuidAndUserId(string $uuid): SignRequest {
315
                $qb = $this->db->getQueryBuilder();
×
316

317
                $qb->select('sr.*')
×
318
                        ->from($this->getTableName(), 'sr')
×
319
                        ->where(
×
320
                                $qb->expr()->eq('sr.uuid', $qb->createNamedParameter($uuid))
×
321
                        );
×
322

323
                /** @var SignRequest */
324
                $signRequest = $this->findEntity($qb);
×
325
                if (!isset($this->signers[$signRequest->getId()])) {
×
326
                        $this->signers[$signRequest->getId()] = $signRequest;
×
327
                }
328
                return $signRequest;
×
329
        }
330

331
        public function getByFileIdAndUserId(int $file_id): SignRequest {
332
                $qb = $this->db->getQueryBuilder();
×
333

334
                $qb->select('sr.*')
×
335
                        ->from($this->getTableName(), 'sr')
×
336
                        ->join('sr', 'libresign_file', 'f', 'sr.file_id = f.id')
×
337
                        ->where(
×
338
                                $qb->expr()->eq('f.node_id', $qb->createNamedParameter($file_id, IQueryBuilder::PARAM_INT))
×
339
                        );
×
340

341
                /** @var SignRequest */
342
                return $this->findEntity($qb);
×
343
        }
344

345
        public function getByFileIdAndEmail(int $file_id, string $email): SignRequest {
346
                $qb = $this->db->getQueryBuilder();
×
347

348
                $qb->select('sr.*')
×
349
                        ->from($this->getTableName(), 'sr')
×
350
                        ->join('sr', 'libresign_file', 'f', 'sr.file_id = f.id')
×
351
                        ->where(
×
352
                                $qb->expr()->eq('f.node_id', $qb->createNamedParameter($file_id, IQueryBuilder::PARAM_INT))
×
353
                        )
×
354
                        ->andWhere(
×
355
                                $qb->expr()->eq('sr.email', $qb->createNamedParameter($email))
×
356
                        );
×
357

358
                /** @var SignRequest */
359
                return $this->findEntity($qb);
×
360
        }
361

362
        public function getByFileIdAndSignRequestId(int $fileId, int $signRequestId): SignRequest {
363
                if (isset($this->signers[$signRequestId])) {
2✔
364
                        return $this->signers[$signRequestId];
2✔
365
                }
366
                $qb = $this->db->getQueryBuilder();
×
367

368
                $qb->select('sr.*')
×
369
                        ->from($this->getTableName(), 'sr')
×
370
                        ->join('sr', 'libresign_file', 'f', 'sr.file_id = f.id')
×
371
                        ->where(
×
372
                                $qb->expr()->eq('f.node_id', $qb->createNamedParameter($fileId))
×
373
                        )
×
374
                        ->andWhere(
×
375
                                $qb->expr()->eq('sr.id', $qb->createNamedParameter($signRequestId))
×
376
                        );
×
377

378
                $signRequest = $this->findEntity($qb);
×
379
                if (!isset($this->signers[$signRequest->getId()])) {
×
380
                        $this->signers[$signRequest->getId()] = $signRequest;
×
381
                }
382
                /** @var SignRequest */
383
                return end($this->signers);
×
384
        }
385

386
        public function getFilesAssociatedFilesWithMeFormatted(
387
                IUser $user,
388
                array $filter,
389
                ?int $page = null,
390
                ?int $length = null,
391
                ?array $sort = [],
392
        ): array {
393
                $filter['email'] = $user->getEMailAddress();
1✔
394
                $filter['length'] = $length;
1✔
395
                $filter['page'] = $page;
1✔
396
                $pagination = $this->getFilesAssociatedFilesWithMeStmt($user->getUID(), $filter, $sort);
1✔
397
                $pagination->setMaxPerPage($length);
1✔
398
                $pagination->setCurrentPage($page);
1✔
399
                $currentPageResults = $pagination->getCurrentPageResults();
1✔
400

401
                $data = [];
1✔
402
                foreach ($currentPageResults as $row) {
1✔
403
                        $data[] = $this->formatListRow($row);
×
404
                }
405
                $return['data'] = $data;
1✔
406
                $return['pagination'] = $pagination;
1✔
407
                return $return;
1✔
408
        }
409

410
        /**
411
         * @param array<SignRequest> $signRequests
412
         * @return FileElement[][]
413
         */
414
        public function getVisibleElementsFromSigners(array $signRequests): array {
415
                $signRequestIds = array_map(fn (SignRequest $signRequest): int => $signRequest->getId(), $signRequests);
5✔
416
                if (!$signRequestIds) {
5✔
417
                        return [];
1✔
418
                }
419
                $qb = $this->db->getQueryBuilder();
4✔
420
                $qb->select('fe.*')
4✔
421
                        ->from('libresign_file_element', 'fe')
4✔
422
                        ->where(
4✔
423
                                $qb->expr()->in('fe.sign_request_id', $qb->createParameter('signRequestIds'))
4✔
424
                        );
4✔
425
                $return = [];
4✔
426
                foreach (array_chunk($signRequestIds, 1000) as $signRequestIdsChunk) {
4✔
427
                        $qb->setParameter('signRequestIds', $signRequestIdsChunk, IQueryBuilder::PARAM_INT_ARRAY);
4✔
428
                        $cursor = $qb->executeQuery();
4✔
429
                        while ($row = $cursor->fetch()) {
4✔
430
                                $fileElement = new FileElement();
×
431
                                $return[$row['sign_request_id']][] = $fileElement->fromRow($row);
×
432
                        }
433
                }
434
                return $return;
4✔
435
        }
436

437
        /**
438
         * @param array<SignRequest> $signRequests
439
         * @return array<array-key, array<array-key, \OCP\AppFramework\Db\Entity&\OCA\Libresign\Db\IdentifyMethod>>
440
         */
441
        public function getIdentifyMethodsFromSigners(array $signRequests): array {
442
                $signRequestIds = array_map(fn (SignRequest $signRequest): int => $signRequest->getId(), $signRequests);
1✔
443
                if (!$signRequestIds) {
1✔
444
                        return [];
1✔
445
                }
446
                $qb = $this->db->getQueryBuilder();
×
447
                $qb->select('im.*')
×
448
                        ->from('libresign_identify_method', 'im')
×
449
                        ->where(
×
450
                                $qb->expr()->in('im.sign_request_id', $qb->createParameter('signRequestIds'))
×
451
                        )
×
452
                        ->orderBy('im.mandatory', 'DESC')
×
453
                        ->addOrderBy('im.identified_at_date', 'ASC');
×
454

455
                $return = [];
×
456
                foreach (array_chunk($signRequestIds, 1000) as $signRequestIdsChunk) {
×
457
                        $qb->setParameter('signRequestIds', $signRequestIdsChunk, IQueryBuilder::PARAM_INT_ARRAY);
×
458
                        $cursor = $qb->executeQuery();
×
459
                        while ($row = $cursor->fetch()) {
×
460
                                $identifyMethod = new IdentifyMethod();
×
461
                                $return[$row['sign_request_id']][$row['identifier_key']] = $identifyMethod->fromRow($row);
×
462
                        }
463
                }
464
                return $return;
×
465
        }
466

467
        public function getMyLibresignFile(string $userId, ?array $filter = []): File {
468
                $qb = $this->getFilesAssociatedFilesWithMeQueryBuilder(
×
469
                        userId: $userId,
×
470
                        filter: $filter,
×
471
                );
×
472
                $cursor = $qb->executeQuery();
×
473
                $row = $cursor->fetch();
×
474
                if (!$row) {
×
475
                        throw new DoesNotExistException('LibreSign file not found');
×
476
                }
477
                $file = new File();
×
478
                return $file->fromRow($row);
×
479
        }
480

481
        private function getFilesAssociatedFilesWithMeQueryBuilder(string $userId, array $filter = [], bool $count = false): IQueryBuilder {
482
                $qb = $this->db->getQueryBuilder();
1✔
483
                $qb->from('libresign_file', 'f')
1✔
484
                        ->leftJoin('f', 'libresign_sign_request', 'sr', 'sr.file_id = f.id')
1✔
485
                        ->leftJoin('f', 'libresign_identify_method', 'im', $qb->expr()->eq('sr.id', 'im.sign_request_id'))
1✔
486
                        ->leftJoin('f', 'libresign_id_docs', 'id', 'id.file_id = f.id');
1✔
487
                if ($count) {
1✔
488
                        $qb->select($qb->func()->count())
1✔
489
                                ->setFirstResult(0)
1✔
490
                                ->setMaxResults(null);
1✔
491
                } else {
492
                        $qb->select(
1✔
493
                                'f.id',
1✔
494
                                'f.node_id',
1✔
495
                                'f.user_id',
1✔
496
                                'f.uuid',
1✔
497
                                'f.name',
1✔
498
                                'f.status',
1✔
499
                                'f.metadata',
1✔
500
                                'f.created_at',
1✔
501
                        )
1✔
502
                                ->groupBy(
1✔
503
                                        'f.id',
1✔
504
                                        'f.node_id',
1✔
505
                                        'f.user_id',
1✔
506
                                        'f.uuid',
1✔
507
                                        'f.name',
1✔
508
                                        'f.status',
1✔
509
                                        'f.created_at',
1✔
510
                                );
1✔
511
                        // metadata is a json column, the right way is to use f.metadata::text
512
                        // when the database is PostgreSQL. The problem is that the command
513
                        // addGroupBy add quotes over all text send as argument. With
514
                        // PostgreSQL json columns don't have problem if not added to group by.
515
                        if ($qb->getConnection()->getDatabaseProvider() !== IDBConnection::PLATFORM_POSTGRES) {
1✔
516
                                $qb->addGroupBy('f.metadata');
1✔
517
                        }
518
                        if (isset($filter['length']) && isset($filter['page'])) {
1✔
519
                                $qb->setFirstResult($filter['length'] * ($filter['page'] - 1));
1✔
520
                                $qb->setMaxResults($filter['length']);
1✔
521
                        }
522
                }
523

524
                $or = [
1✔
525
                        $qb->expr()->eq('f.user_id', $qb->createNamedParameter($userId)),
1✔
526
                        $qb->expr()->andX(
1✔
527
                                $qb->expr()->eq('im.identifier_key', $qb->createNamedParameter(IdentifyMethodService::IDENTIFY_ACCOUNT)),
1✔
528
                                $qb->expr()->eq('im.identifier_value', $qb->createNamedParameter($userId))
1✔
529
                        )
1✔
530
                ];
1✔
531
                $qb->where($qb->expr()->orX(...$or))->andWhere($qb->expr()->isNull('id.id'));
1✔
532
                if ($filter) {
1✔
533
                        if (isset($filter['email']) && filter_var($filter['email'], FILTER_VALIDATE_EMAIL)) {
1✔
534
                                $or[] = $qb->expr()->andX(
×
535
                                        $qb->expr()->eq('im.identifier_key', $qb->createNamedParameter(IdentifyMethodService::IDENTIFY_EMAIL)),
×
536
                                        $qb->expr()->eq('im.identifier_value', $qb->createNamedParameter($filter['email']))
×
537
                                );
×
538
                        }
539
                        if (!empty($filter['signer_uuid'])) {
1✔
540
                                $qb->andWhere(
×
541
                                        $qb->expr()->eq('sr.uuid', $qb->createNamedParameter($filter['signer_uuid']))
×
542
                                );
×
543
                        }
544
                        if (!empty($filter['nodeId'])) {
1✔
545
                                $qb->andWhere(
×
546
                                        $qb->expr()->eq('f.node_id', $qb->createNamedParameter($filter['nodeId'], IQueryBuilder::PARAM_INT))
×
547
                                );
×
548
                        }
549
                        if (!empty($filter['status'])) {
1✔
550
                                $qb->andWhere(
×
551
                                        $qb->expr()->in('f.status', $qb->createNamedParameter($filter['status'], IQueryBuilder::PARAM_INT_ARRAY))
×
552
                                );
×
553
                        }
554
                        if (!empty($filter['start'])) {
1✔
555
                                $qb->andWhere(
×
556
                                        $qb->expr()->gte('f.created_at', $qb->createNamedParameter($filter['start'], IQueryBuilder::PARAM_INT))
×
557
                                );
×
558
                        }
559
                        if (!empty($filter['end'])) {
1✔
560
                                $qb->andWhere(
×
561
                                        $qb->expr()->lte('f.created_at', $qb->createNamedParameter($filter['end'], IQueryBuilder::PARAM_INT))
×
562
                                );
×
563
                        }
564
                }
565
                return $qb;
1✔
566
        }
567

568
        private function getFilesAssociatedFilesWithMeStmt(
569
                string $userId,
570
                ?array $filter = [],
571
                ?array $sort = [],
572
        ): Pagination {
573
                $qb = $this->getFilesAssociatedFilesWithMeQueryBuilder($userId, $filter);
1✔
574
                if (!empty($sort['sortBy'])) {
1✔
575
                        switch ($sort['sortBy']) {
×
576
                                case 'name':
×
577
                                case 'status':
×
578
                                        $qb->orderBy(
×
579
                                                $qb->func()->lower('f.' . $sort['sortBy']),
×
580
                                                $sort['sortDirection'] == 'asc' ? 'asc' : 'desc'
×
581
                                        );
×
582
                                        break;
×
583
                                case 'created_at':
×
584
                                        $qb->orderBy(
×
585
                                                'f.' . $sort['sortBy'],
×
586
                                                $sort['sortDirection'] == 'asc' ? 'asc' : 'desc'
×
587
                                        );
×
588
                        }
589
                }
590

591
                $countQb = $this->getFilesAssociatedFilesWithMeQueryBuilder(
1✔
592
                        userId: $userId,
1✔
593
                        filter: $filter,
1✔
594
                        count: true,
1✔
595
                );
1✔
596

597
                $pagination = new Pagination($qb, $this->urlGenerator, $countQb);
1✔
598
                return $pagination;
1✔
599
        }
600

601
        private function formatListRow(array $row): array {
602
                $row['id'] = (int)$row['id'];
×
603
                $row['status'] = (int)$row['status'];
×
604
                $row['statusText'] = $this->fileMapper->getTextOfStatus($row['status']);
×
605
                $row['nodeId'] = (int)$row['node_id'];
×
606
                $row['requested_by'] = [
×
607
                        'userId' => $row['user_id'],
×
608
                        'displayName' => $this->userManager->get($row['user_id'])?->getDisplayName(),
×
609
                ];
×
610
                $row['created_at'] = (new \DateTime($row['created_at']))->setTimezone(new \DateTimeZone('UTC'))->format(DateTimeInterface::ATOM);
×
611
                $row['file'] = $this->urlGenerator->linkToRoute('libresign.page.getPdf', ['uuid' => $row['uuid']]);
×
612
                $row['nodeId'] = (int)$row['node_id'];
×
613

NEW
614
                $row['name'] = $this->removeExtensionFromName($row['name'], $row['metadata']);
×
615

616
                unset(
×
617
                        $row['user_id'],
×
618
                        $row['node_id'],
×
619
                );
×
620
                return $row;
×
621
        }
622

623
        private function removeExtensionFromName(string $name, ?string $metadataJson): string {
NEW
624
                if (empty($name) || empty($metadataJson)) {
×
NEW
625
                        return $name;
×
626
                }
627

NEW
628
                $metadata = json_decode($metadataJson, true);
×
NEW
629
                if (!isset($metadata['extension'])) {
×
NEW
630
                        return $name;
×
631
                }
632

NEW
633
                $extensionPattern = '/\.' . preg_quote($metadata['extension'], '/') . '$/i';
×
NEW
634
                $result = preg_replace($extensionPattern, '', $name);
×
NEW
635
                return $result ?? $name;
×
636
        }
637
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc