Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.94% |
110 / 128 |
|
85.71% |
6 / 7 |
CRAP | |
0.00% |
0 / 1 |
| ProcessQueue | |
85.94% |
110 / 128 |
|
85.71% |
6 / 7 |
20.00 | |
0.00% |
0 / 1 |
| readResponse | |
100.00% |
30 / 30 |
|
100.00% |
1 / 1 |
5 | |||
| getValidatedForm | |
100.00% |
46 / 46 |
|
100.00% |
1 / 1 |
1 | |||
| readSelectedProcessWithWaitingnumber | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getProcess | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| writeQueuedProcess | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| isOpened | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
4 | |||
| printProcessResponse | |
33.33% |
9 / 27 |
|
0.00% |
0 / 1 |
8.74 | |||
| 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\Zmsadmin\Helper\MailTemplateArrayProvider; |
| 15 | use BO\Zmsentities\Client; |
| 16 | use BO\Zmsentities\Collection\ProcessList; |
| 17 | use BO\Zmsentities\Config; |
| 18 | use BO\Zmsentities\Helper\Messaging; |
| 19 | use BO\Zmsentities\Validator\ProcessValidator; |
| 20 | use BO\Zmsentities\Process as Entity; |
| 21 | use BO\Zmsadmin\Helper\AppointmentFormHelper; |
| 22 | use Psr\Http\Message\RequestInterface; |
| 23 | use Psr\Http\Message\ResponseInterface; |
| 24 | |
| 25 | /** |
| 26 | * Queue a process from appointment formular without appointment |
| 27 | */ |
| 28 | class ProcessQueue extends BaseController |
| 29 | { |
| 30 | /** |
| 31 | * @SuppressWarnings(Param) |
| 32 | */ |
| 33 | public function readResponse( |
| 34 | RequestInterface $request, |
| 35 | ResponseInterface $response, |
| 36 | array $args |
| 37 | ) { |
| 38 | $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 3])->getEntity(); |
| 39 | |
| 40 | $validator = $request->getAttribute('validator'); |
| 41 | $selectedProcessId = $validator->getParameter('selectedprocess')->isNumber()->getValue(); |
| 42 | |
| 43 | if ($selectedProcessId) { |
| 44 | $process = $this->readSelectedProcessWithWaitingnumber($selectedProcessId); |
| 45 | |
| 46 | if ($process && $validator->getParameter('print')->isNumber()->getValue()) { |
| 47 | return $this->printProcessResponse( |
| 48 | $response, |
| 49 | $process, |
| 50 | $validator->getParameter('printType')->isString()->getValue(), |
| 51 | $workstation->scope['provider']['id'] |
| 52 | ); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | $input = $request->getParams(); |
| 57 | $scope = AppointmentFormHelper::readSelectedScope($request, $workstation); |
| 58 | $process = $this->getProcess($input, $scope); |
| 59 | $validatedForm = static::getValidatedForm($validator, $process); |
| 60 | if ($validatedForm['failed']) { |
| 61 | return \BO\Slim\Render::withJson( |
| 62 | $response, |
| 63 | $validatedForm |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | $process = $this->writeQueuedProcess($input, $process); |
| 68 | return \BO\Slim\Render::withHtml( |
| 69 | $response, |
| 70 | 'element/helper/messageHandler.twig', |
| 71 | array( |
| 72 | 'selectedprocess' => $process, |
| 73 | 'success' => 'process_queued' |
| 74 | ) |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | public static function getValidatedForm($validator, $process) |
| 79 | { |
| 80 | $processValidator = new ProcessValidator($process); |
| 81 | $delegatedProcess = $processValidator->getDelegatedProcess(); |
| 82 | $processValidator |
| 83 | ->validateName( |
| 84 | $validator->getParameter('familyName'), |
| 85 | $delegatedProcess->setter('clients', 0, 'familyName') |
| 86 | ) |
| 87 | ->validateMail( |
| 88 | $validator->getParameter('email'), |
| 89 | $delegatedProcess->setter('clients', 0, 'email') |
| 90 | ) |
| 91 | ->validateTelephone( |
| 92 | $validator->getParameter('telephone'), |
| 93 | $delegatedProcess->setter('clients', 0, 'telephone') |
| 94 | ) |
| 95 | ->validateSurvey( |
| 96 | $validator->getParameter('surveyAccepted'), |
| 97 | $delegatedProcess->setter('clients', 0, 'surveyAccepted') |
| 98 | ) |
| 99 | ->validateText( |
| 100 | $validator->getParameter('amendment'), |
| 101 | $delegatedProcess->setter('amendment') |
| 102 | ) |
| 103 | ->validateText( |
| 104 | $validator->getParameter('customTextfield'), |
| 105 | $delegatedProcess->setter('customTextfield') |
| 106 | ) |
| 107 | ->validateText( |
| 108 | $validator->getParameter('customTextfield2'), |
| 109 | $delegatedProcess->setter('customTextfield2') |
| 110 | ) |
| 111 | ->validateReminderTimestamp( |
| 112 | $validator->getParameter('headsUpTime'), |
| 113 | $delegatedProcess->setter('reminderTimestamp'), |
| 114 | new Condition( |
| 115 | $validator->getParameter('sendReminder')->isNumber()->isNotEqualTo(1) |
| 116 | ) |
| 117 | ) |
| 118 | |
| 119 | ; |
| 120 | $processValidator->getCollection()->addValid( |
| 121 | $validator->getParameter('sendConfirmation')->isNumber(), |
| 122 | $validator->getParameter('sendReminder')->isNumber() |
| 123 | ); |
| 124 | |
| 125 | $form = $processValidator->getCollection()->getStatus(null, true); |
| 126 | $form['failed'] = $processValidator->getCollection()->hasFailed(); |
| 127 | return $form; |
| 128 | } |
| 129 | |
| 130 | protected function readSelectedProcessWithWaitingnumber($selectedProcessId) |
| 131 | { |
| 132 | $result = null; |
| 133 | if ($selectedProcessId) { |
| 134 | $result = \App::$http->readGetResult('/process/' . $selectedProcessId . '/')->getEntity(); |
| 135 | } |
| 136 | return $result; |
| 137 | } |
| 138 | |
| 139 | protected function getProcess($input, $scope) |
| 140 | { |
| 141 | $process = new \BO\Zmsentities\Process(); |
| 142 | $notice = (! $this->isOpened($scope)) ? 'Außerhalb der Öffnungszeiten gebucht! ' : ''; |
| 143 | return $process->withUpdatedData($input, \App::$now, $scope, $notice); |
| 144 | } |
| 145 | |
| 146 | protected function writeQueuedProcess($input, $process) |
| 147 | { |
| 148 | $process = \App::$http->readPostResult('/workstation/process/waitingnumber/', $process)->getEntity(); |
| 149 | AppointmentFormHelper::updateMailAndNotification($input, $process); |
| 150 | return $process; |
| 151 | } |
| 152 | |
| 153 | protected function isOpened($scope) |
| 154 | { |
| 155 | if ($scope->getResolveLevel() < 1) { |
| 156 | $scope = \App::$http->readGetResult('/scope/' . $scope->getId() . '/', [ |
| 157 | 'resolveReferences' => 1, |
| 158 | 'gql' => Helper\GraphDefaults::getScope() |
| 159 | ]) |
| 160 | ->getEntity(); |
| 161 | } |
| 162 | try { |
| 163 | $isOpened = \App::$http |
| 164 | ->readGetResult('/scope/' . $scope->getId() . '/availability/', ['resolveReferences' => 0]) |
| 165 | ->getCollection() |
| 166 | ->withScope($scope) |
| 167 | ->isOpened(\App::$now); |
| 168 | } catch (\BO\Zmsclient\Exception $exception) { |
| 169 | if ($exception->template == 'BO\\Zmsapi\\Exception\\Availability\\AvailabilityNotFound') { |
| 170 | $isOpened = false; |
| 171 | } |
| 172 | } |
| 173 | return $isOpened; |
| 174 | } |
| 175 | |
| 176 | private function printProcessResponse( |
| 177 | ResponseInterface $response, |
| 178 | Entity $process, |
| 179 | ?string $printType = null, |
| 180 | ?int $providerId = null |
| 181 | ): ResponseInterface { |
| 182 | if ($printType === 'mail') { |
| 183 | $mergedMailTemplates = \App::$http->readGetResult('/merged-mailtemplates/' . $providerId . '/') |
| 184 | ->getCollection(); |
| 185 | |
| 186 | $templates = []; |
| 187 | |
| 188 | foreach ($mergedMailTemplates as $template) { |
| 189 | $templates[$template->name] = $template->value; |
| 190 | }; |
| 191 | |
| 192 | $templateProvider = new MailTemplateArrayProvider(); |
| 193 | $templateProvider->setTemplates($templates); |
| 194 | |
| 195 | $config = \App::$http->readGetResult('/config/')->getEntity(); |
| 196 | |
| 197 | $mail = (new \BO\Zmsentities\Mail()) |
| 198 | ->setTemplateProvider($templateProvider) |
| 199 | ->toResolvedEntity($process, $config, 'appointment'); |
| 200 | |
| 201 | return \BO\Slim\Render::withHtml( |
| 202 | $response, |
| 203 | 'page/printAppointmentMail.twig', |
| 204 | [ |
| 205 | 'render' => $mail->getHtmlPart() |
| 206 | ] |
| 207 | ); |
| 208 | } |
| 209 | |
| 210 | return \BO\Slim\Render::withHtml( |
| 211 | $response, |
| 212 | 'page/printWaitingNumber.twig', |
| 213 | array( |
| 214 | 'title' => ($process->isWithAppointment()) ? 'Vorgangsnummer drucken' : 'Wartenummer drucken', |
| 215 | 'process' => $process |
| 216 | ) |
| 217 | ); |
| 218 | } |
| 219 | } |