Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Cluster | |
100.00% |
17 / 17 |
|
100.00% |
4 / 4 |
10 | |
100.00% |
1 / 1 |
| getDefaults | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getScopesWorkstationCount | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| hasAccess | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsentities; |
| 4 | |
| 5 | class Cluster extends Schema\Entity implements Useraccount\AccessInterface |
| 6 | { |
| 7 | public const PRIMARY = 'id'; |
| 8 | |
| 9 | public static $schema = "cluster.json"; |
| 10 | |
| 11 | #[\Override] |
| 12 | public function getDefaults() |
| 13 | { |
| 14 | return [ |
| 15 | //'name' => '', |
| 16 | 'scopes' => new Collection\ScopeList(), |
| 17 | ]; |
| 18 | } |
| 19 | |
| 20 | public function getName() |
| 21 | { |
| 22 | return $this->toProperty()->name->get(); |
| 23 | } |
| 24 | |
| 25 | public function getScopesWorkstationCount() |
| 26 | { |
| 27 | $workstationCount = 0; |
| 28 | if ($this->toProperty()->scopes->get()) { |
| 29 | foreach ($this->scopes as $scope) { |
| 30 | $entity = new Scope($scope); |
| 31 | $workstationCount += $entity->status['queue']['workstationCount']; |
| 32 | } |
| 33 | } |
| 34 | return $workstationCount; |
| 35 | } |
| 36 | |
| 37 | public function hasAccess(Useraccount $useraccount) |
| 38 | { |
| 39 | if ($useraccount->hasPermissions(['superuser'])) { |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | foreach ($this->scopes as $scope) { |
| 44 | $scopeEntity = $scope instanceof Scope ? $scope : new Scope($scope); |
| 45 | |
| 46 | if ($useraccount->hasScope($scopeEntity->id)) { |
| 47 | return true; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | return false; |
| 52 | } |
| 53 | } |