Lines
100.00%
18 / 18
Functions and Methods
100.00%
5 / 5
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Owner | 100.00% | 18 / 18 | 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% | 7 / 7 | 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 | public const string PRIMARY = 'id'; | |
| 8 | ||
| 9 | public static $schema = "owner.json"; | |
| 10 | ||
| 11 | /** | |
| 12 | * @return (Collection\OrganisationList|string)[] | |
| 13 | * | |
| 14 | */ | |
| 15 | #[\Override] | |
| 16 | public function getDefaults() | |
| 17 | { | |
| 18 | return [ | |
| 19 | 'organisations' => new Collection\OrganisationList(), | |
| 20 | 'name' => '', | |
| 21 | ]; | |
| 22 | } | |
| 23 | ||
| 24 | public function hasOrganisation(mixed $organisationId): bool | |
| 25 | { | |
| 26 | return $this->getOrganisationList()->hasEntity($organisationId); | |
| 27 | } | |
| 28 | ||
| 29 | public function getOrganisationList(): Collection\OrganisationList | |
| 30 | { | |
| 31 | $organisations = $this->organisations; | |
| 32 | if (!$organisations instanceof Collection\OrganisationList) { | |
| 33 | $organisations = new Collection\OrganisationList($organisations); | |
| 34 | foreach ($organisations as $key => $organisation) { | |
| 35 | $organisations[$key] = new Organisation($organisation); | |
| 36 | } | |
| 37 | $this->organisations = $organisations; | |
| 38 | } | |
| 39 | return $organisations; | |
| 40 | } | |
| 41 | ||
| 42 | ||
| 43 | /** | |
| 44 | * @return bool | |
| 45 | */ | |
| 46 | #[\Override] | |
| 47 | public function hasAccess(Useraccount $useraccount): bool | |
| 48 | { | |
| 49 | return $useraccount->isSuperUser() | |
| 50 | || 0 < $this->getOrganisationList()->withAccess($useraccount)->count(); | |
| 51 | } | |
| 52 | ||
| 53 | /** | |
| 54 | * Reduce data of dereferenced entities to a required minimum | |
| 55 | * | |
| 56 | * @return static | |
| 57 | */ | |
| 58 | #[\Override] | |
| 59 | public function withLessData() | |
| 60 | { | |
| 61 | $entity = clone $this; | |
| 62 | if ($entity->toProperty()->organisations->isAvailable()) { | |
| 63 | unset($entity['organisations']); | |
| 64 | } | |
| 65 | return $entity; | |
| 66 | } | |
| 67 | } |