Lines
100.00%
17 / 17
Functions and Methods
100.00%
4 / 4
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 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 string PRIMARY = 'id'; | |
| 8 | ||
| 9 | public static $schema = "cluster.json"; | |
| 10 | ||
| 11 | /** | |
| 12 | * @return Collection\ScopeList[] | |
| 13 | * | |
| 14 | */ | |
| 15 | #[\Override] | |
| 16 | public function getDefaults() | |
| 17 | { | |
| 18 | return [ | |
| 19 | //'name' => '', | |
| 20 | 'scopes' => new Collection\ScopeList(), | |
| 21 | ]; | |
| 22 | } | |
| 23 | ||
| 24 | public function getName(): mixed | |
| 25 | { | |
| 26 | return $this->toProperty()->name->get(); | |
| 27 | } | |
| 28 | ||
| 29 | public function getScopesWorkstationCount(): mixed | |
| 30 | { | |
| 31 | $workstationCount = 0; | |
| 32 | if ($this->toProperty()->scopes->get()) { | |
| 33 | foreach ($this->scopes as $scope) { | |
| 34 | $entity = new Scope($scope); | |
| 35 | $workstationCount += $entity->status['queue']['workstationCount']; | |
| 36 | } | |
| 37 | } | |
| 38 | return $workstationCount; | |
| 39 | } | |
| 40 | ||
| 41 | /** | |
| 42 | * @return bool | |
| 43 | */ | |
| 44 | #[\Override] | |
| 45 | public function hasAccess(Useraccount $useraccount): bool | |
| 46 | { | |
| 47 | if ($useraccount->hasPermissions(['superuser'])) { | |
| 48 | return true; | |
| 49 | } | |
| 50 | ||
| 51 | foreach ($this->scopes as $scope) { | |
| 52 | $scopeEntity = $scope instanceof Scope ? $scope : new Scope($scope); | |
| 53 | ||
| 54 | if ($useraccount->hasScope($scopeEntity->id)) { | |
| 55 | return true; | |
| 56 | } | |
| 57 | } | |
| 58 | ||
| 59 | return false; | |
| 60 | } | |
| 61 | } |