Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
52 / 52 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| Department | |
100.00% |
52 / 52 |
|
100.00% |
6 / 6 |
9 | |
100.00% |
1 / 1 |
| getEntityMapping | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 | |||
| addRequiredJoins | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
| addConditionScopeId | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| addConditionDepartmentId | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| addConditionOrganisationId | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| reverseEntityMapping | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsdb\Query; |
| 4 | |
| 5 | class 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 | |
| 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_NOTIFICATIONS_UPDATE = ' |
| 23 | |
| 24 | SET @tempSMSId = (SELECT smsID from sms WHERE BehoerdenID=:departmentId); |
| 25 | REPLACE INTO |
| 26 | sms |
| 27 | SET |
| 28 | smsID=@tempSMSId, |
| 29 | BehoerdenID=:departmentId, |
| 30 | enabled=:enabled, |
| 31 | Absender=:identification, |
| 32 | internetbestaetigung=:sendConfirmationEnabled, |
| 33 | interneterinnerung=:sendReminderEnabled |
| 34 | |
| 35 | '; |
| 36 | |
| 37 | const QUERY_MAIL_INSERT = ' |
| 38 | REPLACE INTO |
| 39 | |
| 40 | SET |
| 41 | BehoerdenID=?, |
| 42 | serveradresse="localhost", |
| 43 | absenderadresse=?, |
| 44 | send_reminder=?, |
| 45 | send_reminder_minutes_before=? |
| 46 | '; |
| 47 | |
| 48 | const QUERY_NOTIFICATIONS_INSERT = ' |
| 49 | REPLACE INTO |
| 50 | sms |
| 51 | SET |
| 52 | BehoerdenID=?, |
| 53 | enabled=?, |
| 54 | Absender=?, |
| 55 | internetbestaetigung=?, |
| 56 | interneterinnerung=? |
| 57 | '; |
| 58 | |
| 59 | const QUERY_MAIL_DELETE = ' |
| 60 | DELETE FROM email WHERE BehoerdenID=? |
| 61 | '; |
| 62 | |
| 63 | const QUERY_NOTIFICATIONS_DELETE = ' |
| 64 | DELETE FROM sms WHERE BehoerdenID=? |
| 65 | '; |
| 66 | |
| 67 | public function getEntityMapping() |
| 68 | { |
| 69 | return [ |
| 70 | 'contact__city' => self::expression('TRIM(" " FROM SUBSTRING_INDEX(`department`.`Adresse`, " ", -1))'), |
| 71 | 'contact__street' => 'department.Adresse', |
| 72 | /* |
| 73 | 'contact__streetNumber' => self::expression( |
| 74 | 'TRIM("," FROM SUBSTRING_INDEX(SUBSTRING_INDEX(`department`.`Adresse`, ",", 1), " ", -1))' |
| 75 | ), |
| 76 | 'contact__postalCode' => self::expression( |
| 77 | 'TRIM(" " FROM SUBSTRING_INDEX(SUBSTRING_INDEX(`department`.`Adresse`, " ", -2), " ", 1))' |
| 78 | ), |
| 79 | 'contact__region' => self::expression( |
| 80 | 'TRIM(" " FROM SUBSTRING_INDEX(`department`.`Adresse`, " ", -1))' |
| 81 | ), |
| 82 | */ |
| 83 | 'contact__country' => self::expression('"Germany"'), |
| 84 | 'contact__name' => 'department.Ansprechpartner', |
| 85 | 'email' => 'department_email.absenderadresse', |
| 86 | 'sendEmailReminderEnabled' => 'department_email.send_reminder', |
| 87 | 'sendEmailReminderMinutesBefore' => 'department_email.send_reminder_minutes_before', |
| 88 | 'id' => 'department.BehoerdenID', |
| 89 | 'name' => 'department.Name', |
| 90 | 'preferences__notifications__enabled' => 'department_sms.enabled', |
| 91 | 'preferences__notifications__identification' => 'department_sms.Absender', |
| 92 | 'preferences__notifications__sendConfirmationEnabled' => 'department_sms.internetbestaetigung', |
| 93 | 'preferences__notifications__sendReminderEnabled' => 'department_sms.interneterinnerung' |
| 94 | ]; |
| 95 | } |
| 96 | |
| 97 | public function addRequiredJoins() |
| 98 | { |
| 99 | $this->leftJoin( |
| 100 | new Alias('email', 'department_email'), |
| 101 | 'department.BehoerdenID', |
| 102 | '=', |
| 103 | 'department_email.BehoerdenID' |
| 104 | ); |
| 105 | $this->leftJoin( |
| 106 | new Alias('sms', 'department_sms'), |
| 107 | 'department.BehoerdenID', |
| 108 | '=', |
| 109 | 'department_sms.BehoerdenID' |
| 110 | ); |
| 111 | } |
| 112 | |
| 113 | public function addConditionScopeId($scopeId) |
| 114 | { |
| 115 | $this->leftJoin( |
| 116 | new Alias('standort', 'scope_department'), |
| 117 | 'scope_department.BehoerdenID', |
| 118 | '=', |
| 119 | 'department.BehoerdenID' |
| 120 | ); |
| 121 | $this->query->where('scope_department.StandortID', '=', $scopeId); |
| 122 | return $this; |
| 123 | } |
| 124 | |
| 125 | public function addConditionDepartmentId($departmentId) |
| 126 | { |
| 127 | $this->query->where('department.BehoerdenID', '=', $departmentId); |
| 128 | return $this; |
| 129 | } |
| 130 | |
| 131 | public function addConditionOrganisationId($organisationId) |
| 132 | { |
| 133 | $this->query->where('department.OrganisationsID', '=', $organisationId); |
| 134 | return $this; |
| 135 | } |
| 136 | |
| 137 | public function reverseEntityMapping(\BO\Zmsentities\Department $entity, $parentId = null) |
| 138 | { |
| 139 | $data = array(); |
| 140 | if (null !== $parentId) { |
| 141 | $data['OrganisationsID'] = $parentId; |
| 142 | } |
| 143 | $data['Adresse'] = (isset($entity->contact['street'])) ? $entity->contact['street'] : ''; |
| 144 | $data['Name'] = $entity->name; |
| 145 | $data['Ansprechpartner'] = $entity->getContactPerson(); |
| 146 | $data = array_filter( |
| 147 | $data, |
| 148 | function ($value) { |
| 149 | return ($value !== null && $value !== false); |
| 150 | } |
| 151 | ); |
| 152 | return $data; |
| 153 | } |
| 154 | } |