Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.45% covered (success)
92.45%
49 / 53
85.71% covered (warning)
85.71%
6 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
DepartmentList
92.45% covered (success)
92.45%
49 / 53
85.71% covered (warning)
85.71%
6 / 7
28.34
0.00% covered (danger)
0.00%
0 / 1
 withOutClusterDuplicates
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 getUniqueScopeList
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
5
 getUniqueClusterList
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
4
 withAccess
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
4
 withMatchingScopes
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
5
 sortByName
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
6
 getIds
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace BO\Zmsentities\Collection;
4
5use BO\Zmsentities\Helper\Property;
6
7/**
8 * @extends Base<\BO\Zmsentities\Department>
9 */
10class DepartmentList extends Base implements JsonUnindexed
11{
12    public const ENTITY_CLASS = '\BO\Zmsentities\Department';
13
14    public function withOutClusterDuplicates()
15    {
16        $departmentList = new self();
17        foreach ($this as $department) {
18            $entity = new \BO\Zmsentities\Department($department);
19            $departmentList->addEntity($entity->withOutClusterDuplicates());
20        }
21        return $departmentList;
22    }
23
24    public function getUniqueScopeList()
25    {
26        $scopeList = new ScopeList();
27        $clusterList = $this->getUniqueClusterList();
28        foreach ($this as $department) {
29            $entity = new \BO\Zmsentities\Department($department);
30            foreach ($entity->scopes as $scope) {
31                $scope = new \BO\Zmsentities\Scope($scope);
32                $scopeList->addEntity($scope);
33            }
34        }
35        foreach ($clusterList as $cluster) {
36            foreach ($cluster->scopes as $scope) {
37                $scope = new \BO\Zmsentities\Scope($scope);
38                $scopeList->addEntity($scope);
39            }
40        }
41        return $scopeList->withUniqueScopes();
42    }
43
44    public function getUniqueClusterList()
45    {
46        $clusterList = new ClusterList();
47        foreach ($this as $department) {
48            if (Property::__keyExists('clusters', $department)) {
49                foreach ($department['clusters'] as $cluster) {
50                    $entity = new \BO\Zmsentities\Cluster($cluster);
51                    $clusterList->addEntity($entity);
52                }
53            }
54        }
55        return $clusterList->withUniqueClusters();
56    }
57
58    public function withAccess(\BO\Zmsentities\Useraccount $useraccount)
59    {
60        $list = new static();
61        foreach ($this as $department) {
62            if ($department->hasAccess($useraccount)) {
63                if ($useraccount->hasPermissions(['organisation'])) {
64                    return $this;
65                }
66                $list->addEntity($department);
67            }
68        }
69        return $list;
70    }
71
72    public function withMatchingScopes(ScopeList $scopeList)
73    {
74        $list = new static();
75        foreach ($this as $department) {
76            $entity = clone $department;
77            $entity->scopes = new ScopeList();
78            $departmentScopeList = $department->getScopeList()->withUniqueScopes();
79            foreach ($scopeList as $scope) {
80                if ($departmentScopeList->hasEntity($scope->id)) {
81                    $entity->scopes->addEntity($scope);
82                }
83            }
84            if ($entity->scopes->count()) {
85                $list->addEntity($entity);
86            }
87        }
88        return $list;
89    }
90
91    #[\Override]
92    public function sortByName()
93    {
94        parent::sortByName();
95        foreach ($this as $department) {
96            if (isset($department->clusters) && $department->clusters instanceof ClusterList) {
97                $department->clusters->sortByName();
98            }
99            if (isset($department->scopes) && $department->scopes instanceof ScopeList) {
100                $department->scopes->sortByName();
101            }
102        }
103        return $this;
104    }
105
106    #[\Override]
107    public function getIds()
108    {
109        $ids = [];
110        foreach ($this as $department) {
111            $ids[] = $department->id;
112        }
113
114        return $ids;
115    }
116}