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 string 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    /**
27     * @return array[]
28     *
29     */
30    public function toDepartmentListByOrganisationName(): array
31    {
32        $list = array();
33        foreach ($this as $entity) {
34            $organisationList = $this->getOrganisationsByOwnerId($entity->id);
35            foreach ($organisationList as $organisation) {
36                $list[$entity->name][$organisation->name] = $organisation->departments;
37            }
38        }
39        return $list;
40    }
41
42    public function withAccess(\BO\Zmsentities\Useraccount $useraccount): static
43    {
44        $list = new static();
45        foreach ($this as $owner) {
46            $owner = clone $owner;
47            $owner->organisations = $owner->getOrganisationList()->withAccess($useraccount);
48            $owner->organisations->sortByName();
49            if ($owner->hasAccess($useraccount)) {
50                $list[] = $owner;
51            }
52        }
53        return $list;
54    }
55}