Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
21.28% covered (danger)
21.28%
10 / 47
25.00% covered (danger)
25.00%
2 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
Closure
21.28% covered (danger)
21.28%
10 / 47
25.00% covered (danger)
25.00%
2 / 8
82.25
0.00% covered (danger)
0.00%
0 / 1
 getEntityMapping
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 addConditionDate
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 addConditionScopeId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionScopeIds
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
30
 addConditionDateRange
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 addSelectVirtualDate
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 addConditionId
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 postProcess
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace BO\Zmsdb\Query;
4
5use DateTime;
6use DateTimeInterface;
7
8class Closure extends Base implements MappingInterface
9{
10    /**
11     * @var String TABLE mysql table reference
12     */
13    const TABLE = 'closures';
14
15    /**
16     * No resolving required here
17     */
18    protected $resolveLevel = 0;
19
20    #[\Override]
21    public function getEntityMapping()
22    {
23        return [
24            'id' => 'closure.id',
25            'scopeId'    => 'closure.StandortID',
26            'year' => 'closure.year',
27            'month' => 'closure.month',
28            'day' => 'closure.day',
29            'lastChange' => 'closure.updateTimestamp'
30        ];
31    }
32
33    public function addConditionDate(DateTime $date)
34    {
35        $this->query->where('closure.year', '=', $date->format('Y'));
36        $this->query->where('closure.month', '=', $date->format('m'));
37        $this->query->where('closure.day', '=', $date->format('d'));
38        return $this;
39    }
40
41    public function addConditionScopeId($scopeId)
42    {
43        $this->query->where('closure.StandortID', '=', $scopeId);
44        return $this;
45    }
46
47    public function addConditionScopeIds(array $scopeIds)
48    {
49        $ids = array_values(array_unique(array_map('intval', $scopeIds)));
50
51        if (empty($ids)) {
52            $this->query->where(self::expression('1 = 0'));
53            return $this;
54        }
55
56        if (count($ids) === 1) {
57            return $this->addConditionScopeId($ids[0]);
58        }
59
60        $this->query->where(function ($conditions) use ($ids) {
61            $first = true;
62            foreach ($ids as $id) {
63                if ($first) {
64                    $conditions->andWith('closure.StandortID', '=', $id);
65                    $first = false;
66                } else {
67                    $conditions->orWith('closure.StandortID', '=', $id);
68                }
69            }
70        });
71
72        return $this;
73    }
74
75    public function addConditionDateRange(\DateTimeInterface $from, \DateTimeInterface $until)
76    {
77        $dateExpr = self::expression(
78            "DATE(CONCAT(closure.year,'-',LPAD(closure.month,2,'0'),'-',LPAD(closure.day,2,'0')))"
79        );
80        $this->query->where($dateExpr, '>=', $from->format('Y-m-d'));
81        $this->query->where($dateExpr, '<=', $until->format('Y-m-d'));
82        return $this;
83    }
84
85    public function addSelectVirtualDate()
86    {
87        $this->query->select([
88            $this->getPrefixed('date') => self::expression(
89                "DATE(CONCAT(closure.year,'-',LPAD(closure.month,2,'0'),'-',LPAD(closure.day,2,'0')))"
90            )
91        ]);
92        return $this;
93    }
94
95    public function addConditionId($id)
96    {
97        $this->query->where('closure.id', '=', $id);
98        return $this;
99    }
100
101    #[\Override]
102    public function postProcess($data)
103    {
104        $data[$this->getPrefixed("lastChange")] =
105            (new \DateTime($data[$this->getPrefixed("lastChange")] . \BO\Zmsdb\Connection\Select::$connectionTimezone))
106            ->getTimestamp();
107        return $data;
108    }
109}