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