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