Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
82.14% |
23 / 28 |
|
57.14% |
4 / 7 |
CRAP | |
0.00% |
0 / 1 |
| CustomFieldCollectorService | |
82.14% |
23 / 28 |
|
57.14% |
4 / 7 |
8.36 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFieldsForEntity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAllFields | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFieldDefinitionsForEntity | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| hasFieldsForEntity | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getAvailableEntities | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| convertToFieldDefinition | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | // src/Service/CustomFieldCollectorService.php |
| 3 | |
| 4 | declare(strict_types=1); |
| 5 | |
| 6 | namespace Satag\AmicronEntityBundle\Service; |
| 7 | |
| 8 | class CustomFieldCollectorService |
| 9 | { |
| 10 | public function __construct( |
| 11 | private readonly CustomFieldCompilerService $compilerService |
| 12 | ) { |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Alle verfügbaren CustomFields für eine Entity holen |
| 17 | * |
| 18 | * @return array<string, array<string, mixed>> Array der Felder, indiziert nach Identifier |
| 19 | */ |
| 20 | public function getFieldsForEntity(string $entityName): array |
| 21 | { |
| 22 | return $this->compilerService->getFieldsForEntity($entityName); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Alle kompilierten Fields gruppiert nach Entity |
| 27 | * |
| 28 | * @return array<string, array<string, array<string, mixed>>> Array der Entities -> Felder -> Felddaten |
| 29 | */ |
| 30 | public function getAllFields(): array |
| 31 | { |
| 32 | return $this->compilerService->getCompiledFields(); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Field-Definitionen im Format für CustomFieldService zurückgeben |
| 37 | * |
| 38 | * @return array<string, array<string, mixed>> Array der Felddefinitionen, indiziert nach Identifier |
| 39 | */ |
| 40 | public function getFieldDefinitionsForEntity(string $entityName): array |
| 41 | { |
| 42 | $fields = $this->getFieldsForEntity($entityName); |
| 43 | $definitions = []; |
| 44 | |
| 45 | foreach ($fields as $identifier => $fieldData) { |
| 46 | $definitions[$identifier] = $this->convertToFieldDefinition($fieldData); |
| 47 | } |
| 48 | |
| 49 | return $definitions; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Prüft ob für eine Entity CustomFields verfügbar sind |
| 54 | */ |
| 55 | public function hasFieldsForEntity(string $entityName): bool |
| 56 | { |
| 57 | $fields = $this->getFieldsForEntity($entityName); |
| 58 | |
| 59 | return !empty($fields); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Liste aller verfügbaren Entity-Namen |
| 64 | * |
| 65 | * @return array<int, string> |
| 66 | */ |
| 67 | public function getAvailableEntities(): array |
| 68 | { |
| 69 | $allFields = $this->getAllFields(); |
| 70 | |
| 71 | return array_keys($allFields); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @param array<string, mixed> $fieldData |
| 76 | * |
| 77 | * @return array<string, mixed> |
| 78 | */ |
| 79 | private function convertToFieldDefinition(array $fieldData): array |
| 80 | { |
| 81 | // Standardformat für CustomFieldService (unterstützt beide Schreibweisen) |
| 82 | return [ |
| 83 | 'name' => $fieldData['name'] ?? '', |
| 84 | 'key' => $fieldData['identifier'] ?? '', |
| 85 | 'typ' => $fieldData['type'] ?? 'String', |
| 86 | 'list' => $fieldData['list'] ?? true, |
| 87 | 'listwidth' => $fieldData['listwidth'] ?? ($fieldData['listWidth'] ?? 100), |
| 88 | 'readonly' => $fieldData['readonly'] ?? ($fieldData['readOnly'] ?? false), |
| 89 | 'required' => $fieldData['required'] ?? false, |
| 90 | 'firebird' => $fieldData['firebird'] ?? null, |
| 91 | 'placeholder' => $fieldData['placeholder'] ?? '', |
| 92 | 'validation' => $fieldData['validation'] ?? null, |
| 93 | 'validationminlength' => $fieldData['validationminlength'] ?? ($fieldData['validationMinLength'] ?? null), |
| 94 | 'validationmaxlength' => $fieldData['validationmaxlength'] ?? ($fieldData['validationMaxLength'] ?? null), |
| 95 | 'options' => $fieldData['options'] ?? null, |
| 96 | 'order' => $fieldData['order'] ?? null, |
| 97 | ]; |
| 98 | } |
| 99 | } |