forked from Krassmus/LernmodulePlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLernmodulePlugin.class.php
More file actions
executable file
·188 lines (173 loc) · 6.95 KB
/
LernmodulePlugin.class.php
File metadata and controls
executable file
·188 lines (173 loc) · 6.95 KB
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
<?php
require_once __DIR__."/lib/CustomLernmodul.interface.php";
require_once __DIR__."/lib/Lernmodul.php";
require_once __DIR__."/lib/VanillalmLernmodul.php";
require_once __DIR__."/lib/HtmlLernmodul.php";
require_once __DIR__."/lib/ScormLernmodul.php";
require_once __DIR__."/lib/H5pLernmodul.php";
require_once __DIR__."/lib/LernmodulAttempt.php";
require_once __DIR__."/lib/LernmodulCourse.php";
require_once __DIR__."/lib/LernmodulBlock.php";
require_once __DIR__."/lib/LernmodulCourseSettings.php";
require_once __DIR__."/lib/LernmodulDependency.php";
require_once __DIR__."/lib/LernmodulGame.php";
require_once __DIR__."/lib/LernmodulGameAttendance.php";
require_once __DIR__."/lib/LernmodulAdmission/LernmodulAdmission.class.php";
require_once __DIR__."/lib/H5P/H5PLib.php";
require_once 'app/controllers/plugin_controller.php';
if (!isset($GLOBALS['FILESYSTEM_UTF8'])) {
$GLOBALS['FILESYSTEM_UTF8'] = true;
}
class LernmodulePlugin extends StudIPPlugin implements StandardPlugin, SystemPlugin {
public function __construct()
{
parent::__construct();
if (UpdateInformation::isCollecting()) {
$data = Request::getArray("page_info");
if (mb_stripos(Request::get("page"), "plugins.php/lernmoduleplugin") !== false && isset($data['Lernmodule'])) {
$data['Lernmodule']['attempt_id'];
$attempt = new LernmodulAttempt($data['Lernmodule']['attempt_id']);
if ($attempt['user_id'] === $GLOBALS['user']->id) {
if ($data['Lernmodule']['customData']) {
$attempt['customData'] = $data['Lernmodule']['customData'];
}
if (!$attempt['successful']) {
$attempt['chdate'] = time();
}
$attempt->store();
}
}
}
if ($GLOBALS['perm']->have_perm("root")) {
$nav = new Navigation(
dgettext("lernmoduleplugin","H5P-Bibliotheken"),
PluginEngine::getURL($this, array(), "h5p/admin_libraries")
);
Navigation::addItem("/admin/locations/h5p", $nav);
}
NotificationCenter::addObserver($this, "removeLernmoduleFromDeletedCourse", "CourseDidDelete");
}
public function getTabNavigation($course_id)
{
$this->settings = new LernmodulCourseSettings($course_id);
$tabname = $this->settings['tabname'] ?: (Config::get()->LERNMODUL_GLOBAL_NAME ?: dgettext("lernmoduleplugin","Lernmodule"));
$tab = new Navigation(
$tabname,
PluginEngine::getURL($this, array(), "lernmodule/overview")
);
$tab->setImage(
Icon::create("learnmodule", "info_alt")
);
$tab->addSubNavigation("overview", new Navigation($tabname, PluginEngine::getURL($this, array(), "lernmodule/overview")));
$tab->addSubNavigation("participants", new Navigation(dgettext("lernmoduleplugin","Teilnehmer"), PluginEngine::getURL($this, array(), "participants")));
return array('lernmodule' => $tab);
}
public function getIconNavigation($course_id, $last_visit, $user_id)
{
$tab = new Navigation(dgettext("lernmoduleplugin","Lernmodule"), PluginEngine::getURL($this, array(), "lernmodule/overview"));
$new = Lernmodul::countBySQL("INNER JOIN lernmodule_courses USING (module_id) WHERE lernmodule_courses.seminar_id = :course_id AND lernmodule_module.chdate >= :last_visit AND user_id <> :user_id", array(
'course_id' => $course_id,
'last_visit' => $last_visit,
'user_id' => $GLOBALS['user']->id
));
if (!$new) {
$new = count(LernmodulGame::findOpenGames($course_id));
}
if ($new > 0) {
$tab->setImage(
Icon::create("learnmodule+new", "new", array('title' => sprintf(dgettext("lernmoduleplugin","%s neue Lernmodule"), $new)))
);
} else {
$tab->setImage(
Icon::create("learnmodule", "inactive", array('title' => dgettext("lernmoduleplugin","Lernmodule")))
);
}
return $tab;
}
public function getNotificationObjects($course_id, $since, $user_id)
{
return null;
}
public function getInfoTemplate($course_id)
{
return null;
}
public function perform($unconsumed_path)
{
$this->addStylesheet("assets/lernmodule.less");
bindtextdomain("lernmoduleplugin", $this->getPluginPath()."/locale");
bind_textdomain_codeset("lernmoduleplugin", 'UTF-8');
parent::perform($unconsumed_path);
}
static public function mayEditSandbox()
{
return $GLOBALS['perm']->have_perm("admin")
|| RolePersistence::isAssignedRole($GLOBALS['user']->id, "Lernmodule-Admin");
}
public function getDisplayTitle()
{
return dgettext("lernmoduleplugin","Lernmodule");
}
public function removeLernmoduleFromDeletedCourse($event, $course)
{
LernmodulCourse::deleteBySQL("seminar_id = ?", [$course->getId()]);
LernmodulCourseSettings::deleteBySQL("seminar_id = ?", [$course->getId()]);
}
static public function bytesFromPHPIniValue($val) {
$val = trim($val);
$last = strtolower($val[strlen($val)-1]);
switch($last) {
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}
return $val;
}
/**
* Processes a topological sort. We need this for H5P support.
* @param $nodeids : array of ids
* @param array $edges : array of arrays like array(node1_id, node2_id)
* @return array|bool : either the sorted array of ids or false if the graph has cycles.
*/
static public function topologicalSort($nodeids, $edges) {
$L = $S = $nodes = array();
foreach($nodeids as $id) {
$nodes[$id] = array(
'in'=>array(),
'out'=>array()
);
foreach($edges as $e) {
if ($id == $e[0]) {
$nodes[$id]['out'][] = $e[1];
}
if ($id == $e[1]) {
$nodes[$id]['in'][] = $e[0];
}
}
}
foreach ($nodes as $id => $n) {
if (empty($n['in'])) {
$S[] = $id;
}
}
while (!empty($S)) {
$L[] = $id = (string) array_shift($S);
foreach($nodes[$id]['out'] as $m) {
$nodes[$m]['in'] = array_diff($nodes[$m]['in'], array($id));
if (empty($nodes[$m]['in'])) {
$S[] = $m;
}
}
$nodes[$id]['out'] = array();
}
foreach($nodes as $n) {
if (!empty($n['in']) or !empty($n['out'])) {
return false; // not sortable as graph is cyclic
}
}
return $L;
}
}