aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/Lti/Controller/AdminBaseController.php
blob: 3cd0fce621c6665857f106aa490d3a2e2251bffb (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace Studip\Lti\Controller;

use Icon;
use Context;
use Sidebar;
use LtiToolModule;
use ViewsWidget;
use ActionsWidget;
use AccessDeniedException;
use AuthenticatedController;

abstract class AdminBaseController extends AuthenticatedController
{
    protected ?string $range_id = null;
    protected bool $isModerator = false;
    protected bool $isToolSharingEnabled = false;

    public function before_filter(&$action, &$args)
    {
        parent::before_filter($action, $args);

        $this->range_id = Context::getId();
        $this->isModerator = LtiToolModule::isModerator($this->range_id);

        if (!$this->isModerator) {
            throw new AccessDeniedException();
        }

        $this->isToolSharingEnabled = LtiToolModule::isToolSharingEnabled();
    }

    protected function buildRegistrationsSidebar(): void
    {
        // views:
        $viewWidget = new ViewsWidget();

        $viewWidget->addLink(
            _('LTI-Tools'),
            $this->url_for('admin/lti/registrations', ['role' => 'tool']),
        )->setActive($this->ltiRole !== 'platform');

        if ($this->isToolSharingEnabled) {
            $viewWidget->addLink(
                _('LTI-Platforms'),
                $this->url_for('admin/lti/registrations', ['role' => 'platform'])
            )->setActive($this->ltiRole === 'platform');
        }

        Sidebar::Get()->addWidget($viewWidget);

        // actions:
        $actions = new ActionsWidget();
        $actions->addLink(
            _('Neues LTI-Tool registrieren'),
            $this->url_for('admin/lti/registrations/create', ['role' => 'tool']),
            Icon::create('add')
        )->asDialog('width=900;height=700');

        if ($this->isToolSharingEnabled) {
            $actions->addLink(
                _('Neues LTI-Platform registrieren'),
                $this->url_for('admin/lti/registrations/create', ['role' => 'platform']),
                Icon::create('add')
            )->asDialog('width=900;height=700');
        }

        $actions->addLink(
            _('Daten zur LTI-Plattform anzeigen'),
            $this->url_for('admin/lti/registrations/platform_data'),
            Icon::create('info')
        )->asDialog('width=900;height=700');

        if ($this->isToolSharingEnabled) {
            $actions->addLink(
                _('Daten zur LTI-Tool anzeigen'),
                $this->url_for('admin/lti/registrations/tool_data'),
                Icon::create('info')
            )->asDialog('width=900;height=700');
        }

        Sidebar::get()->addWidget($actions);
    }

    protected function buildPublicationsSidebar(): void
    {
        if($this->isToolSharingEnabled) {
            // actions:
            $actions = new ActionsWidget();
            $actions->addLink(
                _('Neue Veröffentlichung anlegen'),
                $this->url_for('admin/lti/publications/create'),
                Icon::create('add')
            )->asDialog('width=700');

            Sidebar::get()->addWidget($actions);
        }
    }

}