summaryrefslogtreecommitdiff
path: root/app/frontend/dto/CalendarGridDayDTO.php
blob: ba65eb988a1bcd9ff7623712af953883831b8c23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php

Prado::using('Application.dto.EventDTO');
Prado::using('Application.dto.GridEventDTO');

class CalendarGridDayDTO {

    public $Date;
    public $Events;

    public function __construct(DateTimeImmutable $date, array $events) {
        $this->Date = $date->format('Y-m-d');
        $this->Events = array_filter($events, [$this, '_checkEventDate']);
        // initial sort (date and calendar name)
        // events are going to be re-sorted after assigning grid priorities
        usort($this->Events, ['EventDTO', '__compare']);
    }

    private function _checkEventDate(GridEventDTO $event) {
        if (!$this->Date) {
            return FALSE;
        }
        return ($this->Date >= $event->DateFrom) && ($this->Date <= $event->DateTo);
    }

}

?>