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