Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
48 / 48 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| Provider | |
100.00% |
48 / 48 |
|
100.00% |
6 / 6 |
11 | |
100.00% |
1 / 1 |
| getEntityMapping | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
2 | |||
| addConditionIsAssigned | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
3 | |||
| addConditionProviderId | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| addConditionProviderSource | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| addConditionRequestCsv | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
| postProcess | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsdb\Query; |
| 4 | |
| 5 | class Provider extends Base |
| 6 | { |
| 7 | const TABLE = 'provider'; |
| 8 | |
| 9 | public function getEntityMapping() |
| 10 | { |
| 11 | $mapping = [ |
| 12 | 'contact__city' => 'provider.contact__city', |
| 13 | 'contact__country' => self::expression('"Germany"'), |
| 14 | 'contact__name' => 'provider.name', |
| 15 | 'contact__postalCode' => 'provider.contact__postalCode', |
| 16 | 'contact__region' => 'provider.contact__region', |
| 17 | 'contact__street' => 'provider.contact__street', |
| 18 | 'contact__streetNumber' => 'provider.contact__streetNumber', |
| 19 | 'id' => 'provider.id', |
| 20 | 'link' => 'provider.link', |
| 21 | 'name' => 'provider.name', |
| 22 | 'displayName' => 'provider.display_name', |
| 23 | 'source' => 'provider.source', |
| 24 | 'parent_id' => 'provider.parent_id' |
| 25 | ]; |
| 26 | if ($this->getResolveLevel() > 0) { |
| 27 | $mapping['data'] = 'provider.data'; |
| 28 | } |
| 29 | return $mapping; |
| 30 | } |
| 31 | |
| 32 | public function addConditionIsAssigned($isAssigned) |
| 33 | { |
| 34 | $this->leftJoin( |
| 35 | new Alias(Scope::TABLE, 'assignedscope'), |
| 36 | 'provider.id', |
| 37 | '=', |
| 38 | 'assignedscope.InfoDienstleisterID' |
| 39 | ); |
| 40 | if (true === $isAssigned) { |
| 41 | $this->query->where('assignedscope.InfoDienstleisterID', 'IS NOT', null); |
| 42 | } elseif (false === $isAssigned) { |
| 43 | $this->query->where('assignedscope.InfoDienstleisterID', 'IS', null); |
| 44 | } |
| 45 | return $this; |
| 46 | } |
| 47 | |
| 48 | public function addConditionProviderId($providerId) |
| 49 | { |
| 50 | $this->query->where('provider.id', '=', $providerId); |
| 51 | return $this; |
| 52 | } |
| 53 | |
| 54 | public function addConditionProviderSource($source) |
| 55 | { |
| 56 | $this->query->where('provider.source', '=', $source); |
| 57 | return $this; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @todo find calls and implement "sourceName"-parameter to remove default value |
| 62 | */ |
| 63 | public function addConditionRequestCsv($requestIdCsv, $sourceName = 'dldb') |
| 64 | { |
| 65 | $requestIdList = explode(',', $requestIdCsv); |
| 66 | $this->leftJoin( |
| 67 | new Alias("request_provider", 'xprovider'), |
| 68 | 'provider.id', |
| 69 | '=', |
| 70 | 'xprovider.provider__id' |
| 71 | ); |
| 72 | $this->query->where(function (\BO\Zmsdb\Query\Builder\ConditionBuilder $query) use ($requestIdList, $sourceName) { |
| 73 | $query->andWith('xprovider.request__id', 'IN', $requestIdList); |
| 74 | $query->andWith('xprovider.bookable', '=', 1); |
| 75 | $query->andWith('xprovider.source', '=', $sourceName); |
| 76 | }); |
| 77 | } |
| 78 | |
| 79 | public function postProcess($data) |
| 80 | { |
| 81 | if (isset($data[$this->getPrefixed('data')]) && $data[$this->getPrefixed('data')]) { |
| 82 | $data[$this->getPrefixed('data')] = json_decode($data[$this->getPrefixed('data')], true); |
| 83 | } |
| 84 | return $data; |
| 85 | } |
| 86 | } |