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