Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.29% |
93 / 103 |
|
79.17% |
19 / 24 |
CRAP | |
0.00% |
0 / 1 |
| Workstation | |
90.29% |
93 / 103 |
|
79.17% |
19 / 24 |
68.87 | |
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 | |||
| validateProcessScopeAccess | |
94.44% |
17 / 18 |
|
0.00% |
0 / 1 |
5.00 | |||
| 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 validateProcessScopeAccess($scopeList, $process = null) |
| 160 | { |
| 161 | if (null === $process) { |
| 162 | $process = $this->process; |
| 163 | } |
| 164 | if (! $scopeList->hasEntity($process->getScopeId())) { |
| 165 | $exception = new Exception\WorkstationProcessMatchScopeFailed(); |
| 166 | $scopeContactName = null; |
| 167 | $currentScope = $process->getCurrentScope(); |
| 168 | if ($currentScope && isset($currentScope['contact']['name'])) { |
| 169 | $scopeContactName = $currentScope['contact']['name']; |
| 170 | } |
| 171 | |
| 172 | $exception->data = [ |
| 173 | 'id' => $process->getId(), |
| 174 | 'scope' => [ |
| 175 | 'id' => $process->getScopeId(), |
| 176 | 'contact' => [ |
| 177 | 'name' => $scopeContactName |
| 178 | ] |
| 179 | ] |
| 180 | ]; |
| 181 | throw $exception; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | public function setValidatedName(array $formData) |
| 186 | { |
| 187 | if (isset($formData['workstation']) && trim($formData['workstation']->getValue())) { |
| 188 | $this->name = $formData['workstation']->getValue(); |
| 189 | } elseif (isset($formData['workstation']) && ! trim($formData['workstation']->getValue())) { |
| 190 | $this->name = ''; |
| 191 | } |
| 192 | return $this; |
| 193 | } |
| 194 | |
| 195 | public function setValidatedHint(array $formData) |
| 196 | { |
| 197 | if (isset($formData['hint']) && $formData['hint']->getValue()) { |
| 198 | $this->hint = $formData['hint']->getValue(); |
| 199 | } elseif (isset($formData['hint']) && ! $formData['hint']->getValue()) { |
| 200 | $this->hint = ''; |
| 201 | } |
| 202 | return $this; |
| 203 | } |
| 204 | |
| 205 | public function setValidatedScope(array $formData) |
| 206 | { |
| 207 | if (isset($formData['scope']) && 'cluster' === $formData['scope']->getValue()) { |
| 208 | $this->queue['clusterEnabled'] = 1; |
| 209 | } elseif (isset($formData['scope'])) { |
| 210 | $this->queue['clusterEnabled'] = 0; |
| 211 | $this->scope = new Scope([ |
| 212 | 'id' => $formData['scope']->getValue(), |
| 213 | ]); |
| 214 | } |
| 215 | return $this; |
| 216 | } |
| 217 | |
| 218 | public function setValidatedAppointmentsOnly(array $formData) |
| 219 | { |
| 220 | $this->queue['appointmentsOnly'] = (isset($formData['appointmentsOnly'])) ? |
| 221 | $formData['appointmentsOnly']->getValue() : |
| 222 | 0; |
| 223 | return $this; |
| 224 | } |
| 225 | |
| 226 | public function isClusterEnabled() |
| 227 | { |
| 228 | return $this->queue['clusterEnabled'] ? true : false; |
| 229 | } |
| 230 | |
| 231 | public function hasAccessToUseraccount($useraccount) |
| 232 | { |
| 233 | $departmentList = $this->getDepartmentList(); |
| 234 | $accessedList = $departmentList->withAccess($useraccount); |
| 235 | return ($accessedList->count()) ? true : false; |
| 236 | } |
| 237 | } |