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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
<?php
use Lti\ResourceLink;
/**
* course/lti.php - LTI Resources
*
* 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 Course_LtiController extends StudipController
{
protected $with_session = true;
protected bool $isModerator = false;
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
$this->range_id = Context::getId();
$this->course = Course::find($this->range_id);
$this->isModerator = LtiToolModule::isModerator($this->range_id);
}
/**
* Display the list of LTI Resources.
*/
public function index_action(): void
{
if (Navigation::hasItem('/course/lti/index')) {
Navigation::activateItem('/course/lti/index');
}
PageLayout::setTitle(_('LTI-Ressourcen'));
Helpbar::get()->addPlainText('', _('Auf dieser Seite können Sie externe Anwendungen einbinden, sofern diese den LTI-Standard (Version 1.x order 1.3a) unterstützen.'));
if ($this->isModerator) {
$widget = Sidebar::get()->addWidget(new ActionsWidget());
$widget->addLink(
_('LTI-Ressource hinzufügen'),
$this->url_for('admin/lti/resources/create'),
Icon::create('add')
);
}
//Check for error messages:
if (Request::get('resource_link_id') && (Request::submitted('lti_msg') || Request::submitted('lti_errormsg'))) {
$resourceLink = ResourceLink::findOneBySQL(
"`id` = :id AND `course_id` = :course_id",
[
'id' => Request::get('resource_link_id'),
'course_id' => $this->range_id
]
);
if ($resourceLink) {
if (Request::get('lti_msg')) {
PageLayout::postInfo(htmlReady($resourceLink->title), [Request::get('lti_msg')]);
}
if (Request::get('lti_errormsg')) {
PageLayout::postError(htmlReady($resourceLink->title), [Request::get('lti_errormsg')]);
}
}
}
$this->render_vue_app(
Studip\VueApp::create('lti/resources/Index')
);
}
/**
* Display the (simple) LTI grade book.
*/
public function grades_action(): void
{
if (Navigation::hasItem('/course/lti/grades')) {
Navigation::activateItem('/course/lti/grades');
}
$this->lti_data_array = ResourceLink::findBySQL(
"`course_id` = :course_id ORDER BY `position`",
['course_id' => $this->range_id]
);
if ($this->isModerator) {
$this->desc = Request::int('desc');
$this->members = CourseMember::findByCourseAndStatus($this->range_id, 'autor');
if ($this->desc) {
$this->members = array_reverse($this->members);
}
$widget = Sidebar::get()->addWidget(new ExportWidget());
$widget->addLink(
_('Ergebnisse exportieren'),
$this->url_for('course/lti/export_grades'),
Icon::create('download')
);
} else {
$this->render_action('grades_user');
}
Helpbar::get()->addPlainText('', _('Auf dieser Seite können Sie die Ergebnisse sehen, die von LTI-Tools zurückgemeldet wurden.'));
}
/**
* Export grades from the gradebook in CSV format.
*/
public function export_grades_action(): void
{
$lti_data_array = ResourceLink::findByCourse_id($this->range_id, 'ORDER BY position');
$columns = [_('Nachname'), _('Vorname')];
// add one column for each LTI tool block
foreach ($lti_data_array as $lti_data) {
$columns[] = $lti_data->title;
}
$data = [$columns];
foreach (CourseMember::findByCourseAndStatus($this->range_id, 'autor') as $member) {
$row = [$member->nachname, $member->vorname];
foreach ($lti_data_array as $lti_data) {
if ($grade = $lti_data->grades->findOneBy('user_id', $member->user_id)) {
$row[] = (float) $grade->score;
} else {
$row[] = '';
}
}
$data[] = $row;
}
$filename = Context::get()->name . ' - ' . _('Ergebnisse') . '.csv';
$this->render_csv($data, $filename);
}
}
|