Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
16 / 16 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
Owner | |
100.00% |
16 / 16 |
|
100.00% |
5 / 5 |
9 | |
100.00% |
1 / 1 |
getDefaults | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
hasOrganisation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getOrganisationList | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
hasAccess | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
withLessData | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace BO\Zmsentities; |
4 | |
5 | class Owner extends Schema\Entity implements Useraccount\AccessInterface |
6 | { |
7 | const PRIMARY = 'id'; |
8 | |
9 | public static $schema = "owner.json"; |
10 | |
11 | public function getDefaults() |
12 | { |
13 | return [ |
14 | 'organisations' => new Collection\OrganisationList(), |
15 | 'name' => '', |
16 | ]; |
17 | } |
18 | |
19 | public function hasOrganisation($organisationId) |
20 | { |
21 | return $this->getOrganisationList()->hasEntity($organisationId); |
22 | } |
23 | |
24 | public function getOrganisationList() |
25 | { |
26 | if (!$this->organisations instanceof Collection\OrganisationList) { |
27 | $this->organisations = new Collection\OrganisationList($this->organisations); |
28 | foreach ($this->organisations as $key => $organisation) { |
29 | $this->organisations[$key] = new Organisation($organisation); |
30 | } |
31 | } |
32 | return $this->organisations; |
33 | } |
34 | |
35 | |
36 | public function hasAccess(Useraccount $useraccount) |
37 | { |
38 | return $useraccount->hasRights(['superuser']) |
39 | || 0 < $this->getOrganisationList()->withAccess($useraccount)->count(); |
40 | } |
41 | |
42 | /** |
43 | * Reduce data of dereferenced entities to a required minimum |
44 | * |
45 | */ |
46 | public function withLessData() |
47 | { |
48 | $entity = clone $this; |
49 | if ($entity->toProperty()->organisations->isAvailable()) { |
50 | unset($entity['organisations']); |
51 | } |
52 | return $entity; |
53 | } |
54 | } |