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