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