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