Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
61.73% |
50 / 81 |
|
63.64% |
7 / 11 |
CRAP | |
0.00% |
0 / 1 |
Useraccount | |
61.73% |
50 / 81 |
|
63.64% |
7 / 11 |
45.72 | |
0.00% |
0 / 1 |
getEntityMapping | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
1 | |||
addConditionLoginName | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
addConditionUserId | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
addConditionPassword | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
addConditionXauthKey | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
addConditionDepartmentAndSearch | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
12 | |||
addConditionRoleLevel | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
addConditionDepartmentId | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
addConditionSearch | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
reverseEntityMapping | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
7 | |||
postProcess | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 |
1 | <?php |
2 | |
3 | namespace BO\Zmsdb\Query; |
4 | |
5 | class Useraccount extends Base implements MappingInterface |
6 | { |
7 | /** |
8 | * @var String TABLE mysql table reference |
9 | */ |
10 | const TABLE = 'nutzer'; |
11 | const TABLE_ASSIGNMENT = 'nutzerzuordnung'; |
12 | |
13 | const QUERY_READ_ID_BY_USERNAME = ' |
14 | SELECT user.`NutzerID` AS id |
15 | FROM ' . self::TABLE . ' user |
16 | WHERE |
17 | user.`Name`=? |
18 | '; |
19 | |
20 | const QUERY_WRITE_ASSIGNED_DEPARTMENTS = ' |
21 | REPLACE INTO |
22 | ' . self::TABLE_ASSIGNMENT . ' |
23 | SET |
24 | nutzerid=?, |
25 | behoerdenid=? |
26 | '; |
27 | |
28 | const QUERY_DELETE_ASSIGNED_DEPARTMENTS = ' |
29 | DELETE FROM |
30 | ' . self::TABLE_ASSIGNMENT . ' |
31 | WHERE |
32 | nutzerid=? |
33 | ORDER BY behoerdenid |
34 | '; |
35 | |
36 | const QUERY_READ_SUPERUSER_DEPARTMENTS = ' |
37 | SELECT behoerde.`BehoerdenID` AS id, |
38 | organisation.Organisationsname as organisation__name |
39 | FROM ' . Department::TABLE . ' |
40 | LEFT JOIN ' . Organisation::TABLE . ' USING(OrganisationsID) |
41 | ORDER BY organisation.Organisationsname, behoerde.Name |
42 | '; |
43 | |
44 | const QUERY_READ_ASSIGNED_DEPARTMENTS = ' |
45 | SELECT userAssignment.`behoerdenid` AS id, |
46 | organisation.Organisationsname as organisation__name |
47 | FROM ' . self::TABLE_ASSIGNMENT . ' userAssignment |
48 | LEFT JOIN ' . self::TABLE . ' useraccount ON useraccount.Name = :useraccountName |
49 | LEFT JOIN ' . Department::TABLE . ' ON userAssignment.behoerdenid = behoerde.BehoerdenID |
50 | LEFT JOIN ' . Organisation::TABLE . ' USING(OrganisationsID) |
51 | WHERE |
52 | useraccount.`NutzerID` = userAssignment.`nutzerid` |
53 | ORDER BY organisation.Organisationsname, behoerde.Name |
54 | '; |
55 | |
56 | public function getEntityMapping() |
57 | { |
58 | return [ |
59 | 'id' => 'useraccount.Name', |
60 | 'password' => 'useraccount.Passworthash', |
61 | 'email' => 'useraccount.email', |
62 | 'lastLogin' => 'useraccount.lastUpdate', |
63 | 'rights__superuser' => self::expression('`useraccount`.`Berechtigung` = 90'), |
64 | 'rights__organisation' => self::expression('`useraccount`.`Berechtigung` >= 70'), |
65 | 'rights__department' => self::expression('`useraccount`.`Berechtigung` >= 50'), |
66 | 'rights__cluster' => self::expression('`useraccount`.`Berechtigung` >= 40'), |
67 | 'rights__useraccount' => self::expression('`useraccount`.`Berechtigung` >= 40'), |
68 | 'rights__scope' => self::expression('`useraccount`.`Berechtigung` >= 30'), |
69 | 'rights__availability' => self::expression('`useraccount`.`Berechtigung` >= 20'), |
70 | 'rights__ticketprinter' => self::expression('`useraccount`.`Berechtigung` >= 15'), |
71 | 'rights__sms' => self::expression('`useraccount`.`Berechtigung` >= 10'), |
72 | 'rights__audit' => self::expression('`useraccount`.`Berechtigung` = 5 OR `useraccount`.`Berechtigung` = 90'), |
73 | 'rights__basic' => self::expression('`useraccount`.`Berechtigung` >= 0'), |
74 | ]; |
75 | } |
76 | |
77 | public function addConditionLoginName($loginName) |
78 | { |
79 | $this->query->where('useraccount.Name', '=', $loginName); |
80 | return $this; |
81 | } |
82 | |
83 | public function addConditionUserId($userId) |
84 | { |
85 | $this->query->where('useraccount.NutzerID', '=', $userId); |
86 | return $this; |
87 | } |
88 | |
89 | public function addConditionPassword($password) |
90 | { |
91 | $this->query->where('useraccount.Passworthash', '=', $password); |
92 | return $this; |
93 | } |
94 | |
95 | public function addConditionXauthKey($xAuthKey) |
96 | { |
97 | $this->query->where('useraccount.SessionID', '=', $xAuthKey); |
98 | return $this; |
99 | } |
100 | |
101 | public function addConditionDepartmentAndSearch($departmentId, $queryString = null, $orWhere = false) |
102 | { |
103 | |
104 | $this->leftJoin( |
105 | new Alias(static::TABLE_ASSIGNMENT, 'useraccount_department'), |
106 | 'useraccount.NutzerID', |
107 | '=', |
108 | 'useraccount_department.nutzerid' |
109 | ); |
110 | |
111 | $this->query->where('useraccount_department.behoerdenid', '=', $departmentId); |
112 | |
113 | if ($queryString) { |
114 | $condition = function (\Solution10\SQL\ConditionBuilder $query) use ($queryString) { |
115 | $queryString = trim($queryString); |
116 | $query->orWith('useraccount.NutzerID', 'LIKE', "%$queryString%"); |
117 | $query->orWith('useraccount.Name', 'LIKE', "%$queryString%"); |
118 | $query->orWith('useraccount.email', 'LIKE', "%$queryString%"); |
119 | }; |
120 | |
121 | if ($orWhere) { |
122 | $this->query->orWhere($condition); |
123 | } else { |
124 | $this->query->where($condition); |
125 | } |
126 | } |
127 | |
128 | return $this; |
129 | } |
130 | |
131 | public function addConditionRoleLevel($roleLevel) |
132 | { |
133 | $this->query->where('useraccount.Berechtigung', '=', $roleLevel); |
134 | return $this; |
135 | } |
136 | |
137 | public function addConditionDepartmentId($departmentId) |
138 | { |
139 | $this->leftJoin( |
140 | new Alias(static::TABLE_ASSIGNMENT, 'useraccount_department'), |
141 | 'useraccount.NutzerID', |
142 | '=', |
143 | 'useraccount_department.nutzerid' |
144 | ); |
145 | $this->query->where('useraccount_department.behoerdenid', '=', $departmentId); |
146 | return $this; |
147 | } |
148 | |
149 | public function addConditionSearch($queryString, $orWhere = false) |
150 | { |
151 | $condition = function (\Solution10\SQL\ConditionBuilder $query) use ($queryString) { |
152 | $queryString = trim($queryString); |
153 | $query->orWith('useraccount.NutzerID', 'LIKE', "%$queryString%"); |
154 | $query->orWith('useraccount.Name', 'LIKE', "%$queryString%"); |
155 | $query->orWith('useraccount.email', 'LIKE', "%$queryString%"); |
156 | }; |
157 | if ($orWhere) { |
158 | $this->query->orWhere($condition); |
159 | } else { |
160 | $this->query->where($condition); |
161 | } |
162 | return $this; |
163 | } |
164 | |
165 | public function reverseEntityMapping(\BO\Zmsentities\Useraccount $entity) |
166 | { |
167 | $data = array(); |
168 | $data['Name'] = $entity->id; |
169 | $data['email'] = (isset($entity->email)) ? $entity->email : null; |
170 | $data['Passworthash'] = (isset($entity->password)) ? $entity->password : null; |
171 | $data['Berechtigung'] = $entity->getRightsLevel(); |
172 | $data['BehoerdenID'] = 0; |
173 | if (!$entity->isSuperUser() && isset($entity->departments) && 0 < $entity->departments->count()) { |
174 | $data['BehoerdenID'] = $entity->departments->getFirst()->id; |
175 | } |
176 | //default values because of strict mode |
177 | $data['notrufinitiierung'] = 0; |
178 | $data['notrufantwort'] = 0; |
179 | |
180 | $data = array_filter($data, function ($value) { |
181 | return ($value !== null && $value !== false); |
182 | }); |
183 | return $data; |
184 | } |
185 | |
186 | public function postProcess($data) |
187 | { |
188 | $data[$this->getPrefixed("lastLogin")] = ('0000-00-00' != $data[$this->getPrefixed("lastLogin")]) ? |
189 | strtotime($data[$this->getPrefixed("lastLogin")]) : |
190 | null; |
191 | return $data; |
192 | } |
193 | } |