forked from elan-ev/ePortfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EportfolioPlugin.class.php
348 lines (293 loc) · 13.6 KB
/
EportfolioPlugin.class.php
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<?
require __DIR__ . '/bootstrap.php';
/**
* EportfolioPlugin.class.php
* @author Marcel Kipp
* @version 0.18
*/
class EportfolioPlugin extends StudIPPlugin implements StandardPlugin, SystemPlugin
{
public function __construct()
{
parent::__construct();
$navigation = new Navigation(_('ePortfolios'));
$navigation->setURL(PluginEngine::getURL($this, [], "show"));
if (!Request::get('username') || Request::get('username') == $GLOBALS['user']->username) {
Navigation::addItem('/profile/eportfolioplugin', $navigation);
}
NotificationCenter::addObserver($this, "setup_navigation", "PageWillRender");
NotificationCenter::addObserver($this, "store_activity", "UserDidPostSupervisorNotiz");
NotificationCenter::addObserver($this, "store_activity", "SupervisorDidPostAnswer");
NotificationCenter::addObserver($this, "store_activity", "UserDidPostNotiz");
NotificationCenter::addObserver($this, "prevent_settings_access", "NavigationDidActivateItem");
// generate css to hide all portfolio seminars on the my_realm page - DIRTY HACK, i know
PageLayout::addStyle('#my_seminars {display: none; }');
$stmt = DBManager::get()->prepare('SELECT Seminar_id FROM seminar_user
JOIN eportfolio_user USING (Seminar_id)
WHERE seminar_user.user_id = ?');
$stmt->execute([$GLOBALS['user']->id]);
$js = '';
while ($semid = $stmt->fetchColumn()) {
$js .= "jQuery('#my_seminars .course-$semid').parent().parent().remove();\n";
}
$js .= 'jQuery("#my_seminars").show(); jQuery("#my_seminars .mycourses").each(function() {
if (jQuery(this).find("tbody tr").length == 0) {
jQuery(this).remove();
}
})';
if ($js) {
PageLayout::addHeadElement('script', [], "jQuery(function() { $js })");
}
}
public function getCardInfos($cid)
{
$db = DBManager::get();
$return_arr = [];
$query = "SELECT id, title FROM mooc_blocks WHERE seminar_id = :id AND type = 'Chapter' ORDER BY position ASC";
$statement = $db->prepare($query);
$statement->execute([':id' => $cid]);
$getCardInfos = $statement->fetchAll();
foreach ($getCardInfos as $value) {
$arrayOne = [];
$arrayOne['id'] = $value['id'];
$arrayOne['title'] = $value['title'];
// get sections of chapter
$query = "SELECT id, title FROM mooc_blocks WHERE parent_id = :id";
$statement = $db->prepare($query);
$statement->execute([':id' => $value['id']]);
$arrayOne['section'] = $statement->fetchAll();
array_push($return_arr, $arrayOne);
}
return $return_arr;
}
public function initialize()
{
$this->addStylesheet('assets/style.less');
PageLayout::addStylesheet($this->getPluginURL() . '/assets/flexboxgrid.min.css');
PageLayout::addScript($this->getPluginURL() . '/assets/js/jquery.tablesorter.min.js');
}
public function getTabNavigation($course_id)
{
$tabs = [];
$isSupervisor = SupervisorGroup::isUserInGroup($GLOBALS['user']->id, $course_id)
|| $GLOBALS['perm']->have_perm('root');
//Veranstaltungsreiter in Vorlesung
if (!$this->isPortfolio() && !$this->isVorlage()) {
if ($isSupervisor) {
$navigation = new Navigation('Portfolio-Arbeit', PluginEngine::getURL($this, compact('cid'), 'showsupervisor', true));
$navigation->setImage(Icon::create('group4', 'info_alt'));
$navigation->setActiveImage(Icon::create('group4', 'info'));
$item = new Navigation(_('Portfolio-Arbeit'), PluginEngine::getURL($this, compact('cid'), 'showsupervisor', true));
$navigation->addSubNavigation('supervision', $item);
$item = new Navigation(_('Activity Feed'), PluginEngine::getURL($this, compact('cid'), 'showsupervisor/activityfeed', true));
$navigation->addSubNavigation('portfoliofeed', $item);
$item = new Navigation(_('Berechtigungen Portfolioarbeit'), PluginEngine::getURL($this, compact('cid'), 'supervisorgroup', true));
$navigation->addSubNavigation('supervisorgroup', $item);
} else {
$navigation = new Navigation('Portfolio-Arbeit', PluginEngine::getURL($this, compact('cid'), 'showstudent', true));
$navigation->setImage(Icon::create('group4', 'info_alt'));
$navigation->setActiveImage(Icon::create('group4', 'info'));
}
} else if ($this->isPortfolio() || $this->isVorlage()) {
if ($isSupervisor && !$this->isVorlage()) {
$navigation = new Navigation(
_('Übersicht'),
PluginEngine::getURL($this, ['cid' => $course_id], 'eportfolioplugin', true)
);
$navigation->setImage(Icon::create('group4', 'info_alt'));
$navigation->setActiveImage(Icon::create('group4', 'info'));
}
if (Request::option('return_to')) {
$_SESSION['return_to'] = Request::option('return_to');
}
if ($_SESSION['return_to']) {
if ($_SESSION['return_to'] == 'overview') {
$tabs['return'] = new Navigation(
_('Zurück zum Profil'),
PluginEngine::getURL($this, [], 'show', true)
);
} else {
if ($GLOBALS['perm']->have_studip_perm('tutor', $_SESSION['return_to'])) {
$return_to = 'showsupervisor';
} else {
$return_to = 'showstudent';
}
$tabs['return'] = new Navigation(
_('Zurück zur Veranstaltung'),
PluginEngine::getURL($this, ['cid' => $_SESSION['return_to']], $return_to, true)
);
}
}
}
$owner = Eportfoliomodel::isOwner($course_id, $GLOBALS['user']->id);
if ($this->isPortfolio() && $owner) {
$navigationSettings = new Navigation('Zugriffsrechte', PluginEngine::getURL($this, compact('cid'), 'settings', true));
$navigationSettings->setImage(Icon::create('admin', 'info_alt'));
$navigationSettings->setActiveImage(Icon::create('admin', 'info'));
$tabs['settings'] = $navigationSettings;
} else if ($isSupervisor == true && $this->isVorlage()) {
$navigationSettings = new Navigation('Einstellungen', PluginEngine::getURL($this, compact('cid'), 'blocksettings', true));
$navigationSettings->setImage(Icon::create('admin', 'info_alt'));
$navigationSettings->setActiveImage(Icon::create('admin', 'info'));
$tabs['blocksettings'] = $navigationSettings;
}
$tabs['eportfolioplugin'] = $navigation;
return array_reverse($tabs);
}
public function getNotificationObjects($course_id, $since, $user_id)
{
return [];
}
public function getIconNavigation($course_id, $last_visit, $user_id)
{
global $perm;
if ($perm->have_studip_perm('dozent', $course_id)) {
$url = 'showsupervisor/activityfeed';
} else {
$url = 'showstudent';
}
$icon = new AutoNavigation(
'Portfolio-Arbeit',
PluginEngine::getURL($this, ['cid' => $course_id, 'iconnav' => 'true'], $url, true)
);
$group = EportfolioGroup::find($course_id);
if ($group) {
$new_ones = sizeof($group->getActivities());
if ($new_ones) {
if ($perm->have_studip_perm('dozent', $course_id)) {
$title = $new_ones > 1 ? sprintf(_('%s neue Ereignisse in Studierenden-Portfolios'), $new_ones) : _('1 neues Ereignisse in Studierenden-Portfolio');
} else {
$title = _('Keine neuen Ereignisse.');
}
$icon->setImage(Icon::create('eportfolio', 'attention', ['title' => $title]));
$icon->setBadgeNumber($new_ones);
} else {
$icon->setImage(Icon::create('eportfolio', 'inactive', ['title' => 'Supervision']));
}
}
return $icon;
}
public function getInfoTemplate($course_id)
{
// ...
}
private function getSemClass()
{
global $SEM_CLASS, $SEM_TYPE, $SessSemName;
return $SEM_CLASS[$SEM_TYPE[$SessSemName['art_num']]['class']];
}
private function isSlotModule()
{
if (!$this->getSemClass()) {
return false;
}
return $this->getSemClass()->isSlotModule(get_class($this));
}
//aktuelle cid/seminarid
static function getSeminarId()
{
if (!Request::option('cid')) {
if ($GLOBALS['SessionSeminar']) {
URLHelper::bindLinkParam('cid', $GLOBALS['SessionSeminar']);
return $GLOBALS['SessionSeminar'];
}
return false;
}
return Request::option('cid');
}
private function isPortfolio()
{
$course = Course::findCurrent();
if ($course) {
$status = $course->status;
if ($status == Config::get()->SEM_CLASS_PORTFOLIO) {
return true;
}
}
return false;
}
private function isVorlage()
{
$course = Course::findCurrent();
if ($course) {
$status = $course->status;
if ($status == Config::get()->getValue('SEM_CLASS_PORTFOLIO_VORLAGE')) {
return true;
}
}
return false;
}
private function isSupervisionsgruppe()
{
$course = Course::findCurrent();
if ($course) {
$status = $course->status;
if ($status == Config::get()->getValue('SEM_CLASS_PORTFOLIO_Supervisionsgruppe')) {
return true;
}
}
return false;
}
public function setup_navigation()
{
if (($this->isPortfolio() || $this->isVorlage()) && Navigation::hasItem('/course/mooc_courseware')) {
if ($this->isVorlage()) {
$stmt = DBManager::get()->prepare("UPDATE mooc_blocks
SET title = 'Vorlage'
WHERE type = 'Courseware'
AND seminar_id = ?");
$stmt->execute([Context::getId()]);
Navigation::getItem('/course/mooc_courseware')->setTitle('Vorlage');
} else {
$stmt = DBManager::get()->prepare("UPDATE mooc_blocks
SET title = 'Vorlage'
WHERE type = 'Courseware'
AND seminar_id = ?");
$stmt->execute([Context::getId()]);
Navigation::getItem('/course/mooc_courseware')->setTitle('ePortfolio');
}
//default Courseware-Hilfe ersetzen
$widgets = Helpbar::get()->getWidgets();
foreach ($widgets as $index => $widget) {
$elements = $widget->getElements();
Helpbar::get()->removeWidget($index);
}
if ($this->isPortfolio()) {
$description = _('Unter **Zugriffsrechte** können Sie einzelne Kapitel für Komilitonen oder Ihre Supervisoren freigeben.') . ' ';
$description .= _('') . '';
$tip = _('Unter **ePortfolio** können Sie Ihr Portfolio bearbeiten. ');
$tip .= _('');
$bearbeiten = _('Um Inhalte oder Kapitel hinzuzufügen, klicken Sie im Reiter **ePortfolio** oben rechts auf den Doktorandenhut');
Helpbar::get()->addPlainText(_(''), $description, '');
Helpbar::get()->addPlainText(_(''), $tip, '');
Helpbar::get()->addPlainText(_('Tip zum Bearbeiten'), $bearbeiten, Icon::create('doctoral-cap', 'info_alt'));
}
if ($this->isVorlage()) {
$description = _('Unter **Teilnehmende** können Sie festlegen, wer Zugriff auf diese Vorlage hat. ') . ' ';
$description .= _('Ausserdem können Sie unter **Einstellungen** Inhalte der Vorlage für die spätere Bearbeitung durch Studierende sperren.') . '';
$tip = _('Unter **Vorlage** können Sie die Vorlage bearbeiten. ');
$tip .= _('');
$bearbeiten = _('Um Inhalte oder Kapitel hinzuzufügen, klicken Sie im Reiter **Vorlage** oben rechts auf den Doktorandenhut');
Helpbar::get()->addPlainText(_(''), $description, '');
Helpbar::get()->addPlainText(_(''), $tip, '');
Helpbar::get()->addPlainText(_('Tip zum Bearbeiten'), $bearbeiten, Icon::create('doctoral-cap', 'info_alt'));
}
}
// rename Dateien to Meine Portfoliodateien
if ($this->isPortfolio() && Navigation::hasItem('/course/files')) {
Navigation::getItem('/course/files')->setTitle('Meine Portfoliodateien');
}
}
function prevent_settings_access($event, $path)
{
if (($this->isPortfolio() || $this->isVorlage())
&& $path == '/course/mooc_courseware/settings')
{
throw new AccessDeniedException();
}
}
public function store_activity($notification, $block_id, $course_id)
{
EportfolioActivity::addActivity($course_id, $block_id, $notification);
}
}