summaryrefslogtreecommitdiff
path: root/app/php/controls/UpcomingEvents.php
blob: 80f29a50d973f39e30da08bc39bb1b850352c7f3 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php

Prado::using('Application.web.TemplateControl');

Prado::using('Application.facades.EventFacade');

class UpcomingEvents extends TemplateControl {

    public function setFacade(Facade $facade) {
        $this->setViewState('Facade', $facade);
    }

    public function getFacade() {
        return $this->getViewState('Facade');
    }

    public function getUserToDisplay() {
        return $this->getControlState('user');
    }

    public function setUserToDisplay($user) {
        $this->setControlState('user', $user);
    }

    public function onPreRender($param) {
        parent::onPreRender($param);
        $this->Events->setDataSource(
            $this->_getEventsForUser($this->UserToDisplay)
        );
        $this->Events->dataBind();
    }

    private function _getEventsForUser(DbUser $user) {
        $utc = new DateTimeZone('UTC');
        $dateFrom = new DateTime('now', $utc);
        $dateTo = new DateTime('+7 days', $utc);
        return $this->getFacade()->getTimeframeListForUser(
            $user,
            $dateFrom, $dateTo
        );
    }

}

?>