Lines
0.00%
0 / 120
Functions and Methods
0.00%
0 / 6
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ProcessChange | 0.00% | 0 / 120 | 0.00% | 0 / 6 | 240 | 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 / 70 | 0.00% | 0 / 1 | 20 | |||||
| writeChangedProcess | 0.00% | 0 / 21 | 0.00% | 0 / 1 | 20 | |||||
| writeDeletedMail | 0.00% | 0 / 2 | 0.00% | 0 / 1 | 2 | |||||
| writeConfirmedMail | 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 \Psr\Http\Message\ResponseInterface | |
| 25 | */ | |
| 26 | #[\Override] | |
| 27 | public function readResponse( | |
| 28 | \Psr\Http\Message\RequestInterface $request, | |
| 29 | \Psr\Http\Message\ResponseInterface $response, | |
| 30 | array $args | |
| 31 | ): \Psr\Http\Message\ResponseInterface { | |
| 32 | $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 2])->getEntity(); | |
| 33 | $input = $request->getParams(); | |
| 34 | $scope = Helper\AppointmentFormHelper::readSelectedScope($request, $workstation); | |
| 35 | $oldProcess = \App::$http | |
| 36 | ->readGetResult('/process/' . $input['selectedprocess'] . '/')->getEntity(); | |
| 37 | $newProcess = $this->getNewProcess($input, $oldProcess, $scope); | |
| 38 | $validatedForm = static::getValidatedForm($request->getAttribute('validator'), $newProcess); | |
| 39 | if ($validatedForm['failed']) { | |
| 40 | return Render::withJson( | |
| 41 | $response, | |
| 42 | $validatedForm | |
| 43 | ); | |
| 44 | } | |
| 45 | ||
| 46 | $process = static::writeChangedProcess($input, $oldProcess, $newProcess); | |
| 47 | $queryParams = ('confirmed' == $process->getStatus()) ? | |
| 48 | ['selectedprocess' => $process, 'success' => 'process_changed'] : | |
| 49 | []; | |
| 50 | ||
| 51 | return Render::withHtml( | |
| 52 | $response, | |
| 53 | 'element/helper/messageHandler.twig', | |
| 54 | $queryParams | |
| 55 | ); | |
| 56 | } | |
| 57 | ||
| 58 | protected function getNewProcess($input, $process, $scope) | |
| 59 | { | |
| 60 | $newProcess = clone $process; | |
| 61 | $selectedTime = str_replace('-', ':', $input['selectedtime']); | |
| 62 | $dateTime = \DateTime::createFromFormat('Y-m-d H:i', $input['selecteddate'] . ' ' . $selectedTime); | |
| 63 | return $newProcess->withUpdatedData($input, $dateTime, $scope); | |
| 64 | } | |
| 65 | ||
| 66 | /** | |
| 67 | * @return (bool|mixed)[] | |
| 68 | * | |
| 69 | */ | |
| 70 | protected static function getValidatedForm($validator, $process): array | |
| 71 | { | |
| 72 | $processValidator = new ProcessValidator($process); | |
| 73 | $delegatedProcess = $processValidator->getDelegatedProcess(); | |
| 74 | $processValidator | |
| 75 | ->validateName( | |
| 76 | $validator->getParameter('familyName'), | |
| 77 | $delegatedProcess->setter('clients', 0, 'familyName') | |
| 78 | ) | |
| 79 | ->validateRequests( | |
| 80 | $validator->getParameter('requests'), | |
| 81 | function () use ($process, $delegatedProcess) { | |
| 82 | $arrayKeys = array_keys(json_decode(json_encode($process->requests), true)); | |
| 83 | foreach ($arrayKeys as $key) { | |
| 84 | $delegatedProcess->setter('requests', $key, 'id'); | |
| 85 | $delegatedProcess->setter('requests', $key, 'source'); | |
| 86 | } | |
| 87 | } | |
| 88 | ) | |
| 89 | ->validateMail( | |
| 90 | $validator->getParameter('email'), | |
| 91 | $delegatedProcess->setter('clients', 0, 'email'), | |
| 92 | new Condition( | |
| 93 | $validator->getParameter('sendMailConfirmation')->isNumber()->isNotEqualTo(1), | |
| 94 | $validator->getParameter('surveyAccepted')->isString()->isDevoidOf([1]) | |
| 95 | ) | |
| 96 | ) | |
| 97 | ->validateTelephone( | |
| 98 | $validator->getParameter('telephone'), | |
| 99 | $delegatedProcess->setter('clients', 0, 'telephone'), | |
| 100 | new Condition( | |
| 101 | $validator->getParameter('sendConfirmation')->isNumber()->isNotEqualTo(1), | |
| 102 | $validator->getParameter('sendReminder')->isNumber()->isNotEqualTo(1) | |
| 103 | ) | |
| 104 | ) | |
| 105 | ->validateSurvey( | |
| 106 | $validator->getParameter('surveyAccepted'), | |
| 107 | $delegatedProcess->setter('clients', 0, 'surveyAccepted') | |
| 108 | ) | |
| 109 | ->validateText( | |
| 110 | $validator->getParameter('amendment'), | |
| 111 | $delegatedProcess->setter('amendment') | |
| 112 | ) | |
| 113 | ; | |
| 114 | ||
| 115 | $scope = $process->getCurrentScope(); | |
| 116 | if ((int) $scope->getCustomTextfieldActivated()) { | |
| 117 | $processValidator->validateCustomTextfield( | |
| 118 | $validator->getParameter('customTextfield'), | |
| 119 | $delegatedProcess->setter('customTextfield'), | |
| 120 | (bool) (int) $scope->getCustomTextfieldRequired() | |
| 121 | ); | |
| 122 | } | |
| 123 | if ((int) $scope->getCustomTextfield2Activated()) { | |
| 124 | $processValidator->validateCustomTextfield( | |
| 125 | $validator->getParameter('customTextfield2'), | |
| 126 | $delegatedProcess->setter('customTextfield2'), | |
| 127 | (bool) (int) $scope->getCustomTextfield2Required() | |
| 128 | ); | |
| 129 | } | |
| 130 | ||
| 131 | $processValidator | |
| 132 | ->validateReminderTimestamp( | |
| 133 | $validator->getParameter('headsUpTime'), | |
| 134 | $delegatedProcess->setter('reminderTimestamp'), | |
| 135 | new Condition( | |
| 136 | $validator->getParameter('sendReminder')->isNumber()->isNotEqualTo(1) | |
| 137 | ) | |
| 138 | ) | |
| 139 | ; | |
| 140 | ||
| 141 | ||
| 142 | $processValidator->getCollection()->addValid( | |
| 143 | $validator->getParameter('sendConfirmation')->isNumber(), | |
| 144 | $validator->getParameter('sendReminder')->isNumber() | |
| 145 | ); | |
| 146 | ||
| 147 | $form = $processValidator->getCollection()->getStatus(null, true); | |
| 148 | $form['failed'] = $processValidator->getCollection()->hasFailed(); | |
| 149 | return $form; | |
| 150 | } | |
| 151 | ||
| 152 | protected static function writeChangedProcess($input, $oldProcess, $newProcess) | |
| 153 | { | |
| 154 | $oldAppointment = $oldProcess->getFirstAppointment(); | |
| 155 | $newAppointment = $newProcess->getFirstAppointment(); | |
| 156 | \App::$http->readPostResult( | |
| 157 | '/process/' . $newProcess['id'] . '/' . $newProcess['authKey'] . '/', | |
| 158 | $newProcess, | |
| 159 | ['initiator' => 'admin'] | |
| 160 | ); | |
| 161 | if (! $oldAppointment->isMatching($newAppointment)) { | |
| 162 | $newProcess = \App::$http->readPostResult( | |
| 163 | '/process/' . $oldProcess->id . '/' . $oldProcess->authKey . '/appointment/', | |
| 164 | $newAppointment, | |
| 165 | [ | |
| 166 | 'resolveReferences' => 1, | |
| 167 | 'slotType' => 'intern', | |
| 168 | 'clientkey' => \App::CLIENTKEY, | |
| 169 | 'slotsRequired' => (isset($input['slotCount']) && 1 < $input['slotCount']) ? $input['slotCount'] : 0 | |
| 170 | ] | |
| 171 | )->getEntity(); | |
| 172 | } | |
| 173 | static::writeDeletedMail($oldProcess); | |
| 174 | static::writeConfirmedMail($input, $newProcess); | |
| 175 | return $newProcess; | |
| 176 | } | |
| 177 | ||
| 178 | protected static function writeDeletedMail($oldProcess): void | |
| 179 | { | |
| 180 | $oldProcess->status = 'deleted'; | |
| 181 | ProcessDelete::writeDeleteMailNotifications($oldProcess); | |
| 182 | } | |
| 183 | ||
| 184 | protected static function writeConfirmedMail($input, $newProcess): void | |
| 185 | { | |
| 186 | if ('confirmed' == $newProcess->getStatus()) { | |
| 187 | Helper\AppointmentFormHelper::updateMail($input, $newProcess); | |
| 188 | } | |
| 189 | } | |
| 190 | } |