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 TABLE = 'request'; |
| 8 | |
| 9 | const BATABLE = 'buergeranliegen'; |
| 10 | |
| 11 | const 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 | public function getEntityMapping() |
| 27 | { |
| 28 | $mapping = [ |
| 29 | 'id' => 'request.id', |
| 30 | 'link' => 'request.link', |
| 31 | 'name' => 'request.name', |
| 32 | 'group' => 'request.group', |
| 33 | 'source' => 'request.source', |
| 34 | 'parent_id' => 'request.parent_id', |
| 35 | 'variant_id' => 'request.variant_id', |
| 36 | ]; |
| 37 | if ($this->getResolveLevel() > 0) { |
| 38 | $mapping['data'] = 'request.data'; |
| 39 | } |
| 40 | return $mapping; |
| 41 | } |
| 42 | |
| 43 | public function addConditionRequestId($requestId) |
| 44 | { |
| 45 | $this->query->where('id', '=', $requestId); |
| 46 | return $this; |
| 47 | } |
| 48 | |
| 49 | public function addConditionRequestIdList(array $requestIds): self |
| 50 | { |
| 51 | $this->query->where('request.id', 'IN', array_map('strval', $requestIds)); |
| 52 | |
| 53 | return $this; |
| 54 | } |
| 55 | |
| 56 | public function addConditionProcessId($processId) |
| 57 | { |
| 58 | $this->leftJoin( |
| 59 | new \BO\Zmsbackend\Query\Alias("buergeranliegen", 'buergeranliegen'), |
| 60 | self::expression(' |
| 61 | buergeranliegen.AnliegenID = request.id |
| 62 | AND buergeranliegen.source = request.source |
| 63 | ') |
| 64 | ); |
| 65 | $this->query->where('buergeranliegen.BuergerID', '=', $processId); |
| 66 | $this->query->orderBy('buergeranliegen.BuergeranliegenID', 'ASC'); |
| 67 | return $this; |
| 68 | } |
| 69 | |
| 70 | public function addConditionProcessIds(array $processIds): self |
| 71 | { |
| 72 | $this->leftJoin( |
| 73 | new \BO\Zmsbackend\Query\Alias("buergeranliegen", 'buergeranliegen'), |
| 74 | self::expression(' |
| 75 | buergeranliegen.AnliegenID = request.id |
| 76 | AND buergeranliegen.source = request.source |
| 77 | ') |
| 78 | ); |
| 79 | $this->query->whereIn( |
| 80 | 'buergeranliegen.BuergerID', |
| 81 | array_values(array_map('intval', $processIds)) |
| 82 | ); |
| 83 | $this->query->orderBy('buergeranliegen.BuergerID', 'ASC'); |
| 84 | $this->query->orderBy('buergeranliegen.BuergeranliegenID', 'ASC'); |
| 85 | return $this; |
| 86 | } |
| 87 | |
| 88 | public function addEntityMappingWithProcessId(): self |
| 89 | { |
| 90 | $entityMapping = $this->getPrefixedList(array_merge( |
| 91 | $this->getEntityMapping(), |
| 92 | ['processId' => 'buergeranliegen.BuergerID'] |
| 93 | )); |
| 94 | $this->query->select($entityMapping); |
| 95 | return $this; |
| 96 | } |
| 97 | |
| 98 | public function addConditionArchiveId($archiveId) |
| 99 | { |
| 100 | $this->leftJoin( |
| 101 | new \BO\Zmsbackend\Query\Alias("buergeranliegen", 'buergeranliegen'), |
| 102 | self::expression(' |
| 103 | buergeranliegen.AnliegenID = request.id |
| 104 | AND buergeranliegen.source = request.source |
| 105 | ') |
| 106 | ); |
| 107 | $this->query->where('buergeranliegen.BuergerarchivID', '=', $archiveId); |
| 108 | $this->query->orderBy('buergeranliegen.BuergeranliegenID', 'ASC'); |
| 109 | return $this; |
| 110 | } |
| 111 | |
| 112 | public function addConditionProvider($providerId, $source) |
| 113 | { |
| 114 | $this->leftJoin( |
| 115 | new \BO\Zmsbackend\Query\Alias("request_provider", 'xrequest'), |
| 116 | 'request.id', |
| 117 | '=', |
| 118 | 'xrequest.request__id' |
| 119 | ); |
| 120 | $this->query->where(function (\BO\Zmsbackend\Query\Builder\ConditionBuilder $query) use ($providerId, $source) { |
| 121 | $query->andWith('xrequest.provider__id', '=', $providerId); |
| 122 | $query->andWith('xrequest.source', '=', $source); |
| 123 | $query->andWith('xrequest.bookable', '=', 1); |
| 124 | }); |
| 125 | return $this; |
| 126 | } |
| 127 | |
| 128 | public function addConditionRequestSource($source) |
| 129 | { |
| 130 | $this->query->where('request.source', '=', $source); |
| 131 | return $this; |
| 132 | } |
| 133 | |
| 134 | #[\Override] |
| 135 | public function postProcess($data) |
| 136 | { |
| 137 | if (isset($data[$this->getPrefixed('data')]) && $data[$this->getPrefixed('data')]) { |
| 138 | $data[$this->getPrefixed('data')] = json_decode($data[$this->getPrefixed('data')], true); |
| 139 | } |
| 140 | return $data; |
| 141 | } |
| 142 | |
| 143 | public function addConditionIds($ids) |
| 144 | { |
| 145 | $this->query->where(function (\BO\Zmsbackend\Query\Builder\ConditionBuilder $query) use ($ids) { |
| 146 | foreach ($ids as $id) { |
| 147 | $query->orWith('request.id', '=', $id); |
| 148 | } |
| 149 | }); |
| 150 | |
| 151 | return $this; |
| 152 | } |
| 153 | } |