Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| TerminLabelEndpointTrait | |
0.00% |
0 / 30 |
|
0.00% |
0 / 6 |
132 | |
0.00% |
0 / 1 |
| getEntityData | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 | |||
| updateEntityWithData | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| persistUploads | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| editUploads | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getEntityById | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| listEntities | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Termine\Endpoints; |
| 4 | |
| 5 | use Olz\Entity\Termine\TerminLabel; |
| 6 | use Olz\Utils\WithUtilsTrait; |
| 7 | use PhpTypeScriptApi\HttpError; |
| 8 | |
| 9 | /** |
| 10 | * @phpstan-type OlzTerminLabelId int |
| 11 | * @phpstan-type OlzTerminLabelData array{ |
| 12 | * ident: non-empty-string, |
| 13 | * name: non-empty-string, |
| 14 | * details: string, |
| 15 | * icon?: ?non-empty-string, |
| 16 | * position?: ?float, |
| 17 | * imageIds: array<non-empty-string>, |
| 18 | * fileIds: array<non-empty-string>, |
| 19 | * } |
| 20 | */ |
| 21 | trait TerminLabelEndpointTrait { |
| 22 | use WithUtilsTrait; |
| 23 | |
| 24 | /** @return OlzTerminLabelData */ |
| 25 | public function getEntityData(TerminLabel $entity): array { |
| 26 | return [ |
| 27 | 'ident' => $entity->getIdent() ? $entity->getIdent() : '-', |
| 28 | 'name' => $entity->getName() ? $entity->getName() : '-', |
| 29 | 'details' => $entity->getDetails() ?? '', |
| 30 | 'icon' => $entity->getIcon() ? $entity->getIcon() : null, |
| 31 | 'position' => $entity->getPosition(), |
| 32 | 'imageIds' => $entity->getStoredImageUploadIds(), |
| 33 | 'fileIds' => $entity->getStoredFileUploadIds(), |
| 34 | ]; |
| 35 | } |
| 36 | |
| 37 | /** @param OlzTerminLabelData $input_data */ |
| 38 | public function updateEntityWithData(TerminLabel $entity, array $input_data): void { |
| 39 | $valid_icon_file_id = $this->uploadUtils()->getValidUploadId($input_data['icon'] ?? null); |
| 40 | |
| 41 | $entity->setIdent($input_data['ident']); |
| 42 | $entity->setName($input_data['name']); |
| 43 | $entity->setDetails($input_data['details']); |
| 44 | $entity->setIcon($valid_icon_file_id); |
| 45 | $entity->setPosition($input_data['position'] ?? 0); |
| 46 | } |
| 47 | |
| 48 | /** @param OlzTerminLabelData $input_data */ |
| 49 | public function persistUploads(TerminLabel $entity, array $input_data): void { |
| 50 | $this->persistOlzImages($entity, $input_data['imageIds']); |
| 51 | $this->persistOlzFiles($entity, $input_data['fileIds']); |
| 52 | $icon = $input_data['icon'] ?? null; |
| 53 | if ($icon) { |
| 54 | $this->persistOlzFiles($entity, [$icon]); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | public function editUploads(TerminLabel $entity): void { |
| 59 | $image_ids = $this->uploadUtils()->getStoredUploadIds("{$entity->getImagesPathForStorage()}img/"); |
| 60 | $this->editOlzImages($entity, $image_ids); |
| 61 | $this->editOlzFiles($entity); |
| 62 | } |
| 63 | |
| 64 | protected function getEntityById(int $id): TerminLabel { |
| 65 | $repo = $this->entityManager()->getRepository(TerminLabel::class); |
| 66 | $entity = $repo->findOneBy(['id' => $id]); |
| 67 | if (!$entity) { |
| 68 | throw new HttpError(404, "Nicht gefunden."); |
| 69 | } |
| 70 | return $entity; |
| 71 | } |
| 72 | |
| 73 | /** @return array<TerminLabel> */ |
| 74 | protected function listEntities(): array { |
| 75 | $repo = $this->entityManager()->getRepository(TerminLabel::class); |
| 76 | return $repo->findBy(['on_off' => 1], ['position' => 'ASC']); |
| 77 | } |
| 78 | } |