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