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    public function getEntityMapping()
21    {
22        return [
23            'id' => 'closure.id',
24            'scopeId'    => 'closure.StandortID',
25            'year' => 'closure.year',
26            'month' => 'closure.month',
27            'day' => 'closure.day',
28            'lastChange' => 'closure.updateTimestamp'
29        ];
30    }
31
32    public function addConditionDate(DateTime $date)
33    {
34        $this->query->where('closure.year', '=', $date->format('Y'));
35        $this->query->where('closure.month', '=', $date->format('m'));
36        $this->query->where('closure.day', '=', $date->format('d'));
37        return $this;
38    }
39
40    public function addConditionScopeId($scopeId)
41    {
42        $this->query->where('closure.StandortID', '=', $scopeId);
43        return $this;
44    }
45
46    public function addConditionScopeIds(array $scopeIds)
47    {
48        $ids = array_values(array_unique(array_map('intval', $scopeIds)));
49
50        if (empty($ids)) {
51            $this->query->where(self::expression('1 = 0'));
52            return $this;
53        }
54
55        if (count($ids) === 1) {
56            return $this->addConditionScopeId($ids[0]);
57        }
58
59        $this->query->where(function ($conditions) use ($ids) {
60            $first = true;
61            foreach ($ids as $id) {
62                if ($first) {
63                    $conditions->andWith('closure.StandortID', '=', $id);
64                    $first = false;
65                } else {
66                    $conditions->orWith('closure.StandortID', '=', $id);
67                }
68            }
69        });
70
71        return $this;
72    }
73
74    public function addConditionDateRange(\DateTimeInterface $from, \DateTimeInterface $until)
75    {
76        $dateExpr = self::expression(
77            "DATE(CONCAT(closure.year,'-',LPAD(closure.month,2,'0'),'-',LPAD(closure.day,2,'0')))"
78        );
79        $this->query->where($dateExpr, '>=', $from->format('Y-m-d'));
80        $this->query->where($dateExpr, '<=', $until->format('Y-m-d'));
81        return $this;
82    }
83
84    public function addSelectVirtualDate()
85    {
86        $this->query->select([
87            $this->getPrefixed('date') => self::expression(
88                "DATE(CONCAT(closure.year,'-',LPAD(closure.month,2,'0'),'-',LPAD(closure.day,2,'0')))"
89            )
90        ]);
91        return $this;
92    }
93
94    public function addConditionId($id)
95    {
96        $this->query->where('closure.id', '=', $id);
97        return $this;
98    }
99
100    public function postProcess($data)
101    {
102        $data[$this->getPrefixed("lastChange")] =
103            (new \DateTime($data[$this->getPrefixed("lastChange")] . \BO\Zmsdb\Connection\Select::$connectionTimezone))
104            ->getTimestamp();
105        return $data;
106    }
107}