Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
45 / 45 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
NotificationAssign | |
100.00% |
45 / 45 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
readResponse | |
100.00% |
26 / 26 |
|
100.00% |
1 / 1 |
2 | |||
writeUpdateProcessWithNotification | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * |
5 | * @package Zmsticketprinter |
6 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
7 | * |
8 | */ |
9 | |
10 | namespace BO\Zmsticketprinter; |
11 | |
12 | use BO\Slim\Render; |
13 | use Psr\Http\Message\RequestInterface; |
14 | use Psr\Http\Message\ResponseInterface; |
15 | use BO\Zmsticketprinter\Helper\QueueListHelper; |
16 | |
17 | class NotificationAssign extends BaseController |
18 | { |
19 | /** |
20 | * @SuppressWarnings(UnusedFormalParameter) |
21 | * @return ResponseInterface |
22 | */ |
23 | public function readResponse( |
24 | RequestInterface $request, |
25 | ResponseInterface $response, |
26 | array $args |
27 | ) { |
28 | $validator = $request->getAttribute('validator'); |
29 | $telephone = $validator->getParameter('telephone')->isString()->isBiggerThan(10); |
30 | //get process |
31 | $processId = $validator->getParameter('processId')->isNumber()->getValue(); |
32 | $authKey = $validator->getParameter('authKey')->isString()->getValue(); |
33 | $process = \App::$http->readGetResult('/process/' . $processId . '/' . $authKey . '/')->getEntity(); |
34 | |
35 | if ($telephone->hasFailed()) { |
36 | return Render::redirect( |
37 | 'Message', |
38 | [ |
39 | 'status' => 'process_notification_number_unvalid' |
40 | ], |
41 | [ |
42 | 'scopeId' => $process->getScopeId(), |
43 | 'notHome' => 1 |
44 | ] |
45 | ); |
46 | } |
47 | |
48 | $process = $this->writeUpdateProcessWithNotification($process, $telephone); |
49 | |
50 | return Render::redirect( |
51 | 'Message', |
52 | [ |
53 | 'status' => 'process_notification_success' |
54 | ], |
55 | [ |
56 | 'scopeId' => $process->getScopeId() |
57 | ] |
58 | ); |
59 | } |
60 | |
61 | protected function writeUpdateProcessWithNotification(\BO\Zmsentities\Process $process, $telephone) |
62 | { |
63 | //update process client data |
64 | $client = $process->getClients()->getFirst(); |
65 | $client->telephone = $telephone->getValue(); |
66 | //update calculated reminderTimestamp |
67 | $headsUpTime = $process->getCurrentScope()->getPreference('notifications', 'headsUpTime'); |
68 | $queue = $process->queue; |
69 | $number = ($queue->withAppointment) ? $process->getId() : $queue->number; |
70 | $waitingTimeEstimate = (new QueueListHelper($process->getCurrentScope())) |
71 | ->getList() |
72 | ->getQueueByNumber($number) |
73 | ->waitingTimeEstimate; |
74 | $process->reminderTimestamp = $queue->arrivalTime + ($waitingTimeEstimate * 60) - ($headsUpTime * 60); |
75 | |
76 | //add notification to queue |
77 | $process->status = 'queued'; |
78 | $process = \App::$http |
79 | ->readPostResult('/process/' . $process->id . '/' . $process->authKey . '/', $process) |
80 | ->getEntity(); |
81 | |
82 | \App::$http->readPostResult( |
83 | '/process/' . $process->id . '/' . $process->authKey . '/confirmation/notification/', |
84 | $process |
85 | ); |
86 | |
87 | return $process; |
88 | } |
89 | } |