Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
OwnerList
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
3 / 3
10
100.00% covered (success)
100.00%
1 / 1
 getOrganisationsByOwnerId
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
4
 toDepartmentListByOrganisationName
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 withAccess
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace BO\Zmsentities\Collection;
4
5/**
6 * @extends Base<\BO\Zmsentities\Owner>
7 */
8class OwnerList extends Base
9{
10    public const ENTITY_CLASS = '\BO\Zmsentities\Owner';
11
12    public function getOrganisationsByOwnerId($entityId)
13    {
14        $organisationList = new OrganisationList();
15        foreach ($this as $entity) {
16            if ($entityId == $entity->id) {
17                foreach ($entity->organisations as $organisation) {
18                    $organisation = new \BO\Zmsentities\Organisation($organisation);
19                    $organisationList->addEntity($organisation);
20                }
21            }
22        }
23        return $organisationList->sortByName();
24    }
25
26    public function toDepartmentListByOrganisationName()
27    {
28        $list = array();
29        foreach ($this as $entity) {
30            $organisationList = $this->getOrganisationsByOwnerId($entity->id);
31            foreach ($organisationList as $organisation) {
32                $list[$entity->name][$organisation->name] = $organisation->departments;
33            }
34        }
35        return $list;
36    }
37
38    public function withAccess(\BO\Zmsentities\Useraccount $useraccount)
39    {
40        $list = new static();
41        foreach ($this as $owner) {
42            $owner = clone $owner;
43            $owner->organisations = $owner->getOrganisationList()->withAccess($useraccount);
44            $owner->organisations->sortByName();
45            if ($owner->hasAccess($useraccount)) {
46                $list[] = $owner;
47            }
48        }
49        return $list;
50    }
51}