Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
75.68% |
28 / 37 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| FileElementMapper | |
75.68% |
28 / 37 |
|
80.00% |
4 / 5 |
8.92 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getByFileId | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| getByFileIds | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| getByFileIdAndSignRequestId | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
2 | |||
| getById | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 | |||
| 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 OCP\AppFramework\Db\QBMapper; |
| 12 | use OCP\DB\QueryBuilder\IQueryBuilder; |
| 13 | use OCP\IDBConnection; |
| 14 | |
| 15 | /** |
| 16 | * Class FileElementsMapper |
| 17 | * |
| 18 | * @package OCA\Libresign\DB |
| 19 | * @template-extends QBMapper<FileElement> |
| 20 | */ |
| 21 | class FileElementMapper extends QBMapper { |
| 22 | /** @var FileElement[][] */ |
| 23 | private $cache = []; |
| 24 | |
| 25 | public function __construct(IDBConnection $db) { |
| 26 | parent::__construct($db, 'libresign_file_element'); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @return FileElement[] |
| 31 | */ |
| 32 | public function getByFileId(int $fileId): array { |
| 33 | $qb = $this->db->getQueryBuilder(); |
| 34 | |
| 35 | $qb->select('fe.*') |
| 36 | ->from($this->getTableName(), 'fe') |
| 37 | ->where( |
| 38 | $qb->expr()->eq('fe.file_id', $qb->createNamedParameter($fileId)) |
| 39 | ); |
| 40 | |
| 41 | /** @var FileElement[] */ |
| 42 | return $this->findEntities($qb); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @param int[] $fileIds |
| 47 | * @return FileElement[] |
| 48 | */ |
| 49 | public function getByFileIds(array $fileIds): array { |
| 50 | if (empty($fileIds)) { |
| 51 | return []; |
| 52 | } |
| 53 | |
| 54 | $qb = $this->db->getQueryBuilder(); |
| 55 | |
| 56 | $qb->select('fe.*') |
| 57 | ->from($this->getTableName(), 'fe') |
| 58 | ->where( |
| 59 | $qb->expr()->in('fe.file_id', $qb->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY)) |
| 60 | ); |
| 61 | |
| 62 | /** @var FileElement[] */ |
| 63 | return $this->findEntities($qb); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @return FileElement[] |
| 68 | */ |
| 69 | public function getByFileIdAndSignRequestId(int $fileId, ?int $signRequestId): array { |
| 70 | $qb = $this->db->getQueryBuilder(); |
| 71 | |
| 72 | $qb->select('fe.*') |
| 73 | ->from($this->getTableName(), 'fe') |
| 74 | ->where( |
| 75 | $qb->expr()->eq('fe.file_id', $qb->createNamedParameter($fileId)) |
| 76 | ); |
| 77 | if ($signRequestId) { |
| 78 | $qb->andWhere( |
| 79 | $qb->expr()->eq('fe.sign_request_id', $qb->createNamedParameter($signRequestId, IQueryBuilder::PARAM_INT)) |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | /** @var FileElement[] */ |
| 84 | return $this->findEntities($qb); |
| 85 | } |
| 86 | |
| 87 | public function getById(int $id): FileElement { |
| 88 | if (!isset($this->cache['documentElementId'][$id])) { |
| 89 | $qb = $this->db->getQueryBuilder(); |
| 90 | |
| 91 | $qb->select('fe.*') |
| 92 | ->from($this->getTableName(), 'fe') |
| 93 | ->where( |
| 94 | $qb->expr()->eq('fe.id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)) |
| 95 | ); |
| 96 | |
| 97 | /** @var FileElement */ |
| 98 | $this->cache['documentElementId'][$id] = $this->findEntity($qb); |
| 99 | } |
| 100 | return $this->cache['documentElementId'][$id]; |
| 101 | } |
| 102 | } |