summaryrefslogtreecommitdiff
path: root/app/php/controls/UserSelection.php
blob: 83c7bae6be01c51fc542376119758110c931b29d (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
<?php

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

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

class UserSelection 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->Categories->setDataSource(
            $this->_getUserSelection($this->UserToDisplay)
        );
        $this->Categories->dataBind();
    }

    public function categoryDataBind($sender, $param) {
        $param->Item->Calendars->setDataSource($param->Item->Data->Calendars);
        $param->Item->Calendars->dataBind();
    }

    public function removeFromSelection($sender, $param) {
        if (!$this->UserToDisplay->IsGuest) {
            return $this->getFacade()->removeFromPreference(
                $this->UserToDisplay,
                $param->CommandParameter
            );
        }
    }

    private function _getUserSelection(DbUser $user) {
        return $this->getFacade()->getPreferenceList($user);
    }

}

?>