Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
98.21% covered (success)
98.21%
275 / 280
88.89% covered (warning)
88.89%
24 / 27
CRAP
0.00% covered (danger)
0.00%
0 / 1
Scope
98.21% covered (success)
98.21%
275 / 280
88.89% covered (warning)
88.89%
24 / 27
49
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%
19 / 19
100.00% covered (success)
100.00%
1 / 1
5
 getEntityMapping
100.00% covered (success)
100.00%
82 / 82
100.00% covered (success)
100.00%
1 / 1
6
 addConditionScopeId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionScopeIds
66.67% covered (warning)
66.67%
4 / 6
0.00% covered (danger)
0.00%
0 / 1
2.15
 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%
70 / 70
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\Zmsbackend\Query;
4
5class Scope extends Base implements MappingInterface
6{
7    /**
8     * @var String TABLE mysql table reference
9     */
10    const string TABLE = 'standort';
11
12    const string 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(): string
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(): string
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(): string
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(): string
55    {
56        return '
57            SELECT s.StandortID AS id, p.name AS contact__name, s.standortkuerzel AS shortName
58            FROM `clusterzuordnung` AS cz
59            INNER JOIN `standort` AS s ON s.StandortID = cz.standortID
60            LEFT JOIN `provider` AS p ON s.InfoDienstleisterID = p.id
61                AND p.source = s.source
62            WHERE
63                cz.clusterID = ?
64        ';
65    }
66
67    public function getQuerySimpleDepartmentMatch(): string
68    {
69        return '
70            SELECT s.StandortID AS id, p.name AS contact__name, s.standortkuerzel AS shortName
71            FROM `standort` AS s
72            LEFT JOIN `provider` AS p ON s.InfoDienstleisterID = p.id
73                AND p.source = s.source
74            WHERE
75                s.BehoerdenID = ?
76        ';
77    }
78
79    public function getQueryDepartmentIdByScopeId(): string
80    {
81        return 'SELECT BehoerdenID FROM standort WHERE StandortID = ?';
82    }
83
84    public function getQueryClusterIdsByScopeId(): string
85    {
86        return 'SELECT clusterID FROM clusterzuordnung WHERE standortID = ?';
87    }
88
89    public function getQueryReadImageData(): string
90    {
91        return '
92            SELECT `imagecontent`, `imagename`
93            FROM `imagedata`
94            WHERE
95                `imagename` LIKE :imagename
96        ';
97    }
98
99    public function getQueryWriteImageData(): string
100    {
101        return '
102            REPLACE INTO `imagedata`
103            SET
104                imagename=:imagename,
105                imagecontent=:imagedata
106        ';
107    }
108
109    public function getQueryDeleteImage(): string
110    {
111        return '
112            DELETE FROM `imagedata`
113            WHERE
114                `imagename` LIKE :imagename
115        ';
116    }
117
118    #[\Override]
119    public function addJoin()
120    {
121        if ($this->shouldLoadEntity('provider')) {
122            $this->leftJoin(
123                new \BO\Zmsbackend\Query\Alias(\BO\Zmsbackend\Provider\Repository\Provider::getTablename(), 'provider'),
124                self::expression('scope.InfoDienstleisterID = provider.id && scope.source = provider.source')
125            );
126            $providerQuery = new \BO\Zmsbackend\Provider\Repository\Provider($this, $this->getPrefixed('provider__'));
127            return [$providerQuery];
128        }
129
130        return [];
131    }
132
133    /**
134     * @return void
135     */
136    #[\Override]
137    protected function addRequiredJoins()
138    {
139
140        if ($this->shouldLoadEntity('scopedepartment')) {
141            $this->leftJoin(
142                new \BO\Zmsbackend\Query\Alias(\BO\Zmsbackend\Department\Repository\Department::TABLE, 'scopedepartment'),
143                'scope.BehoerdenID',
144                '=',
145                'scopedepartment.BehoerdenID'
146            );
147        }
148
149        if ($this->shouldLoadEntity('scopemail') && $this->shouldLoadEntity('scopedepartment')) {
150            $this->leftJoin(
151                new \BO\Zmsbackend\Query\Alias('email', 'scopemail'),
152                'scopedepartment.BehoerdenID',
153                '=',
154                'scopemail.BehoerdenID'
155            );
156        }
157
158        if ($this->shouldLoadEntity('scopeprovider')) {
159            $this->leftJoin(
160                new \BO\Zmsbackend\Query\Alias(\BO\Zmsbackend\Provider\Repository\Provider::getTablename(), 'scopeprovider'),
161                self::expression('scope.InfoDienstleisterID = scopeprovider.id && scope.source = scopeprovider.source')
162            );
163        }
164    }
165
166    //Todo: now() Parameter to enable query cache
167    /**
168     * @return (Builder\Expression|string)[]
169     *
170     */
171    #[\Override]
172    public function getEntityMapping()
173    {
174        return array_filter([
175            'hint' => 'scope.Hinweis',
176            'id' => 'scope.StandortID',
177            'contact__name' => $this->shouldLoadEntity('scopeprovider') ? 'scopeprovider.name' : '',
178            'contact__street' => 'scope.Adresse',
179            'contact__email' => 'scope.emailstandortadmin',
180            'contact__country' => self::expression('"Germany"'),
181            'lastChange' => 'scope.updateTimestamp',
182            'preferences__appointment__deallocationDuration' => 'scope.loeschdauer',
183            'preferences__appointment__infoForAppointment' => 'scope.info_for_appointment',
184            'preferences__appointment__infoForAllAppointments' => 'scope.info_for_all_appointments',
185            'preferences__appointment__endInDaysDefault' => 'scope.Termine_bis',
186            'preferences__appointment__multipleSlotsEnabled' => 'scope.mehrfachtermine',
187            'preferences__appointment__reservationDuration' => 'scope.reservierungsdauer',
188            'preferences__appointment__activationDuration' => 'scope.aktivierungsdauer',
189            'preferences__appointment__startInDaysDefault' => 'scope.Termine_ab',
190            'preferences__client__amendmentActivated' => 'scope.anmerkungPflichtfeld',
191            'preferences__client__amendmentLabel' => 'scope.anmerkungLabel',
192            'preferences__client__emailFrom' => $this->shouldLoadEntity('scopemail')
193                ? 'scopemail.absenderadresse'
194                : '',
195            'preferences__client__emailRequired' => 'scope.emailPflichtfeld',
196            'preferences__client__emailConfirmationActivated' => 'scope.email_confirmation_activated',
197            'preferences__client__telephoneActivated' => 'scope.telefonaktiviert',
198            'preferences__client__telephoneRequired' => 'scope.telefonPflichtfeld',
199            'preferences__client__appointmentsPerMail' => 'scope.appointments_per_mail',
200            'preferences__client__slotsPerAppointment' => 'scope.slots_per_appointment',
201            'preferences__client__whitelistedMails' => 'scope.whitelisted_mails',
202            'preferences__client__customTextfieldActivated' => 'scope.custom_text_field_active',
203            'preferences__client__customTextfieldRequired' => 'scope.custom_text_field_required',
204            'preferences__client__customTextfieldLabel' => 'scope.custom_text_field_label',
205            'preferences__client__customTextfield2Activated' => 'scope.custom_text_field2_active',
206            'preferences__client__customTextfield2Required' => 'scope.custom_text_field2_required',
207            'preferences__client__customTextfield2Label' => 'scope.custom_text_field2_label',
208            'preferences__client__captchaActivatedRequired' => 'scope.captcha_activated_required',
209            'preferences__client__adminMailOnAppointment' => 'scope.admin_mail_on_appointment',
210            'preferences__client__adminMailOnDeleted' => 'scope.admin_mail_on_deleted',
211            'preferences__client__adminMailOnUpdated' => 'scope.admin_mail_on_updated',
212            'preferences__client__adminMailOnMailSent' => 'scope.admin_mail_on_mail_sent',
213            'preferences__queue__callCountMax' => 'scope.anzahlwiederaufruf',
214            'preferences__queue__callDisplayText' => 'scope.aufrufanzeigetext',
215            'preferences__queue__firstNumber' => 'scope.startwartenr',
216            'preferences__queue__lastNumber' => 'scope.endwartenr',
217            'preferences__queue__maxNumberContingent' => 'scope.wartenummernkontingent',
218            'preferences__queue__displayNumberPrefix' => 'scope.display_number_prefix',
219            'preferences__queue__processingTimeAverage' => self::expression(
220                'FLOOR(TIME_TO_SEC(`scope`.`Bearbeitungszeit`) / 60)'
221            ),
222            'preferences__queue__statisticsEnabled' => self::expression('NOT `scope`.`ohnestatistik`'),
223            'preferences__survey__emailContent' => 'scope.kundenbef_emailtext',
224            'preferences__survey__enabled' => 'scope.kundenbefragung',
225            'preferences__survey__label' => 'scope.kundenbef_label',
226            'preferences__ticketprinter__buttonName' => self::expression(
227                'IF(`scope`.`standortinfozeile`!="", `scope`.`standortinfozeile`, `scope`.`Bezeichnung`)'
228            ),
229            'preferences__ticketprinter__deactivatedText' => 'scope.wartenrhinweis',
230            'preferences__workstation__emergencyEnabled' => 'scope.notruffunktion',
231            'preferences__workstation__emergencyRefreshInterval' => self::expression(
232                '(SELECT `value` FROM config WHERE `name`="emergency__refreshInterval")'
233            ),
234            'shortName' => 'scope.standortkuerzel',
235            'status__emergency__acceptedByWorkstation' => 'scope.notrufantwort',
236            'status__emergency__activated' => 'scope.notrufausgeloest',
237            'status__emergency__calledByWorkstation' => 'scope.notrufinitiierung',
238            'status__queue__ghostWorkstationCount' => 'scope.virtuellesachbearbeiterzahl',
239            'status__queue__givenNumberCount' => 'scope.vergebenewartenummern',
240            'status__queue__lastGivenNumber' => 'scope.letztewartenr',
241            'status__queue__lastDisplayNumber' => 'scope.last_display_number',
242            'status__queue__maxDisplayNumber' => 'scope.max_display_number',
243            'status__queue__lastGivenNumberTimestamp' => 'scope.wartenrdatum',
244            'status__ticketprinter__deactivated' => 'scope.wartenrsperre',
245            'provider__id' => $this->shouldLoadEntity('scopeprovider') ? self::expression(
246                'IF(`scopeprovider`.`id`!="", `scopeprovider`.`id`, `scope`.`InfoDienstleisterID`)'
247            ) : '',
248            'provider__source' => $this->shouldLoadEntity('scopeprovider') ? self::expression(
249                'IF(`scopeprovider`.`source`!="", `scopeprovider`.`source`, `scope`.`source`)'
250            ) : '',
251            'provider__data' => $this->shouldLoadEntity('scopeprovider') ? self::expression(
252                'IFNULL(`scopeprovider`.`data`, "{}")'
253            ) : '',
254            'source' => 'scope.source'
255        ], 'strlen');
256    }
257
258    public function addConditionScopeId($scopeId): static
259    {
260        $this->query->where('scope.StandortID', '=', $scopeId);
261        return $this;
262    }
263
264    public function addConditionScopeIds(array $scopeIds): static
265    {
266        $scopeIds = array_values(array_unique(array_map('intval', $scopeIds)));
267        if (!$scopeIds) {
268            $this->query->where(self::expression('1'), '=', 0);
269            return $this;
270        }
271
272        $this->query->whereIn('scope.StandortID', $scopeIds);
273        return $this;
274    }
275
276    public function addConditionWithAdminEmail(): static
277    {
278        $this->query->where('scope.emailstandortadmin', '!=', '');
279        return $this;
280    }
281
282    /**
283     * @psalm-api
284     */
285    public function addSelectWorkstationCount($dateTime): void
286    {
287        $this->query->select(
288            ['status__queue__workstationCount' => self::expression('
289                IF(
290                    `scope`.`virtuellesachbearbeiterzahl` > -1,
291                    `scope`.`virtuellesachbearbeiterzahl`,
292                    (
293                        SELECT COUNT(*)
294                        FROM nutzer
295                        WHERE nutzer.StandortID = scope.StandortID
296                        AND nutzer.Datum = "' . $dateTime->format('Y-m-d') . '"
297                        AND nutzer.Arbeitsplatznr <> 0
298                    )
299                )
300            ')
301            ]
302        );
303    }
304
305    public function addConditionProviderId($providerId): static
306    {
307        $this->query->where('scope.InfoDienstleisterID', '=', $providerId);
308        return $this;
309    }
310
311    public function addConditionDepartmentId($departmentId): static
312    {
313        $this->query->where('scope.BehoerdenID', '=', $departmentId);
314        return $this;
315    }
316
317    public function addConditionClusterId($clusterId): static
318    {
319        $this->leftJoin(
320            new \BO\Zmsbackend\Query\Alias('clusterzuordnung', 'cluster_scope'),
321            'scope.StandortID',
322            '=',
323            'cluster_scope.standortID'
324        );
325        $this->query->where('cluster_scope.clusterID', '=', $clusterId);
326        return $this;
327    }
328
329    /**
330     * @return (int|mixed|string)[]
331     *
332     */
333    public function reverseEntityMapping(\BO\Zmsentities\Scope $entity, $parentId = null): array
334    {
335        $data = array();
336        if ($parentId) {
337            $data['BehoerdenID'] = $parentId;
338        }
339        $data['InfoDienstleisterID'] = $entity->getProviderId();
340        $data['emailstandortadmin'] = $entity->getContactEMail();
341        $data['standortinfozeile'] = $entity->getScopeInfo();
342        $data['Hinweis'] = $entity->getScopeHint();
343        $data['Bezeichnung'] = $entity->getName();
344        $data['standortkuerzel'] = $entity->shortName;
345        $data['Adresse'] = (isset($entity->contact['street'])) ? $entity->contact['street'] : '';
346        $data['loeschdauer'] = $entity->getPreference('appointment', 'deallocationDuration');
347        $data['info_for_appointment'] = $entity->getPreference('appointment', 'infoForAppointment');
348        $data['info_for_all_appointments'] = $entity->getPreference('appointment', 'infoForAllAppointments');
349        $data['Termine_bis'] = $entity->getPreference('appointment', 'endInDaysDefault');
350        $data['Termine_ab'] = $entity->getPreference('appointment', 'startInDaysDefault');
351        $data['mehrfachtermine'] = $entity->getPreference('appointment', 'multipleSlotsEnabled', true);
352        $data['reservierungsdauer'] = $entity->getPreference('appointment', 'reservationDuration');
353        $data['aktivierungsdauer'] = $entity->getPreference('appointment', 'activationDuration');
354        $data['anmerkungPflichtfeld'] = $entity->getPreference('client', 'amendmentActivated', true);
355        $data['anmerkungLabel'] = $entity->getPreference('client', 'amendmentLabel');
356        $data['emailPflichtfeld'] = $entity->getPreference('client', 'emailRequired', true);
357        $data['email_confirmation_activated'] = $entity->getPreference('client', 'emailConfirmationActivated', true);
358        $data['telefonaktiviert'] = $entity->getPreference('client', 'telephoneActivated', true);
359        $data['telefonPflichtfeld'] = $entity->getPreference('client', 'telephoneRequired', true);
360        $data['custom_text_field_active'] = $entity->getPreference('client', 'customTextfieldActivated', true);
361        $data['custom_text_field_required'] = $entity->getPreference('client', 'customTextfieldRequired', true);
362        $data['custom_text_field_label'] = $entity->getPreference('client', 'customTextfieldLabel');
363        $data['custom_text_field2_active'] = $entity->getPreference('client', 'customTextfield2Activated', true);
364        $data['custom_text_field2_required'] = $entity->getPreference('client', 'customTextfield2Required', true);
365        $data['custom_text_field2_label'] = $entity->getPreference('client', 'customTextfield2Label');
366        $data['captcha_activated_required'] = $entity->getPreference('client', 'captchaActivatedRequired');
367        $data['appointments_per_mail'] = (int) $entity->getPreference('client', 'appointmentsPerMail');
368        $data['slots_per_appointment'] = (int) $entity->getPreference('client', 'slotsPerAppointment');
369        $data['info_for_appointment'] = $entity->getPreference('appointment', 'infoForAppointment');
370        $data['whitelisted_mails'] = $entity->getPreference('client', 'whitelistedMails');
371        $data['admin_mail_on_appointment'] = $entity->getPreference('client', 'adminMailOnAppointment', true);
372        $data['admin_mail_on_deleted'] = $entity->getPreference('client', 'adminMailOnDeleted');
373        $data['admin_mail_on_updated'] = $entity->getPreference('client', 'adminMailOnUpdated', true);
374        $data['admin_mail_on_mail_sent'] = $entity->getPreference('client', 'adminMailOnMailSent', true);
375        $data['anzahlwiederaufruf'] = $entity->getPreference('queue', 'callCountMax');
376        $data['aufrufanzeigetext'] = $entity->getPreference('queue', 'callDisplayText', false, '');
377        $data['startwartenr'] = $entity->getPreference('queue', 'firstNumber');
378        $data['endwartenr'] = $entity->getPreference('queue', 'lastNumber');
379        $data['wartenummernkontingent'] = $entity->getPreference('queue', 'maxNumberContingent');
380        $data['display_number_prefix'] = $entity->getPreference('queue', 'displayNumberPrefix')
381            ? strtoupper($entity->getPreference('queue', 'displayNumberPrefix'))
382            : '';
383        $data['Bearbeitungszeit'] = gmdate("H:i", $entity->getPreference('queue', 'processingTimeAverage') * 60);
384        $data['ohnestatistik'] = (0 == $entity->getPreference('queue', 'statisticsEnabled', true)) ? 1 : 0;
385        $data['kundenbef_emailtext'] = $entity->getPreference('survey', 'emailContent');
386        $data['kundenbefragung'] = $entity->getPreference('survey', 'enabled', true);
387        $data['kundenbef_label'] = $entity->getPreference('survey', 'label');
388        $data['wartenrhinweis'] = $entity->getPreference('ticketprinter', 'deactivatedText', false, '');
389        $data['notruffunktion'] = $entity->getPreference('workstation', 'emergencyEnabled', true);
390        $data['notrufantwort'] = $entity->getStatus('emergency', 'acceptedByWorkstation');
391        $data['notrufausgeloest'] = $entity->getStatus('emergency', 'activated');
392        $data['notrufinitiierung'] = $entity->getStatus('emergency', 'calledByWorkstation');
393        $data['virtuellesachbearbeiterzahl'] = $entity->getStatus('queue', 'ghostWorkstationCount');
394        $data['vergebenewartenummern'] = $entity->getStatus('queue', 'givenNumberCount');
395        $data['letztewartenr'] = $entity->getStatus('queue', 'lastGivenNumber');
396        $data['last_display_number'] = $entity->getStatus('queue', 'lastDisplayNumber');
397        $data['max_display_number'] = $entity->getStatus('queue', 'maxDisplayNumber');
398        $lastGivenTimestamp = $entity->getStatus('queue', 'lastGivenNumberTimestamp');
399        $data['wartenrdatum'] = ($lastGivenTimestamp) ? date('Y-m-d', $lastGivenTimestamp) : null;
400        $data['wartenrsperre'] = $entity->getStatus('ticketprinter', 'deactivated');
401        $data['source'] = $entity->getProvider()->source;
402
403        $data = array_filter($data, function ($value) {
404            return ($value !== null && $value !== false);
405        });
406        return $data;
407    }
408
409    /**
410     * @return (int|mixed)[]
411     *
412     */
413    public function setEmergencyEntityMapping(\BO\Zmsentities\Scope $entity): array
414    {
415        $data['notrufantwort'] = ($entity->toProperty()->status->emergency->acceptedByWorkstation->get(-1));
416        $data['notrufausgeloest'] = intval($entity->toProperty()->status->emergency->activated->get(0));
417        $data['notrufinitiierung'] = ($entity->toProperty()->status->emergency->calledByWorkstation->get(-1));
418        return $data;
419    }
420
421    /**
422     * @return (mixed|string)[]
423     *
424     */
425    public function setGhostWorkstationCountEntityMapping(\BO\Zmsentities\Scope $entity, \DateTimeInterface $dateTime): array
426    {
427        $data['virtuellesachbearbeiterzahl'] = $entity->getStatus('queue', 'ghostWorkstationCount');
428        $data['datumvirtuellesachbearbeiterzahl'] = $dateTime->format('Y-m-d');
429        return $data;
430    }
431
432    #[\Override]
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\Zmsbackend\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, string $checkKey, array $setKeys): void
506    {
507        if (!$data[$this->getPrefixed($checkKey)]) {
508            foreach ($setKeys as $key => $value) {
509                $data[$this->getPrefixed($key)] = $value;
510            }
511        }
512    }
513}