Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
98.46% |
64 / 65 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
Notification | |
98.46% |
64 / 65 |
|
75.00% |
3 / 4 |
14 | |
0.00% |
0 / 1 |
readResponse | |
97.78% |
44 / 45 |
|
0.00% |
0 / 1 |
4 | |||
getValidatedResponse | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
5 | |||
getReminderNotification | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
getCustomNotification | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | /** |
4 | * @package Zmsadmin |
5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
6 | **/ |
7 | |
8 | namespace BO\Zmsadmin; |
9 | |
10 | use BO\Zmsentities\Notification as Entity; |
11 | use BO\Mellon\Validator; |
12 | |
13 | /** |
14 | * Send notification, API proxy |
15 | * |
16 | */ |
17 | class Notification extends BaseController |
18 | { |
19 | /** |
20 | * @SuppressWarnings(UnusedFormalParameter) |
21 | * @return \Psr\Http\Message\ResponseInterface |
22 | */ |
23 | public function readResponse( |
24 | \Psr\Http\Message\RequestInterface $request, |
25 | \Psr\Http\Message\ResponseInterface $response, |
26 | array $args |
27 | ) { |
28 | $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 2])->getEntity(); |
29 | $workstationRequest = new \BO\Zmsclient\WorkstationRequests(\App::$http, $workstation); |
30 | $department = $workstationRequest->readDepartment(); |
31 | $selectedProcessId = Validator::param('selectedprocess')->isNumber()->getValue(); |
32 | $success = Validator::param('success')->isString()->getValue(); |
33 | $error = Validator::param('error')->isString()->getValue(); |
34 | $dialog = Validator::param('dialog')->isNumber()->getValue(); |
35 | $formResponse = null; |
36 | $config = \App::$http->readGetResult('/config/')->getEntity(); |
37 | $input = $request->getParsedBody(); |
38 | $process = ($selectedProcessId) ? |
39 | \App::$http->readGetResult('/process/' . $selectedProcessId . '/')->getEntity() : |
40 | null; |
41 | $formResponse = $this->getValidatedResponse($input, $process, $config, $department); |
42 | if ($formResponse instanceof Entity) { |
43 | $query = [ |
44 | 'selectedprocess' => $process->getId(), |
45 | 'dialog' => $dialog |
46 | ]; |
47 | $message = ($formResponse->hasId()) |
48 | ? ['success' => 'notification_sent'] |
49 | : ['error' => 'notification_failed']; |
50 | $query = array_merge($message, $query); |
51 | return \BO\Slim\Render::redirect( |
52 | 'notification', |
53 | [], |
54 | $query |
55 | ); |
56 | } |
57 | |
58 | return \BO\Slim\Render::withHtml( |
59 | $response, |
60 | 'page/notification.twig', |
61 | array( |
62 | 'title' => 'SMS-Versand', |
63 | 'menuActive' => $workstation->getVariantName(), |
64 | 'workstation' => $workstation, |
65 | 'department' => $department, |
66 | 'process' => $process, |
67 | 'success' => $success, |
68 | 'error' => $error, |
69 | 'status' => $input['submit'] ?? null, |
70 | 'dialog' => $dialog, |
71 | 'form' => $formResponse, |
72 | 'redirect' => $workstation->getVariantName() |
73 | ) |
74 | ); |
75 | } |
76 | |
77 | protected function getValidatedResponse($input, $process, $config, $department) |
78 | { |
79 | $formResponse = null; |
80 | if (array_key_exists('submit', (array)$input) && 'reminder' == $input['submit']) { |
81 | $formResponse = $this->getReminderNotification($process, $config, $department); |
82 | } elseif (array_key_exists('submit', (array)$input) && 'form' == $input['submit']) { |
83 | $formResponse = $this->getCustomNotification($process, $department); |
84 | } |
85 | return $formResponse; |
86 | } |
87 | |
88 | protected function getReminderNotification($process, $config, $department) |
89 | { |
90 | $notification = (new Entity())->toResolvedEntity($process, $config, $department, 'reminder'); |
91 | // maybe should be $notification->department->hasNotificationReminderEnabled() |
92 | return ($notification->department->hasNotificationEnabled()) |
93 | ? \App::$http->readPostResult('/notification/', $notification)->getEntity() |
94 | : $notification; |
95 | } |
96 | |
97 | protected function getCustomNotification($process, $department) |
98 | { |
99 | $collection = array(); |
100 | $collection['message'] = Validator::param('message')->isString() |
101 | ->isBiggerThan(2, "Es muss eine aussagekräftige Nachricht eingegeben werden"); |
102 | $collection = Validator::collection($collection); |
103 | if (! $collection->hasFailed()) { |
104 | $notification = (new Entity())->toCustomMessageEntity($process, $collection->getValues(), $department); |
105 | return ($notification->department->hasNotificationEnabled()) |
106 | ? \App::$http->readPostResult('/notification/', $notification)->getEntity() |
107 | : $notification; |
108 | } |
109 | return $collection->getStatus(); |
110 | } |
111 | } |