Lines
0.00%
0 / 13
Functions and Methods
0.00%
0 / 5
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Closure | 0.00% | 0 / 13 | 0.00% | 0 / 5 | 72 | 0.00% | 0 / 1 | |||
| getDefaults | 0.00% | 0 / 4 | 0.00% | 0 / 1 | 2 | |||||
| setTimestampFromDateformat | 0.00% | 0 / 4 | 0.00% | 0 / 1 | 6 | |||||
| getDateTime | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| isNewerThan | 0.00% | 0 / 3 | 0.00% | 0 / 1 | 12 | |||||
| isAffectingAvailability | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsentities; | |
| 4 | ||
| 5 | class Closure extends Schema\Entity | |
| 6 | { | |
| 7 | public const string PRIMARY = 'id'; | |
| 8 | ||
| 9 | public static $schema = "closure.json"; | |
| 10 | ||
| 11 | /** | |
| 12 | * @return int[] | |
| 13 | * | |
| 14 | */ | |
| 15 | #[\Override] | |
| 16 | public function getDefaults() | |
| 17 | { | |
| 18 | return [ | |
| 19 | 'id' => 0, | |
| 20 | 'lastChange' => 1447924981 | |
| 21 | ]; | |
| 22 | } | |
| 23 | ||
| 24 | public function setTimestampFromDateformat(string $fromFormat = 'd.m.Y'): static | |
| 25 | { | |
| 26 | $dateTime = \DateTimeImmutable::createFromFormat($fromFormat, $this->date, new \DateTimeZone('UTC')); | |
| 27 | if ($dateTime) { | |
| 28 | $this->date = $dateTime->modify('00:00:00')->getTimestamp(); | |
| 29 | } | |
| 30 | return $this; | |
| 31 | } | |
| 32 | ||
| 33 | public function getDateTime(): Helper\DateTime | |
| 34 | { | |
| 35 | return (new \BO\Zmsentities\Helper\DateTime($this->year . '-' . $this->month . '-' . $this->day)); | |
| 36 | } | |
| 37 | ||
| 38 | /** | |
| 39 | * Check if closure is newer than given time | |
| 40 | * | |
| 41 | * @return bool | |
| 42 | */ | |
| 43 | public function isNewerThan(\DateTimeInterface $dateTime, mixed $filterByAvailability = null, mixed $now = null) | |
| 44 | { | |
| 45 | if ($filterByAvailability && !$this->isAffectingAvailability($filterByAvailability, $now)) { | |
| 46 | return false; | |
| 47 | } | |
| 48 | return ($dateTime->getTimestamp() < $this->lastChange); | |
| 49 | } | |
| 50 | ||
| 51 | public function isAffectingAvailability(Availability $availabiliy, \DateTimeInterface $now): bool | |
| 52 | { | |
| 53 | return $availabiliy->isBookable($this->getDateTime(), $now); | |
| 54 | } | |
| 55 | } |