Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
97.08% covered (success)
97.08%
299 / 308
88.89% covered (warning)
88.89%
24 / 27
CRAP
0.00% covered (danger)
0.00%
0 / 1
Scope
97.08% covered (success)
97.08%
299 / 308
88.89% covered (warning)
88.89%
24 / 27
52
0.00% covered (danger)
0.00%
0 / 1
 getQueryLastWaitingNumber
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getQueryLastDisplayNumber
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getQueryGivenNumbersInContingent
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getQuerySimpleClusterMatch
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getQuerySimpleDepartmentMatch
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getQueryDepartmentIdByScopeId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getQueryClusterIdsByScopeId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getQueryReadImageData
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getQueryWriteImageData
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getQueryDeleteImage
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addJoin
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
2.01
 addRequiredJoins
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
1 / 1
7
 getEntityMapping
100.00% covered (success)
100.00%
96 / 96
100.00% covered (success)
100.00%
1 / 1
7
 addConditionScopeId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionScopeIds
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
 addConditionWithAdminEmail
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addSelectWorkstationCount
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 addConditionProviderId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionDepartmentId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionClusterId
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 reverseEntityMapping
100.00% covered (success)
100.00%
77 / 77
100.00% covered (success)
100.00%
1 / 1
7
 setEmergencyEntityMapping
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 setGhostWorkstationCountEntityMapping
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 postProcess
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 convertTimestamps
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
3
 setDefaultValues
