Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
97.78% |
88 / 90 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ProcessSearch | |
97.78% |
88 / 90 |
|
33.33% |
1 / 3 |
21 | |
0.00% |
0 / 1 |
| readResponse | |
100.00% |
74 / 74 |
|
100.00% |
1 / 1 |
10 | |||
| filterProcessListForUserRights | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
4.05 | |||
| filterLogListForUserRights | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
7.07 | |||
| 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\Collection\LogList; |
| 11 | use BO\Zmsentities\Collection\ProcessList; |
| 12 | use DateTime; |
| 13 | |
| 14 | /** |
| 15 | * Handle requests concerning services |
| 16 | * |
| 17 | */ |
| 18 | class ProcessSearch extends BaseController |
| 19 | { |
| 20 | /** |
| 21 | * @SuppressWarnings(Param) |
| 22 | * @return String |
| 23 | */ |
| 24 | public function readResponse( |
| 25 | \Psr\Http\Message\RequestInterface $request, |
| 26 | \Psr\Http\Message\ResponseInterface $response, |
| 27 | array $args |
| 28 | ) { |
| 29 | $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 2])->getEntity(); |
| 30 | $validator = $request->getAttribute('validator'); |
| 31 | $queryString = $validator->getParameter('query') |
| 32 | ->isString() |
| 33 | ->getValue(); |
| 34 | $page = $validator->getParameter('page') |
| 35 | ->isNumber() |
| 36 | ->setDefault(1) |
| 37 | ->getValue(); |
| 38 | $service = $validator->getParameter('service') |
| 39 | ->isString() |
| 40 | ->setDefault('') |
| 41 | ->getValue(); |
| 42 | $provider = $validator->getParameter('provider') |
| 43 | ->isString() |
| 44 | ->setDefault('') |
| 45 | ->getValue(); |
| 46 | $date = $validator->getParameter('date') |
| 47 | ->isString() |
| 48 | ->setDefault(null) |
| 49 | ->getValue(); |
| 50 | $userAction = $validator->getParameter('user') |
| 51 | ->isNumber() |
| 52 | ->setDefault(0) |
| 53 | ->getValue(); |
| 54 | $perPage = $validator->getParameter('perPage') |
| 55 | ->isNumber() |
| 56 | ->setDefault(100) |
| 57 | ->getValue(); |
| 58 | $processList = !empty($queryString) ? \App::$http->readGetResult('/process/search/', [ |
| 59 | 'query' => $queryString, |
| 60 | 'resolveReferences' => 1, |
| 61 | ])->getCollection() : new ProcessList(); |
| 62 | |
| 63 | $scopeIds = $workstation->getUseraccount()->getDepartmentList()->getUniqueScopeList()->getIds(); |
| 64 | if (!empty($processList) && !$workstation->hasSuperUseraccount()) { |
| 65 | $processList = $this->filterProcessListForUserRights($processList, $scopeIds); |
| 66 | } |
| 67 | |
| 68 | if ($workstation->hasAuditAccount()) { |
| 69 | $queryString = urlencode($queryString); |
| 70 | $logList = \App::$http |
| 71 | ->readGetResult("/log/process/", [ |
| 72 | 'searchQuery' => $queryString, |
| 73 | 'page' => $page, |
| 74 | 'perPage' => $perPage, |
| 75 | 'service' => $service ? trim($service) : null, |
| 76 | 'provider' => $provider ? trim($provider) : null, |
| 77 | 'userAction' => (int) $userAction, |
| 78 | 'date' => $date |
| 79 | ]) |
| 80 | ->getCollection(); |
| 81 | $logList = $this->filterLogListForUserRights($logList, $scopeIds); |
| 82 | } |
| 83 | |
| 84 | $processList = $processList ?? new \BO\Zmsentities\Collection\ProcessList(); |
| 85 | $processListOther = new \BO\Zmsentities\Collection\ProcessList(); |
| 86 | if (!$workstation->hasSuperUseraccount()) { |
| 87 | $processListOther = $processList->withOutScopeId($workstation->scope['id']); |
| 88 | $processList = $processList->withScopeId($workstation->scope['id']); |
| 89 | } |
| 90 | return \BO\Slim\Render::withHtml( |
| 91 | $response, |
| 92 | 'page/search.twig', |
| 93 | array( |
| 94 | 'title' => 'Suche', |
| 95 | 'service' => $service ? trim($service) : null, |
| 96 | 'provider' => $provider ? trim($provider) : null, |
| 97 | 'userAction' => (int) $userAction, |
| 98 | 'date' => $date, |
| 99 | 'page' => $page, |
| 100 | 'perPage' => $perPage, |
| 101 | 'workstation' => $workstation, |
| 102 | 'processList' => $processList, |
| 103 | 'processListOther' => $processListOther, |
| 104 | 'logList' => $logList ?? [], |
| 105 | 'searchProcessQuery' => urldecode($queryString), |
| 106 | 'menuActive' => 'search' |
| 107 | ) |
| 108 | ); |
| 109 | } |
| 110 | |
| 111 | private function filterProcessListForUserRights(?ProcessList $processList, array $scopeIds) |
| 112 | { |
| 113 | if (empty($processList)) { |
| 114 | return new ProcessList(); |
| 115 | } |
| 116 | |
| 117 | $list = new ProcessList(); |
| 118 | |
| 119 | foreach ($processList as $process) { |
| 120 | if (in_array($process->scope->id, $scopeIds)) { |
| 121 | $list->addEntity(clone $process); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | return $list; |
| 126 | } |
| 127 | |
| 128 | private function filterLogListForUserRights(?LogList $logList, array $scopeIds) |
| 129 | { |
| 130 | if (!isset($logList) || !$logList) { |
| 131 | $logList = new LogList(); |
| 132 | } |
| 133 | |
| 134 | $list = new LogList(); |
| 135 | |
| 136 | foreach ($logList as $log) { |
| 137 | $data = isset($log->data) ? json_decode($log->data, true) : null; |
| 138 | $log->data = $data; |
| 139 | |
| 140 | if (isset($log->scope_id) && in_array($log->scope_id, $scopeIds)) { |
| 141 | $list->addEntity(clone $log); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | return $list; |
| 146 | } |
| 147 | } |