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