Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
96.92% covered (success)
96.92%
63 / 65
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ProcessSearch
96.92% covered (success)
96.92%
63 / 65
33.33% covered (danger)
33.33%
1 / 3
16
0.00% covered (danger)
0.00%
0 / 1
 readResponse
100.00% covered (success)
100.00%
49 / 49
100.00% covered (success)
100.00%
1 / 1
5
 filterProcessListForUserRights
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
4.05
 filterLogListForUserRights
88.89% covered (warning)
88.89%
8 / 9
0.00% covered (danger)
0.00%
0 / 1
7.07
1<?php
2
3/**
4 * @package Zmsadmin
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsadmin;
9
10use BO\Zmsentities\Collection\LogList;
11use BO\Zmsentities\Collection\ProcessList;
12
13/**
14  * Handle requests concerning services
15  *
16  */
17class ProcessSearch extends BaseController
18{
19    /**
20     * @SuppressWarnings(Param)
21     * @return String
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        $validator = $request->getAttribute('validator');
30        $queryString = $validator->getParameter('query')
31            ->isString()
32            ->getValue();
33        $page = $validator->getParameter('page')
34            ->isNumber()
35            ->setDefault(1)
36            ->getValue();
37        $perPage = $validator->getParameter('perPage')
38            ->isNumber()
39            ->setDefault(100)
40            ->getValue();
41        $processList = \App::$http->readGetResult('/process/search/', [
42            'query' => $queryString,
43            'resolveReferences' => 1,
44        ])->getCollection();
45
46        $scopeIds = $workstation->getUseraccount()->getDepartmentList()->getUniqueScopeList()->getIds();
47        if (!$workstation->hasSuperUseraccount()) {
48            $processList = $this->filterProcessListForUserRights($processList, $scopeIds);
49        }
50
51        $processList = $processList ? $processList : new \BO\Zmsentities\Collection\ProcessList();
52        if ($workstation->hasAuditAccount()) {
53            $queryString = urlencode($queryString);
54            $logList = \App::$http
55                ->readGetResult("/log/process/$queryString/", [
56                        'page' => $page,
57                        'perPage' => $perPage
58                    ])
59                ->getCollection();
60            $logList = $this->filterLogListForUserRights($logList, $scopeIds);
61        }
62
63        $processListOther = new \BO\Zmsentities\Collection\ProcessList();
64        if (!$workstation->hasSuperUseraccount()) {
65            $processListOther = $processList->withOutScopeId($workstation->scope['id']);
66            $processList = $processList->withScopeId($workstation->scope['id']);
67        }
68        return \BO\Slim\Render::withHtml(
69            $response,
70            'page/search.twig',
71            array(
72                'title' => 'Suche',
73                'page' => $page,
74                'perPage' => $perPage,
75                'workstation' => $workstation,
76                'processList' => $processList,
77                'processListOther' => $processListOther,
78                'logList' => $logList ?? [],
79                'searchProcessQuery' => urldecode($queryString),
80                'menuActive' => 'search'
81            )
82        );
83    }
84
85    private function filterProcessListForUserRights(?ProcessList $processList, array $scopeIds)
86    {
87        if (empty($processList)) {
88            return new ProcessList();
89        }
90
91        $list = new ProcessList();
92
93        foreach ($processList as $process) {
94            if (in_array($process->scope->id, $scopeIds)) {
95                $list->addEntity(clone $process);
96            }
97        }
98
99        return $list;
100    }
101
102    private function filterLogListForUserRights(?LogList $logList, array $scopeIds)
103    {
104        if (!isset($logList) || !$logList) {
105            $logList = new LogList();
106        }
107
108        $list = new LogList();
109
110        foreach ($logList as $log) {
111            $data = isset($log->data) ? json_decode($log->data, true) : null;
112            $log->data = $data;
113
114            if (isset($log->scope_id) && in_array($log->scope_id, $scopeIds)) {
115                $list->addEntity(clone $log);
116            }
117        }
118
119        return $list;
120    }
121}