Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| TerminLocationEndpointTrait | |
0.00% |
0 / 21 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 1 |
| getEntityData | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| updateEntityWithData | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| persistUploads | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| editUploads | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getEntityById | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Termine\Endpoints; |
| 4 | |
| 5 | use Olz\Entity\Termine\TerminLocation; |
| 6 | use Olz\Utils\WithUtilsTrait; |
| 7 | use PhpTypeScriptApi\HttpError; |
| 8 | |
| 9 | /** |
| 10 | * Note: `latitude` may be from -90.0 to 90.0, `longitude` from -180.0 to 180.0. |
| 11 | * |
| 12 | * @phpstan-type OlzTerminLocationId int |
| 13 | * @phpstan-type OlzTerminLocationData array{ |
| 14 | * name: non-empty-string, |
| 15 | * details: string, |
| 16 | * latitude: float, |
| 17 | * longitude: float, |
| 18 | * imageIds: array<non-empty-string>, |
| 19 | * } |
| 20 | */ |
| 21 | trait TerminLocationEndpointTrait { |
| 22 | use WithUtilsTrait; |
| 23 | |
| 24 | /** @return OlzTerminLocationData */ |
| 25 | public function getEntityData(TerminLocation $entity): array { |
| 26 | $valid_image_ids = $this->uploadUtils()->getValidUploadIds($entity->getImageIds()); |
| 27 | |
| 28 | return [ |
| 29 | 'name' => $entity->getName() ?: '-', |
| 30 | 'details' => $entity->getDetails() ?? '', |
| 31 | 'latitude' => $entity->getLatitude(), |
| 32 | 'longitude' => $entity->getLongitude(), |
| 33 | 'imageIds' => $valid_image_ids, |
| 34 | ]; |
| 35 | } |
| 36 | |
| 37 | /** @param OlzTerminLocationData $input_data */ |
| 38 | public function updateEntityWithData(TerminLocation $entity, array $input_data): void { |
| 39 | $valid_image_ids = $this->uploadUtils()->getValidUploadIds($input_data['imageIds']); |
| 40 | |
| 41 | $entity->setName($input_data['name']); |
| 42 | $entity->setDetails($input_data['details']); |
| 43 | $entity->setLatitude($input_data['latitude']); |
| 44 | $entity->setLongitude($input_data['longitude']); |
| 45 | $entity->setImageIds($valid_image_ids); |
| 46 | } |
| 47 | |
| 48 | public function persistUploads(TerminLocation $entity): void { |
| 49 | $this->persistOlzImages($entity, $entity->getImageIds()); |
| 50 | } |
| 51 | |
| 52 | public function editUploads(TerminLocation $entity): void { |
| 53 | $this->editOlzImages($entity, $entity->getImageIds()); |
| 54 | } |
| 55 | |
| 56 | protected function getEntityById(int $id): TerminLocation { |
| 57 | $repo = $this->entityManager()->getRepository(TerminLocation::class); |
| 58 | $entity = $repo->findOneBy(['id' => $id]); |
| 59 | if (!$entity) { |
| 60 | throw new HttpError(404, "Nicht gefunden."); |
| 61 | } |
| 62 | return $entity; |
| 63 | } |
| 64 | } |