Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| DocumentTemplateRepository | |
0.00% |
0 / 11 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| findActive | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Domain\Document\Repository; |
| 6 | |
| 7 | use App\Domain\Document\Data\DocumentTemplateData; |
| 8 | use App\Support\Row; |
| 9 | use PDO; |
| 10 | use RuntimeException; |
| 11 | |
| 12 | final readonly class DocumentTemplateRepository |
| 13 | { |
| 14 | private const string SELECT_COLUMNS = ' |
| 15 | template_id AS "templateId", |
| 16 | name, |
| 17 | description, |
| 18 | active, |
| 19 | display_order AS "displayOrder", |
| 20 | recipient_role AS "recipientRole", |
| 21 | created_at AS "createdAt", |
| 22 | updated_at AS "updatedAt" |
| 23 | '; |
| 24 | |
| 25 | public function __construct( |
| 26 | private PDO $pdo, |
| 27 | ) {} |
| 28 | |
| 29 | /** |
| 30 | * @return list<DocumentTemplateData> |
| 31 | */ |
| 32 | public function findActive(): array |
| 33 | { |
| 34 | $stmt = $this->pdo->query( |
| 35 | 'SELECT ' . self::SELECT_COLUMNS . ' |
| 36 | FROM document_templates |
| 37 | WHERE active = TRUE |
| 38 | ORDER BY display_order, name', |
| 39 | ); |
| 40 | |
| 41 | if ($stmt === false) { |
| 42 | throw new RuntimeException('Failed to query active document templates'); |
| 43 | } |
| 44 | |
| 45 | $templates = []; |
| 46 | foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { |
| 47 | $templates[] = DocumentTemplateData::fromRow(Row::from($row)); |
| 48 | } |
| 49 | |
| 50 | return $templates; |
| 51 | } |
| 52 | } |