Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
31 / 31
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
OrganisationList
100.00% covered (success)
100.00%
31 / 31
100.00% covered (success)
100.00%
4 / 4
15
100.00% covered (success)
100.00%
1 / 1
 getByDepartmentId
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 withAccess
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
4
 sortByName
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 withMatchingDepartments
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3namespace BO\Zmsentities\Collection;
4
5class OrganisationList extends Base
6{
7    const ENTITY_CLASS = '\BO\Zmsentities\Organisation';
8
9    public function getByDepartmentId($departmentId)
10    {
11        $organisationList = new self();
12        foreach ($this as $entity) {
13            $organisation = new \BO\Zmsentities\Organisation($entity);
14            if ($organisation->hasDepartment($departmentId)) {
15                $organisationList->addEntity($organisation);
16            }
17        }
18        return $organisationList;
19    }
20
21    public function withAccess(\BO\Zmsentities\Useraccount $useraccount)
22    {
23        $list = new static();
24        foreach ($this as $organisation) {
25            $organisation = clone $organisation;
26            if ($useraccount->hasRights(['department'])) {
27                $organisation->departments = $organisation->getDepartmentList();
28            } else {
29                $organisation->departments = $organisation->getDepartmentList()->withAccess($useraccount);
30            }
31            if ($organisation->hasAccess($useraccount)) {
32                $list[] = $organisation;
33            }
34        }
35        return $list;
36    }
37
38    public function sortByName()
39    {
40        parent::sortByName();
41        foreach ($this as $organisation) {
42            if ($organisation->departments instanceof DepartmentList) {
43                $organisation->departments->sortByName();
44            }
45        }
46        return $this;
47    }
48
49    public function withMatchingDepartments(DepartmentList $departmentList)
50    {
51        $list = new static();
52        foreach ($this as $organisation) {
53            $entity = clone $organisation;
54            $entity->departments = new DepartmentList();
55            $departmentMatchList = $organisation->getDepartmentList();
56            foreach ($departmentList as $department) {
57                if ($departmentMatchList->hasEntity($department->id)) {
58                    $entity->departments->addEntity($department);
59                }
60            }
61            if ($entity->departments->count()) {
62                $list->addEntity($entity);
63            }
64        }
65        return $list;
66    }
67}