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