Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
66 / 66
100.00% covered (success)
100.00%
14 / 14
CRAP
100.00% covered (success)
100.00%
1 / 1
Workstation
100.00% covered (success)
100.00%
66 / 66
100.00% covered (success)
100.00%
14 / 14
21
100.00% covered (success)
100.00%
1 / 1
 addRequiredJoins
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLockWorkstationId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getEntityMapping
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 addJoin
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 addJoinScope
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 addJoinUseraccount
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 addConditionLoginName
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionWorkstationName
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionWorkstationIsNotCounter
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionWorkstationId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionScopeId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionTime
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionDepartmentId
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 reverseEntityMapping
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
6
1<?php
2
3namespace BO\Zmsdb\Query;
4
5/**
6 * @SuppressWarnings(Public)
7 *
8 */
9class Workstation extends Base implements MappingInterface
10{
11    /**
12     * @var String TABLE mysql table reference
13     */
14    const TABLE = 'nutzer';
15
16    const QUERY_LOGIN = '
17        UPDATE
18            ' . self::TABLE . '
19        SET
20            `SessionID`=SHA2(?, 256),
21            `sessionExpiry`=?,
22            `Datum`=?,
23            `lastUpdate`=?,
24            `Arbeitsplatznr`="",
25            `aufrufzusatz`="",
26            `StandortID`=0
27        WHERE
28            `Name`=? AND
29            `Passworthash` = ?
30    ';
31
32    const QUERY_LOGIN_OIDC = '
33        UPDATE
34            ' . self::TABLE . '
35        SET
36            `SessionID`=SHA2(?, 256),
37            `sessionExpiry`=?,
38            `Datum`=?,
39            `Arbeitsplatznr`="",
40            `aufrufzusatz`="",
41            `StandortID`=0
42        WHERE
43            `Name`=?
44    ';
45
46    const QUERY_PROCESS_RESET = '
47        UPDATE
48            ' . Process::TABLE . '
49        SET
50            `NutzerID` = 0,
51            `aufrufzeit` = "00:00:00"
52        WHERE
53            `NutzerID` = ?
54    ';
55
56    const QUERY_LOGOUT = '
57        UPDATE
58            ' . self::TABLE . '
59        SET
60            `SessionID`="",
61            `sessionExpiry`=NULL,
62            `StandortID`=0,
63            `Datum`="0000-00-00",
64            `Arbeitsplatznr`="",
65            `aufrufzusatz`=""
66        WHERE
67            `Name`= ?
68    ';
69
70    const QUERY_LOGGEDIN_CHECK = '
71        SELECT
72            SessionID as hash
73        FROM
74            ' . self::TABLE . '
75        WHERE
76            `Name` = :loginName
77        LIMIT 1
78    ';
79
80    const QUERY_UPDATE_AUTHKEY = '
81        UPDATE
82            ' . self::TABLE . '
83        SET
84            `SessionID`=SHA2(?, 256),
85            `sessionExpiry`=?
86        WHERE
87            `Name`= ?  AND
88            `Passworthash` = ?
89    ';
90
91    protected function addRequiredJoins()
92    {
93    }
94
95    public function getLockWorkstationId()
96    {
97        return 'SELECT * FROM `' . self::getTablename() . '` A
98            WHERE A.`NutzerID` = :workstationId FOR UPDATE';
99    }
100
101    public function getEntityMapping()
102    {
103        return [
104            'id' => 'workstation.NutzerID',
105            'hint' => 'workstation.aufrufzusatz',
106            'name' => 'workstation.Arbeitsplatznr',
107            'queue__appointmentsOnly' => 'workstation.Kalenderansicht',
108            'queue__clusterEnabled' => 'workstation.clusteransicht',
109            'scope__id' => 'workstation.StandortID'
110        ];
111    }
112
113    public function addJoin()
114    {
115        $joins = [];
116
117        if ($this->shouldLoadEntity('useraccount')) {
118            $joins[] = $this->addJoinUseraccount();
119        }
120
121        if ($this->shouldLoadEntity('scope')) {
122            $joins[] = $this->addJoinScope();
123        }
124
125        return $joins;
126    }
127
128    public function addJoinScope()
129    {
130        $this->leftJoin(
131            new Alias(Scope::TABLE, 'scope'),
132            'workstation.StandortID',
133            '=',
134            'scope.StandortID'
135        );
136        $joinQuery = new Scope($this, $this->getPrefixed('scope__'));
137        return $joinQuery;
138    }
139
140
141    public function addJoinUseraccount()
142    {
143        $this->leftJoin(
144            new Alias(Useraccount::TABLE, 'useraccount'),
145            'workstation.NutzerID',
146            '=',
147            'useraccount.NutzerID'
148        );
149        $joinQuery = new Useraccount($this, $this->getPrefixed('useraccount__'));
150        return $joinQuery;
151    }
152
153    public function addConditionLoginName($loginName)
154    {
155        $this->query->where('workstation.Name', '=', $loginName);
156        return $this;
157    }
158
159    public function addConditionWorkstationName($workstationName)
160    {
161        $this->query->where('workstation.Arbeitsplatznr', '=', $workstationName);
162        return $this;
163    }
164
165    public function addConditionWorkstationIsNotCounter()
166    {
167        $this->query->where('workstation.Arbeitsplatznr', '>', 0);
168        return $this;
169    }
170
171    public function addConditionWorkstationId($workstationId)
172    {
173        $this->query->where('workstation.NutzerID', '=', $workstationId);
174        return $this;
175    }
176
177    public function addConditionScopeId($scopeId)
178    {
179        $this->query->where('workstation.StandortID', '=', $scopeId);
180        return $this;
181    }
182
183    public function addConditionTime($now)
184    {
185        $this->query->where('workstation.Datum', '=', $now->format('Y-m-d'));
186        return $this;
187    }
188
189    public function addConditionDepartmentId($departmentId)
190    {
191        $this->leftJoin(
192            new Alias(Useraccount::TABLE_ASSIGNMENT, 'workstation_department'),
193            'workstation.NutzerID',
194            '=',
195            'workstation_department.nutzerid'
196        );
197        $this->query->where('workstation_department.behoerdenid', '=', $departmentId);
198        return $this;
199    }
200
201    public function reverseEntityMapping(\BO\Zmsentities\Workstation $entity)
202    {
203        $data = array();
204        if ((isset($entity['hint']) && '' == $entity['hint']) || ! isset($entity['hint'])) {
205            $data['aufrufzusatz'] = $entity->name;
206        } else {
207            $data['aufrufzusatz'] = $entity['hint'];
208        }
209
210        $data['Kalenderansicht'] = $entity->getQueuePreference('appointmentsOnly', true);
211        $data['clusteransicht'] = $entity->getQueuePreference('clusterEnabled', true);
212        if (isset($entity->scope['id'])) {
213            $data['StandortID'] = $entity->scope['id'];
214        }
215        $data['Arbeitsplatznr'] = $entity->name;
216
217        $data = array_filter($data, function ($value) {
218            return ($value !== null && $value !== false);
219        });
220        return $data;
221    }
222}