aboutsummaryrefslogtreecommitdiff
path: root/lib/navigation/ConsultationNavigation.php
blob: 73aaf5497f597ea816be8b5a6e90c82e60eb975e (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
74
75
<?php
class ConsultationNavigation extends Navigation
{
    /** @var Range */
    protected $range;

    public function __construct(Range $range)
    {
        $this->range = $range;

        parent::__construct($range->getConfiguration()->CONSULTATION_TAB_TITLE);
    }

    public function initItem()
    {
        parent::initItem();

        if ($this->range->isEditableByUser()) {
            $this->setURL('dispatch.php/consultation/admin');
        }
    }

    /**
     * Determine whether this navigation item is active.
     */
    public function isActive()
    {
        $active = parent::isActive();

        if ($active) {
            if ($this->range instanceof User) {
                URLHelper::addLinkParam('username', $this->range->username);
            } elseif ($this->range instanceof Course || $this->range instanceof Institute) {
                URLHelper::addLinkParam('cid', $this->range->id);
            }
        }

        return $active;
    }

    /**
     * Initialize the subnavigation of this item. This method
     * is called once before the first item is added or removed.
     */
    public function initSubNavigation()
    {
        parent::initSubNavigation();

        if ($this->range->isEditableByUser()) {
            $this->addSubNavigation('admin', new Navigation(
                _('Verwaltung'),
                'dispatch.php/consultation/admin'
            ));

            return;
        }

        if ($this->range instanceof User) {
            // Permissions that are allowed to book reservervations
            $allowed = ['user', 'autor', 'tutor'];
            if (Config::get()->CONSULTATION_ALLOW_DOCENTS_RESERVING) {
                $allowed[] = 'dozent';
            }

            // User does not have required permissions
            if (!in_array($GLOBALS['user']->perms, $allowed)) {
                return null;
            }
        }

        // Create visitor navigation
        $this->addSubNavigation('overview', new Navigation(_('Übersicht'), 'dispatch.php/consultation/overview'));
        $this->addSubNavigation('booked', new Navigation(_('Meine Buchungen'), 'dispatch.php/consultation/overview/booked'));
    }
}