Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
82.49% |
146 / 177 |
|
85.71% |
12 / 14 |
CRAP | |
0.00% |
0 / 1 |
Workstation | |
82.49% |
146 / 177 |
|
85.71% |
12 / 14 |
41.58 | |
0.00% |
0 / 1 |
readEntity | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 | |||
readResolvedReferences | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
3 | |||
readLoggedInHashByName | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
readLoggedInListByScope | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
4 | |||
readLoggedInListByCluster | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
readWorkstationByScopeAndName | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
2 | |||
readCollectionByDepartmentId | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
4 | |||
writeEntityLoginByOidc | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
6 | |||
writeEntityLoginByName | |
100.00% |
23 / 23 |
|
100.00% |
1 / 1 |
3 | |||
writeEntityLogoutByName | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
writeAssignedProcess | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
1 | |||
writeRemovedProcess | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
3 | |||
updateEntity | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
updateEntityAuthkey | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace BO\Zmsdb; |
4 | |
5 | use BO\Zmsentities\Workstation as Entity; |
6 | use BO\Zmsentities\Useraccount as UseraccountEntity; |
7 | use BO\Zmsentities\Scope as ScopeEntity; |
8 | use BO\Zmsentities\Process as ProcessEntity; |
9 | use BO\Zmsentities\Collection\WorkstationList as Collection; |
10 | |
11 | /** |
12 | * @SuppressWarnings(Coupling) |
13 | * @SuppressWarnings(Public) |
14 | * |
15 | */ |
16 | class Workstation extends Base |
17 | { |
18 | public function readEntity($loginName, $resolveReferences = 0) |
19 | { |
20 | $query = new Query\Workstation(Query\Base::SELECT); |
21 | $query |
22 | ->addEntityMapping() |
23 | ->addConditionLoginName($loginName) |
24 | ->addResolvedReferences($resolveReferences); |
25 | $workstation = $this->fetchOne($query, new Entity()); |
26 | if (! $workstation->hasId()) { |
27 | return null; |
28 | } |
29 | return $this->readResolvedReferences($workstation, $resolveReferences); |
30 | } |
31 | |
32 | public function readResolvedReferences(\BO\Zmsentities\Schema\Entity $workstation, $resolveReferences) |
33 | { |
34 | if (0 < $resolveReferences) { |
35 | $workstation->useraccount = (new Useraccount()) |
36 | ->readResolvedReferences( |
37 | new UseraccountEntity($workstation->useraccount), |
38 | $resolveReferences - 1 |
39 | ); |
40 | if ($workstation->scope['id']) { |
41 | $workstation->scope = (new Scope())->readResolvedReferences( |
42 | new ScopeEntity($workstation->scope), |
43 | $resolveReferences - 1 |
44 | ); |
45 | $workstation->scope->cluster = (new Cluster())->readByScopeId($workstation->scope->id); |
46 | $department = (new Department())->readByScopeId($workstation->scope['id']); |
47 | $workstation->linkList = (new Link())->readByDepartmentId($department->getId()); |
48 | } |
49 | $workstation->process = (new Process())->readByWorkstation($workstation, $resolveReferences - 1); |
50 | $config = (new Config())->readEntity(); |
51 | $workstation->support = $config->support; |
52 | } |
53 | return $workstation; |
54 | } |
55 | |
56 | public function readLoggedInHashByName($loginName) |
57 | { |
58 | $query = Query\Workstation::QUERY_LOGGEDIN_CHECK; |
59 | $loggedInWorkstation = $this->getReader()->fetchOne($query, ['loginName' => $loginName]); |
60 | return ($loggedInWorkstation['hash']) ? $loggedInWorkstation['hash'] : null; |
61 | } |
62 | |
63 | public function readLoggedInListByScope($scopeId, \DateTimeInterface $dateTime, $resolveReferences = 0) |
64 | { |
65 | $workstationList = new \BO\Zmsentities\Collection\WorkstationList(); |
66 | $query = new Query\Workstation(Query\Base::SELECT); |
67 | $query |
68 | ->addEntityMapping() |
69 | ->addConditionScopeId($scopeId) |
70 | ->addConditionWorkstationIsNotCounter() |
71 | ->addConditionTime($dateTime) |
72 | ->addResolvedReferences($resolveReferences); |
73 | $result = $this->fetchList($query, new Entity()); |
74 | if ($result) { |
75 | foreach ($result as $entity) { |
76 | if ($entity->hasId()) { |
77 | $entity = $this->readResolvedReferences($entity, $resolveReferences); |
78 | $workstationList->addEntity($entity); |
79 | } |
80 | } |
81 | } |
82 | return $workstationList; |
83 | } |
84 | |
85 | public function readLoggedInListByCluster($clusterId, \DateTimeInterface $dateTime, $resolveReferences = 0) |
86 | { |
87 | $workstationList = new \BO\Zmsentities\Collection\WorkstationList(); |
88 | $cluster = (new Cluster())->readEntity($clusterId, $resolveReferences); |
89 | if ($cluster->toProperty()->scopes->get()) { |
90 | foreach ($cluster->scopes as $scope) { |
91 | $workstationList->addList($this->readLoggedInListByScope($scope['id'], $dateTime, $resolveReferences)); |
92 | } |
93 | } |
94 | return $workstationList; |
95 | } |
96 | |
97 | public function readWorkstationByScopeAndName($scopeId, $workstationName, $resolveReferences = 0) |
98 | { |
99 | $query = new Query\Workstation(Query\Base::SELECT); |
100 | $query |
101 | ->addEntityMapping() |
102 | ->addConditionScopeId($scopeId) |
103 | ->addConditionWorkstationName($workstationName) |
104 | ->addResolvedReferences($resolveReferences); |
105 | $workstation = $this->fetchOne($query, new Entity()); |
106 | if (! $workstation->hasId()) { |
107 | return null; |
108 | } |
109 | $workstation = $this->readResolvedReferences($workstation, $resolveReferences); |
110 | return $workstation; |
111 | } |
112 | |
113 | public function readCollectionByDepartmentId($departmentId, $resolveReferences = 0) |
114 | { |
115 | $collection = new Collection(); |
116 | $query = new Query\Workstation(Query\Base::SELECT); |
117 | $query->addResolvedReferences($resolveReferences) |
118 | ->addConditionDepartmentId($departmentId) |
119 | ->addEntityMapping(); |
120 | $result = $this->fetchList($query, new Entity()); |
121 | if (count($result)) { |
122 | foreach ($result as $entity) { |
123 | if ($entity instanceof Entity) { |
124 | $entity = $this->readResolvedReferences($entity, $resolveReferences); |
125 | $collection->addEntity($entity); |
126 | } |
127 | } |
128 | } |
129 | return $collection; |
130 | } |
131 | |
132 | public function writeEntityLoginByOidc($loginName, $authKey, \DateTimeInterface $dateTime, \DateTimeInterface $sessionExpiry, $resolveReferences = 0) |
133 | { |
134 | $workstation = new Entity(); |
135 | $query = Query\Workstation::QUERY_LOGIN_OIDC; |
136 | $result = $this->perform( |
137 | $query, |
138 | array( |
139 | $authKey, |
140 | $sessionExpiry->format('Y-m-d H:i:s'), |
141 | $dateTime->format('Y-m-d'), |
142 | $loginName |
143 | ) |
144 | ); |
145 | if ($result) { |
146 | $workstation = $this->readEntity($loginName, $resolveReferences); |
147 | $workstation->authkey = $authKey; |
148 | $query = Query\Workstation::QUERY_PROCESS_RESET; |
149 | $this->perform($query, [$workstation->id]); |
150 | } |
151 | return $workstation; |
152 | } |
153 | |
154 | public function writeEntityLoginByName($loginName, $password, \DateTimeInterface $dateTime, \DateTimeInterface $sessionExpiry, $resolveReferences = 0) |
155 | { |
156 | $useraccount = new Useraccount(); |
157 | $workstation = new Entity(); |
158 | if ($useraccount->readIsUserExisting($loginName, $password)) { |
159 | $query = Query\Workstation::QUERY_LOGIN; |
160 | $authKey = (new \BO\Zmsentities\Workstation())->getAuthKey(); |
161 | $result = $this->perform( |
162 | $query, |
163 | array( |
164 | $authKey, |
165 | $sessionExpiry->format('Y-m-d H:i:s'), |
166 | $dateTime->format('Y-m-d'), |
167 | $dateTime->format('Y-m-d H:i:s'), |
168 | $loginName, |
169 | $password |
170 | ) |
171 | ); |
172 | if ($result) { |
173 | $workstation = $this->readEntity($loginName, $resolveReferences); |
174 | $workstation->authkey = $authKey; |
175 | $query = Query\Workstation::QUERY_PROCESS_RESET; |
176 | $this->perform($query, [$workstation->id]); |
177 | } |
178 | } else { |
179 | throw new Exception\Useraccount\InvalidCredentials(); |
180 | } |
181 | return $workstation; |
182 | } |
183 | |
184 | public function writeEntityLogoutByName($loginName, $resolveReferences = 0) |
185 | { |
186 | $query = Query\Workstation::QUERY_LOGOUT; |
187 | $result = $this->perform($query, [$loginName]); |
188 | $workstation = $this->readEntity($loginName, $resolveReferences); |
189 | return ($result) ? $workstation : null; |
190 | } |
191 | |
192 | /** |
193 | * |
194 | * assign a process to workstation |
195 | * |
196 | * @param |
197 | * workstation |
198 | * |
199 | * @return Resource Process |
200 | */ |
201 | public function writeAssignedProcess( |
202 | \BO\Zmsentities\Workstation $workstation, |
203 | \BO\Zmsentities\Process $process, |
204 | \DateTimeInterface $dateTime |
205 | ) { |
206 | $processEntity = $process; |
207 | $process = (new Process())->updateEntity( |
208 | $process, |
209 | $dateTime, |
210 | 0, |
211 | null, |
212 | $workstation->getUseraccount() |
213 | ); |
214 | $query = new Query\Process(Query\Base::UPDATE); |
215 | $query->addConditionProcessId($process->id); |
216 | $query->addValues(['NutzerID' => $workstation->id]); |
217 | $this->writeItem($query); |
218 | $checksum = sha1($process->id . '-' . $workstation->getUseraccount()->id); |
219 | Log::writeProcessLog( |
220 | "UPDATE (Workstation::writeAssignedProcess) $checksum ", |
221 | Log::ACTION_CALLED, |
222 | $processEntity |
223 | ); |
224 | |
225 | return $process; |
226 | } |
227 | |
228 | /** |
229 | * |
230 | * remove a process from workstation |
231 | * |
232 | * @param |
233 | * workstation |
234 | * |
235 | * @return Boolean |
236 | */ |
237 | public function writeRemovedProcess(\BO\Zmsentities\Workstation $workstation) |
238 | { |
239 | $process = new \BO\Zmsentities\Process($workstation->process); |
240 | $query = new Query\Process(Query\Base::UPDATE); |
241 | $query->addConditionProcessId($process->id); |
242 | $query->addValues( |
243 | [ |
244 | 'aufrufzeit' => 0, |
245 | 'NutzerID' => 0, |
246 | 'AnzahlAufrufe' => $process->queue['callCount'], |
247 | 'nicht_erschienen' => ('missed' == $process->status) ? 1 : 0, |
248 | 'parked' => ('parked' == $process->status) ? 1 : 0 |
249 | ] |
250 | ); |
251 | Log::writeProcessLog( |
252 | "UPDATE (Workstation::writeRemovedProcess)", |
253 | Log::ACTION_REMOVED, |
254 | $process, |
255 | $workstation->getUseraccount() |
256 | ); |
257 | return $this->writeItem($query); |
258 | } |
259 | |
260 | |
261 | /** |
262 | * update a workstation |
263 | * |
264 | * @param |
265 | * useraccountId |
266 | * |
267 | * @return Entity |
268 | */ |
269 | public function updateEntity(\BO\Zmsentities\Workstation $entity, $resolveReferences = 0) |
270 | { |
271 | $query = new Query\Workstation(Query\Base::UPDATE); |
272 | $query->addConditionWorkstationId($entity->getId()); |
273 | $values = $query->reverseEntityMapping($entity); |
274 | $query->addValues($values); |
275 | |
276 | if ($this->perform($query->getLockWorkstationId(), ['workstationId' => $entity->getId()])) { |
277 | $this->writeItem($query); |
278 | } |
279 | return $this->readEntity($entity->useraccount['id'], $resolveReferences); |
280 | } |
281 | |
282 | /** |
283 | * update a workstations authkey - is needed for openid login |
284 | * |
285 | * @param |
286 | * useraccountId |
287 | * |
288 | * @return Entity |
289 | */ |
290 | public function updateEntityAuthkey($loginName, $password, $authKey, \DateTimeInterface $sessionExpiry, $resolveReferences) |
291 | { |
292 | $query = Query\Workstation::QUERY_UPDATE_AUTHKEY; |
293 | $result = $this->perform( |
294 | $query, |
295 | array( |
296 | $authKey, |
297 | $sessionExpiry->format('Y-m-d H:i:s'), |
298 | $loginName, |
299 | $password |
300 | ) |
301 | ); |
302 | if ($result) { |
303 | $workstation = $this->readEntity($loginName, $resolveReferences); |
304 | $workstation->authkey = $authKey; |
305 | } |
306 | return $workstation; |
307 | } |
308 | } |