-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocallib.php
293 lines (266 loc) · 11.5 KB
/
locallib.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
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Helper functions for course_overview block
*
* @package block_course_overview
* @copyright 2012 Adam Olley <adam.olley@netspot.com.au>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Display overview for courses
*
* @param array $courses courses for which overview needs to be shown
* @return array html overview
*/
function block_course_overview_ext_get_overviews($courses) {
$htmlarray = array();
if ($modules = get_plugin_list_with_function('mod', 'print_overview')) {
// Split courses list into batches with no more than MAX_MODINFO_CACHE_SIZE courses in one batch.
// Otherwise we exceed the cache limit in get_fast_modinfo() and rebuild it too often.
if (defined('MAX_MODINFO_CACHE_SIZE') && MAX_MODINFO_CACHE_SIZE > 0 && count($courses) > MAX_MODINFO_CACHE_SIZE) {
$batches = array_chunk($courses, MAX_MODINFO_CACHE_SIZE, true);
} else {
$batches = array($courses);
}
foreach ($batches as $courses) {
foreach ($modules as $fname) {
$fname($courses, $htmlarray);
}
//ISIS2 Neue/veränderte Aktivitäten anzeigen $JE 2014/06/12
//ISIS2 Es ist wichtig, dass unsere Funktion NACH dem Aufruf von $fname ausgeführt wird!!!
//ISIS2 Ich baue in der Erzeugung der Einträge von $htmlarray, dass die Infos zu den Modulen schon aufgebaut sind.
//ISIS2 Update 02/09/2014: Bug - Ein(ige) Nutzer konnte(n) nicht mehr auf die my-Startseite zugreifen, sobald der Block
//ISIS2 über die Navigation verschoben wurde (local/isis/lib.php wurde dann nicht eingebunden).
global $CFG; //ISIS2 Bugfix $JE 02/09/2014
if (file_exists($CFG->dirroot . '/local/isis/lib.php')) //ISIS2 Bugfix $JE 02/09/2014
{ //ISIS2 Bugfix $JE 02/09/2014
require_once $CFG->dirroot . '/local/isis/lib.php';
foreach ($courses as $course)
block_course_overview_ext_structural_changes($course, $htmlarray);
//ISIS2 Endfix $JE 2014/06/12
} //ISIS2 Bugfix $JE 02/09/2014
}
}
return $htmlarray;
}
/**
* Bis wohin soll das log in der Kursübersicht durchgesucht werden?
*
* @param int $courseid
*
* @see block_recent_activity::get_timestart()
* @package block_course_overview
* @author Jan Eberhardt <eberhardt@math.tu-berlin.de>
*/
function block_course_overview_ext_get_timestart($courseid = SITEID)
{
global $USER, $DB;
switch (get_user_preferences("course_overview_timestart_for_log", 0)) {
case 1:
$timestart = strtotime("now -1 day");
break;
case 2:
$timestart = strtotime("now -1 week");
break;
case 3:
$timestart = strtotime("now -1 month");
break;
case 4:
$timestart = $USER->lastlogin;
break;
default:
$timestart = round(time() - COURSE_MAX_RECENT_PERIOD, -2);
if (!isguestuser() && !empty($USER->lastcourseaccess[$courseid])) {
$timestart = $DB->get_field("logstore_standard_log",
"MAX(timecreated)",
array("userid" => $USER->id,
"contextinstanceid" => (int)$courseid,
"contextlevel" => CONTEXT_COURSE)); //durch Verwendung des Kontextes nutzen wir einen Index aus
if ($USER->lastcourseaccess[$courseid] > $timestart) {
$timestart = $USER->lastcourseaccess[$courseid];
}
}
}
return $timestart;
}
/**
* Findet die neuesten Aktivitäten / Aktivitätsupdates eines Kurses
*
* @param stdClass $course
* @param array<string> $htmlarray Änderungen werden dort abgelegt
*
* @package block_course_overview
* @see block_recent_activity::get_structural_changes()
* @author Jan Eberhardt <eberhardt@math.tu-berlin.de>
*/
function block_course_overview_ext_structural_changes($course, &$htmlarray)
{
global $USER, $DB;
$context = context_course::instance($course->id);
$canviewdeleted = has_capability('block/recent_activity:viewdeletemodule', $context);
$canviewupdated = has_capability('block/recent_activity:viewaddupdatemodule', $context);
if (!$canviewdeleted && !$canviewupdated) {
return;
}
$sql = "SELECT
cmid, MIN(action) AS minaction, MAX(action) AS maxaction, MAX(modname) AS modname, MAX(timecreated) AS timemodified
FROM {block_recent_activity}
WHERE timecreated > :tc AND courseid = :cid
GROUP BY cmid
ORDER BY timemodified ASC";
$params = array("tc" => block_course_overview_ext_get_timestart($course->id), "cid" => $course->id);
$logs = $DB->get_records_sql($sql, $params);
if (isset($logs[0])) {
// If special record for this course and cmid=0 is present, migrate logs.
self::migrate_logs($course);
$logs = $DB->get_records_sql($sql, $params);
}
if ($logs) {
$changelist = array();
$modinfo = get_fast_modinfo($course);
$modnames = get_module_types_names();
foreach ($logs as $log) {
// We used aggregate functions since constants CM_CREATED, CM_UPDATED and CM_DELETED have ascending order (0,1,2).
$wasdeleted = ($log->maxaction == block_recent_activity_observer::CM_DELETED);
$wascreated = ($log->minaction == block_recent_activity_observer::CM_CREATED);
if ($wasdeleted && $wascreated) {
// Activity was created and deleted within this interval. Do not show it.
continue;
} else if ($wasdeleted && $canviewdeleted) {
if (plugin_supports('mod', $log->modname, FEATURE_NO_VIEW_LINK, false)) {
// Better to call cm_info::has_view() because it can be dynamic.
// But there is no instance of cm_info now.
continue;
}
// Unfortunately we do not know if the mod was visible.
$info = html_writer::div(get_string("deleted") . ": " . userdate($log->timemodified), "details");
$changelist[$log->cmid] = array(
'info' => array(
"action" => "deletedactivity",
"infotext" => html_writer::div($info, $log->modname . " overview")),
'module' => $log->modname
); // Die Struktur von $changelist wurde gegenüber der Vorlage geändert.
} else if (!$wasdeleted && isset($modinfo->cms[$log->cmid]) && $canviewupdated) {
// Module was either added or updated during this interval and it currently exists.
// If module was both added and updated show only "add" action.
$cm = $modinfo->cms[$log->cmid];
$info = html_writer::div(get_string("name") . ": " . html_writer::link($cm->url, $cm->name), "name")
. html_writer::div(get_string("modified") . ": " . userdate($log->timemodified), "info");
if ($cm->has_view() && $cm->uservisible) {
$changelist[$log->cmid] = array(
"info" => array(
"action" => $wascreated ? "added" : "updated",
"infotext" => html_writer::div($info, $cm->modname . " overview")),
"module" => $cm->modname
);
}
}
}
if (!empty($changelist)) {
if (!isset($htmlarray[$course->id]))
$htmlarray[$course->id] = array();
foreach ($changelist as $change) {
$module = $change["module"];
$action = $change["info"]["action"];
if (isset($htmlarray[$course->id][$module])) {
//div block davor entfernt, da die Änderungen am Anfang des blocks und nicht am anfang der Änderung steht
$htmlarray[$course->id][$module] = //html_writer::div(html_writer::div(get_string($action . "_course_overview_info", "block_course_overview_ext"), "info"), $module . " overview")
$htmlarray[$course->id][$module]; // add/update VOR der "normalen" Nachricht anzeigen
} else {
$htmlarray[$course->id]["isis2".$module] = $change["info"];
//dieser String wird woanders aufgebaut
//@see block_course_overview_renderer::activity_display
}
}
}
}
}
/**
* Startzeit-Selektor für Kursübersicht
*
* @param moodle_url $url URL der Weiterleitung, nach dem Einstellen der Option
* @param string $name Name des Objektes
* @return single_select
*
* @see block_course_overview_renderer::editing_bar_head
* @package block_course_overview
* @author Jan Eberhardt <eberhardt@math.tu-berlin.de>
*/
function block_course_overview_ext_timestart_select(moodle_url $url, $name = "mytimestart")
{
$modes = array(
"0" => get_string("lastcourseaccess", "block_course_overview_ext"),
"1" => get_string("lastday", "block_course_overview_ext"),
"2" => get_string("lastweek", "block_course_overview_ext"),
"3" => get_string("lastmonth", "block_course_overview_ext"),
"4" => get_string("lastlogin", "block_course_overview_ext")
);
$select = new single_select(new moodle_url("/my/index.php"), $name, $modes, get_user_preferences("course_overview_timestart_for_log", "0"));
$select->set_label(get_string("co_timestart_label", "block_course_overview_ext"));
return $select;
}
/**
* Neues Aussehen für die Kursübersicht
*
* @param moodle_url $url URL der Weiterleitung, nach dem Einstellen der Option (params werden überschrieben!)
* @param string $name Name des Parameters
* @return single_button
*
* @see block_course_overview_renderer::editing_bar_head
* @package block_course_overview
* @author Nicolas Klenert <klenert@math.tu-berlin.de>
*/
function block_course_overview_ext_view(moodle_url $url, $name = "myview")
{
$modes = array(
0 => get_string("view_standard", "block_course_overview_ext"),
2 =>get_string("view_tiles_without_pictures", "block_course_overview_ext")
//get_string("view_tiles_with_pictures", "block_course_overview_ext")
);
if(isset($url) && $url instanceof moodle_url){
$select = new single_select($url, $name, $modes, get_user_preferences("course_overview_view","0"));
}else{
$select = new single_select(new moodle_url("/my/index.php"), $name, $modes, get_user_preferences("course_overview_view", "0"));
}
$select->set_label(get_string("co_view", "block_course_overview_ext"));
return $select;
}
function block_course_overview_ext_saveColors(moodle_url $url, $class = '',$name = 'saveColor'){
if(isset($url) && $url instanceof moodle_url){
$url->params(array($name=>"true"));
$select = new single_button($url, get_string('co_save_colors','block_course_overview_ext'));
$select->class .= $class;
}else{
$select = new single_button(new moodle_url("/my/index.php",array($name => true)), get_string('co_save_colors','block_course_overview_ext'));
$select->class .= $class;
}
return $select;
}
function block_course_overview_ext_resetColors(moodle_url $url, $name = 'resetColor'){
if(isset($url) && $url instanceof moodle_url){
//$url->params(array($name=>"true"));
$select = new single_button($url, get_string('co_reset_colors','block_course_overview_ext'));
}else{
$select = new single_button(new moodle_url("/my/index.php",array()), get_string('co_reset_colors','block_course_overview_ext')); //$name => true
}
return $select;
}
function block_course_overview_ext_update_coursecolor($courselist, $colorlist){
$arr = array_combine($courselist, $colorlist);
$string = serialize($arr);
set_user_preference("course_overview_coursecolor", $string);
}