Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
Organisation
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
6 / 6
12
100.00% covered (success)
100.00%
1 / 1
 getDefaults
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 hasDepartment
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDepartmentList
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 getPreference
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasAccess
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 withLessData
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3namespace BO\Zmsentities;
4
5class Organisation extends Schema\Entity implements Useraccount\AccessInterface
6{
7    public const string PRIMARY = 'id';
8
9    public static $schema = "organisation.json";
10
11    /**
12     * @return (Collection\DepartmentList|string)[]
13     *
14     */
15    #[\Override]
16    public function getDefaults()
17    {
18        return [
19            'departments' => new Collection\DepartmentList(),
20            'name' => '',
21        ];
22    }
23
24    public function hasDepartment($departmentId)
25    {
26        return $this->getDepartmentList()->hasEntity($departmentId);
27    }
28
29    public function getDepartmentList(): Collection\DepartmentList
30    {
31        if (!$this->departments instanceof Collection\DepartmentList) {
32            $this->departments = new Collection\DepartmentList((array)$this->departments);
33            foreach ($this->departments as $key => $department) {
34                $this->departments[$key] = new Department($department);
35            }
36        }
37        return $this->departments;
38    }
39
40    public function getPreference($index)
41    {
42        return $this->toProperty()->preferences->$index->get();
43    }
44
45    /**
46     * @return bool
47     */
48    #[\Override]
49    public function hasAccess(Useraccount $useraccount)
50    {
51        return $useraccount->isSuperUser()
52            || 0 < $this->getDepartmentList()->withAccess($useraccount)->count();
53    }
54
55    /**
56     * Reduce data of dereferenced entities to a required minimum
57     *
58     * @return static
59     */
60    #[\Override]
61    public function withLessData(array $keepArray = [])
62    {
63        $entity = clone $this;
64        if (! in_array('preferences', $keepArray)) {
65            unset($entity['preferences']);
66        }
67        if (! in_array('ticketprinters', $keepArray)) {
68            unset($entity['ticketprinters']);
69        }
70        if (! in_array('departments', $keepArray)) {
71            unset($entity['departments']);
72        }
73        return $entity;
74    }
75}