100.00% covered (success)
100.00%
32 / 32
100.00% covered (success)
100.00%
1 / 1
2
 setIfEmpty
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace BO\Zmsdb\Query;
4
5class Scope extends Base implements MappingInterface
6{
7    /**
8     * @var String TABLE mysql table reference
9     */
10    const TABLE = 'standort';
11
12    const QUERY_BY_DEPARTMENTID = 'SELECT
13            scope.`StandortID` AS id
14        FROM `standort` scope
15        WHERE
16            scope.`BehoerdenID` = :department_id
17    ';
18
19    public function getQueryLastWaitingNumber()
20    {
21        return '
22            SELECT letztewartenr
23            FROM `standort` scope
24            WHERE scope.`StandortID` = :scope_id LIMIT 1 FOR UPDATE';
25    }
26
27    public function getQueryLastDisplayNumber()
28    {
29        return '
30            SELECT last_display_number
31            FROM `standort` scope
32            WHERE scope.`StandortID` = :scope_id LIMIT 1 FOR UPDATE';
33    }
34
35    public function getQueryGivenNumbersInContingent()
36    {
37        return '
38            SELECT *
39            FROM `standort` scope
40            WHERE
41                scope.`StandortID` = :scope_id AND
42                IF(
43                    scope.`wartenummernkontingent` > 0,
44                    IF(
45                        isNull(scope.`vergebenewartenummern`), 
46                        0, 
47                        scope.`vergebenewartenummern`
48                    ) < scope.`wartenummernkontingent`,
49                    scope.`StandortID`
50                )
51        ';
52    }
53
54    public function getQuerySimpleClusterMatch()
55    {
56        return '
57            SELECT standortID AS id
58            FROM `clusterzuordnung`
59            WHERE
60                clusterID = ?
61        ';
62    }
63
64    public function getQuerySimpleDepartmentMatch()
65    {
66        return '
67            SELECT s.StandortID AS id, p.name AS contact__name
68            FROM `standort` AS s
69            LEFT JOIN `provider` AS p ON s.InfoDienstleisterID = p.id
70                AND p.source = s.source
71            WHERE
72                s.BehoerdenID = ?
73        ';
74    }
75
76    public function getQueryDepartmentIdByScopeId()
77    {
78        return 'SELECT BehoerdenID FROM standort WHERE StandortID = ?';
79    }
80
81    public function getQueryClusterIdsByScopeId()
82    {
83        return 'SELECT clusterID FROM clusterzuordnung WHERE standortID = ?';
84    }
85
86    public function getQueryReadImageData()
87    {
88        return '
89            SELECT `imagecontent`, `imagename`
90            FROM `imagedata`
91            WHERE
92                `imagename` LIKE :imagename
93        ';
94    }
95
96    public function getQueryWriteImageData()
97    {
98        return '
99            REPLACE INTO `imagedata`
100            SET
101                imagename=:imagename,
102                imagecontent=:imagedata
103        ';
104    }
105
106    public function getQueryDeleteImage()
107    {
108        return '
109            DELETE FROM `imagedata`
110            WHERE
111                `imagename` LIKE :imagename
112        ';
113    }
114
115    public function addJoin()
116    {
117        if ($this->shouldLoadEntity('provider')) {
118            $this->leftJoin(
119                new Alias(Provider::getTablename(), 'provider'),
120                self::expression('scope.InfoDienstleisterID = provider.id && scope.source = provider.source')
121            );
122            $providerQuery = new Provider($this, $this->getPrefixed('provider__'));
123            return [$providerQuery];
124        }
125
126        return [];
127    }
128
129    protected function addRequiredJoins()
130    {
131
132        if ($this->shouldLoadEntity('scopedepartment')) {
133            $this->leftJoin(
134                new Alias(Department::TABLE, 'scopedepartment'),
135                'scope.BehoerdenID',
136                '=',
137                'scopedepartment.BehoerdenID'
138            );
139        }
140
141        if ($this->shouldLoadEntity('scopesms') && $this->shouldLoadEntity('scopedepartment')) {
142            $this->leftJoin(
143                new Alias('sms', 'scopesms'),
144                'scopedepartment.BehoerdenID',
145                '=',
146                'scopesms.BehoerdenID'
147            );
148        }
149
150        if ($this->shouldLoadEntity('scopemail') && $this->shouldLoadEntity('scopedepartment')) {
151            $this->leftJoin(
152                new Alias('email', 'scopemail'),
153                'scopedepartment.BehoerdenID',
154                '=',
155                'scopemail.BehoerdenID'
156            );
157        }
158
159        if ($this->shouldLoadEntity('scopeprovider')) {
160            $this->leftJoin(
161                new Alias(Provider::getTablename(), 'scopeprovider'),
162                self::expression('scope.InfoDienstleisterID = scopeprovider.id && scope.source = scopeprovider.source')
163            );
164        }
165    }
166
167    //Todo: now() Parameter to enable query cache
168    public function getEntityMapping()
169    {
170        return array_filter([
171            'hint' => 'scope.Hinweis',
172            'id' => 'scope.StandortID',
173            'contact__name' => $this->shouldLoadEntity('scopeprovider') ? 'scopeprovider.name' : '',
174            'contact__street' => 'scope.Adresse',
175            'contact__email' => 'scope.emailstandortadmin',
176            'contact__country' => self::expression('"Germany"'),
177            'lastChange' => 'scope.updateTimestamp',
178            'preferences__appointment__deallocationDuration' => 'scope.loeschdauer',
179            'preferences__appointment__infoForAppointment' => 'scope.info_for_appointment',
180            'preferences__appointment__infoForAllAppointments' => 'scope.info_for_all_appointments',
181            'preferences__appointment__endInDaysDefault' => 'scope.Termine_bis',
182            'preferences__appointment__multipleSlotsEnabled' => 'scope.mehrfachtermine',
183            'preferences__appointment__reservationDuration' => 'scope.reservierungsdauer',
184            'preferences__appointment__activationDuration' => 'scope.aktivierungsdauer',
185            'preferences__appointment__startInDaysDefault' => 'scope.Termine_ab',
186            'preferences__appointment__notificationConfirmationEnabled' =>
187                $this->shouldLoadEntity('scopesms')
188                    ? self::expression(
189                        'scopesms.enabled && scopesms.Absender != "" && scopesms.internetbestaetigung'
190                    )
191                : '',
192            'preferences__appointment__notificationHeadsUpEnabled' =>
193                $this->shouldLoadEntity('scopesms')
194                ? self::expression('scopesms.enabled && scopesms.Absender != "" && scopesms.interneterinnerung')
195                : '',
196            'preferences__client__amendmentActivated' => 'scope.anmerkungPflichtfeld',
197            'preferences__client__amendmentLabel' => 'scope.anmerkungLabel',
198            'preferences__client__emailFrom' => $this->shouldLoadEntity('scopemail')
199                ? 'scopemail.absenderadresse'
200                : '',
201            'preferences__client__emailRequired' => 'scope.emailPflichtfeld',
202            'preferences__client__emailConfirmationActivated' => 'scope.email_confirmation_activated',
203            'preferences__client__telephoneActivated' => 'scope.telefonaktiviert',
204            'preferences__client__telephoneRequired' => 'scope.telefonPflichtfeld',
205            'preferences__client__appointmentsPerMail' => 'scope.appointments_per_mail',
206            'preferences__client__slotsPerAppointment' => 'scope.slots_per_appointment',
207            'preferences__client__whitelistedMails' => 'scope.whitelisted_mails',
208            'preferences__client__customTextfieldActivated' => 'scope.custom_text_field_active',
209            'preferences__client__customTextfieldRequired' => 'scope.custom_text_field_required',
210            'preferences__client__customTextfieldLabel' => 'scope.custom_text_field_label',
211            'preferences__client__customTextfield2Activated' => 'scope.custom_text_field2_active',
212            'preferences__client__customTextfield2Required' => 'scope.custom_text_field2_required',
213            'preferences__client__customTextfield2Label' => 'scope.custom_text_field2_label',
214            'preferences__client__captchaActivatedRequired' => 'scope.captcha_activated_required',
215            'preferences__client__adminMailOnAppointment' => 'scope.admin_mail_on_appointment',
216            'preferences__client__adminMailOnDeleted' => 'scope.admin_mail_on_deleted',
217            'preferences__client__adminMailOnUpdated' => 'scope.admin_mail_on_updated',
218            'preferences__client__adminMailOnMailSent' => 'scope.admin_mail_on_mail_sent',
219            'preferences__notifications__confirmationContent' => 'scope.smsbestaetigungstext',
220            'preferences__notifications__headsUpContent' => 'scope.smsbenachrichtigungstext',
221            'preferences__notifications__headsUpTime' => 'scope.smsbenachrichtigungsfrist',
222            'preferences__queue__callCountMax' => 'scope.anzahlwiederaufruf',
223            'preferences__queue__callDisplayText' => 'scope.aufrufanzeigetext',
224            'preferences__queue__firstNumber' => 'scope.startwartenr',
225            'preferences__queue__lastNumber' => 'scope.endwartenr',
226            'preferences__queue__maxNumberContingent' => 'scope.wartenummernkontingent',
227            'preferences__queue__displayNumberPrefix' => 'scope.display_number_prefix',
228            'preferences__queue__processingTimeAverage' => self::expression(
229                'FLOOR(TIME_TO_SEC(`scope`.`Bearbeitungszeit`) / 60)'
230            ),
231            'preferences__queue__statisticsEnabled' => self::expression('NOT `scope`.`ohnestatistik`'),
232            'preferences__survey__emailContent' => 'scope.kundenbef_emailtext',
233            'preferences__survey__enabled' => 'scope.kundenbefragung',
234            'preferences__survey__label' => 'scope.kundenbef_label',
235            'preferences__ticketprinter__buttonName' => self::expression(
236                'IF(`scope`.`standortinfozeile`!="", `scope`.`standortinfozeile`, `scope`.`Bezeichnung`)'
237            ),
238            'preferences__ticketprinter__confirmationEnabled' => 'scope.smswmsbestaetigung',
239            'preferences__ticketprinter__deactivatedText' => 'scope.wartenrhinweis',
240            'preferences__ticketprinter__notificationsAmendmentEnabled' => 'scope.smsnachtrag',
241            'preferences__ticketprinter__notificationsEnabled' => 'scope.smswarteschlange',
242            'preferences__ticketprinter__notificationsDelay' => 'scope.smskioskangebotsfrist',
243            'preferences__workstation__emergencyEnabled' => 'scope.notruffunktion',
244            'preferences__workstation__emergencyRefreshInterval' => self::expression(
245                '(SELECT `value` FROM config WHERE `name`="emergency__refreshInterval")'
246            ),
247            'shortName' => 'scope.standortkuerzel',
248            'status__emergency__acceptedByWorkstation' => 'scope.notrufantwort',
249            'status__emergency__activated' => 'scope.notrufausgeloest',
250            'status__emergency__calledByWorkstation' => 'scope.notrufinitiierung',
251            'status__queue__ghostWorkstationCount' => 'scope.virtuellesachbearbeiterzahl',
252            'status__queue__givenNumberCount' => 'scope.vergebenewartenummern',
253            'status__queue__lastGivenNumber' => 'scope.letztewartenr',
254            'status__queue__lastDisplayNumber' => 'scope.last_display_number',
255            'status__queue__maxDisplayNumber' => 'scope.max_display_number',
256            'status__queue__lastGivenNumberTimestamp' => 'scope.wartenrdatum',
257            'status__ticketprinter__deactivated' => 'scope.wartenrsperre',
258            'provider__id' => $this->shouldLoadEntity('scopeprovider') ? self::expression(
259                'IF(`scopeprovider`.`id`!="", `scopeprovider`.`id`, `scope`.`InfoDienstleisterID`)'
260            ) : '',
261            'provider__source' => $this->shouldLoadEntity('scopeprovider') ? self::expression(
262                'IF(`scopeprovider`.`source`!="", `scopeprovider`.`source`, `scope`.`source`)'
263            ) : '',
264            'source' => 'scope.source'
265        ], 'strlen');
266    }
267
268    public function addConditionScopeId($scopeId)
269    {
270        $this->query->where('scope.StandortID', '=', $scopeId);
271        return $this;
272    }
273
274    public function addConditionScopeIds(array $scopeIds)
275    {
276        $scopeIds = array_values(array_unique(array_map('intval', $scopeIds)));
277        if (!$scopeIds) {
278            $this->query->where(self::expression('1'), '=', 0);
279            return $this;
280        }
281
282        $this->query->whereIn('scope.StandortID', $scopeIds);
283        return $this;
284    }
285
286    public function addConditionWithAdminEmail()
287    {
288        $this->query->where('scope.emailstandortadmin', '!=', '');
289        return $this;
290    }
291
292    public function addSelectWorkstationCount($dateTime)
293    {
294        $this->query->select(
295            ['status__queue__workstationCount' => self::expression('
296                IF(
297                    `scope`.`virtuellesachbearbeiterzahl` > -1,
298                    `scope`.`virtuellesachbearbeiterzahl`,
299                    (
300                        SELECT COUNT(*)
301                        FROM nutzer
302                        WHERE nutzer.StandortID = scope.StandortID
303                        AND nutzer.Datum = "' . $dateTime->format('Y-m-d') . '"
304                        AND nutzer.Arbeitsplatznr <> 0
305                    )
306                )
307            ')
308            ]
309        );
310    }
311
312    public function addConditionProviderId($providerId)
313    {
314        $this->query->where('scope.InfoDienstleisterID', '=', $providerId);
315        return $this;
316    }
317
318    public function addConditionDepartmentId($departmentId)
319    {
320        $this->query->where('scope.BehoerdenID', '=', $departmentId);
321        return $this;
322    }
323
324    public function addConditionClusterId($clusterId)
325    {
326        $this->leftJoin(
327            new Alias('clusterzuordnung', 'cluster_scope'),
328            'scope.StandortID',
329            '=',
330            'cluster_scope.standortID'
331        );
332        $this->query->where('cluster_scope.clusterID', '=', $clusterId);
333        return $this;
334    }
335
336    public function reverseEntityMapping(\BO\Zmsentities\Scope $entity, $parentId = null)
337    {
338        $data = array();
339        if ($parentId) {
340            $data['BehoerdenID'] = $parentId;
341        }
342        $data['InfoDienstleisterID'] = $entity->getProviderId();
343        $data['emailstandortadmin'] = $entity->getContactEMail();
344        $data['standortinfozeile'] = $entity->getScopeInfo();
345        $data['Hinweis'] = $entity->getScopeHint();
346        $data['Bezeichnung'] = $entity->getName();
347        $data['standortkuerzel'] = $entity->shortName;
348        $data['Adresse'] = (isset($entity->contact['street'])) ? $entity->contact['street'] : '';
349        $data['loeschdauer'] = $entity->getPreference('appointment', 'deallocationDuration');
350        $data['info_for_appointment'] = $entity->getPreference('appointment', 'infoForAppointment');
351        $data['info_for_all_appointments'] = $entity->getPreference('appointment', 'infoForAllAppointments');
352        $data['Termine_bis'] = $entity->getPreference('appointment', 'endInDaysDefault');
353        $data['Termine_ab'] = $entity->getPreference('appointment', 'startInDaysDefault');
354        $data['mehrfachtermine'] = $entity->getPreference('appointment', 'multipleSlotsEnabled', true);
355        // notificationConfirmationEnabled and notificationHeadsUpEnabled are saved in department!
356        $data['reservierungsdauer'] = $entity->getPreference('appointment', 'reservationDuration');
357        $data['aktivierungsdauer'] = $entity->getPreference('appointment', 'activationDuration');
358        $data['anmerkungPflichtfeld'] = $entity->getPreference('client', 'amendmentActivated', true);
359        $data['anmerkungLabel'] = $entity->getPreference('client', 'amendmentLabel');
360        $data['emailPflichtfeld'] = $entity->getPreference('client', 'emailRequired', true);
361        $data['email_confirmation_activated'] = $entity->getPreference('client', 'emailConfirmationActivated', true);
362        $data['telefonaktiviert'] = $entity->getPreference('client', 'telephoneActivated', true);
363        $data['telefonPflichtfeld'] = $entity->getPreference('client', 'telephoneRequired', true);
364        $data['custom_text_field_active'] = $entity->getPreference('client', 'customTextfieldActivated', true);
365        $data['custom_text_field_required'] = $entity->getPreference('client', 'customTextfieldRequired', true);
366        $data['custom_text_field_label'] = $entity->getPreference('client', 'customTextfieldLabel');
367        $data['custom_text_field2_active'] = $entity->getPreference('client', 'customTextfield2Activated', true);
368        $data['custom_text_field2_required'] = $entity->getPreference('client', 'customTextfield2Required', true);
369        $data['custom_text_field2_label'] = $entity->getPreference('client', 'customTextfield2Label');
370        $data['captcha_activated_required'] = $entity->getPreference('client', 'captchaActivatedRequired');
371        $data['appointments_per_mail'] = (int) $entity->getPreference('client', 'appointmentsPerMail');
372        $data['slots_per_appointment'] = (int) $entity->getPreference('client', 'slotsPerAppointment');
373        $data['info_for_appointment'] = $entity->getPreference('appointment', 'infoForAppointment');
374        $data['whitelisted_mails'] = $entity->getPreference('client', 'whitelistedMails');
375        $data['admin_mail_on_appointment'] = $entity->getPreference('client', 'adminMailOnAppointment', true);
376        $data['admin_mail_on_deleted'] = $entity->getPreference('client', 'adminMailOnDeleted');
377        $data['admin_mail_on_updated'] = $entity->getPreference('client', 'adminMailOnUpdated', true);
378        $data['admin_mail_on_mail_sent'] = $entity->getPreference('client', 'adminMailOnMailSent', true);
379        $data['smsbestaetigungstext'] = $entity->getPreference('notifications', 'confirmationContent');
380        $data['smsbenachrichtigungstext'] = $entity->getPreference('notifications', 'headsUpContent');
381        $data['smsbenachrichtigungsfrist'] = $entity->getPreference('notifications', 'headsUpTime');
382        $data['anzahlwiederaufruf'] = $entity->getPreference('queue', 'callCountMax');
383        $data['aufrufanzeigetext'] = $entity->getPreference('queue', 'callDisplayText', false, '');
384        $data['startwartenr'] = $entity->getPreference('queue', 'firstNumber');
385        $data['endwartenr'] = $entity->getPreference('queue', 'lastNumber');
386        $data['wartenummernkontingent'] = $entity->getPreference('queue', 'maxNumberContingent');
387        $data['display_number_prefix'] = $entity->getPreference('queue', 'displayNumberPrefix')
388            ? strtoupper($entity->getPreference('queue', 'displayNumberPrefix'))
389            : '';
390        $data['Bearbeitungszeit'] = gmdate("H:i", $entity->getPreference('queue', 'processingTimeAverage') * 60);
391        $data['ohnestatistik'] = (0 == $entity->getPreference('queue', 'statisticsEnabled', true)) ? 1 : 0;
392        $data['kundenbef_emailtext'] = $entity->getPreference('survey', 'emailContent');
393        $data['kundenbefragung'] = $entity->getPreference('survey', 'enabled', true);
394        $data['kundenbef_label'] = $entity->getPreference('survey', 'label');
395        $data['smswmsbestaetigung'] = $entity->getPreference('ticketprinter', 'confirmationEnabled', true);
396        $data['wartenrhinweis'] = $entity->getPreference('ticketprinter', 'deactivatedText', false, '');
397        $data['smsnachtrag'] = $entity->getPreference('ticketprinter', 'notificationsAmendmentEnabled', true);
398        $data['smswarteschlange'] = $entity->getPreference('ticketprinter', 'notificationsEnabled', true);
399        $data['smskioskangebotsfrist'] = $entity->getPreference('ticketprinter', 'notificationsDelay');
400        $data['notruffunktion'] = $entity->getPreference('workstation', 'emergencyEnabled', true);
401        $data['notrufantwort'] = $entity->getStatus('emergency', 'acceptedByWorkstation');
402        $data['notrufausgeloest'] = $entity->getStatus('emergency', 'activated');
403        $data['notrufinitiierung'] = $entity->getStatus('emergency', 'calledByWorkstation');
404        $data['virtuellesachbearbeiterzahl'] = $entity->getStatus('queue', 'ghostWorkstationCount');
405        $data['vergebenewartenummern'] = $entity->getStatus('queue', 'givenNumberCount');
406        $data['letztewartenr'] = $entity->getStatus('queue', 'lastGivenNumber');
407        $data['last_display_number'] = $entity->getStatus('queue', 'lastDisplayNumber');
408        $data['max_display_number'] = $entity->getStatus('queue', 'maxDisplayNumber');
409        $lastGivenTimestamp = $entity->getStatus('queue', 'lastGivenNumberTimestamp');
410        $data['wartenrdatum'] = ($lastGivenTimestamp) ? date('Y-m-d', $lastGivenTimestamp) : null;
411        $data['wartenrsperre'] = $entity->getStatus('ticketprinter', 'deactivated');
412        $data['source'] = $entity->getProvider()->source;
413
414        $data = array_filter($data, function ($value) {
415            return ($value !== null && $value !== false);
416        });
417        return $data;
418    }
419
420    public function setEmergencyEntityMapping(\BO\Zmsentities\Scope $entity)
421    {
422        $data['notrufantwort'] = ($entity->toProperty()->status->emergency->acceptedByWorkstation->get(-1));
423        $data['notrufausgeloest'] = intval($entity->toProperty()->status->emergency->activated->get(0));
424        $data['notrufinitiierung'] = ($entity->toProperty()->status->emergency->calledByWorkstation->get(-1));
425        return $data;
426    }
427
428    public function setGhostWorkstationCountEntityMapping(\BO\Zmsentities\Scope $entity, \DateTimeInterface $dateTime)
429    {
430        $data['virtuellesachbearbeiterzahl'] = $entity->getStatus('queue', 'ghostWorkstationCount');
431        $data['datumvirtuellesachbearbeiterzahl'] = $dateTime->format('Y-m-d');
432        return $data;
433    }
434
435    public function postProcess($data)
436    {
437        $data = $this->convertTimestamps($data);
438        $data = $this->setDefaultValues($data);
439        return $data;
440    }
441
442
443    private function convertTimestamps($data)
444    {
445        $lastGivenNumberTimestampKey = $this->getPrefixed("status__queue__lastGivenNumberTimestamp");
446        $lastGivenNumberTimestamp = $data[$lastGivenNumberTimestampKey] ?? null;
447        $data[$lastGivenNumberTimestampKey] = $lastGivenNumberTimestamp !== null ? strtotime($lastGivenNumberTimestamp) : null;
448
449        $lastChangeKey = $this->getPrefixed("lastChange");
450        $lastChange = $data[$lastChangeKey] ?? null;
451        if ($lastChange !== null) {
452            $data[$lastChangeKey] = (new \DateTime($lastChange . \BO\Zmsdb\Connection\Select::$connectionTimezone))
453                ->getTimestamp();
454        } else {
455            $data[$lastChangeKey] = null;
456        }
457
458        return $data;
459    }
460
461    private function setDefaultValues($data)
462    {
463        if ($this->shouldLoadEntity('scopemail')) {
464            $this->setIfEmpty($data, 'preferences__client__emailFrom', [
465                'preferences__client__emailRequired' => 0
466            ]);
467        }
468
469        $this->setIfEmpty($data, 'preferences__client__telephoneActivated', [
470            'preferences__client__telephoneRequired' => 0
471        ]);
472
473        $this->setIfEmpty($data, 'preferences__client__emailConfirmationActivated', [
474            'preferences__client__emailConfirmationActivated' => 0
475        ]);
476
477        $this->setIfEmpty($data, 'contact__email', [
478            'preferences__client__adminMailOnAppointment' => 0,
479            'preferences__client__adminMailOnDeleted' => 0,
480            'preferences__client__adminMailOnUpdated' => 0,
481            'preferences__client__adminMailOnMailSent' => 0,
482        ]);
483
484        $this->setIfEmpty($data, 'preferences__client__customTextfieldActivated', [
485            'preferences__client__customTextfieldRequired' => 0
486        ]);
487
488        $this->setIfEmpty($data, 'preferences__client__customTextfield2Activated', [
489            'preferences__client__customTextfield2Required' => 0
490        ]);
491
492        $this->setIfEmpty($data, 'preferences__client__appointmentsPerMail', [
493            'preferences__client__appointmentsPerMail' => null
494        ]);
495
496        $this->setIfEmpty($data, 'preferences__client__slotsPerAppointment', [
497            'preferences__client__slotsPerAppointment' => null
498        ]);
499
500        $this->setIfEmpty($data, 'preferences__client__whitelistedMails', [
501            'preferences__client__whitelistedMails' => null
502        ]);
503
504        return $data;
505    }
506
507    private function setIfEmpty(&$data, $checkKey, array $setKeys)
508    {
509        if (!$data[$this->getPrefixed($checkKey)]) {
510            foreach ($setKeys as $key => $value) {
511                $data[$this->getPrefixed($key)] = $value;
512            }
513        }
514    }
515}