Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 113 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| ProcessChange | |
0.00% |
0 / 113 |
|
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 / 63 |
|
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 | ->validateText( |
| 113 | $validator->getParameter('customTextfield2'), |
| 114 | $delegatedProcess->setter('customTextfield2') |
| 115 | ) |
| 116 | ->validateReminderTimestamp( |
| 117 | $validator->getParameter('headsUpTime'), |
| 118 | $delegatedProcess->setter('reminderTimestamp'), |
| 119 | new Condition( |
| 120 | $validator->getParameter('sendReminder')->isNumber()->isNotEqualTo(1) |
| 121 | ) |
| 122 | ) |
| 123 | ; |
| 124 | |
| 125 | |
| 126 | $processValidator->getCollection()->addValid( |
| 127 | $validator->getParameter('sendConfirmation')->isNumber(), |
| 128 | $validator->getParameter('sendReminder')->isNumber() |
| 129 | ); |
| 130 | |
| 131 | $form = $processValidator->getCollection()->getStatus(null, true); |
| 132 | $form['failed'] = $processValidator->getCollection()->hasFailed(); |
| 133 | return $form; |
| 134 | } |
| 135 | |
| 136 | protected static function writeChangedProcess($input, $oldProcess, $newProcess) |
| 137 | { |
| 138 | $oldAppointment = $oldProcess->getFirstAppointment(); |
| 139 | $newAppointment = $newProcess->getFirstAppointment(); |
| 140 | \App::$http->readPostResult( |
| 141 | '/process/' . $newProcess['id'] . '/' . $newProcess['authKey'] . '/', |
| 142 | $newProcess, |
| 143 | ['initiator' => 'admin'] |
| 144 | ); |
| 145 | if (! $oldAppointment->isMatching($newAppointment)) { |
| 146 | $newProcess = \App::$http->readPostResult( |
| 147 | '/process/' . $oldProcess->id . '/' . $oldProcess->authKey . '/appointment/', |
| 148 | $newAppointment, |
| 149 | [ |
| 150 | 'resolveReferences' => 1, |
| 151 | 'slotType' => 'intern', |
| 152 | 'clientkey' => \App::CLIENTKEY, |
| 153 | 'slotsRequired' => (isset($input['slotCount']) && 1 < $input['slotCount']) ? $input['slotCount'] : 0 |
| 154 | ] |
| 155 | )->getEntity(); |
| 156 | } |
| 157 | static::writeDeletedMailAndNotification($oldProcess); |
| 158 | static::writeConfirmedMailAndNotification($input, $newProcess); |
| 159 | return $newProcess; |
| 160 | } |
| 161 | |
| 162 | protected static function writeDeletedMailAndNotification($oldProcess) |
| 163 | { |
| 164 | $oldProcess->status = 'deleted'; |
| 165 | ProcessDelete::writeDeleteMailNotifications($oldProcess); |
| 166 | } |
| 167 | |
| 168 | protected static function writeConfirmedMailAndNotification($input, $newProcess) |
| 169 | { |
| 170 | if ('confirmed' == $newProcess->getStatus()) { |
| 171 | Helper\AppointmentFormHelper::updateMailAndNotification($input, $newProcess); |
| 172 | } |
| 173 | } |
| 174 | } |