Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 109 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
ProcessChange | |
0.00% |
0 / 109 |
|
0.00% |
0 / 6 |
182 | |
0.00% |
0 / 1 |
readResponse | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
12 | |||
getNewProcess | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getValidatedForm | |
0.00% |
0 / 59 |
|
0.00% |
0 / 1 |
6 | |||
writeChangedProcess | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
20 | |||
writeDeletedMailAndNotification | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
writeConfirmedMailAndNotification | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | /** |
4 | * |
5 | * @package Zmsadmin |
6 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
7 | * |
8 | */ |
9 | |
10 | namespace BO\Zmsadmin; |
11 | |
12 | use BO\Mellon\Condition; |
13 | use BO\Slim\Render; |
14 | use BO\Zmsentities\Validator\ProcessValidator; |
15 | use BO\Zmsentities\Process as Entity; |
16 | |
17 | /** |
18 | * Change process data but keep id |
19 | */ |
20 | class ProcessChange extends BaseController |
21 | { |
22 | /** |
23 | * @SuppressWarnings(Param) |
24 | * @return String |
25 | */ |
26 | public function readResponse( |
27 | \Psr\Http\Message\RequestInterface $request, |
28 | \Psr\Http\Message\ResponseInterface $response, |
29 | array $args |
30 | ) { |
31 | $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 2])->getEntity(); |
32 | $input = $request->getParams(); |
33 | $scope = Helper\AppointmentFormHelper::readSelectedScope($request, $workstation); |
34 | $oldProcess = \App::$http |
35 | ->readGetResult('/process/' . $input['selectedprocess'] . '/')->getEntity(); |
36 | $newProcess = $this->getNewProcess($input, $oldProcess, $scope); |
37 | $validatedForm = static::getValidatedForm($request->getAttribute('validator'), $newProcess); |
38 | if ($validatedForm['failed']) { |
39 | return \BO\Slim\Render::withJson( |
40 | $response, |
41 | $validatedForm |
42 | ); |
43 | } |
44 | |
45 | $process = static::writeChangedProcess($input, $oldProcess, $newProcess); |
46 | $queryParams = ('confirmed' == $process->getStatus()) ? |
47 | ['selectedprocess' => $process, 'success' => 'process_changed'] : |
48 | []; |
49 | |
50 | return \BO\Slim\Render::withHtml( |
51 | $response, |
52 | 'element/helper/messageHandler.twig', |
53 | $queryParams |
54 | ); |
55 | } |
56 | |
57 | protected function getNewProcess($input, $process, $scope) |
58 | { |
59 | $newProcess = clone $process; |
60 | $selectedTime = str_replace('-', ':', $input['selectedtime']); |
61 | $dateTime = \DateTime::createFromFormat('Y-m-d H:i', $input['selecteddate'] . ' ' . $selectedTime); |
62 | return $newProcess->withUpdatedData($input, $dateTime, $scope); |
63 | } |
64 | |
65 | protected static function getValidatedForm($validator, $process) |
66 | { |
67 | $processValidator = new ProcessValidator($process); |
68 | $delegatedProcess = $processValidator->getDelegatedProcess(); |
69 | $processValidator |
70 | ->validateName( |
71 | $validator->getParameter('familyName'), |
72 | $delegatedProcess->setter('clients', 0, 'familyName') |
73 | ) |
74 | ->validateRequests( |
75 | $validator->getParameter('requests'), |
76 | function () use ($process, $delegatedProcess) { |
77 | $arrayKeys = array_keys(json_decode(json_encode($process->requests), true)); |
78 | foreach ($arrayKeys as $key) { |
79 | $delegatedProcess->setter('requests', $key, 'id'); |
80 | $delegatedProcess->setter('requests', $key, 'source'); |
81 | } |
82 | } |
83 | ) |
84 | ->validateMail( |
85 | $validator->getParameter('email'), |
86 | $delegatedProcess->setter('clients', 0, 'email'), |
87 | new Condition( |
88 | $validator->getParameter('sendMailConfirmation')->isNumber()->isNotEqualTo(1), |
89 | $validator->getParameter('surveyAccepted')->isString()->isDevoidOf([1]) |
90 | ) |
91 | ) |
92 | ->validateTelephone( |
93 | $validator->getParameter('telephone'), |
94 | $delegatedProcess->setter('clients', 0, 'telephone'), |
95 | new Condition( |
96 | $validator->getParameter('sendConfirmation')->isNumber()->isNotEqualTo(1), |
97 | $validator->getParameter('sendReminder')->isNumber()->isNotEqualTo(1) |
98 | ) |
99 | ) |
100 | ->validateSurvey( |
101 | $validator->getParameter('surveyAccepted'), |
102 | $delegatedProcess->setter('clients', 0, 'surveyAccepted') |
103 | ) |
104 | ->validateText( |
105 | $validator->getParameter('amendment'), |
106 | $delegatedProcess->setter('amendment') |
107 | ) |
108 | ->validateText( |
109 | $validator->getParameter('customTextfield'), |
110 | $delegatedProcess->setter('customTextfield') |
111 | ) |
112 | ->validateReminderTimestamp( |
113 | $validator->getParameter('headsUpTime'), |
114 | $delegatedProcess->setter('reminderTimestamp'), |
115 | new Condition( |
116 | $validator->getParameter('sendReminder')->isNumber()->isNotEqualTo(1) |
117 | ) |
118 | ) |
119 | ; |
120 | |
121 | |
122 | $processValidator->getCollection()->addValid( |
123 | $validator->getParameter('sendConfirmation')->isNumber(), |
124 | $validator->getParameter('sendReminder')->isNumber() |
125 | ); |
126 | |
127 | $form = $processValidator->getCollection()->getStatus(null, true); |
128 | $form['failed'] = $processValidator->getCollection()->hasFailed(); |
129 | return $form; |
130 | } |
131 | |
132 | protected static function writeChangedProcess($input, $oldProcess, $newProcess) |
133 | { |
134 | $oldAppointment = $oldProcess->getFirstAppointment(); |
135 | $newAppointment = $newProcess->getFirstAppointment(); |
136 | \App::$http->readPostResult( |
137 | '/process/' . $newProcess['id'] . '/' . $newProcess['authKey'] . '/', |
138 | $newProcess, |
139 | ['initiator' => 'admin'] |
140 | ); |
141 | if (! $oldAppointment->isMatching($newAppointment)) { |
142 | $newProcess = \App::$http->readPostResult( |
143 | '/process/' . $oldProcess->id . '/' . $oldProcess->authKey . '/appointment/', |
144 | $newAppointment, |
145 | [ |
146 | 'resolveReferences' => 1, |
147 | 'slotType' => 'intern', |
148 | 'clientkey' => \App::CLIENTKEY, |
149 | 'slotsRequired' => (isset($input['slotCount']) && 1 < $input['slotCount']) ? $input['slotCount'] : 0 |
150 | ] |
151 | )->getEntity(); |
152 | } |
153 | static::writeDeletedMailAndNotification($oldProcess); |
154 | static::writeConfirmedMailAndNotification($input, $newProcess); |
155 | return $newProcess; |
156 | } |
157 | |
158 | protected static function writeDeletedMailAndNotification($oldProcess) |
159 | { |
160 | $oldProcess->status = 'deleted'; |
161 | ProcessDelete::writeDeleteMailNotifications($oldProcess); |
162 | } |
163 | |
164 | protected static function writeConfirmedMailAndNotification($input, $newProcess) |
165 | { |
166 | if ('confirmed' == $newProcess->getStatus()) { |
167 | Helper\AppointmentFormHelper::updateMailAndNotification($input, $newProcess); |
168 | } |
169 | } |
170 | } |