Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
96.75% covered (success)
96.75%
268 / 277
88.89% covered (warning)
88.89%
24 / 27
CRAP
0.00% covered (danger)
0.00%
0 / 1
Scope
96.75% covered (success)
96.75%
268 / 277
88.89% covered (warning)
88.89%
24 / 27
48
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%
79 / 79
100.00% covered (success)
100.00%
1 / 1
5
 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            'source' => 'scope.source'
242        ], 'strlen');
243    }
244
245    public function addConditionScopeId($scopeId)
246    {
247        $this->query->where('scope.StandortID', '=', $scopeId);
248        return $this;
249    }
250
251    public function addConditionScopeIds(array $scopeIds)
252    {
253        $scopeIds = array_values(array_unique(array_map('intval', $scopeIds)));
254        if (!$scopeIds) {
255            $this->query->where(self::expression('1'), '=', 0);
256            return $this;
257        }
258
259        $this->query->whereIn('scope.StandortID', $scopeIds);
260        return $this;
261    }
262
263    public function addConditionWithAdminEmail()
264    {
265        $this->query->where('scope.emailstandortadmin', '!=', '');
266        return $this;
267    }
268
269    public function addSelectWorkstationCount($dateTime)
270    {
271        $this->query->select(
272            ['status__queue__workstationCount' => self::expression('
273                IF(
274                    `scope`.`virtuellesachbearbeiterzahl` > -1,
275                    `scope`.`virtuellesachbearbeiterzahl`,
276                    (
277                        SELECT COUNT(*)
278                        FROM nutzer
279                        WHERE nutzer.StandortID = scope.StandortID
280                        AND nutzer.Datum = "' . $dateTime->format('Y-m-d') . '"
281                        AND nutzer.Arbeitsplatznr <> 0
282                    )
283                )
284            ')
285            ]
286        );
287    }
288
289    public function addConditionProviderId($providerId)
290    {
291        $this->query->where('scope.InfoDienstleisterID', '=', $providerId);
292        return $this;
293    }
294
295    public function addConditionDepartmentId($departmentId)
296    {
297        $this->query->where('scope.BehoerdenID', '=', $departmentId);
298        return $this;
299    }
300
301    public function addConditionClusterId($clusterId)
302    {
303        $this->leftJoin(
304            new Alias('clusterzuordnung', 'cluster_scope'),
305            'scope.StandortID',
306            '=',
307            'cluster_scope.standortID'
308        );
309        $this->query->where('cluster_scope.clusterID', '=', $clusterId);
310        return $this;
311    }
312
313    public function reverseEntityMapping(\BO\Zmsentities\Scope $entity, $parentId = null)
314    {
315        $data = array();
316        if ($parentId) {
317            $data['BehoerdenID'] = $parentId;
318        }
319        $data['InfoDienstleisterID'] = $entity->getProviderId();
320        $data['emailstandortadmin'] = $entity->getContactEMail();
321        $data['standortinfozeile'] = $entity->getScopeInfo();
322        $data['Hinweis'] = $entity->getScopeHint();
323        $data['Bezeichnung'] = $entity->getName();
324        $data['standortkuerzel'] = $entity->shortName;
325        $data['Adresse'] = (isset($entity->contact['street'])) ? $entity->contact['street'] : '';
326        $data['loeschdauer'] = $entity->getPreference('appointment', 'deallocationDuration');
327        $data['info_for_appointment'] = $entity->getPreference('appointment', 'infoForAppointment');
328        $data['info_for_all_appointments'] = $entity->getPreference('appointment', 'infoForAllAppointments');
329        $data['Termine_bis'] = $entity->getPreference('appointment', 'endInDaysDefault');
330        $data['Termine_ab'] = $entity->getPreference('appointment', 'startInDaysDefault');
331        $data['mehrfachtermine'] = $entity->getPreference('appointment', 'multipleSlotsEnabled', true);
332        $data['reservierungsdauer'] = $entity->getPreference('appointment', 'reservationDuration');
333        $data['aktivierungsdauer'] = $entity->getPreference('appointment', 'activationDuration');
334        $data['anmerkungPflichtfeld'] = $entity->getPreference('client', 'amendmentActivated', true);
335        $data['anmerkungLabel'] = $entity->getPreference('client', 'amendmentLabel');
336        $data['emailPflichtfeld'] = $entity->getPreference('client', 'emailRequired', true);
337        $data['email_confirmation_activated'] = $entity->getPreference('client', 'emailConfirmationActivated', true);
338        $data['telefonaktiviert'] = $entity->getPreference('client', 'telephoneActivated', true);
339        $data['telefonPflichtfeld'] = $entity->getPreference('client', 'telephoneRequired', true);
340        $data['custom_text_field_active'] = $entity->getPreference('client', 'customTextfieldActivated', true);
341        $data['custom_text_field_required'] = $entity->getPreference('client', 'customTextfieldRequired', true);
342        $data['custom_text_field_label'] = $entity->getPreference('client', 'customTextfieldLabel');
343        $data['custom_text_field2_active'] = $entity->getPreference('client', 'customTextfield2Activated', true);
344        $data['custom_text_field2_required'] = $entity->getPreference('client', 'customTextfield2Required', true);
345        $data['custom_text_field2_label'] = $entity->getPreference('client', 'customTextfield2Label');
346        $data['captcha_activated_required'] = $entity->getPreference('client', 'captchaActivatedRequired');
347        $data['appointments_per_mail'] = (int) $entity->getPreference('client', 'appointmentsPerMail');
348        $data['slots_per_appointment'] = (int) $entity->getPreference('client', 'slotsPerAppointment');
349        $data['info_for_appointment'] = $entity->getPreference('appointment', 'infoForAppointment');
350        $data['whitelisted_mails'] = $entity->getPreference('client', 'whitelistedMails');
351        $data['admin_mail_on_appointment'] = $entity->getPreference('client', 'adminMailOnAppointment', true);
352        $data['admin_mail_on_deleted'] = $entity->getPreference('client', 'adminMailOnDeleted');
353        $data['admin_mail_on_updated'] = $entity->getPreference('client', 'adminMailOnUpdated', true);
354        $data['admin_mail_on_mail_sent'] = $entity->getPreference('client', 'adminMailOnMailSent', true);
355        $data['anzahlwiederaufruf'] = $entity->getPreference('queue', 'callCountMax');
356        $data['aufrufanzeigetext'] = $entity->getPreference('queue', 'callDisplayText', false, '');
357        $data['startwartenr'] = $entity->getPreference('queue', 'firstNumber');
358        $data['endwartenr'] = $entity->getPreference('queue', 'lastNumber');
359        $data['wartenummernkontingent'] = $entity->getPreference('queue', 'maxNumberContingent');
360        $data['display_number_prefix'] = $entity->getPreference('queue', 'displayNumberPrefix')
361            ? strtoupper($entity->getPreference('queue', 'displayNumberPrefix'))
362            : '';
363        $data['Bearbeitungszeit'] = gmdate("H:i", $entity->getPreference('queue', 'processingTimeAverage') * 60);
364        $data['ohnestatistik'] = (0 == $entity->getPreference('queue', 'statisticsEnabled', true)) ? 1 : 0;
365        $data['kundenbef_emailtext'] = $entity->getPreference('survey', 'emailContent');
366        $data['kundenbefragung'] = $entity->getPreference('survey', 'enabled', true);
367        $data['kundenbef_label'] = $entity->getPreference('survey', 'label');
368        $data['wartenrhinweis'] = $entity->getPreference('ticketprinter', 'deactivatedText', false, '');
369        $data['notruffunktion'] = $entity->getPreference('workstation', 'emergencyEnabled', true);
370        $data['notrufantwort'] = $entity->getStatus('emergency', 'acceptedByWorkstation');
371        $data['notrufausgeloest'] = $entity->getStatus('emergency', 'activated');
372        $data['notrufinitiierung'] = $entity->getStatus('emergency', 'calledByWorkstation');
373        $data['virtuellesachbearbeiterzahl'] = $entity->getStatus('queue', 'ghostWorkstationCount');
374        $data['vergebenewartenummern'] = $entity->getStatus('queue', 'givenNumberCount');
375        $data['letztewartenr'] = $entity->getStatus('queue', 'lastGivenNumber');
376        $data['last_display_number'] = $entity->getStatus('queue', 'lastDisplayNumber');
377        $data['max_display_number'] = $entity->getStatus('queue', 'maxDisplayNumber');
378        $lastGivenTimestamp = $entity->getStatus('queue', 'lastGivenNumberTimestamp');
379        $data['wartenrdatum'] = ($lastGivenTimestamp) ? date('Y-m-d', $lastGivenTimestamp) : null;
380        $data['wartenrsperre'] = $entity->getStatus('ticketprinter', 'deactivated');
381        $data['source'] = $entity->getProvider()->source;
382
383        $data = array_filter($data, function ($value) {
384            return ($value !== null && $value !== false);
385        });
386        return $data;
387    }
388
389    public function setEmergencyEntityMapping(\BO\Zmsentities\Scope $entity)
390    {
391        $data['notrufantwort'] = ($entity->toProperty()->status->emergency->acceptedByWorkstation->get(-1));
392        $data['notrufausgeloest'] = intval($entity->toProperty()->status->emergency->activated->get(0));
393        $data['notrufinitiierung'] = ($entity->toProperty()->status->emergency->calledByWorkstation->get(-1));
394        return $data;
395    }
396
397    public function setGhostWorkstationCountEntityMapping(\BO\Zmsentities\Scope $entity, \DateTimeInterface $dateTime)
398    {
399        $data['virtuellesachbearbeiterzahl'] = $entity->getStatus('queue', 'ghostWorkstationCount');
400        $data['datumvirtuellesachbearbeiterzahl'] = $dateTime->format('Y-m-d');
401        return $data;
402    }
403
404    public function postProcess($data)
405    {
406        $data = $this->convertTimestamps($data);
407        $data = $this->setDefaultValues($data);
408        return $data;
409    }
410
411
412    private function convertTimestamps($data)
413    {
414        $lastGivenNumberTimestampKey = $this->getPrefixed("status__queue__lastGivenNumberTimestamp");
415        $lastGivenNumberTimestamp = $data[$lastGivenNumberTimestampKey] ?? null;
416        $data[$lastGivenNumberTimestampKey] = $lastGivenNumberTimestamp !== null ? strtotime($lastGivenNumberTimestamp) : null;
417
418        $lastChangeKey = $this->getPrefixed("lastChange");
419        $lastChange = $data[$lastChangeKey] ?? null;
420        if ($lastChange !== null) {
421            $data[$lastChangeKey] = (new \DateTime($lastChange . \BO\Zmsdb\Connection\Select::$connectionTimezone))
422                ->getTimestamp();
423        } else {
424            $data[$lastChangeKey] = null;
425        }
426
427        return $data;
428    }
429
430    private function setDefaultValues($data)
431    {
432        if ($this->shouldLoadEntity('scopemail')) {
433            $this->setIfEmpty($data, 'preferences__client__emailFrom', [
434                'preferences__client__emailRequired' => 0
435            ]);
436        }
437
438        $this->setIfEmpty($data, 'preferences__client__telephoneActivated', [
439            'preferences__client__telephoneRequired' => 0
440        ]);
441
442        $this->setIfEmpty($data, 'preferences__client__emailConfirmationActivated', [
443            'preferences__client__emailConfirmationActivated' => 0
444        ]);
445
446        $this->setIfEmpty($data, 'contact__email', [
447            'preferences__client__adminMailOnAppointment' => 0,
448            'preferences__client__adminMailOnDeleted' => 0,
449            'preferences__client__adminMailOnUpdated' => 0,
450            'preferences__client__adminMailOnMailSent' => 0,
451        ]);
452
453        $this->setIfEmpty($data, 'preferences__client__customTextfieldActivated', [
454            'preferences__client__customTextfieldRequired' => 0
455        ]);
456
457        $this->setIfEmpty($data, 'preferences__client__customTextfield2Activated', [
458            'preferences__client__customTextfield2Required' => 0
459        ]);
460
461        $this->setIfEmpty($data, 'preferences__client__appointmentsPerMail', [
462            'preferences__client__appointmentsPerMail' => null
463        ]);
464
465        $this->setIfEmpty($data, 'preferences__client__slotsPerAppointment', [
466            'preferences__client__slotsPerAppointment' => null
467        ]);
468
469        $this->setIfEmpty($data, 'preferences__client__whitelistedMails', [
470            'preferences__client__whitelistedMails' => null
471        ]);
472
473        return $data;
474    }
475
476    private function setIfEmpty(&$data, $checkKey, array $setKeys)
477    {
478        if (!$data[$this->getPrefixed($checkKey)]) {
479            foreach ($setKeys as $key => $value) {
480                $data[$this->getPrefixed($key)] = $value;
481            }
482        }
483    }
484}