Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
96.00% covered (success)
96.00%
48 / 50
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ProcessSearch
96.00% covered (success)
96.00%
48 / 50
33.33% covered (danger)
33.33%
1 / 3
16
0.00% covered (danger)
0.00%
0 / 1
 readResponse
100.00% covered (success)
100.00%
34 / 34
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        $processList = \App::$http->readGetResult('/process/search/', [
34            'query' => $queryString,
35            'resolveReferences' => 1,
36        ])->getCollection();
37
38        $scopeIds = $workstation->getUseraccount()->getDepartmentList()->getUniqueScopeList()->getIds();
39        if (!$workstation->hasSuperUseraccount()) {
40            $processList = $this->filterProcessListForUserRights($processList, $scopeIds);
41        }
42
43        $processList = $processList ? $processList : new \BO\Zmsentities\Collection\ProcessList();
44        if ($workstation->hasAuditAccount()) {
45            $queryString = urlencode($queryString);
46            $logList = \App::$http->readGetResult("/log/process/$queryString/")->getCollection();
47            $logList = $this->filterLogListForUserRights($logList, $scopeIds);
48        }
49
50        $processListOther = new \BO\Zmsentities\Collection\ProcessList();
51        if (!$workstation->hasSuperUseraccount()) {
52            $processListOther = $processList->withOutScopeId($workstation->scope['id']);
53            $processList = $processList->withScopeId($workstation->scope['id']);
54        }
55        return \BO\Slim\Render::withHtml(
56            $response,
57            'page/search.twig',
58            array(
59                'title' => 'Suche',
60                'workstation' => $workstation,
61                'processList' => $processList,
62                'processListOther' => $processListOther,
63                'logList' => $logList ?? [],
64                'searchProcessQuery' => urldecode($queryString),
65                'menuActive' => 'search'
66            )
67        );
68    }
69
70    private function filterProcessListForUserRights(?ProcessList $processList, array $scopeIds)
71    {
72        if (empty($processList)) {
73            return new ProcessList();
74        }
75
76        $list = new ProcessList();
77
78        foreach ($processList as $process) {
79            if (in_array($process->scope->id, $scopeIds)) {
80                $list->addEntity(clone $process);
81            }
82        }
83
84        return $list;
85    }
86
87    private function filterLogListForUserRights(?LogList $logList, array $scopeIds)
88    {
89        if (!isset($logList) || !$logList) {
90            $logList = new LogList();
91        }
92
93        $list = new LogList();
94
95        foreach ($logList as $log) {
96            $data = isset($log->data) ? json_decode($log->data, true) : null;
97            $log->data = $data;
98
99            if (isset($log->scope_id) && in_array($log->scope_id, $scopeIds)) {
100                $list->addEntity(clone $log);
101            }
102        }
103
104        return $list;
105    }
106}