Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
93.48% covered (success)
93.48%
86 / 92
82.61% covered (warning)
82.61%
19 / 23
CRAP
0.00% covered (danger)
0.00%
0 / 1
Workstation
93.48% covered (success)
93.48%
86 / 92
82.61% covered (warning)
82.61%
19 / 23
59.97
0.00% covered (danger)
0.00%
0 / 1
 getDefaults
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 getQueuePreference
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
5
 getUseraccount
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getDepartmentById
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDepartmentList
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 testDepartmentList
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 getProviderOfGivenScope
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasSuperUseraccount
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasAuditAccount
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAuthKey
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasAuthKey
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 getVariantName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 getScope
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
3.07
 getScopeList
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 getScopeListFromAssignedDepartments
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
5
 validateProcessScopeAccess
94.44% covered (success)
94.44%
17 / 18
0.00% covered (danger)
0.00%
0 / 1
5.00
 setValidatedName
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
5
 setValidatedHint
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
5
 setValidatedScope
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
 setValidatedAppointmentsOnly
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 isClusterEnabled
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
 hasAccessToUseraccount
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace BO\Zmsentities;
4
5use BO\Zmsentities\Helper\Property;
6
7/**
8 * @SuppressWarnings(Complexity)
9 *
10 */
11class Workstation extends Schema\Entity
12{
13    public const PRIMARY = 'id';
14
15    public static $schema = "workstation.json";
16
17    #[\Override]
18    public function getDefaults()
19    {
20        return [
21            'id' => 0,
22            'useraccount' => new Useraccount(),
23            'process' => new Process(),
24            'name' => '',
25            'scope' => new Scope()
26        ];
27    }
28
29    public function getQueuePreference($key, $isBoolean = false)
30    {
31        $result = null;
32        if (isset($this['queue']) && Property::__keyExists($key, $this['queue'])) {
33            if ($isBoolean) {
34                $result = ($this['queue'][$key]) ? 1 : 0;
35            } else {
36                $result = $this['queue'][$key];
37            }
38        }
39        return $result;
40    }
41
42    public function getUseraccount()
43    {
44        if (!$this->useraccount instanceof Useraccount) {
45            $this->useraccount = new Useraccount($this->useraccount);
46        }
47        return $this->useraccount;
48    }
49
50    public function getDepartmentById($departmentId)
51    {
52        return $this->getUseraccount()->getDepartmentById($departmentId);
53    }
54
55    public function getDepartmentList()
56    {
57        $departmentList = new Collection\DepartmentList();
58        foreach ($this->getUseraccount()->departments as $department) {
59            $departmentList->addEntity(new Department($department));
60        }
61        return $departmentList;
62    }
63
64    public function testDepartmentList()
65    {
66        if (0 == $this->getDepartmentList()->count()) {
67            throw new Exception\WorkstationMissingAssignedDepartments();
68        }
69    }
70
71    public function getProviderOfGivenScope()
72    {
73        return $this->toProperty()->scope->provider->id->get();
74    }
75
76    public function hasSuperUseraccount()
77    {
78        return $this->getUseraccount()->isSuperUser();
79    }
80
81    public function hasAuditAccount()
82    {
83        return $this->getUseraccount()->hasPermissions(['logs']);
84    }
85
86    public function getAuthKey()
87    {
88        return bin2hex(openssl_random_pseudo_bytes(16));
89    }
90
91    public function hasAuthKey()
92    {
93        return (isset($this->authkey)) ? true : false;
94    }
95
96    public function getVariantName()
97    {
98        return (! trim($this->name)) ? 'counter' : 'workstation';
99    }
100
101    public function getName()
102    {
103        return ($this->name) ? $this->name : "Tresen";
104    }
105
106    public function getScope()
107    {
108        if (!$this->offsetExists('scope')) {
109            $this->scope = new Scope();
110        } elseif (!$this->scope instanceof Scope) {
111            $this->scope = new Scope($this->scope);
112        }
113        return $this->scope;
114    }
115
116    public function getScopeList($cluster = null)
117    {
118        $scopeList = new Collection\ScopeList();
119        $scopeList->addEntity(new Scope($this->getScope()));
120        if ($cluster && 1 == $this->queue['clusterEnabled']) {
121            $scopeList = new Collection\ScopeList();
122            $scopeList->addList($cluster->scopes);
123        }
124        return $scopeList;
125    }
126
127    public function getScopeListFromAssignedDepartments()
128    {
129        $scopeList = new Collection\ScopeList();
130        foreach ($this->getDepartmentList() as $department) {
131            $scopeList->addList($department->getScopeList());
132        }
133        foreach ($this->getScopeList() as $scope) {
134            if (! $scopeList->hasEntity($scope->id) && $scope instanceof Scope) {
135                $scopeList->addEntity($scope);
136            }
137        }
138        return $scopeList;
139    }
140
141    public function validateProcessScopeAccess($scopeList, $process = null)
142    {
143        if (null === $process) {
144            $process = $this->process;
145        }
146        if (! $scopeList->hasEntity($process->getScopeId())) {
147            $exception = new Exception\WorkstationProcessMatchScopeFailed();
148            $scopeContactName = null;
149            $currentScope = $process->getCurrentScope();
150            if ($currentScope && isset($currentScope['contact']['name'])) {
151                $scopeContactName = $currentScope['contact']['name'];
152            }
153
154            $exception->data = [
155                'id' => $process->getId(),
156                'scope' => [
157                    'id' => $process->getScopeId(),
158                    'contact' => [
159                        'name' => $scopeContactName
160                    ]
161                ]
162            ];
163            throw $exception;
164        }
165    }
166
167    public function setValidatedName(array $formData)
168    {
169        if (isset($formData['workstation']) && trim($formData['workstation']->getValue())) {
170            $this->name = $formData['workstation']->getValue();
171        } elseif (isset($formData['workstation']) && ! trim($formData['workstation']->getValue())) {
172            $this->name = '';
173        }
174        return $this;
175    }
176
177    public function setValidatedHint(array $formData)
178    {
179        if (isset($formData['hint']) && $formData['hint']->getValue()) {
180            $this->hint = $formData['hint']->getValue();
181        } elseif (isset($formData['hint']) && ! $formData['hint']->getValue()) {
182            $this->hint = '';
183        }
184        return $this;
185    }
186
187    public function setValidatedScope(array $formData)
188    {
189        if (isset($formData['scope']) && 'cluster' === $formData['scope']->getValue()) {
190            $this->queue['clusterEnabled'] = 1;
191        } elseif (isset($formData['scope'])) {
192            $this->queue['clusterEnabled'] = 0;
193            $this->scope = new Scope([
194                'id' => $formData['scope']->getValue(),
195            ]);
196        }
197        return $this;
198    }
199
200    public function setValidatedAppointmentsOnly(array $formData)
201    {
202        $this->queue['appointmentsOnly'] = (isset($formData['appointmentsOnly'])) ?
203            $formData['appointmentsOnly']->getValue() :
204            0;
205        return $this;
206    }
207
208    public function isClusterEnabled()
209    {
210        return $this->queue['clusterEnabled'] ? true : false;
211    }
212
213    public function hasAccessToUseraccount($useraccount)
214    {
215        $departmentList = $this->getDepartmentList();
216        $accessedList = $departmentList->withAccess($useraccount);
217        return ($accessedList->count()) ? true : false;
218    }
219}