Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
71 / 71 |
|
100.00% |
12 / 12 |
CRAP | |
100.00% |
1 / 1 |
| Calldisplay | |
100.00% |
71 / 71 |
|
100.00% |
12 / 12 |
36 | |
100.00% |
1 / 1 |
| getDefaults | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| withResolvedCollections | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
| hasScopeList | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasClusterList | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setServerTime | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getFullScopeList | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
5 | |||
| getScopeList | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| getClusterList | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| getImageName | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| withOutClusterDuplicates | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
8 | |||
| getScopeListFromCsv | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| getClusterListFromCsv | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsentities; |
| 4 | |
| 5 | use BO\Zmsentities\Helper\Property; |
| 6 | |
| 7 | /** |
| 8 | * Schema-backed entity (ArrayObject::ARRAY_AS_PROPS); document dynamic keys for Psalm. |
| 9 | * |
| 10 | * @property Collection\ClusterList|array $clusters |
| 11 | * @property Collection\ScopeList|array $scopes |
| 12 | * @property Organisation $organisation |
| 13 | * @property int|float $serverTime |
| 14 | */ |
| 15 | class Calldisplay extends Schema\Entity |
| 16 | { |
| 17 | public const string PRIMARY = 'serverTime'; |
| 18 | |
| 19 | public static $schema = "calldisplay.json"; |
| 20 | |
| 21 | /** |
| 22 | * @return (Collection\ClusterList|Collection\ScopeList|Organisation|int)[] |
| 23 | * |
| 24 | */ |
| 25 | #[\Override] |
| 26 | public function getDefaults() |
| 27 | { |
| 28 | return [ |
| 29 | 'serverTime' => (new \DateTime())->getTimestamp(), |
| 30 | 'clusters' => new Collection\ClusterList(), |
| 31 | 'scopes' => new Collection\ScopeList(), |
| 32 | 'organisation' => new Organisation(), |
| 33 | ]; |
| 34 | } |
| 35 | |
| 36 | public function withResolvedCollections($input): static |
| 37 | { |
| 38 | $input = (is_object($input)) ? $input->getArrayCopy() : $input; |
| 39 | if (Property::__keyExists('scopelist', $input)) { |
| 40 | $this->scopes = $this->getScopeListFromCsv($input['scopelist']); |
| 41 | } |
| 42 | if (Property::__keyExists('clusterlist', $input)) { |
| 43 | $this->clusters = $this->getClusterListFromCsv($input['clusterlist']); |
| 44 | } |
| 45 | return $this; |
| 46 | } |
| 47 | |
| 48 | public function hasScopeList(): bool |
| 49 | { |
| 50 | return (0 < $this->getScopeList()->count()); |
| 51 | } |
| 52 | |
| 53 | public function hasClusterList(): bool |
| 54 | { |
| 55 | return (0 < $this->getClusterList()->count()); |
| 56 | } |
| 57 | |
| 58 | public function setServerTime($timestamp): static |
| 59 | { |
| 60 | $this->serverTime = $timestamp; |
| 61 | return $this; |
| 62 | } |
| 63 | |
| 64 | public function getFullScopeList() |
| 65 | { |
| 66 | $scopeList = $this->getScopeList(); |
| 67 | foreach ($this->clusters as $cluster) { |
| 68 | if (Property::__keyExists('scopes', $cluster)) { |
| 69 | foreach ($cluster['scopes'] as $clusterScope) { |
| 70 | $scope = new Scope($clusterScope); |
| 71 | if (! $scopeList->hasEntity($scope['id'])) { |
| 72 | $scopeList->addEntity($scope); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | return $scopeList; |
| 78 | } |
| 79 | |
| 80 | public function getScopeList(): Collection\ScopeList |
| 81 | { |
| 82 | if (!$this->scopes instanceof Collection\ScopeList) { |
| 83 | $scopeList = new Collection\ScopeList(); |
| 84 | foreach ($this->scopes as $scope) { |
| 85 | $scopeList->addEntity(new Scope($scope)); |
| 86 | } |
| 87 | $this->scopes = $scopeList; |
| 88 | } |
| 89 | return $this->scopes; |
| 90 | } |
| 91 | |
| 92 | public function getClusterList(): Collection\ClusterList |
| 93 | { |
| 94 | if (!$this->clusters instanceof Collection\ClusterList) { |
| 95 | $clusterList = new Collection\ClusterList(); |
| 96 | foreach ($this->clusters as $cluster) { |
| 97 | $clusterList->addEntity(new Cluster($cluster)); |
| 98 | } |
| 99 | $this->clusters = $clusterList; |
| 100 | } |
| 101 | return $this->clusters; |
| 102 | } |
| 103 | |
| 104 | public function getImageName(): string |
| 105 | { |
| 106 | $name = ''; |
| 107 | if (1 == $this->getScopeList()->count()) { |
| 108 | $name = "s_" . $this->getScopeList()->getFirst()->id . "_bild"; |
| 109 | } elseif (1 == $this->getClusterList()->count()) { |
| 110 | $name = "c_" . $this->getClusterList()->getFirst()->id . "_bild"; |
| 111 | } |
| 112 | return $name; |
| 113 | } |
| 114 | |
| 115 | public function withOutClusterDuplicates(): self |
| 116 | { |
| 117 | $calldisplay = new self($this); |
| 118 | if ($calldisplay->hasClusterList() && $calldisplay->hasScopeList()) { |
| 119 | $clusterScopeList = new Collection\ScopeList(); |
| 120 | foreach ($calldisplay->clusters as $cluster) { |
| 121 | if (Property::__keyExists('scopes', $cluster)) { |
| 122 | foreach ($cluster['scopes'] as $clusterScope) { |
| 123 | $scope = new Scope($clusterScope); |
| 124 | $clusterScopeList->addEntity($scope); |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | $scopeList = new Collection\ScopeList(); |
| 129 | foreach ($calldisplay->scopes as $scope) { |
| 130 | if (! $clusterScopeList->hasEntity($scope['id'])) { |
| 131 | $scope = new Scope($scope); |
| 132 | $scopeList->addEntity($scope); |
| 133 | } |
| 134 | } |
| 135 | $calldisplay->scopes = $scopeList; |
| 136 | } |
| 137 | return $calldisplay; |
| 138 | } |
| 139 | |
| 140 | protected function getScopeListFromCsv($scopeIds = ''): Collection\ScopeList |
| 141 | { |
| 142 | $scopeList = new Collection\ScopeList(); |
| 143 | $scopeIds = explode(',', $scopeIds); |
| 144 | if ($scopeIds) { |
| 145 | foreach ($scopeIds as $scopeId) { |
| 146 | $scope = new Scope(array('id' => $scopeId)); |
| 147 | $scopeList->addEntity($scope); |
| 148 | } |
| 149 | } |
| 150 | return $scopeList; |
| 151 | } |
| 152 | |
| 153 | protected function getClusterListFromCsv($clusterIds = ''): Collection\ClusterList |
| 154 | { |
| 155 | $clusterList = new Collection\ClusterList(); |
| 156 | $clusterIds = explode(',', $clusterIds); |
| 157 | if ($clusterIds) { |
| 158 | foreach ($clusterIds as $clusterId) { |
| 159 | $cluster = new Cluster(array('id' => $clusterId)); |
| 160 | $clusterList->addEntity($cluster); |
| 161 | } |
| 162 | } |
| 163 | return $clusterList; |
| 164 | } |
| 165 | } |