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