Lines
100.00%
30 / 30
Functions and Methods
100.00%
4 / 4
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Link | 100.00% | 30 / 30 | 100.00% | 4 / 4 | 8 | 100.00% | 1 / 1 | |||
| getEntityMapping | 100.00% | 8 / 8 | 100.00% | 1 / 1 | 1 | |||||
| addConditionLinkId | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | |||||
| addConditionDepartmentId | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 1 | |||||
| reverseEntityMapping | 100.00% | 11 / 11 | 100.00% | 1 / 1 | 5 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsbackend\Link\Repository; | |
| 4 | ||
| 5 | class Link extends \BO\Zmsbackend\Query\Base | |
| 6 | { | |
| 7 | /** | |
| 8 | * @var String TABLE mysql table reference | |
| 9 | */ | |
| 10 | const string TABLE = 'kundenlinks'; | |
| 11 | ||
| 12 | /** | |
| 13 | * No resolving required here | |
| 14 | */ | |
| 15 | protected $resolveLevel = 0; | |
| 16 | ||
| 17 | /** | |
| 18 | * @psalm-api | |
| 19 | * | |
| 20 | * @return string[] | |
| 21 | * | |
| 22 | */ | |
| 23 | public function getEntityMapping(): array | |
| 24 | { | |
| 25 | return [ | |
| 26 | 'id' => 'link.linkid', | |
| 27 | 'name' => 'link.beschreibung', | |
| 28 | 'url' => 'link.link', | |
| 29 | 'target' => 'link.neuerFrame', | |
| 30 | 'public' => 'link.oeffentlich', | |
| 31 | 'organisation' => 'link.organisationsid' | |
| 32 | ]; | |
| 33 | } | |
| 34 | ||
| 35 | public function addConditionLinkId($linkId): static | |
| 36 | { | |
| 37 | $this->query->where('link.linkid', '=', $linkId); | |
| 38 | return $this; | |
| 39 | } | |
| 40 | ||
| 41 | public function addConditionDepartmentId($departmentId): static | |
| 42 | { | |
| 43 | $this->leftJoin( | |
| 44 | new \BO\Zmsbackend\Query\Alias('behoerde', 'link_department'), | |
| 45 | 'link_department.OrganisationsID', | |
| 46 | '=', | |
| 47 | 'link.organisationsid' | |
| 48 | ); | |
| 49 | $this->query->where('link_department.BehoerdenID', '=', $departmentId); | |
| 50 | $this->query->orWhere('link.behoerdenid', '=', $departmentId); | |
| 51 | return $this; | |
| 52 | } | |
| 53 | ||
| 54 | /** | |
| 55 | * @return (int|mixed)[] | |
| 56 | * | |
| 57 | */ | |
| 58 | public function reverseEntityMapping(\BO\Zmsentities\Link $entity, $departmentId): array | |
| 59 | { | |
| 60 | $data = array(); | |
| 61 | $data['behoerdenid'] = ($entity->organisation) ? 0 : $departmentId; | |
| 62 | $data['organisationsid'] = $entity->organisation; | |
| 63 | $data['beschreibung'] = $entity->name; | |
| 64 | $data['link'] = $entity->url; | |
| 65 | $data['neuerFrame'] = ($entity->target) ? 1 : 0; | |
| 66 | $data['oeffentlich'] = ($entity->public) ? 1 : 0; | |
| 67 | ||
| 68 | $data = array_filter($data, function ($value) { | |
| 69 | return ($value !== null && $value !== false); | |
| 70 | }); | |
| 71 | return $data; | |
| 72 | } | |
| 73 | } |