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 PRIMARY = 'id';
8
9    public static $schema = "organisation.json";
10
11    #[\Override]
12    public function getDefaults()
13    {
14        return [
15            'departments' => new Collection\DepartmentList(),
16            'name' => '',
17        ];
18    }
19
20    public function hasDepartment($departmentId)
21    {
22        return $this->getDepartmentList()->hasEntity($departmentId);
23    }
24
25    public function getDepartmentList()
26    {
27        if (!$this->departments instanceof Collection\DepartmentList) {
28            $this->departments = new Collection\DepartmentList((array)$this->departments);
29            foreach ($this->departments as $key => $department) {
30                $this->departments[$key] = new Department($department);
31            }
32        }
33        return $this->departments;
34    }
35
36    public function getPreference($index)
37    {
38        return $this->toProperty()->preferences->$index->get();
39    }
40
41    #[\Override]
42    public function hasAccess(Useraccount $useraccount)
43    {
44        return $useraccount->hasRights(['superuser'])
45            || 0 < $this->getDepartmentList()->withAccess($useraccount)->count();
46    }
47
48    /**
49     * Reduce data of dereferenced entities to a required minimum
50     *
51     */
52    #[\Override]
53    public function withLessData(array $keepArray = [])
54    {
55        $entity = clone $this;
56        if (! in_array('preferences', $keepArray)) {
57            unset($entity['preferences']);
58        }
59        if (! in_array('ticketprinters', $keepArray)) {
60            unset($entity['ticketprinters']);
61        }
62        if (! in_array('departments', $keepArray)) {
63            unset($entity['departments']);
64        }
65        return $entity;
66    }
67}