Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
14.58% |
7 / 48 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
Closure | |
14.58% |
7 / 48 |
|
0.00% |
0 / 6 |
72.32 | |
0.00% |
0 / 1 |
readByScopeId | |
70.00% |
7 / 10 |
|
0.00% |
0 / 1 |
4.43 | |||
readByScopeIdAndDate | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
readByScopesInRange | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 | |||
deleteEntity | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
createOne | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
readEntity | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace BO\Zmsdb; |
4 | |
5 | use BO\Zmsentities\Closure as Entity; |
6 | use BO\Zmsentities\Collection\ClosureList as Collection; |
7 | use DateTime; |
8 | |
9 | class Closure extends Base |
10 | { |
11 | public function readByScopeId($scopeId = 0) |
12 | { |
13 | $closureList = new Collection(); |
14 | $query = new Query\Closure(Query\Base::SELECT); |
15 | $query->addEntityMapping() |
16 | ->addConditionScopeId($scopeId); |
17 | $result = $this->fetchList($query, new Entity()); |
18 | if (count($result)) { |
19 | foreach ($result as $entity) { |
20 | if ($entity instanceof Entity) { |
21 | $closureList->addEntity($entity); |
22 | } |
23 | } |
24 | } |
25 | return $closureList; |
26 | } |
27 | |
28 | public function readByScopeIdAndDate($scopeId, DateTime $date) |
29 | { |
30 | $query = new Query\Closure(Query\Base::SELECT); |
31 | $query->addEntityMapping() |
32 | ->addConditionScopeId($scopeId) |
33 | ->addConditionDate($date); |
34 | |
35 | return $this->fetchOne($query, new \BO\Zmsentities\Closure()); |
36 | } |
37 | |
38 | public function readByScopesInRange( |
39 | array $scopeIds, |
40 | \DateTimeInterface $from, |
41 | \DateTimeInterface $until |
42 | ): array { |
43 | $query = (new \BO\Zmsdb\Query\Closure(\BO\Zmsdb\Query\Base::SELECT)) |
44 | ->addEntityMapping() |
45 | ->addSelectVirtualDate() |
46 | ->addConditionScopeIds($scopeIds) |
47 | ->addConditionDateRange($from, $until); |
48 | |
49 | $entities = $this->fetchList($query, new Entity()); |
50 | |
51 | $result = []; |
52 | foreach ($entities as $entity) { |
53 | $date = $entity->date ?? $entity->getDateTime()->format('Y-m-d'); |
54 | $result [] = [ |
55 | 'scopeId' => (int) $entity->scopeId, |
56 | 'date' => (string) $date, |
57 | ]; |
58 | } |
59 | return $result ; |
60 | } |
61 | |
62 | public function deleteEntity($itemId) |
63 | { |
64 | $query = new Query\Closure(Query\Base::DELETE); |
65 | $query->addConditionId($itemId); |
66 | return ($this->deleteItem($query)); |
67 | } |
68 | |
69 | public function createOne($scopeId, DateTime $date) |
70 | { |
71 | $query = new Query\Closure(Query\Base::INSERT); |
72 | $query->addValues( |
73 | array( |
74 | 'StandortID' => $scopeId, |
75 | 'year' => (int) $date->format('Y'), |
76 | 'month' => (int) $date->format('m'), |
77 | 'day' => (int) $date->format('d') |
78 | ) |
79 | ); |
80 | $this->writeItem($query); |
81 | $id = $this->getWriter()->lastInsertId(); |
82 | |
83 | return $this->readEntity($id); |
84 | } |
85 | |
86 | public function readEntity($id) |
87 | { |
88 | $query = new Query\Closure(Query\Base::SELECT); |
89 | $query->addEntityMapping() |
90 | ->addConditionId($id); |
91 | |
92 | return $this->fetchOne($query, new \BO\Zmsentities\Closure()); |
93 | } |
94 | } |