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