Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
26 / 26 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
Month | |
100.00% |
26 / 26 |
|
100.00% |
5 / 5 |
9 | |
100.00% |
1 / 1 |
getDefaults | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getFirstDay | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getDayList | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
setDays | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
createForDateFromDayList | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace BO\Zmsentities; |
4 | |
5 | class Month extends Schema\Entity |
6 | { |
7 | const PRIMARY = 'month'; |
8 | |
9 | public $calendarDayList; |
10 | |
11 | public static $schema = "month.json"; |
12 | |
13 | public function getDefaults() |
14 | { |
15 | return [ |
16 | 'days' => new Collection\DayList(), |
17 | ]; |
18 | } |
19 | |
20 | public function getFirstDay() |
21 | { |
22 | $dateTime = Helper\DateTime::create($this['year'] . '-' . $this['month'] . '-1'); |
23 | return $dateTime->modify('00:00:00'); |
24 | } |
25 | |
26 | public function getDayList() |
27 | { |
28 | if (!$this->days instanceof Collection\DayList) { |
29 | $this->days = new Collection\DayList($this->days); |
30 | } |
31 | return $this->days; |
32 | } |
33 | |
34 | public function setDays(Collection\DayList $dayList) |
35 | { |
36 | foreach ($this->getDayList() as $key => $day) { |
37 | if (!$day instanceof Day) { |
38 | $day = new Day($day); |
39 | } |
40 | $this->days[$key] = $dayList->getDayByDay($day); |
41 | } |
42 | return $this; |
43 | } |
44 | |
45 | public static function createForDateFromDayList( |
46 | \DateTimeInterface $currentDate, |
47 | \BO\Zmsentities\Collection\DayList $dayList |
48 | ) { |
49 | $startDow = date('w', mktime(0, 0, 0, $currentDate->format('m'), 1, $currentDate->format('Y'))); |
50 | $monthDayList = $dayList->withAssociatedDays($currentDate); |
51 | $month = (new self( |
52 | array( |
53 | 'year' => $currentDate->format('Y'), |
54 | 'month' => $currentDate->format('m'), |
55 | 'calHeadline' => \BO\Zmsentities\Helper\DateTime::getFormatedDates($currentDate, 'MMMM yyyy'), |
56 | 'startDow' => ($startDow == 0) ? 6 : $startDow - 1, // change for week start with monday on 0, |
57 | 'days' => $monthDayList, |
58 | 'appointmentExists' => $monthDayList->hasDayWithAppointments(), |
59 | ) |
60 | )); |
61 | return $month; |
62 | } |
63 | } |