Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
CreateRegistrationEndpoint | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
handle | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | namespace Olz\Apps\Anmelden\Endpoints; |
4 | |
5 | use Olz\Api\OlzCreateEntityTypedEndpoint; |
6 | use Olz\Entity\Anmelden\Registration; |
7 | use Olz\Entity\Anmelden\RegistrationInfo; |
8 | |
9 | /** |
10 | * @phpstan-import-type OlzRegistrationId from RegistrationEndpointTrait |
11 | * @phpstan-import-type OlzRegistrationData from RegistrationEndpointTrait |
12 | * |
13 | * TODO: Those should not be necessary! |
14 | * @phpstan-import-type OlzRegistrationInfo from RegistrationEndpointTrait |
15 | * @phpstan-import-type ValidRegistrationInfoType from RegistrationEndpointTrait |
16 | * |
17 | * @extends OlzCreateEntityTypedEndpoint<OlzRegistrationId, OlzRegistrationData> |
18 | */ |
19 | class CreateRegistrationEndpoint extends OlzCreateEntityTypedEndpoint { |
20 | use RegistrationEndpointTrait; |
21 | |
22 | protected function handle(mixed $input): mixed { |
23 | $this->checkPermission('any'); |
24 | |
25 | $input_data = $input['data']; |
26 | |
27 | $registration = new Registration(); |
28 | $this->entityUtils()->createOlzEntity($registration, $input['meta']); |
29 | $this->updateEntityWithData($registration, $input['data']); |
30 | |
31 | $this->entityManager()->persist($registration); |
32 | |
33 | foreach ($input_data['infos'] as $index => $info_spec) { |
34 | $title_ident = preg_replace('/[^a-zA-Z0-9]+/', '_', $info_spec['title']); |
35 | $ident = "{$index}-{$title_ident}"; |
36 | |
37 | $options_json = json_encode($info_spec['options'] ?? []) ?: '{}'; |
38 | |
39 | $registration_info = new RegistrationInfo(); |
40 | $this->entityUtils()->createOlzEntity($registration_info, $input['meta']); |
41 | $registration_info->setRegistration($registration); |
42 | $registration_info->setIndexWithinRegistration($index); |
43 | $registration_info->setIdent($ident); |
44 | $registration_info->setTitle($info_spec['title']); |
45 | $registration_info->setDescription($info_spec['description']); |
46 | $registration_info->setType($info_spec['type']); |
47 | $registration_info->setIsOptional($info_spec['isOptional'] ? true : false); |
48 | $registration_info->setOptions($options_json); |
49 | |
50 | $this->entityManager()->persist($registration_info); |
51 | } |
52 | $this->entityManager()->flush(); |
53 | |
54 | $internal_id = $registration->getId() ?? 0; |
55 | $external_id = $this->idUtils()->toExternalId($internal_id, 'Registration') ?: '-'; |
56 | |
57 | return [ |
58 | 'id' => $external_id, |
59 | ]; |
60 | } |
61 | } |