Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
45 / 45
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
1 / 1
Department
100.00% covered (success)
100.00%
45 / 45
100.00% covered (success)
100.00%
7 / 7
11
100.00% covered (success)
100.00%
1 / 1
 getEntityMapping
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
 addRequiredJoins
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 addConditionScopeId
100.00% covered (success)
100.00%
8 / 8
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
 addConditionDepartmentIds
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 addConditionOrganisationId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 reverseEntityMapping
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3namespace BO\Zmsdb\Query;
4
5class Department extends Base implements MappingInterface
6{
7    const TABLE = 'behoerde';
8
9    const QUERY_MAIL_UPDATE = '
10        SET @tempEmailID = (SELECT emailID from email WHERE BehoerdenID=:departmentId);
11        REPLACE INTO
12            email
13        SET
14            emailID=@tempEmailID,
15            BehoerdenID=:departmentId,
16            absenderadresse=:email,
17            serveradresse="localhost",
18            send_reminder=:sendEmailReminderEnabled,
19            send_reminder_minutes_before=:sendEmailReminderMinutesBefore
20    ';
21
22    const QUERY_MAIL_DELETE = '
23        DELETE FROM email WHERE BehoerdenID=?
24    ';
25
26    #[\Override]
27    public function getEntityMapping()
28    {
29        return [
30            'contact__city' => self::expression('TRIM(" " FROM SUBSTRING_INDEX(`department`.`Adresse`, " ", -1))'),
31            'contact__street' => 'department.Adresse',
32            /*
33            'contact__streetNumber' => self::expression(
34                'TRIM("," FROM SUBSTRING_INDEX(SUBSTRING_INDEX(`department`.`Adresse`, ",", 1), " ", -1))'
35            ),
36            'contact__postalCode' => self::expression(
37                'TRIM(" " FROM SUBSTRING_INDEX(SUBSTRING_INDEX(`department`.`Adresse`, " ", -2), " ", 1))'
38            ),
39            'contact__region' => self::expression(
40                'TRIM(" " FROM SUBSTRING_INDEX(`department`.`Adresse`, " ", -1))'
41            ),
42            */
43            'contact__country' => self::expression('"Germany"'),
44            'contact__name' => 'department.Ansprechpartner',
45            'email' => 'department_email.absenderadresse',
46            'sendEmailReminderEnabled' => 'department_email.send_reminder',
47            'sendEmailReminderMinutesBefore' => 'department_email.send_reminder_minutes_before',
48            'id' => 'department.BehoerdenID',
49            'name' => 'department.Name'
50        ];
51    }
52
53    #[\Override]
54    public function addRequiredJoins()
55    {
56        $this->leftJoin(
57            new Alias('email', 'department_email'),
58            'department.BehoerdenID',
59            '=',
60            'department_email.BehoerdenID'
61        );
62    }
63
64    public function addConditionScopeId($scopeId)
65    {
66        $this->leftJoin(
67            new Alias('standort', 'scope_department'),
68            'scope_department.BehoerdenID',
69            '=',
70            'department.BehoerdenID'
71        );
72        $this->query->where('scope_department.StandortID', '=', $scopeId);
73        return $this;
74    }
75
76    public function addConditionDepartmentId($departmentId)
77    {
78        $this->query->where('department.BehoerdenID', '=', $departmentId);
79        return $this;
80    }
81
82    public function addConditionDepartmentIds(array $departmentIds)
83    {
84        if (!empty($departmentIds)) {
85            $this->query->whereIn('department.BehoerdenID', $departmentIds);
86        }
87        return $this;
88    }
89
90    public function addConditionOrganisationId($organisationId)
91    {
92        $this->query->where('department.OrganisationsID', '=', $organisationId);
93        return $this;
94    }
95
96    public function reverseEntityMapping(\BO\Zmsentities\Department $entity, $parentId = null)
97    {
98        $data = array();
99        if (null !== $parentId) {
100            $data['OrganisationsID'] = $parentId;
101        }
102        $data['Adresse'] = (isset($entity->contact['street'])) ? $entity->contact['street'] : '';
103        $data['Name'] = $entity->name;
104        $data['Ansprechpartner'] = $entity->getContactPerson();
105        $data = array_filter(
106            $data,
107            function ($value) {
108                return ($value !== null && $value !== false);
109            }
110        );
111        return $data;
112    }
113}