summaryrefslogtreecommitdiff
path: root/app/frontend/controls/CalendarGrid.php
blob: b168379cfe6a93229e376ea2853ee48ecf9e9366 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php

Prado::using('Application.web.FacadeTemplateControl');
Prado::using('Application.facades.EventFacade');
Prado::using('Application.user.DbUser');

class CalendarGrid extends FacadeTemplateControl {

    public function setMonth($month) {
        $this->setControlState('Month', $month);
    }

    public function getMonth() {
        return $this->getControlState('Month');
    }

    public function setYear($year) {
        $this->setControlState('Year', $year);
    }

    public function getYear() {
        return $this->getControlState('Year');
    }

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

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

    private function _getGrid() {
        return $this->getFacade()->getCalendarListForUser(
            $this->UserToDisplay,
            $this->Month,
            $this->Year
        );
    }

    public function onPreRender($param) {
        parent::onPreRender($param);
        $this->Weeks->DataSource = $this->_getGrid()->Weeks;
        $this->Weeks->dataBind();
    }

    public function weekDataBind($sender, $param) {
        $param->Item->Days->DataSource = $param->Item->Data;
        $param->Item->Days->dataBind();
    }

    public function dayDataBind($sender, $param) {
        $param->Item->Events->DataSource = $param->Item->Data->Events;
        $param->Item->Events->dataBind();
    }

    public function eventCreate($sender, $param) {
        if (preg_match('/Item$/', $param->Item->ItemType)) {
            $renderer = 'Dummy';
            if ($param->Item->Data) {
                $renderer = $param->Item->Data->getRendererClass();
            }
            $eventTemplate = Prado::createComponent(
                'Application.controls.grid.' . $renderer . 'GridElement'
            );
            $eventTemplate->setData($param->Item->Data);
            $param->Item->addParsedObject($eventTemplate);
        }
    }

}

?>