Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
30 / 30 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
RequestRelation | |
100.00% |
30 / 30 |
|
100.00% |
8 / 8 |
8 | |
100.00% |
1 / 1 |
getEntityMapping | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
getReferenceMapping | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
addConditionRequestId | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
addConditionProviderId | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
addConditionBookable | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
addConditionSource | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getQueryCountByProvider | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getQueryCountByRequest | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace BO\Zmsdb\Query; |
4 | |
5 | class RequestRelation extends Base implements MappingInterface |
6 | { |
7 | const TABLE = 'request_provider'; |
8 | |
9 | const ALIAS = 'request_provider'; |
10 | |
11 | public function getEntityMapping() |
12 | { |
13 | return [ |
14 | 'request__id' => self::TABLE . '.request__id', |
15 | 'provider__id' => self::TABLE . '.provider__id', |
16 | 'source' => self::TABLE . '.source', |
17 | 'slots' => self::TABLE . '.slots', |
18 | 'public' => self::TABLE . '.public_visibility', |
19 | 'maxQuantity' => self::TABLE . '.max_quantity' |
20 | ]; |
21 | } |
22 | |
23 | public function getReferenceMapping() |
24 | { |
25 | return [ |
26 | 'request__$ref' => self::expression( |
27 | 'CONCAT("/request/", `' . self::TABLE . '`.`source`, "/", `' . self::TABLE . '`.`request__id`, "/")' |
28 | ), |
29 | 'provider__$ref' => self::expression( |
30 | 'CONCAT("/provider/", `' . self::TABLE . '`.`source`, "/", `' . self::TABLE . '`.`provider__id`, "/")' |
31 | ) |
32 | ]; |
33 | } |
34 | |
35 | public function addConditionRequestId($requestId) |
36 | { |
37 | $this->query->where(self::TABLE . '.request__id', '=', $requestId); |
38 | return $this; |
39 | } |
40 | |
41 | public function addConditionProviderId($providerId) |
42 | { |
43 | $this->query->where(self::TABLE . '.provider__id', '=', $providerId); |
44 | return $this; |
45 | } |
46 | |
47 | public function addConditionBookable() |
48 | { |
49 | $this->query->where(self::TABLE . '.bookable', '=', 1); |
50 | return $this; |
51 | } |
52 | |
53 | public function addConditionSource($sourceName) |
54 | { |
55 | $this->query->where(self::TABLE . '.source', '=', $sourceName); |
56 | return $this; |
57 | } |
58 | |
59 | public function getQueryCountByProvider(): string |
60 | { |
61 | return ' |
62 | SELECT COUNT(*) |
63 | FROM ' . self::TABLE . ' |
64 | WHERE provider__id = :provider_id |
65 | AND source = :source |
66 | '; |
67 | } |
68 | |
69 | public function getQueryCountByRequest(): string |
70 | { |
71 | return ' |
72 | SELECT COUNT(*) |
73 | FROM ' . self::TABLE . ' |
74 | WHERE request__id = :request_id |
75 | AND source = :source |
76 | '; |
77 | } |
78 | } |