Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
72 / 72 |
|
100.00% |
11 / 11 |
CRAP | |
100.00% |
1 / 1 |
| Request | |
100.00% |
72 / 72 |
|
100.00% |
11 / 11 |
15 | |
100.00% |
1 / 1 |
| getEntityMapping | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
2 | |||
| addConditionRequestId | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| addConditionRequestIdList | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| addConditionProcessId | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| addConditionProcessIds | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
| addEntityMappingWithProcessId | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| addConditionArchiveId | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| addConditionProvider | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
| addConditionRequestSource | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| postProcess | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
| addConditionIds | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsbackend\Request\Repository; |
| 4 | |
| 5 | class Request extends \BO\Zmsbackend\Query\Base |
| 6 | { |
| 7 | const string TABLE = 'request'; |
| 8 | |
| 9 | const string BATABLE = 'buergeranliegen'; |
| 10 | |
| 11 | const string QUERY_BY_PROCESSID = 'SELECT |
| 12 | ba.`AnliegenID` AS id |
| 13 | FROM `buergeranliegen` ba |
| 14 | WHERE |
| 15 | ba.`BuergerID` = :process_id |
| 16 | '; |
| 17 | |
| 18 | public const string QUERY_BY_ARCHIVEID = 'SELECT |
| 19 | ba.`AnliegenID` AS id |
| 20 | FROM `buergeranliegen` ba |
| 21 | WHERE |
| 22 | ba.`BuergerarchivID` = :archive_id |
| 23 | ORDER BY ba.`BuergeranliegenID` ASC |
| 24 | '; |
| 25 | |
| 26 | /** |
| 27 | * @return string[] |
| 28 | * |
| 29 | */ |
| 30 | public function getEntityMapping(): array |
| 31 | { |
| 32 | $mapping = [ |
| 33 | 'id' => 'request.id', |
| 34 | 'link' => 'request.link', |
| 35 | 'name' => 'request.name', |
| 36 | 'group' => 'request.group', |
| 37 | 'source' => 'request.source', |
| 38 | 'parent_id' => 'request.parent_id', |
| 39 | 'variant_id' => 'request.variant_id', |
| 40 | ]; |
| 41 | if ($this->getResolveLevel() > 0) { |
| 42 | $mapping['data'] = 'request.data'; |
| 43 | } |
| 44 | return $mapping; |
| 45 | } |
| 46 | |
| 47 | public function addConditionRequestId($requestId): static |
| 48 | { |
| 49 | $this->query->where('id', '=', $requestId); |
| 50 | return $this; |
| 51 | } |
| 52 | |
| 53 | public function addConditionRequestIdList(array $requestIds): self |
| 54 | { |
| 55 | $this->query->where('request.id', 'IN', array_map('strval', $requestIds)); |
| 56 | |
| 57 | return $this; |
| 58 | } |
| 59 | |
| 60 | public function addConditionProcessId($processId): static |
| 61 | { |
| 62 | $this->leftJoin( |
| 63 | new \BO\Zmsbackend\Query\Alias("buergeranliegen", 'buergeranliegen'), |
| 64 | self::expression(' |
| 65 | buergeranliegen.AnliegenID = request.id |
| 66 | AND buergeranliegen.source = request.source |
| 67 | ') |
| 68 | ); |
| 69 | $this->query->where('buergeranliegen.BuergerID', '=', $processId); |
| 70 | $this->query->orderBy('buergeranliegen.BuergeranliegenID', 'ASC'); |
| 71 | return $this; |
| 72 | } |
| 73 | |
| 74 | public function addConditionProcessIds(array $processIds): self |
| 75 | { |
| 76 | $this->leftJoin( |
| 77 | new \BO\Zmsbackend\Query\Alias("buergeranliegen", 'buergeranliegen'), |
| 78 | self::expression(' |
| 79 | buergeranliegen.AnliegenID = request.id |
| 80 | AND buergeranliegen.source = request.source |
| 81 | ') |
| 82 | ); |
| 83 | $this->query->whereIn( |
| 84 | 'buergeranliegen.BuergerID', |
| 85 | array_values(array_map('intval', $processIds)) |
| 86 | ); |
| 87 | $this->query->orderBy('buergeranliegen.BuergerID', 'ASC'); |
| 88 | $this->query->orderBy('buergeranliegen.BuergeranliegenID', 'ASC'); |
| 89 | return $this; |
| 90 | } |
| 91 | |
| 92 | public function addEntityMappingWithProcessId(): self |
| 93 | { |
| 94 | $entityMapping = $this->getPrefixedList(array_merge( |
| 95 | $this->getEntityMapping(), |
| 96 | ['processId' => 'buergeranliegen.BuergerID'] |
| 97 | )); |
| 98 | $this->query->select($entityMapping); |
| 99 | return $this; |
| 100 | } |
| 101 | |
| 102 | public function addConditionArchiveId($archiveId): static |
| 103 | { |
| 104 | $this->leftJoin( |
| 105 | new \BO\Zmsbackend\Query\Alias("buergeranliegen", 'buergeranliegen'), |
| 106 | self::expression(' |
| 107 | buergeranliegen.AnliegenID = request.id |
| 108 | AND buergeranliegen.source = request.source |
| 109 | ') |
| 110 | ); |
| 111 | $this->query->where('buergeranliegen.BuergerarchivID', '=', $archiveId); |
| 112 | $this->query->orderBy('buergeranliegen.BuergeranliegenID', 'ASC'); |
| 113 | return $this; |
| 114 | } |
| 115 | |
| 116 | public function addConditionProvider($providerId, $source): static |
| 117 | { |
| 118 | $this->leftJoin( |
| 119 | new \BO\Zmsbackend\Query\Alias("request_provider", 'xrequest'), |
| 120 | 'request.id', |
| 121 | '=', |
| 122 | 'xrequest.request__id' |
| 123 | ); |
| 124 | $this->query->where(function (\BO\Zmsbackend\Query\Builder\ConditionBuilder $query) use ($providerId, $source) { |
| 125 | $query->andWith('xrequest.provider__id', '=', $providerId); |
| 126 | $query->andWith('xrequest.source', '=', $source); |
| 127 | $query->andWith('xrequest.bookable', '=', 1); |
| 128 | }); |
| 129 | return $this; |
| 130 | } |
| 131 | |
| 132 | public function addConditionRequestSource($source): static |
| 133 | { |
| 134 | $this->query->where('request.source', '=', $source); |
| 135 | return $this; |
| 136 | } |
| 137 | |
| 138 | #[\Override] |
| 139 | public function postProcess($data) |
| 140 | { |
| 141 | if (isset($data[$this->getPrefixed('data')]) && $data[$this->getPrefixed('data')]) { |
| 142 | $data[$this->getPrefixed('data')] = json_decode($data[$this->getPrefixed('data')], true); |
| 143 | } |
| 144 | return $data; |
| 145 | } |
| 146 | |
| 147 | public function addConditionIds($ids): static |
| 148 | { |
| 149 | $this->query->where(function (\BO\Zmsbackend\Query\Builder\ConditionBuilder $query) use ($ids) { |
| 150 | foreach ($ids as $id) { |
| 151 | $query->orWith('request.id', '=', $id); |
| 152 | } |
| 153 | }); |
| 154 | |
| 155 | return $this; |
| 156 | } |
| 157 | } |