Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.00% |
18 / 20 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| FileTypeMapper | |
90.00% |
18 / 20 |
|
50.00% |
2 / 4 |
8.06 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getNameOfType | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| getDescriptionOfType | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| getTypes | |
92.31% |
12 / 13 |
|
0.00% |
0 / 1 |
3.00 | |||
| 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\IDBConnection; |
| 13 | use OCP\IL10N; |
| 14 | |
| 15 | /** |
| 16 | * Class FileTypeMapper |
| 17 | * |
| 18 | * @package OCA\Libresign\DB |
| 19 | * @template-extends QBMapper<FileType> |
| 20 | */ |
| 21 | class FileTypeMapper extends QBMapper { |
| 22 | private $types = []; |
| 23 | |
| 24 | public function __construct( |
| 25 | IDBConnection $db, |
| 26 | private IL10N $l, |
| 27 | ) { |
| 28 | parent::__construct($db, 'libresign_file_type'); |
| 29 | } |
| 30 | |
| 31 | public function getNameOfType($type): string { |
| 32 | if (!isset($this->types[$type])) { |
| 33 | $this->getTypes(); |
| 34 | } |
| 35 | return $this->types[$type]['name']; |
| 36 | } |
| 37 | |
| 38 | public function getDescriptionOfType($type): string { |
| 39 | if (!isset($this->types[$type])) { |
| 40 | $this->getTypes(); |
| 41 | } |
| 42 | return $this->types[$type]['description']; |
| 43 | } |
| 44 | |
| 45 | public function getTypes(): array { |
| 46 | if (empty($this->types)) { |
| 47 | $qb = $this->db->getQueryBuilder(); |
| 48 | $qb->select('*') |
| 49 | ->from($this->getTableName()); |
| 50 | $cursor = $qb->executeQuery(); |
| 51 | |
| 52 | $this->types['IDENTIFICATION'] = [ |
| 53 | 'type' => 'IDENTIFICATION', |
| 54 | // TRANSLATORS Display name of the LibreSign file type used for identity documents that signers upload for approval before signing. |
| 55 | 'name' => $this->l->t('Identification Document'), |
| 56 | // TRANSLATORS Description of the LibreSign file type used for identity documents that signers upload for approval before signing. |
| 57 | 'description' => $this->l->t('Identification Document'), |
| 58 | ]; |
| 59 | while ($row = $cursor->fetch()) { |
| 60 | $this->types[$row['type']] = $this->mapRowToEntity($row); |
| 61 | } |
| 62 | } |
| 63 | return $this->types; |
| 64 | } |
| 65 | } |