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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
<?php
use Grading\Definition;
use Grading\Instance;
/**
* GradebookModule.class.php - Gradebook 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 <mlunzena@uos.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
*/
class GradebookModule extends CorePlugin implements SystemPlugin, StudipModule
{
public function __construct()
{
parent::__construct();
NotificationCenter::on('UserDidDelete', function ($event, $user) {
Instance::deleteBySQL('user_id = ?', [$user->id]);
});
NotificationCenter::on('CourseDidDelete', function ($event, $course) {
Definition::deleteBySQL('course_id = ?', [$course->id]);
});
}
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getInfoTemplate($courseId)
{
return null;
}
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
public function getIconNavigation($courseId, $lastVisit, $userId)
{
if ($userId === 'nobody') {
return null;
}
$title = _('Gradebook');
if ($GLOBALS['perm']->have_studip_perm('tutor', $courseId, $userId)) {
$changed = Instance::countBySQL(
'INNER JOIN grading_definitions gd ON(gd.id = definition_id) '.
'WHERE gd.course_id = ? AND grading_instances.chdate > ?',
[$courseId, $lastVisit]
);
} else {
$changed = Instance::countBySQL(
'INNER JOIN grading_definitions gd ON(gd.id = definition_id) '.
'WHERE gd.course_id = ? AND grading_instances.chdate > ? AND user_id = ?',
[$courseId, $lastVisit, $userId]
);
}
$icon = $changed
? Icon::create('assessment', Icon::ROLE_NEW)
: Icon::create('assessment', Icon::ROLE_CLICKABLE);
$navigation = new Navigation($title, 'dispatch.php/course/gradebook/overview');
$navigation->setImage($icon, ['title' => $title]);
return $navigation;
}
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
public function getTabNavigation($cid)
{
if ('nobody' === $GLOBALS['user']->id) {
return [];
}
$gradebook = new Navigation('Gradebook');
$gradebook->addSubNavigation('index', new Navigation(_('Erbrachte Leistungen'), 'dispatch.php/course/gradebook/overview'));
if ($GLOBALS['perm']->have_studip_perm('tutor', $cid)) {
$this->addTabNavigationOfLecturers($gradebook, $cid);
}
return compact('gradebook');
}
/**
* @SuppressWarnings(PHPMD.Superglobals)
*/
private function addTabNavigationOfLecturers(\Navigation $navigation, $cid)
{
$navigation->addSubNavigation(
'weights',
new Navigation(_('Gewichtungen'), 'dispatch.php/course/gradebook/lecturers/weights')
);
$navigation->addSubNavigation(
'edit_custom_definitions',
new Navigation(_('Manuelle Leistungen definieren'), 'dispatch.php/course/gradebook/lecturers/edit_custom_definitions')
);
$navigation->addSubNavigation(
'custom_definitions',
new Navigation(_('Noten manuell erfassen'), 'dispatch.php/course/gradebook/lecturers/custom_definitions')
);
}
/**
* {@inheritdoc}
*/
public function exportUserData(StoredUserData $storage)
{
if ($instances = Grading\Instance::findBySql('user_id = ?', [$storage->user_id])) {
$fieldData = array_map(
function ($instance) {
return
array_merge(
$instance->definition->toRawArray('course_id item name tool category weight'),
$instance->toRawArray('rawgrade feedback mkdate chdate')
);
},
$instances
);
if ($fieldData) {
$storage->addTabularData(_('Leistungen'), 'fach', $fieldData);
}
}
}
/**
* Provides metadata like a descriptional text for this module that
* is shown on the course "+" page to inform users about what the
* module acutally does. Additionally, a URL can be specified.
*
* @return array metadata containg description and/or url
*/
public function getMetadata()
{
return [
'summary' => _('Noten- und Fortschrittserfassung (Gradebook)'),
'description' => _('Dieses Modul ermöglicht die manuelle und automatische Erfassung von Noten und Leistungen.'),
'category' => _('Lehr- und Lernorganisation'),
'keywords' => _('automatische und manuelle Erfassung von gewichteten Leistungen;Export von Leistungen;persönliche Fortschrittskontrolle'),
'icon' => Icon::create('assessment', Icon::ROLE_INFO),
'icon_clickable' => Icon::create('assessment', Icon::ROLE_CLICKABLE),
'screenshots' => [
'path' => 'assets/images/plus/screenshots/Gradebook',
'pictures' => [
[
'source' => 'Lehrendensicht.png',
'title' => 'Beispiel für das Gradebook aus der Sicht der Lehrenden',
],
[
'source' => 'Studierendensicht.png',
'title' => 'Beispiel für das Gradebook aus der Sicht der Studierenden',
],
],
],
];
}
public function isActivatableForContext(Range $context)
{
return $context->getRangeType() === 'course';
}
}
|