Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
47 / 47 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
Provider | |
100.00% |
47 / 47 |
|
100.00% |
6 / 6 |
11 | |
100.00% |
1 / 1 |
getEntityMapping | |
100.00% |
17 / 17 |
|
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 | ]; |
25 | if ($this->getResolveLevel() > 0) { |
26 | $mapping['data'] = 'provider.data'; |
27 | } |
28 | return $mapping; |
29 | } |
30 | |
31 | public function addConditionIsAssigned($isAssigned) |
32 | { |
33 | $this->leftJoin( |
34 | new Alias(Scope::TABLE, 'assignedscope'), |
35 | 'provider.id', |
36 | '=', |
37 | 'assignedscope.InfoDienstleisterID' |
38 | ); |
39 | if (true === $isAssigned) { |
40 | $this->query->where('assignedscope.InfoDienstleisterID', 'IS NOT', null); |
41 | } elseif (false === $isAssigned) { |
42 | $this->query->where('assignedscope.InfoDienstleisterID', 'IS', null); |
43 | } |
44 | return $this; |
45 | } |
46 | |
47 | public function addConditionProviderId($providerId) |
48 | { |
49 | $this->query->where('provider.id', '=', $providerId); |
50 | return $this; |
51 | } |
52 | |
53 | public function addConditionProviderSource($source) |
54 | { |
55 | $this->query->where('provider.source', '=', $source); |
56 | return $this; |
57 | } |
58 | |
59 | /** |
60 | * @todo find calls and implement "sourceName"-parameter to remove default value |
61 | */ |
62 | public function addConditionRequestCsv($requestIdCsv, $sourceName = 'dldb') |
63 | { |
64 | $requestIdList = explode(',', $requestIdCsv); |
65 | $this->leftJoin( |
66 | new Alias("request_provider", 'xprovider'), |
67 | 'provider.id', |
68 | '=', |
69 | 'xprovider.provider__id' |
70 | ); |
71 | $this->query->where(function (\Solution10\SQL\ConditionBuilder $query) use ($requestIdList, $sourceName) { |
72 | $query->andWith('xprovider.request__id', 'IN', $requestIdList); |
73 | $query->andWith('xprovider.bookable', '=', 1); |
74 | $query->andWith('xprovider.source', '=', $sourceName); |
75 | }); |
76 | } |
77 | |
78 | public function postProcess($data) |
79 | { |
80 | if (isset($data[$this->getPrefixed('data')]) && $data[$this->getPrefixed('data')]) { |
81 | $data[$this->getPrefixed('data')] = json_decode($data[$this->getPrefixed('data')], true); |
82 | } |
83 | return $data; |
84 | } |
85 | } |