-
Notifications
You must be signed in to change notification settings - Fork 5
/
Courseware.php
executable file
·556 lines (481 loc) · 18.5 KB
/
Courseware.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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
<?php
require_once __DIR__.'/vendor/autoload.php';
use Courseware\Container;
use Mooc\DB\CoursewareFactory;
use Mooc\UI\BlockFactory;
use Courseware\User;
function _cw($message)
{
return dgettext('courseware', $message);
}
/**
* MoocIP.class.php.
*
* ...
*
* @author <[email protected]>
* @author <[email protected]>
* @author <[email protected]>
*/
class Courseware extends StudIPPlugin implements StandardPlugin
{
/**
* @var Container
*/
private $container;
public function __construct()
{
parent::__construct();
$this->setupAutoload();
$this->setupContainer();
// more setup if this plugin is active in this course
if ($this->isActivated($this->container['cid'])) {
// markup for link element to courseware
StudipFormat::addStudipMarkup('courseware', '\[(mooc-forumblock):([0-9]{1,32})\]', null, 'Courseware::markupForumLink');
$this->setupNavigation();
}
// set text-domain for translations in this plugin
bindtextdomain('courseware', dirname(__FILE__).'/locale');
}
public function getPluginname()
{
return 'Courseware';
}
// bei Aufruf des Plugins über plugin.php/mooc/...
public function initialize()
{
//PageLayout::setTitle($_SESSION['SessSemName']['header_line'] . ' - ' . $this->getPluginname());
// setTitle -> courseware_controller.php
PageLayout::setHelpKeyword('Basis/Courseware'); // Hilfeseite im Hilfewiki
$this->getHelpbarContent();
}
/**
* {@inheritdoc}
*/
public function getTabNavigation($courseId)
{
$cid = $courseId;
$tabs = array();
$courseware = $this->container['current_courseware'];
$navigation = new Navigation(
$courseware->title,
PluginEngine::getURL($this, compact('cid'), 'courseware', true)
);
$navigation->setImage(Icon::create('group3', 'info_alt'));
$navigation->setActiveImage(Icon::create('group3', 'info'));
$tabs['mooc_courseware'] = $navigation;
$navigation->addSubnavigation('index', clone $navigation);
//NavigationForLecturers
if ($this->container['current_user']->hasPerm($courseId, 'tutor')) {
$managerUrl = PluginEngine::getURL($this, compact('cid'), 'block_manager/index', true);
$navigation->addSubnavigation(
'block_manager',
new Navigation(_cw('Verwaltung'), $managerUrl)
);
$settingsUrl = PluginEngine::getURL($this, compact('cid'), 'courseware/settings', true);
$navigation->addSubnavigation(
'settings',
new Navigation(_cw('Einstellungen'), $settingsUrl)
);
$navigation->addSubnavigation(
'news',
new Navigation(
_cw('Letzte Änderungen'),
PluginEngine::getURL($this, compact('cid'), 'courseware/news', true)
)
);
$cpoUrl = PluginEngine::getURL($this, compact('cid'), 'cpo', true);
$navigation->addSubnavigation(
'progressoverview',
new Navigation(_cw('Fortschrittsübersicht'), $cpoUrl)
);
$postoverviewUrl = PluginEngine::getURL($this, compact('cid'), 'cpo/postoverview', true);
$navigation->addSubnavigation(
'postoverview',
new Navigation(_cw('Diskussionsübersicht'), $postoverviewUrl)
);
// $exportUrl = PluginEngine::getURL($this, compact('cid'), 'export', true);
// $navigation->addSubnavigation(
// 'export',
// new Navigation(_cw('Export'), $exportUrl)
// );
// $importUrl = PluginEngine::getURL($this, compact('cid'), 'import', true);
// $navigation->addSubnavigation(
// 'import',
// new Navigation(_cw('Import'), $importUrl)
// );
//NavigationForStudents
} else {
if (!$this->container['current_user']->isNobody()) {
$navigation->addSubnavigation(
'news',
new Navigation(
_cw('Letzte Änderungen'),
PluginEngine::getURL($this, compact('cid'), 'courseware/news', true)
)
);
$progressUrl = PluginEngine::getURL($this, compact('cid'), 'progress', true);
$navigation->addSubnavigation(
'progress',
new Navigation(_cw('Fortschrittsübersicht'), $progressUrl)
);
}
}
return $tabs;
}
/**
* {@inheritdoc}
*/
public function getNotificationObjects($courseId, $since, $user_id)
{
return array();
}
/**
* {@inheritdoc}
*/
public function getIconNavigation($courseId, $last_visit, $user_id)
{
if (!$user_id) {
$user_id = $GLOBALS['user']->id;
}
$icon = new AutoNavigation(
$this->getDisplayTitle(),
PluginEngine::getURL($this, array('cid' => $courseId, 'iconnav' => 'true'), 'courseware/news', true)
);
$db = DBManager::get();
$stmt = $db->prepare("
SELECT
COUNT(*)
FROM
mooc_blocks
WHERE
seminar_id = :cid
AND
chdate >= :last_visit
AND
type NOT IN ('Courseware', 'Chapter', 'Subchapter', 'Section')
");
$stmt->bindParam(':cid', $courseId);
$stmt->bindParam(':last_visit', $last_visit);
$stmt->execute();
$new_ones = (int) $stmt->fetch(PDO::FETCH_ASSOC)['COUNT(*)'];
$plugin_manager = \PluginManager::getInstance();
$vips = true;
if ($plugin_manager->getPluginInfo('VipsPlugin') == null){
$vips = false;
}
if($plugin_manager->getPlugin('VipsPlugin')){
$version = $plugin_manager->getPluginManifest($plugin_manager->getPlugin('VipsPlugin')->getPluginPath())['version'];
if (version_compare('1.3',$version) > 0) {
$vips = false;
}
} else {
$vips = false;
}
if ($vips) {
// getting all tests
$stmt = $db->prepare("
SELECT
json_data
FROM
mooc_blocks
JOIN
mooc_fields
ON
mooc_blocks.id = mooc_fields.block_id
WHERE
mooc_blocks.type = 'TestBlock'
AND
mooc_blocks.seminar_id = :cid
AND
mooc_fields.name = 'test_id'
");
$stmt->bindParam(':cid', $courseId);
$stmt->execute();
$tests = $stmt->fetch(PDO::FETCH_ASSOC);
if ($tests) {
$test_ids = array();
foreach ($tests as $key => $value) {
array_push($test_ids, (int) str_replace('"', '', $value));
}
//looking for new tests
$stmt = $db->prepare('
SELECT
COUNT(*)
FROM
vips_exercise_ref
JOIN
vips_exercise
ON
vips_exercise_ref.exercise_id = vips_exercise.ID
WHERE
vips_exercise_ref.test_id IN ('.implode(', ', $test_ids).')
AND
unix_timestamp(created) >= :last_visit
');
$stmt->bindParam(':last_visit', $last_visit);
$stmt->execute();
$new_ones += (int) $stmt->fetch(PDO::FETCH_ASSOC)['COUNT(*)'];
}
}
if ($new_ones) {
$title = $new_ones > 1 ? sprintf(_('%s neue Courseware-Inhalte'), $new_ones) : _('1 neuer Courseware-Inhalt');
$icon->setImage(Icon::create('group3', 'attention', ['title' => $title]));
$icon->setBadgeNumber($new_ones);
} else {
$icon->setImage(Icon::create('group3', 'inactive', ['title' => 'Courseware']));
}
return $icon;
}
/**
* {@inheritdoc}
*/
public function getInfoTemplate($courseId)
{
return null;
}
public function perform($unconsumedPath)
{
if ((!$this->isActivated($this->container['cid']))&& ($_SERVER['REQUEST_METHOD'] === 'GET')) {
throw new AccessDeniedException('plugin not activated for this course!');
}
require_once 'vendor/trails/trails.php';
require_once 'app/controllers/studip_controller.php';
require_once 'app/controllers/authenticated_controller.php';
// load i18n only if plugin is un use
PageLayout::addHeadElement('script', array(),
"String.toLocaleString('".PluginEngine::getLink($this, array('cid' => $this->container['cid']), 'localization')."');");
$dispatcher = new Trails_Dispatcher(
$this->getPluginPath(),
rtrim(PluginEngine::getLink($this, array(), null), '/'),
null
);
$dispatcher->plugin = $this;
$dispatcher->dispatch($unconsumedPath);
}
/**
* @return string
*/
public function getContext()
{
return $GLOBALS['SessionSeminar'];
}
/**
* @return string
*/
public function getCourseId()
{
return $this->container['cid'];
}
/**
* @return CoursewareFactory
*/
public function getCoursewareFactory()
{
return $this->container['courseware_factory'];
}
/**
* @return BlockFactory
*/
public function getBlockFactory()
{
return $this->container['block_factory'];
}
/**
* @return string
*/
public function getCurrentUserId()
{
return $this->container['current_user_id'];
}
/**
* @return User
*/
public function getCurrentUser()
{
return $this->container['current_user'];
}
/**
* @return Pimple
*/
public function getContainer()
{
return $this->container;
}
public static function onEnable($id)
{
$dbm = DBManager::get();
// find plugin activations of old Mooc.IP plugin and duplicate them for the new courseware plugin
$pluginId = (int) $dbm->query("SELECT pluginid FROM plugins WHERE pluginclassname = 'Mooc'")->fetchColumn();
if ($pluginId) {
$dbm->exec("INSERT INTO plugins_activated
SELECT $id as pluginid, poiid, state FROM plugins_activated WHERE pluginid = $pluginId");
}
// enable nobody role by default
RolePersistence::assignPluginRoles($id, array(7));
}
/**********************************************************************/
/* PRIVATE METHODS */
/**********************************************************************/
/*
* Hilfeinhalte
*/
protected function getHelpbarContent()
{
$can_edit = $GLOBALS['perm']->have_studip_perm('tutor', $this->container['cid']);
if ($can_edit) {
$description = _cw('Mit dem Courseware-Modul können Sie interaktive Lernmodule in Stud.IP erstellen. Strukturieren Sie Ihre Inhalte in Kapiteln und Unterkapiteln. Schalten Sie zwischen Teilnehmenden-Sicht und Editier-Modus um und fügen Sie Abschnitte und Blöcke (Text und Bild, Video, Diskussion, Quiz) hinzu. Aufgaben erstellen und verwalten Sie mit dem Vips-Plugin und binden Sie dann in einen Courseware-Abschnitt ein.');
Helpbar::get()->addPlainText(_cw('Information'), $description, 'icons/white/info-circle.svg');
$tip = _cw("Sie können den Courseware-Reiter umbenennen! Wählen Sie dazu den Punkt 'Einstellungen', den Sie im Editiermodus unter der Seitennavigation finden.");
Helpbar::get()->addPlainText(_cw('Tipp'), $tip, 'icons/white/info-circle.svg');
} else {
$description = _cw('Über dieses Modul stellen Ihre Lehrenden Ihnen multimediale Lernmodule direkt in Stud.IP zur Verfügung. Die Module können Texte, Bilder, Videos, Kommunikationselemente und kleine Quizzes beinhalten. Ihren Bearbeitungsfortschritt sehen Sie auf einen Blick im Reiter Fortschrittsübersicht.');
Helpbar::get()->addPlainText(_cw('Hinweis'), $description, 'icons/white/info-circle.svg');
}
}
// setup Pimple container (only once!)
private function setupContainer()
{
static $container;
if (!$container) {
$container = new Courseware\Container($this);
}
$this->container = $container;
}
// autoload the models (only once!)
private function setupAutoload()
{
static $once;
if (!$once) {
$once = true;
StudipAutoloader::addAutoloadPath(__DIR__.'/models');
}
}
private function setupNavigation()
{
// FIXME: hier den Courseware-Block in die Hand zu bekommen,
// ist definitiv falsch.
$courseware = $this->container['current_courseware'];
// hide blubber tab if the discussion block is active
if ($courseware->getDiscussionBlockActivation()) {
Navigation::removeItem('/course/blubberforum');
}
// deactivate Vips-Plugin for students if this course is capture by the mooc-plugin
if ((!$GLOBALS['perm']->have_studip_perm('tutor', $this->container['cid'])) && $courseware->getVipsTabVisible()) {
if (Navigation::hasItem('/course/vipsplugin')) {
Navigation::removeItem('/course/vipsplugin');
}
}
}
private function getSemClass()
{
global $SEM_CLASS, $SEM_TYPE, $SessSemName;
return $SEM_CLASS[$SEM_TYPE[$SessSemName['art_num']]['class']];
}
/* * * * * * * * * * * * * * * * * * * * * * * *
* * * * * F O R U M M A R K U P * * * * *
* * * * * * * * * * * * * * * * * * * * * * * */
public static function markupForumLink($markup, $matches, $contents)
{
// create a widget for given id (md5 hash - ensured by markup regex)
return '<span class="mooc-forumblock">'
.'<a href="'.PluginEngine::getLink('courseware', array('selected' => $matches[2]), 'courseware').'">'
._cw('Zurück zur Courseware')
.'</a></span>';
}
public function getDisplayTitle()
{
return _('Courseware');
}
public function getMetadata()
{
$metadata = parent::getMetadata();
$metadata['pluginname'] = dgettext('Courseware', 'Courseware');
$metadata['displayname'] = dgettext('Courseware', 'Courseware');
$metadata['summary'] = dgettext('Courseware', 'Create and provide interactive multimedia learning modules');
$metadata['description'] = dgettext('Courseware', 'With courseware you can create and use interactive multimedia learning modules. The modules are structured into chapters, subsections and sections and can consist of text blocks, video sequences, tasks (requires the Vips plug-in) and communication elements. Modules can be exported and imported into other courses or other installations.');
$metadata['descriptionShort'] = dgettext('Courseware', 'Create and provide interactive multimedia learning modules');
$metadata['descriptionLong'] = dgettext('Courseware', 'With courseware you can create and use interactive multimedia learning modules. The modules are structured into chapters, subsections and sections and can consist of text blocks, video sequences, tasks (requires the Vips plug-in) and communication elements. Modules can be exported and imported into other courses or other installations.');
$metadata['homepage'] = dgettext('Courseware', 'https://hilfe.studip.de/help/4.0/en/Basis/Courseware');
return $metadata;
}
/* * * * * * * * * * * * * * * * * * * * * * * * *
* * * * Functions for DatenschutzPlugin * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * */
/*
* Returns the tables containing user data.
* the array consists of the tables containing user data
* the expected format for each table is:
* $array[ table display name ] = [ 'table_name' => name of the table, 'table_content' => array of db rows containing userdata]
* @param string $user_id
* @return array
*/
public static function getUserdataInformation($user_id)
{
$db = DBManager::get();
$stmt = $db->prepare('
SELECT
*
FROM
mooc_userprogress
WHERE
user_id = :uid
');
$stmt->bindParam(':uid', $user_id);
$stmt->execute();
$user_progress = $stmt->fetchAll(PDO::FETCH_ASSOC);
$plugin_data = array();
$plugin_data['Courseware - Nutzerfortschritt'] = ['table_name' => 'mooc_userprogress', 'table_content' => $user_progress];
$stmt = $db->prepare('
SELECT
*
FROM
mooc_fields
WHERE
user_id = :uid
');
$stmt->bindParam(':uid', $user_id);
$stmt->execute();
$block_content = $stmt->fetchAll(PDO::FETCH_ASSOC);
$plugin_data['Courseware - Blöcke'] = ['table_name' => 'mooc_userprogress', 'table_content' => $block_content];
return $plugin_data;
}
/**
* Returns the filerefs of given user.
* @param string $user_id
* @return array
*/
public static function getUserFileRefs($user_id)
{
return array();
}
/**
* Deletes the table content containing user data.
* @param string $user_id
* @return boolean
*/
public static function deleteUserdata($user_id)
{
$db = DBManager::get();
$exec = false;
$stmt = $db->prepare('
DELETE FROM
mooc_userprogress
WHERE
user_id = :uid
');
$stmt->bindParam(':uid', $user_id);
$exec = $stmt->execute();
$stmt = $db->prepare('
DELETE FROM
mooc_fields
WHERE
user_id = :uid
AND
(name = "visited" OR name = "lastSelected")
');
$stmt->bindParam(':uid', $user_id);
$exec = $stmt->execute();
return $exec;
}
}