aboutsummaryrefslogtreecommitdiff
path: root/lib/modules/LtiToolModule.php
blob: 2a64e8307d8a4d51e5c31687af5e360f2d357825 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
 * LtiToolModule.php - LTI consumer API for Stud.IP
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * @author      Elmar Ludwig
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 */
class LtiToolModule extends CorePlugin implements StudipModule, SystemPlugin, PrivacyPlugin
{
    /**
     * Initialize the LtiToolModule.
     */
    public function __construct()
    {
        parent::__construct();

        if ($GLOBALS['perm']->have_perm('root')) {
            Navigation::addItem('/admin/config/lti', new Navigation(_('LTI-Tools'), 'dispatch.php/admin/lti'));
        }

        NotificationCenter::on('UserDidDelete', function ($event, $user) {
            LtiGrade::deleteBySQL('user_id = ?', [$user->id]);
        });
        NotificationCenter::on('CourseDidDelete', function ($event, $course) {
            LtiDeployment::deleteBySQL('course_id = ?', [$course->id]);
        });
    }

    /**
     * {@inheritdoc}
     */
    public function getIconNavigation($course_id, $last_visit, $user_id)
    {
        if ($user_id === 'nobody') {
            return null;
        }

        $changed = LtiDeployment::countBySQL('course_id = ? AND chdate > ?', [$course_id, $last_visit]);

        $icon = Icon::create('plugin', $changed ? Icon::ROLE_NEW : Icon::ROLE_CLICKABLE);

        $navigation = new Navigation(_('LTI-Tools'), 'dispatch.php/course/lti');
        $navigation->setImage($icon);
        $navigation->setLinkAttributes(['title' => _('LTI-Tools')]);

        return $navigation;
    }

    /**
     * {@inheritdoc}
     */
    public function getTabNavigation($course_id)
    {
        if ($GLOBALS['user']->id === 'nobody') {
            return [];
        }

        $grades = LtiDeployment::countBySQL('course_id = ?', [$course_id]);

        $navigation = new Navigation(_('LTI-Tools'));
        $navigation->setImage(Icon::create('link-extern', Icon::ROLE_INFO_ALT));
        $navigation->setActiveImage(Icon::create('link-extern', Icon::ROLE_INFO));
        $navigation->addSubNavigation('index', new Navigation(_('LTI-Tools'), 'dispatch.php/course/lti'));

        if ($grades) {
            $navigation->addSubNavigation('grades', new Navigation(_('Ergebnisse'), 'dispatch.php/course/lti/grades'));
        }

        return ['lti' => $navigation];
    }

    /**
     * {@inheritdoc}
     */
    public function getInfoTemplate($course_id)
    {
        return null;
    }

    /**
     * {@inheritdoc}
     */
    public function exportUserData(StoredUserData $storage)
    {
        $db = DBManager::get();

        $data = $db->fetchAll('SELECT * FROM lti_grade WHERE user_id = ?', [$storage->user_id]);
        $storage->addTabularData(_('LTI-Ergebnisse'), 'lti_grade', $data);
    }

    /**
     * {@inheritdoc}
     */
    public function getMetadata()
    {
        return [
            'summary' => _('Anbindung von LTI-Tools'),
            'description' => _('Mit diesem Werkzeug können LTI-Tools eingebunden werden, '.
                               'sofern diese LTI in Version 1.0, 1.1 oder 1.3A unterstützen.'),
            'category' => _('Kommunikation und Zusammenarbeit'),
            'keywords' => implode(';', ['LTI', _('LTI-Tools'), _('E-Learning')]),
            'icon' => Icon::create('plugin', Icon::ROLE_INFO),
            'icon_clickable' => Icon::create('plugin'),
            'screenshots' => [
                'path' => 'assets/images/plus/screenshots/Lti',
                'pictures' => [
                    0 => ['source' => 'LTI_Tool_hinzufuegen.jpg', 'title' => _('LTI-Tool hinzufügen')],
                ]
            ],
            'displayname' => _('LTI-Tools')
        ];
    }
}