Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
50 / 50 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
| Request | |
100.00% |
50 / 50 |
|
100.00% |
8 / 8 |
12 | |
100.00% |
1 / 1 |
| getEntityMapping | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
2 | |||
| addConditionRequestId | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| addConditionProcessId | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| addConditionArchiveId | |
100.00% |
7 / 7 |
|
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\Zmsdb\Query; |
| 4 | |
| 5 | class Request extends 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 function getEntityMapping() |
| 19 | { |
| 20 | $mapping = [ |
| 21 | 'id' => 'request.id', |
| 22 | 'link' => 'request.link', |
| 23 | 'name' => 'request.name', |
| 24 | 'group' => 'request.group', |
| 25 | 'source' => 'request.source', |
| 26 | 'parent_id' => 'request.parent_id', |
| 27 | 'variant_id' => 'request.variant_id', |
| 28 | ]; |
| 29 | if ($this->getResolveLevel() > 0) { |
| 30 | $mapping['data'] = 'request.data'; |
| 31 | } |
| 32 | return $mapping; |
| 33 | } |
| 34 | |
| 35 | public function addConditionRequestId($requestId) |
| 36 | { |
| 37 | $this->query->where('id', '=', $requestId); |
| 38 | return $this; |
| 39 | } |
| 40 | |
| 41 | public function addConditionProcessId($processId) |
| 42 | { |
| 43 | $this->leftJoin( |
| 44 | new Alias("buergeranliegen", 'buergeranliegen'), |
| 45 | self::expression(' |
| 46 | buergeranliegen.AnliegenID = request.id |
| 47 | AND buergeranliegen.source = request.source |
| 48 | ') |
| 49 | ); |
| 50 | $this->query->where('buergeranliegen.BuergerID', '=', $processId); |
| 51 | return $this; |
| 52 | } |
| 53 | |
| 54 | public function addConditionArchiveId($archiveId) |
| 55 | { |
| 56 | $this->leftJoin( |
| 57 | new Alias("buergeranliegen", 'buergeranliegen'), |
| 58 | self::expression(' |
| 59 | buergeranliegen.AnliegenID = request.id |
| 60 | AND buergeranliegen.source = request.source |
| 61 | ') |
| 62 | ); |
| 63 | $this->query->where('buergeranliegen.BuergerarchivID', '=', $archiveId); |
| 64 | return $this; |
| 65 | } |
| 66 | |
| 67 | public function addConditionProvider($providerId, $source) |
| 68 | { |
| 69 | $this->leftJoin( |
| 70 | new Alias("request_provider", 'xrequest'), |
| 71 | 'request.id', |
| 72 | '=', |
| 73 | 'xrequest.request__id' |
| 74 | ); |
| 75 | $this->query->where(function (\BO\Zmsdb\Query\Builder\ConditionBuilder $query) use ($providerId, $source) { |
| 76 | $query->andWith('xrequest.provider__id', '=', $providerId); |
| 77 | $query->andWith('xrequest.source', '=', $source); |
| 78 | $query->andWith('xrequest.bookable', '=', 1); |
| 79 | }); |
| 80 | return $this; |
| 81 | } |
| 82 | |
| 83 | public function addConditionRequestSource($source) |
| 84 | { |
| 85 | $this->query->where('request.source', '=', $source); |
| 86 | return $this; |
| 87 | } |
| 88 | |
| 89 | public function postProcess($data) |
| 90 | { |
| 91 | if (isset($data[$this->getPrefixed('data')]) && $data[$this->getPrefixed('data')]) { |
| 92 | $data[$this->getPrefixed('data')] = json_decode($data[$this->getPrefixed('data')], true); |
| 93 | } |
| 94 | return $data; |
| 95 | } |
| 96 | |
| 97 | public function addConditionIds($ids) |
| 98 | { |
| 99 | $this->query->where(function (\BO\Zmsdb\Query\Builder\ConditionBuilder $query) use ($ids) { |
| 100 | foreach ($ids as $id) { |
| 101 | $query->orWith('request.id', '=', $id); |
| 102 | } |
| 103 | }); |
| 104 | |
| 105 | return $this; |
| 106 | } |
| 107 | } |