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_INSERT = '
23        REPLACE INTO
24            email
25        SET
26            BehoerdenID=?,
27            serveradresse="localhost",
28            absenderadresse=?,
29            send_reminder=?,
30            send_reminder_minutes_before=?
31    ';
32
33    const QUERY_MAIL_DELETE = '
34        DELETE FROM email WHERE BehoerdenID=?
35    ';
36
37    public function getEntityMapping()
38    {
39        return [
40            'contact__city' => self::expression('TRIM(" " FROM SUBSTRING_INDEX(`department`.`Adresse`, " ", -1))'),
41            'contact__street' => 'department.Adresse',
42            /*
43            'contact__streetNumber' => self::expression(
44                'TRIM("," FROM SUBSTRING_INDEX(SUBSTRING_INDEX(`department`.`Adresse`, ",", 1), " ", -1))'
45            ),
46            'contact__postalCode' => self::expression(
47                'TRIM(" " FROM SUBSTRING_INDEX(SUBSTRING_INDEX(`department`.`Adresse`, " ", -2), " ", 1))'
48            ),
49            'contact__region' => self::expression(
50                'TRIM(" " FROM SUBSTRING_INDEX(`department`.`Adresse`, " ", -1))'
51            ),
52            */
53            'contact__country' => self::expression('"Germany"'),
54            'contact__name' => 'department.Ansprechpartner',
55            'email' => 'department_email.absenderadresse',
56            'sendEmailReminderEnabled' => 'department_email.send_reminder',
57            'sendEmailReminderMinutesBefore' => 'department_email.send_reminder_minutes_before',
58            'id' => 'department.BehoerdenID',
59            'name' => 'department.Name'
60        ];
61    }
62
63    public function addRequiredJoins()
64    {
65        $this->leftJoin(
66            new Alias('email', 'department_email'),
67            'department.BehoerdenID',
68            '=',
69            'department_email.BehoerdenID'
70        );
71    }
72
73    public function addConditionScopeId($scopeId)
74    {
75        $this->leftJoin(
76            new Alias('standort', 'scope_department'),
77            'scope_department.BehoerdenID',
78            '=',
79            'department.BehoerdenID'
80        );
81        $this->query->where('scope_department.StandortID', '=', $scopeId);
82        return $this;
83    }
84
85    public function addConditionDepartmentId($departmentId)
86    {
87        $this->query->where('department.BehoerdenID', '=', $departmentId);
88        return $this;
89    }
90
91    public function addConditionDepartmentIds(array $departmentIds)
92    {
93        if (!empty($departmentIds)) {
94            $this->query->whereIn('department.BehoerdenID', $departmentIds);
95        }
96        return $this;
97    }
98
99    public function addConditionOrganisationId($organisationId)
100    {
101        $this->query->where('department.OrganisationsID', '=', $organisationId);
102        return $this;
103    }
104
105    public function reverseEntityMapping(\BO\Zmsentities\Department $entity, $parentId = null)
106    {
107        $data = array();
108        if (null !== $parentId) {
109            $data['OrganisationsID'] = $parentId;
110        }
111        $data['Adresse'] = (isset($entity->contact['street'])) ? $entity->contact['street'] : '';
112        $data['Name'] = $entity->name;
113        $data['Ansprechpartner'] = $entity->getContactPerson();
114        $data = array_filter(
115            $data,
116            function ($value) {
117                return ($value !== null && $value !== false);
118            }
119        );
120        return $data;
121    }
122}