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    #[\Override]
92    protected function addRequiredJoins()
93    {
94    }
95
96    public function getLockWorkstationId()
97    {
98        return 'SELECT * FROM `' . self::getTablename() . '` A
99            WHERE A.`NutzerID` = :workstationId FOR UPDATE';
100    }
101
102    #[\Override]
103    public function getEntityMapping()
104    {
105        return [
106            'id' => 'workstation.NutzerID',
107            'hint' => 'workstation.aufrufzusatz',
108            'name' => 'workstation.Arbeitsplatznr',
109            'queue__appointmentsOnly' => 'workstation.Kalenderansicht',
110            'queue__clusterEnabled' => 'workstation.clusteransicht',
111            'scope__id' => 'workstation.StandortID'
112        ];
113    }
114
115    #[\Override]
116    public function addJoin()
117    {
118        $joins = [];
119
120        if ($this->shouldLoadEntity('useraccount')) {
121            $joins[] = $this->addJoinUseraccount();
122        }
123
124        if ($this->shouldLoadEntity('scope')) {
125            $joins[] = $this->addJoinScope();
126        }
127
128        return $joins;
129    }
130
131    public function addJoinScope()
132    {
133        $this->leftJoin(
134            new Alias(Scope::TABLE, 'scope'),
135            'workstation.StandortID',
136            '=',
137            'scope.StandortID'
138        );
139        $joinQuery = new Scope($this, $this->getPrefixed('scope__'));
140        return $joinQuery;
141    }
142
143
144    public function addJoinUseraccount()
145    {
146        $this->leftJoin(
147            new Alias(Useraccount::TABLE, 'useraccount'),
148            'workstation.NutzerID',
149            '=',
150            'useraccount.NutzerID'
151        );
152        $joinQuery = new Useraccount($this, $this->getPrefixed('useraccount__'));
153        return $joinQuery;
154    }
155
156    public function addConditionLoginName($loginName)
157    {
158        $this->query->where('workstation.Name', '=', $loginName);
159        return $this;
160    }
161
162    public function addConditionWorkstationName($workstationName)
163    {
164        $this->query->where('workstation.Arbeitsplatznr', '=', $workstationName);
165        return $this;
166    }
167
168    public function addConditionWorkstationIsNotCounter()
169    {
170        $this->query->where('workstation.Arbeitsplatznr', '>', 0);
171        return $this;
172    }
173
174    public function addConditionWorkstationId($workstationId)
175    {
176        $this->query->where('workstation.NutzerID', '=', $workstationId);
177        return $this;
178    }
179
180    public function addConditionScopeId($scopeId)
181    {
182        $this->query->where('workstation.StandortID', '=', $scopeId);
183        return $this;
184    }
185
186    public function addConditionTime($now)
187    {
188        $this->query->where('workstation.Datum', '=', $now->format('Y-m-d'));
189        return $this;
190    }
191
192    public function addConditionDepartmentId($departmentId)
193    {
194        $this->leftJoin(
195            new Alias(Useraccount::TABLE_ASSIGNMENT, 'workstation_department'),
196            'workstation.NutzerID',
197            '=',
198            'workstation_department.nutzerid'
199        );
200        $this->query->where('workstation_department.behoerdenid', '=', $departmentId);
201        return $this;
202    }
203
204    public function reverseEntityMapping(\BO\Zmsentities\Workstation $entity)
205    {
206        $data = array();
207        if ((isset($entity['hint']) && '' == $entity['hint']) || ! isset($entity['hint'])) {
208            $data['aufrufzusatz'] = $entity->name;
209        } else {
210            $data['aufrufzusatz'] = $entity['hint'];
211        }
212
213        $data['Kalenderansicht'] = $entity->getQueuePreference('appointmentsOnly', true);
214        $data['clusteransicht'] = $entity->getQueuePreference('clusterEnabled', true);
215        if (isset($entity->scope['id'])) {
216            $data['StandortID'] = $entity->scope['id'];
217        }
218        $data['Arbeitsplatznr'] = $entity->name;
219
220        $data = array_filter($data, function ($value) {
221            return ($value !== null && $value !== false);
222        });
223        return $data;
224    }
225}