Commit | Line | Data |
---|---|---|
c861fe2f | 1 | <?php |
2 | ||
a5cb8d69 | 3 | // This file is part of Moodle - http://moodle.org/ |
4 | // | |
c861fe2f | 5 | // Moodle is free software: you can redistribute it and/or modify |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
a5cb8d69 | 14 | // |
c861fe2f | 15 | // You should have received a copy of the GNU General Public License |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
c4d0753b | 17 | |
18 | /** | |
19 | * deprecatedlib.php - Old functions retained only for backward compatibility | |
20 | * | |
21 | * Old functions retained only for backward compatibility. New code should not | |
22 | * use any of these functions. | |
23 | * | |
78bfb562 | 24 | * @package core |
c861fe2f | 25 | * @subpackage deprecated |
78bfb562 PS |
26 | * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} |
27 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
c861fe2f | 28 | * @deprecated |
c4d0753b | 29 | */ |
30 | ||
78bfb562 PS |
31 | defined('MOODLE_INTERNAL') || die(); |
32 | ||
6b32d6bc PS |
33 | /** |
34 | * Minify JavaScript files. | |
35 | * | |
36 | * @deprecated since 2.6 | |
37 | * | |
38 | * @param array $files | |
39 | * @return string | |
40 | */ | |
41 | function js_minify($files) { | |
42 | debugging('js_minify() is deprecated, use core_minify::js_files() or core_minify::js() instead.'); | |
43 | return core_minify::js_files($files); | |
44 | } | |
45 | ||
46 | /** | |
47 | * Minify CSS files. | |
48 | * | |
49 | * @deprecated since 2.6 | |
50 | * | |
51 | * @param array $files | |
52 | * @return string | |
53 | */ | |
54 | function css_minify_css($files) { | |
55 | debugging('css_minify_css() is deprecated, use core_minify::css_files() or core_minify::css() instead.'); | |
56 | return core_minify::css_files($files); | |
57 | } | |
58 | ||
f0f0e1fe PS |
59 | /** |
60 | * Function to call all event handlers when triggering an event | |
61 | * | |
62 | * @deprecated since 2.6 | |
63 | * | |
64 | * @param string $eventname name of the event | |
65 | * @param mixed $eventdata event data object | |
66 | * @return int number of failed events | |
67 | */ | |
68 | function events_trigger($eventname, $eventdata) { | |
69 | // TODO: uncomment after conversion of all events in standard distribution | |
70 | // debugging('events_trigger() is deprecated, please use new events instead', DEBUG_DEVELOPER); | |
71 | return events_trigger_legacy($eventname, $eventdata); | |
72 | } | |
73 | ||
9e19a0f0 PS |
74 | /** |
75 | * List all core subsystems and their location | |
76 | * | |
77 | * This is a whitelist of components that are part of the core and their | |
78 | * language strings are defined in /lang/en/<<subsystem>>.php. If a given | |
79 | * plugin is not listed here and it does not have proper plugintype prefix, | |
80 | * then it is considered as course activity module. | |
81 | * | |
82 | * The location is optionally dirroot relative path. NULL means there is no special | |
83 | * directory for this subsystem. If the location is set, the subsystem's | |
84 | * renderer.php is expected to be there. | |
85 | * | |
86 | * @deprecated since 2.6, use core_component::get_core_subsystems() | |
87 | * | |
88 | * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons | |
89 | * @return array of (string)name => (string|null)location | |
90 | */ | |
91 | function get_core_subsystems($fullpaths = false) { | |
92 | global $CFG; | |
93 | ||
94 | // NOTE: do not add any other debugging here, keep forever. | |
95 | ||
96 | $subsystems = core_component::get_core_subsystems(); | |
97 | ||
98 | if ($fullpaths) { | |
99 | return $subsystems; | |
100 | } | |
101 | ||
102 | debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER); | |
103 | ||
104 | $dlength = strlen($CFG->dirroot); | |
105 | ||
106 | foreach ($subsystems as $k => $v) { | |
107 | if ($v === null) { | |
108 | continue; | |
109 | } | |
110 | $subsystems[$k] = substr($v, $dlength+1); | |
111 | } | |
112 | ||
113 | return $subsystems; | |
114 | } | |
115 | ||
116 | /** | |
117 | * Lists all plugin types. | |
118 | * | |
119 | * @deprecated since 2.6, use core_component::get_plugin_types() | |
120 | * | |
121 | * @param bool $fullpaths false means relative paths from dirroot | |
122 | * @return array Array of strings - name=>location | |
123 | */ | |
124 | function get_plugin_types($fullpaths = true) { | |
125 | global $CFG; | |
126 | ||
127 | // NOTE: do not add any other debugging here, keep forever. | |
128 | ||
129 | $types = core_component::get_plugin_types(); | |
130 | ||
131 | if ($fullpaths) { | |
132 | return $types; | |
133 | } | |
134 | ||
135 | debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER); | |
136 | ||
137 | $dlength = strlen($CFG->dirroot); | |
138 | ||
139 | foreach ($types as $k => $v) { | |
140 | if ($k === 'theme') { | |
141 | $types[$k] = 'theme'; | |
142 | continue; | |
143 | } | |
144 | $types[$k] = substr($v, $dlength+1); | |
145 | } | |
146 | ||
147 | return $types; | |
148 | } | |
149 | ||
150 | /** | |
151 | * Use when listing real plugins of one type. | |
152 | * | |
153 | * @deprecated since 2.6, use core_component::get_plugin_list() | |
154 | * | |
155 | * @param string $plugintype type of plugin | |
156 | * @return array name=>fulllocation pairs of plugins of given type | |
157 | */ | |
158 | function get_plugin_list($plugintype) { | |
159 | ||
160 | // NOTE: do not add any other debugging here, keep forever. | |
161 | ||
162 | if ($plugintype === '') { | |
163 | $plugintype = 'mod'; | |
164 | } | |
165 | ||
166 | return core_component::get_plugin_list($plugintype); | |
167 | } | |
168 | ||
169 | /** | |
170 | * Get a list of all the plugins of a given type that define a certain class | |
171 | * in a certain file. The plugin component names and class names are returned. | |
172 | * | |
173 | * @deprecated since 2.6, use core_component::get_plugin_list_with_class() | |
174 | * | |
175 | * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'. | |
176 | * @param string $class the part of the name of the class after the | |
177 | * frankenstyle prefix. e.g 'thing' if you are looking for classes with | |
178 | * names like report_courselist_thing. If you are looking for classes with | |
179 | * the same name as the plugin name (e.g. qtype_multichoice) then pass ''. | |
180 | * @param string $file the name of file within the plugin that defines the class. | |
181 | * @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum') | |
182 | * and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice'). | |
183 | */ | |
184 | function get_plugin_list_with_class($plugintype, $class, $file) { | |
185 | ||
186 | // NOTE: do not add any other debugging here, keep forever. | |
187 | ||
188 | return core_component::get_plugin_list_with_class($plugintype, $class, $file); | |
189 | } | |
190 | ||
191 | /** | |
192 | * Returns the exact absolute path to plugin directory. | |
193 | * | |
194 | * @deprecated since 2.6, use core_component::get_plugin_directory() | |
195 | * | |
196 | * @param string $plugintype type of plugin | |
197 | * @param string $name name of the plugin | |
198 | * @return string full path to plugin directory; NULL if not found | |
199 | */ | |
200 | function get_plugin_directory($plugintype, $name) { | |
201 | ||
202 | // NOTE: do not add any other debugging here, keep forever. | |
203 | ||
204 | if ($plugintype === '') { | |
205 | $plugintype = 'mod'; | |
206 | } | |
207 | ||
208 | return core_component::get_plugin_directory($plugintype, $name); | |
209 | } | |
210 | ||
211 | /** | |
212 | * Normalize the component name using the "frankenstyle" names. | |
213 | * | |
214 | * @deprecated since 2.6, use core_component::normalize_component() | |
215 | * | |
216 | * @param string $component | |
217 | * @return array as (string)$type => (string)$plugin | |
218 | */ | |
219 | function normalize_component($component) { | |
220 | ||
221 | // NOTE: do not add any other debugging here, keep forever. | |
222 | ||
223 | return core_component::normalize_component($component); | |
224 | } | |
225 | ||
226 | /** | |
227 | * Return exact absolute path to a plugin directory. | |
228 | * | |
229 | * @deprecated since 2.6, use core_component::normalize_component() | |
230 | * | |
231 | * @param string $component name such as 'moodle', 'mod_forum' | |
232 | * @return string full path to component directory; NULL if not found | |
233 | */ | |
234 | function get_component_directory($component) { | |
235 | ||
236 | // NOTE: do not add any other debugging here, keep forever. | |
237 | ||
238 | return core_component::get_component_directory($component); | |
239 | } | |
240 | ||
241 | ||
242 | // === Deprecated before 2.6.0 === | |
243 | ||
689096bc PS |
244 | /** |
245 | * Hack to find out the GD version by parsing phpinfo output | |
246 | * | |
247 | * @return int GD version (1, 2, or 0) | |
248 | */ | |
249 | function check_gd_version() { | |
250 | // TODO: delete function in Moodle 2.7 | |
251 | debugging('check_gd_version() is deprecated, GD extension is always available now'); | |
252 | ||
253 | $gdversion = 0; | |
254 | ||
255 | if (function_exists('gd_info')){ | |
256 | $gd_info = gd_info(); | |
257 | if (substr_count($gd_info['GD Version'], '2.')) { | |
258 | $gdversion = 2; | |
259 | } else if (substr_count($gd_info['GD Version'], '1.')) { | |
260 | $gdversion = 1; | |
261 | } | |
262 | ||
263 | } else { | |
264 | ob_start(); | |
265 | phpinfo(INFO_MODULES); | |
266 | $phpinfo = ob_get_contents(); | |
267 | ob_end_clean(); | |
268 | ||
269 | $phpinfo = explode("\n", $phpinfo); | |
270 | ||
271 | ||
272 | foreach ($phpinfo as $text) { | |
273 | $parts = explode('</td>', $text); | |
274 | foreach ($parts as $key => $val) { | |
275 | $parts[$key] = trim(strip_tags($val)); | |
276 | } | |
277 | if ($parts[0] == 'GD Version') { | |
278 | if (substr_count($parts[1], '2.0')) { | |
279 | $parts[1] = '2.0'; | |
280 | } | |
281 | $gdversion = intval($parts[1]); | |
282 | } | |
283 | } | |
284 | } | |
285 | ||
286 | return $gdversion; // 1, 2 or 0 | |
287 | } | |
288 | ||
b28247fe PS |
289 | /** |
290 | * Not used any more, the account lockout handling is now | |
291 | * part of authenticate_user_login(). | |
292 | * @deprecated | |
293 | */ | |
294 | function update_login_count() { | |
c4844bf4 PS |
295 | // TODO: delete function in Moodle 2.6 |
296 | debugging('update_login_count() is deprecated, all calls need to be removed'); | |
b28247fe PS |
297 | } |
298 | ||
299 | /** | |
300 | * Not used any more, replaced by proper account lockout. | |
301 | * @deprecated | |
302 | */ | |
303 | function reset_login_count() { | |
c4844bf4 PS |
304 | // TODO: delete function in Moodle 2.6 |
305 | debugging('reset_login_count() is deprecated, all calls need to be removed'); | |
b28247fe PS |
306 | } |
307 | ||
c6d75bff PS |
308 | /** |
309 | * Insert or update log display entry. Entry may already exist. | |
310 | * $module, $action must be unique | |
311 | * @deprecated | |
312 | * | |
313 | * @param string $module | |
314 | * @param string $action | |
315 | * @param string $mtable | |
316 | * @param string $field | |
317 | * @return void | |
318 | * | |
319 | */ | |
320 | function update_log_display_entry($module, $action, $mtable, $field) { | |
321 | global $DB; | |
322 | ||
323 | debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.'); | |
324 | } | |
325 | ||
35716b86 PS |
326 | /** |
327 | * Given some text in HTML format, this function will pass it | |
328 | * through any filters that have been configured for this context. | |
329 | * | |
05226d76 | 330 | * @deprecated use the text formatting in a standard way instead (http://docs.moodle.org/dev/Output_functions) |
35716b86 | 331 | * this was abused mostly for embedding of attachments |
05226d76 | 332 | * @todo final deprecation of this function in MDL-40607 |
35716b86 PS |
333 | * @param string $text The text to be passed through format filters |
334 | * @param int $courseid The current course. | |
335 | * @return string the filtered string. | |
336 | */ | |
337 | function filter_text($text, $courseid = NULL) { | |
338 | global $CFG, $COURSE; | |
339 | ||
05226d76 DP |
340 | debugging('filter_text() is deprecated, use format_text(), format_string() etc instead.', DEBUG_DEVELOPER); |
341 | ||
35716b86 PS |
342 | if (!$courseid) { |
343 | $courseid = $COURSE->id; | |
344 | } | |
345 | ||
b0c6dc1c | 346 | if (!$context = context_course::instance($courseid, IGNORE_MISSING)) { |
35716b86 PS |
347 | return $text; |
348 | } | |
349 | ||
350 | return filter_manager::instance()->filter_text($text, $context); | |
351 | } | |
352 | ||
17c70aa0 PS |
353 | /** |
354 | * This function indicates that current page requires the https | |
355 | * when $CFG->loginhttps enabled. | |
356 | * | |
357 | * By using this function properly, we can ensure 100% https-ized pages | |
358 | * at our entire discretion (login, forgot_password, change_password) | |
359 | * @deprecated use $PAGE->https_required() instead | |
05226d76 | 360 | * @todo final deprecation of this function in MDL-40607 |
17c70aa0 PS |
361 | */ |
362 | function httpsrequired() { | |
363 | global $PAGE; | |
05226d76 | 364 | debugging('httpsrequired() is deprecated use $PAGE->https_required() instead.', DEBUG_DEVELOPER); |
17c70aa0 PS |
365 | $PAGE->https_required(); |
366 | } | |
367 | ||
50a8bd6c PS |
368 | /** |
369 | * Given a physical path to a file, returns the URL through which it can be reached in Moodle. | |
370 | * | |
371 | * @deprecated use moodle_url factory methods instead | |
372 | * | |
373 | * @param string $path Physical path to a file | |
374 | * @param array $options associative array of GET variables to append to the URL | |
375 | * @param string $type (questionfile|rssfile|httpscoursefile|coursefile) | |
376 | * @return string URL to file | |
377 | */ | |
378 | function get_file_url($path, $options=null, $type='coursefile') { | |
17c70aa0 | 379 | global $CFG; |
50a8bd6c PS |
380 | |
381 | $path = str_replace('//', '/', $path); | |
382 | $path = trim($path, '/'); // no leading and trailing slashes | |
383 | ||
384 | // type of file | |
385 | switch ($type) { | |
386 | case 'questionfile': | |
387 | $url = $CFG->wwwroot."/question/exportfile.php"; | |
388 | break; | |
389 | case 'rssfile': | |
390 | $url = $CFG->wwwroot."/rss/file.php"; | |
391 | break; | |
392 | case 'httpscoursefile': | |
393 | $url = $CFG->httpswwwroot."/file.php"; | |
394 | break; | |
395 | case 'coursefile': | |
396 | default: | |
397 | $url = $CFG->wwwroot."/file.php"; | |
398 | } | |
399 | ||
400 | if ($CFG->slasharguments) { | |
401 | $parts = explode('/', $path); | |
402 | foreach ($parts as $key => $part) { | |
403 | /// anchor dash character should not be encoded | |
404 | $subparts = explode('#', $part); | |
405 | $subparts = array_map('rawurlencode', $subparts); | |
406 | $parts[$key] = implode('#', $subparts); | |
407 | } | |
408 | $path = implode('/', $parts); | |
409 | $ffurl = $url.'/'.$path; | |
410 | $separator = '?'; | |
411 | } else { | |
412 | $path = rawurlencode('/'.$path); | |
413 | $ffurl = $url.'?file='.$path; | |
414 | $separator = '&'; | |
415 | } | |
416 | ||
417 | if ($options) { | |
418 | foreach ($options as $name=>$value) { | |
419 | $ffurl = $ffurl.$separator.$name.'='.$value; | |
420 | $separator = '&'; | |
421 | } | |
422 | } | |
423 | ||
424 | return $ffurl; | |
425 | } | |
426 | ||
370f10b7 | 427 | /** |
337965fe DP |
428 | * @deprecated use get_string("pluginname", "auth_[PLUINNAME]") instead. |
429 | * @todo remove completely in MDL-40517 | |
370f10b7 PS |
430 | */ |
431 | function auth_get_plugin_title($authtype) { | |
337965fe | 432 | throw new coding_exception('Function auth_get_plugin_title() is deprecated, please use standard get_string("pluginname", "auth_'.$authtype.'")!'); |
370f10b7 PS |
433 | } |
434 | ||
df997f84 | 435 | /** |
337965fe DP |
436 | * @deprecated use indivividual enrol plugin settings instead |
437 | * @todo remove completely in MDL-40517 | |
df997f84 PS |
438 | */ |
439 | function get_default_course_role($course) { | |
337965fe | 440 | throw new coding_exception('get_default_course_role() can not be used any more, please use enrol plugin settings instead!'); |
df997f84 PS |
441 | } |
442 | ||
1f96e907 | 443 | /** |
337965fe DP |
444 | * @deprecated use get_string_manager()->get_list_of_translations() instead. |
445 | * @todo remove completely in MDL-40517 | |
1f96e907 PS |
446 | */ |
447 | function get_list_of_languages($refreshcache=false, $returnall=false) { | |
337965fe | 448 | throw new coding_exception('get_list_of_languages() can not be used any more, please use get_string_manager()->get_list_of_translations() instead.'); |
1f96e907 | 449 | } |
370f10b7 | 450 | |
97b7d149 | 451 | /** |
337965fe DP |
452 | * @deprecated use get_string_manager()->get_list_of_currencies() instead. |
453 | * @todo remove completely in MDL-40517 | |
97b7d149 PS |
454 | */ |
455 | function get_list_of_currencies() { | |
337965fe | 456 | throw new coding_exception('get_list_of_currencies() can not be used any more, please use get_string_manager()->get_list_of_currencies() instead.'); |
97b7d149 PS |
457 | } |
458 | ||
0aa759b0 | 459 | /** |
337965fe DP |
460 | * @deprecated use get_string_manager()->get_list_of_countries() instead. |
461 | * @todo remove completely in MDL-40517 | |
0aa759b0 PS |
462 | */ |
463 | function get_list_of_countries() { | |
337965fe | 464 | throw new coding_exception('get_list_of_countries() can not be used any more, please use get_string_manager()->get_list_of_countries() instead.'); |
0aa759b0 PS |
465 | } |
466 | ||
613bbd7c | 467 | /** |
4f0c2d00 | 468 | * Return all course participant for a given course |
613bbd7c | 469 | * |
05226d76 DP |
470 | * @deprecated use get_enrolled_users($context) instead. |
471 | * @todo final deprecation of this function in MDL-40607 | |
4f0c2d00 PS |
472 | * @param integer $courseid |
473 | * @return array of user | |
613bbd7c | 474 | */ |
4f0c2d00 | 475 | function get_course_participants($courseid) { |
05226d76 | 476 | debugging('get_course_participants() is deprecated, use get_enrolled_users() instead.', DEBUG_DEVELOPER); |
b0c6dc1c | 477 | return get_enrolled_users(context_course::instance($courseid)); |
613bbd7c | 478 | } |
479 | ||
613bbd7c | 480 | /** |
4f0c2d00 | 481 | * Return true if the user is a participant for a given course |
613bbd7c | 482 | * |
05226d76 DP |
483 | * @deprecated use is_enrolled($context, $userid) instead. |
484 | * @todo final deprecation of this function in MDL-40607 | |
4f0c2d00 PS |
485 | * @param integer $userid |
486 | * @param integer $courseid | |
487 | * @return boolean | |
613bbd7c | 488 | */ |
4f0c2d00 | 489 | function is_course_participant($userid, $courseid) { |
05226d76 | 490 | debugging('is_course_participant() is deprecated, use is_enrolled() instead.', DEBUG_DEVELOPER); |
b0c6dc1c | 491 | return is_enrolled(context_course::instance($courseid), $userid); |
613bbd7c | 492 | } |
493 | ||
494 | /** | |
495 | * Searches logs to find all enrolments since a certain date | |
496 | * | |
497 | * used to print recent activity | |
498 | * | |
613bbd7c | 499 | * @param int $courseid The course in question. |
c861fe2f | 500 | * @param int $timestart The date to check forward of |
613bbd7c | 501 | * @return object|false {@link $USER} records or false if error. |
613bbd7c | 502 | */ |
503 | function get_recent_enrolments($courseid, $timestart) { | |
10df888a | 504 | global $DB; |
364fffda | 505 | |
02ca2cad | 506 | debugging('get_recent_enrolments() is deprecated as it returned inaccurate results.', DEBUG_DEVELOPER); |
613bbd7c | 507 | |
02ca2cad | 508 | $context = context_course::instance($courseid); |
210751f6 | 509 | $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time) |
10df888a | 510 | FROM {user} u, {role_assignments} ra, {log} l |
511 | WHERE l.time > ? | |
512 | AND l.course = ? | |
513 | AND l.module = 'course' | |
514 | AND l.action = 'enrol' | |
9f43d70d | 515 | AND ".$DB->sql_cast_char2int('l.info')." = u.id |
10df888a | 516 | AND u.id = ra.userid |
517 | AND ra.contextid ".get_related_contexts_string($context)." | |
210751f6 PS |
518 | GROUP BY u.id, u.firstname, u.lastname |
519 | ORDER BY MAX(l.time) ASC"; | |
10df888a | 520 | $params = array($timestart, $courseid); |
521 | return $DB->get_records_sql($sql, $params); | |
613bbd7c | 522 | } |
523 | ||
2123b644 | 524 | ########### FROM weblib.php ########################################################################## |
525 | ||
2123b644 | 526 | /** |
337965fe DP |
527 | * @deprecated use $OUTPUT->box() instead. |
528 | * @todo remove completely in MDL-40517 | |
2123b644 | 529 | */ |
530 | function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) { | |
337965fe | 531 | throw new coding_exception('print_simple_box can not be used any more. Please use $OUTPUT->box() instead'); |
2123b644 | 532 | } |
533 | ||
2123b644 | 534 | /** |
337965fe DP |
535 | * @deprecated use $OUTPUT->box_start instead. |
536 | * @todo remove completely in MDL-40517 | |
2123b644 | 537 | */ |
538 | function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) { | |
337965fe | 539 | throw new coding_exception('print_simple_box_start can not be used any more. Please use $OUTPUT->box_start instead'); |
2123b644 | 540 | } |
541 | ||
2123b644 | 542 | /** |
337965fe DP |
543 | * @deprecated use $OUTPUT->box_end instead. |
544 | * @todo remove completely in MDL-40517 | |
2123b644 | 545 | */ |
546 | function print_simple_box_end($return=false) { | |
337965fe | 547 | throw new coding_exception('print_simple_box_end can not be used any more. Please use $OUTPUT->box_end instead'); |
2123b644 | 548 | } |
549 | ||
e0ebc88e | 550 | /** |
337965fe DP |
551 | * @deprecated the urltolink filter now does this job. |
552 | * @todo remove completely in MDL-40517 | |
e0ebc88e DM |
553 | */ |
554 | function convert_urls_into_links($text) { | |
337965fe | 555 | throw new coding_exception('convert_urls_into_links() can not be used any more and replaced by the urltolink filter'); |
e0ebc88e DM |
556 | } |
557 | ||
18097238 | 558 | /** |
337965fe DP |
559 | * @deprecated use the emoticon_manager class instead. |
560 | * @todo remove completely in MDL-40517 | |
18097238 DM |
561 | */ |
562 | function get_emoticons_list_for_help_file() { | |
337965fe | 563 | throw new coding_exception('get_emoticons_list_for_help_file() can not be used any more, use the new emoticon_manager API instead'); |
18097238 DM |
564 | } |
565 | ||
015ba71a | 566 | /** |
337965fe DP |
567 | * @deprecated use emoticon filter now does this job. |
568 | * @todo remove completely in MDL-40517 | |
015ba71a DM |
569 | */ |
570 | function replace_smilies(&$text) { | |
337965fe | 571 | throw new coding_exception('replace_smilies() can not be used any more and replaced with the emoticon filter.'); |
015ba71a DM |
572 | } |
573 | ||
ed5dd29f | 574 | /** |
05226d76 DP |
575 | * @deprecated use clean_param($string, PARAM_FILE) instead. |
576 | * @todo final deprecation of this function in MDL-40607 | |
c861fe2f | 577 | * |
ed5dd29f | 578 | * @param string $string ? |
579 | * @param int $allowdots ? | |
c861fe2f | 580 | * @return bool |
ed5dd29f | 581 | */ |
582 | function detect_munged_arguments($string, $allowdots=1) { | |
05226d76 | 583 | debugging('detect_munged_arguments() is deprecated, please use clean_param(,PARAM_FILE) instead.', DEBUG_DEVELOPER); |
ed5dd29f | 584 | if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references |
585 | return true; | |
586 | } | |
69593309 | 587 | if (preg_match('/[\|\`]/', $string)) { // check for other bad characters |
ed5dd29f | 588 | return true; |
589 | } | |
590 | if (empty($string) or $string == '/') { | |
591 | return true; | |
592 | } | |
593 | ||
594 | return false; | |
595 | } | |
596 | ||
9152fc99 | 597 | |
0c6d2dd4 | 598 | /** |
599 | * Unzip one zip file to a destination dir | |
600 | * Both parameters must be FULL paths | |
601 | * If destination isn't specified, it will be the | |
602 | * SAME directory where the zip file resides. | |
c861fe2f | 603 | * |
604 | * @global object | |
605 | * @param string $zipfile The zip file to unzip | |
606 | * @param string $destination The location to unzip to | |
607 | * @param bool $showstatus_ignored Unused | |
0c6d2dd4 | 608 | */ |
609 | function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) { | |
610 | global $CFG; | |
611 | ||
612 | //Extract everything from zipfile | |
613 | $path_parts = pathinfo(cleardoubleslashes($zipfile)); | |
614 | $zippath = $path_parts["dirname"]; //The path of the zip file | |
615 | $zipfilename = $path_parts["basename"]; //The name of the zip file | |
616 | $extension = $path_parts["extension"]; //The extension of the file | |
617 | ||
618 | //If no file, error | |
619 | if (empty($zipfilename)) { | |
620 | return false; | |
621 | } | |
622 | ||
623 | //If no extension, error | |
624 | if (empty($extension)) { | |
625 | return false; | |
626 | } | |
627 | ||
628 | //Clear $zipfile | |
629 | $zipfile = cleardoubleslashes($zipfile); | |
630 | ||
631 | //Check zipfile exists | |
632 | if (!file_exists($zipfile)) { | |
633 | return false; | |
634 | } | |
635 | ||
636 | //If no destination, passed let's go with the same directory | |
637 | if (empty($destination)) { | |
638 | $destination = $zippath; | |
639 | } | |
640 | ||
641 | //Clear $destination | |
642 | $destpath = rtrim(cleardoubleslashes($destination), "/"); | |
643 | ||
644 | //Check destination path exists | |
645 | if (!is_dir($destpath)) { | |
646 | return false; | |
647 | } | |
648 | ||
0b0bfa93 | 649 | $packer = get_file_packer('application/zip'); |
650 | ||
651 | $result = $packer->extract_to_pathname($zipfile, $destpath); | |
0c6d2dd4 | 652 | |
653 | if ($result === false) { | |
654 | return false; | |
655 | } | |
656 | ||
657 | foreach ($result as $status) { | |
658 | if ($status !== true) { | |
659 | return false; | |
660 | } | |
661 | } | |
662 | ||
663 | return true; | |
664 | } | |
665 | ||
ed94cb66 | 666 | /** |
667 | * Zip an array of files/dirs to a destination zip file | |
668 | * Both parameters must be FULL paths to the files/dirs | |
c861fe2f | 669 | * |
670 | * @global object | |
671 | * @param array $originalfiles Files to zip | |
672 | * @param string $destination The destination path | |
673 | * @return bool Outcome | |
ed94cb66 | 674 | */ |
675 | function zip_files ($originalfiles, $destination) { | |
676 | global $CFG; | |
677 | ||
678 | //Extract everything from destination | |
679 | $path_parts = pathinfo(cleardoubleslashes($destination)); | |
680 | $destpath = $path_parts["dirname"]; //The path of the zip file | |
681 | $destfilename = $path_parts["basename"]; //The name of the zip file | |
682 | $extension = $path_parts["extension"]; //The extension of the file | |
683 | ||
684 | //If no file, error | |
685 | if (empty($destfilename)) { | |
686 | return false; | |
687 | } | |
688 | ||
689 | //If no extension, add it | |
690 | if (empty($extension)) { | |
691 | $extension = 'zip'; | |
692 | $destfilename = $destfilename.'.'.$extension; | |
693 | } | |
694 | ||
695 | //Check destination path exists | |
696 | if (!is_dir($destpath)) { | |
697 | return false; | |
698 | } | |
699 | ||
700 | //Check destination path is writable. TODO!! | |
701 | ||
702 | //Clean destination filename | |
703 | $destfilename = clean_filename($destfilename); | |
704 | ||
705 | //Now check and prepare every file | |
706 | $files = array(); | |
707 | $origpath = NULL; | |
708 | ||
709 | foreach ($originalfiles as $file) { //Iterate over each file | |
710 | //Check for every file | |
711 | $tempfile = cleardoubleslashes($file); // no doubleslashes! | |
712 | //Calculate the base path for all files if it isn't set | |
713 | if ($origpath === NULL) { | |
714 | $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/"); | |
715 | } | |
716 | //See if the file is readable | |
717 | if (!is_readable($tempfile)) { //Is readable | |
718 | continue; | |
719 | } | |
720 | //See if the file/dir is in the same directory than the rest | |
721 | if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) { | |
722 | continue; | |
723 | } | |
724 | //Add the file to the array | |
725 | $files[] = $tempfile; | |
726 | } | |
727 | ||
728 | $zipfiles = array(); | |
729 | $start = strlen($origpath)+1; | |
730 | foreach($files as $file) { | |
731 | $zipfiles[substr($file, $start)] = $file; | |
732 | } | |
733 | ||
0b0bfa93 | 734 | $packer = get_file_packer('application/zip'); |
ed94cb66 | 735 | |
3ed22f1a | 736 | return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename); |
ed94cb66 | 737 | } |
738 | ||
5bf243d1 | 739 | /** |
740 | * Get the IDs for the user's groups in the given course. | |
741 | * | |
c861fe2f | 742 | * @global object |
5bf243d1 | 743 | * @param int $courseid The course being examined - the 'course' table id field. |
c861fe2f | 744 | * @return array|bool An _array_ of groupids, or false |
5bf243d1 | 745 | * (Was return $groupids[0] - consequences!) |
05226d76 DP |
746 | * @deprecated use groups_get_all_groups() instead. |
747 | * @todo final deprecation of this function in MDL-40607 | |
5bf243d1 | 748 | */ |
749 | function mygroupid($courseid) { | |
750 | global $USER; | |
05226d76 DP |
751 | |
752 | debugging('mygroupid() is deprecated, please use groups_get_all_groups() instead.', DEBUG_DEVELOPER); | |
753 | ||
5bf243d1 | 754 | if ($groups = groups_get_all_groups($courseid, $USER->id)) { |
755 | return array_keys($groups); | |
756 | } else { | |
757 | return false; | |
758 | } | |
759 | } | |
760 | ||
5bf243d1 | 761 | |
5bf243d1 | 762 | /** |
763 | * Returns the current group mode for a given course or activity module | |
364fffda | 764 | * |
5bf243d1 | 765 | * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin) |
c861fe2f | 766 | * |
767 | * @param object $course Course Object | |
768 | * @param object $cm Course Manager Object | |
769 | * @return mixed $course->groupmode | |
5bf243d1 | 770 | */ |
771 | function groupmode($course, $cm=null) { | |
772 | ||
773 | if (isset($cm->groupmode) && empty($course->groupmodeforce)) { | |
774 | return $cm->groupmode; | |
775 | } | |
776 | return $course->groupmode; | |
777 | } | |
778 | ||
c584346c | 779 | /** |
780 | * Sets the current group in the session variable | |
781 | * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups. | |
782 | * Sets currentgroup[$courseid] in the session variable appropriately. | |
783 | * Does not do any permission checking. | |
c861fe2f | 784 | * |
785 | * @global object | |
c584346c | 786 | * @param int $courseid The course being examined - relates to id field in |
787 | * 'course' table. | |
788 | * @param int $groupid The group being examined. | |
789 | * @return int Current group id which was set by this function | |
790 | */ | |
791 | function set_current_group($courseid, $groupid) { | |
792 | global $SESSION; | |
793 | return $SESSION->currentgroup[$courseid] = $groupid; | |
794 | } | |
795 | ||
5bf243d1 | 796 | |
5bf243d1 | 797 | /** |
364fffda | 798 | * Gets the current group - either from the session variable or from the database. |
5bf243d1 | 799 | * |
c861fe2f | 800 | * @global object |
364fffda | 801 | * @param int $courseid The course being examined - relates to id field in |
5bf243d1 | 802 | * 'course' table. |
364fffda | 803 | * @param bool $full If true, the return value is a full record object. |
5bf243d1 | 804 | * If false, just the id of the record. |
c861fe2f | 805 | * @return int|bool |
5bf243d1 | 806 | */ |
807 | function get_current_group($courseid, $full = false) { | |
808 | global $SESSION; | |
809 | ||
810 | if (isset($SESSION->currentgroup[$courseid])) { | |
811 | if ($full) { | |
812 | return groups_get_group($SESSION->currentgroup[$courseid]); | |
813 | } else { | |
814 | return $SESSION->currentgroup[$courseid]; | |
815 | } | |
816 | } | |
817 | ||
818 | $mygroupid = mygroupid($courseid); | |
819 | if (is_array($mygroupid)) { | |
820 | $mygroupid = array_shift($mygroupid); | |
821 | set_current_group($courseid, $mygroupid); | |
822 | if ($full) { | |
823 | return groups_get_group($mygroupid); | |
824 | } else { | |
825 | return $mygroupid; | |
826 | } | |
827 | } | |
828 | ||
829 | if ($full) { | |
830 | return false; | |
831 | } else { | |
832 | return 0; | |
833 | } | |
834 | } | |
835 | ||
836 | ||
8ec50604 | 837 | /** |
a8ab8de9 PS |
838 | * Inndicates fatal error. This function was originally printing the |
839 | * error message directly, since 2.0 it is throwing exception instead. | |
3400bf6c | 840 | * The error printing is handled in default exception handler. |
a8ab8de9 | 841 | * |
8ec50604 | 842 | * Old method, don't call directly in new code - use print_error instead. |
843 | * | |
8ec50604 | 844 | * @param string $message The message to display to the user about the error. |
845 | * @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page. | |
a8ab8de9 | 846 | * @return void, always throws moodle_exception |
8ec50604 | 847 | */ |
245ac557 | 848 | function error($message, $link='') { |
78946b9b | 849 | throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()'); |
251387d0 | 850 | } |
8ec50604 | 851 | |
8ec50604 | 852 | |
cf615522 | 853 | /** |
05226d76 | 854 | * @deprecated use $PAGE->requires->js_module() instead. |
cf615522 | 855 | */ |
856 | function require_js($lib) { | |
1c76d55a | 857 | throw new coding_exception('require_js() was removed, use new JS api'); |
cf615522 | 858 | } |
5af6ec1b | 859 | |
b7009474 | 860 | /** |
861 | * @deprecated use $PAGE->theme->name instead. | |
05226d76 | 862 | * @todo final deprecation of this function in MDL-40607 |
b7009474 | 863 | * @return string the name of the current theme. |
864 | */ | |
865 | function current_theme() { | |
866 | global $PAGE; | |
05226d76 DP |
867 | |
868 | debugging('current_theme() is deprecated, please use $PAGE->theme->name instead', DEBUG_DEVELOPER); | |
b7009474 | 869 | return $PAGE->theme->name; |
870 | } | |
871 | ||
8954245a | 872 | /** |
873 | * Prints some red text using echo | |
874 | * | |
875 | * @deprecated | |
876 | * @param string $error The text to be displayed in red | |
877 | */ | |
878 | function formerr($error) { | |
3bd6b994 | 879 | debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).'); |
8954245a | 880 | global $OUTPUT; |
881 | echo $OUTPUT->error_text($error); | |
882 | } | |
883 | ||
34a2777c | 884 | /** |
885 | * Return the markup for the destination of the 'Skip to main content' links. | |
886 | * Accessibility improvement for keyboard-only users. | |
887 | * | |
888 | * Used in course formats, /index.php and /course/index.php | |
889 | * | |
890 | * @deprecated use $OUTPUT->skip_link_target() in instead. | |
05226d76 | 891 | * @todo final deprecation of this function in MDL-40607 |
34a2777c | 892 | * @return string HTML element. |
893 | */ | |
894 | function skip_main_destination() { | |
895 | global $OUTPUT; | |
05226d76 DP |
896 | |
897 | debugging('skip_main_destination() is deprecated, please use $OUTPUT->skip_link_target() instead.', DEBUG_DEVELOPER); | |
34a2777c | 898 | return $OUTPUT->skip_link_target(); |
899 | } | |
900 | ||
901 | /** | |
337965fe DP |
902 | * @deprecated use $OUTPUT->heading() instead. |
903 | * @todo remove completely in MDL-40517 | |
34a2777c | 904 | */ |
905 | function print_headline($text, $size=2, $return=false) { | |
337965fe | 906 | throw new coding_exception('print_headline() can not be used any more. Please use $OUTPUT->heading() instead.'); |
34a2777c | 907 | } |
908 | ||
909 | /** | |
337965fe DP |
910 | * @deprecated use $OUTPUT->heading() instead. |
911 | * @todo remove completely in MDL-40517 | |
34a2777c | 912 | */ |
913 | function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') { | |
337965fe | 914 | throw new coding_exception('print_heading() can not be used any more. Please use $OUTPUT->heading() instead.'); |
34a2777c | 915 | } |
916 | ||
917 | /** | |
337965fe DP |
918 | * @deprecated use $OUTPUT->heading() instead. |
919 | * @todo remove completely in MDL-40517 | |
34a2777c | 920 | */ |
921 | function print_heading_block($heading, $class='', $return=false) { | |
337965fe | 922 | throw new coding_exception('print_heading_with_block() can not be used any more. Please use $OUTPUT->heading() instead.'); |
34a2777c | 923 | } |
924 | ||
925 | /** | |
337965fe DP |
926 | * @deprecated use $OUTPUT->box() instead. |
927 | * @todo remove completely in MDL-40517 | |
34a2777c | 928 | */ |
929 | function print_box($message, $classes='generalbox', $ids='', $return=false) { | |
337965fe | 930 | throw new coding_exception('print_box() can not be used any more. Please use $OUTPUT->box() instead.'); |
34a2777c | 931 | } |
932 | ||
933 | /** | |
337965fe DP |
934 | * @deprecated use $OUTPUT->box_start() instead. |
935 | * @todo remove completely in MDL-40517 | |
34a2777c | 936 | */ |
937 | function print_box_start($classes='generalbox', $ids='', $return=false) { | |
337965fe | 938 | throw new coding_exception('print_box_start() can not be used any more. Please use $OUTPUT->box_start() instead.'); |
34a2777c | 939 | } |
940 | ||
941 | /** | |
337965fe DP |
942 | * @deprecated use $OUTPUT->box_end() instead. |
943 | * @todo remove completely in MDL-40517 | |
34a2777c | 944 | */ |
945 | function print_box_end($return=false) { | |
337965fe | 946 | throw new coding_exception('print_box_end() can not be used any more. Please use $OUTPUT->box_end() instead.'); |
34a2777c | 947 | } |
948 | ||
949 | /** | |
950 | * Print a message in a standard themed container. | |
951 | * | |
05226d76 DP |
952 | * @deprecated use $OUTPUT->container() instead. |
953 | * @todo final deprecation of this function in MDL-40607 | |
34a2777c | 954 | * @param string $message, the content of the container |
955 | * @param boolean $clearfix clear both sides | |
956 | * @param string $classes, space-separated class names. | |
957 | * @param string $idbase | |
958 | * @param boolean $return, return as string or just print it | |
959 | * @return string|void Depending on value of $return | |
960 | */ | |
961 | function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) { | |
962 | global $OUTPUT; | |
05226d76 DP |
963 | |
964 | debugging('print_container() is deprecated. Please use $OUTPUT->container() instead.', DEBUG_DEVELOPER); | |
34a2777c | 965 | if ($clearfix) { |
966 | $classes .= ' clearfix'; | |
967 | } | |
968 | $output = $OUTPUT->container($message, $classes, $idbase); | |
969 | if ($return) { | |
970 | return $output; | |
971 | } else { | |
972 | echo $output; | |
973 | } | |
974 | } | |
975 | ||
976 | /** | |
977 | * Starts a container using divs | |
978 | * | |
05226d76 DP |
979 | * @deprecated use $OUTPUT->container_start() instead. |
980 | * @todo final deprecation of this function in MDL-40607 | |
34a2777c | 981 | * @param boolean $clearfix clear both sides |
982 | * @param string $classes, space-separated class names. | |
983 | * @param string $idbase | |
984 | * @param boolean $return, return as string or just print it | |
985 | * @return string|void Based on value of $return | |
986 | */ | |
987 | function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) { | |
988 | global $OUTPUT; | |
05226d76 DP |
989 | |
990 | debugging('print_container_start() is deprecated. Please use $OUTPUT->container_start() instead.', DEBUG_DEVELOPER); | |
991 | ||
34a2777c | 992 | if ($clearfix) { |
993 | $classes .= ' clearfix'; | |
994 | } | |
995 | $output = $OUTPUT->container_start($classes, $idbase); | |
996 | if ($return) { | |
997 | return $output; | |
998 | } else { | |
999 | echo $output; | |
1000 | } | |
1001 | } | |
1002 | ||
78946b9b | 1003 | /** |
337965fe DP |
1004 | * @deprecated do not use any more, is not automatic |
1005 | * @todo remove completely in MDL-40517 | |
78946b9b PS |
1006 | */ |
1007 | function check_theme_arrows() { | |
337965fe | 1008 | throw new coding_exception('check_theme_arrows() has been deprecated, do not use it anymore, it is now automatic.'); |
78946b9b PS |
1009 | } |
1010 | ||
34a2777c | 1011 | /** |
1012 | * Simple function to end a container (see above) | |
1013 | * | |
05226d76 DP |
1014 | * @deprecated use $OUTPUT->container_end() instead. |
1015 | * @todo final deprecation of this function in MDL-40607 | |
34a2777c | 1016 | * @param boolean $return, return as string or just print it |
1017 | * @return string|void Based on $return | |
1018 | */ | |
1019 | function print_container_end($return=false) { | |
1020 | global $OUTPUT; | |
05226d76 | 1021 | debugging('print_container_end() is deprecated. Please use $OUTPUT->container_end() instead.', DEBUG_DEVELOPER); |
34a2777c | 1022 | $output = $OUTPUT->container_end(); |
1023 | if ($return) { | |
1024 | return $output; | |
1025 | } else { | |
1026 | echo $output; | |
1027 | } | |
1028 | } | |
1029 | ||
1030 | /** | |
1031 | * Print a bold message in an optional color. | |
1032 | * | |
1033 | * @deprecated use $OUTPUT->notification instead. | |
1034 | * @param string $message The message to print out | |
1035 | * @param string $style Optional style to display message text in | |
1036 | * @param string $align Alignment option | |
1037 | * @param bool $return whether to return an output string or echo now | |
a5cb8d69 | 1038 | * @return string|bool Depending on $result |
34a2777c | 1039 | */ |
1040 | function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) { | |
1041 | global $OUTPUT; | |
1042 | ||
1043 | if ($classes == 'green') { | |
1044 | debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER); | |
1045 | $classes = 'notifysuccess'; // Backward compatible with old color system | |
1046 | } | |
1047 | ||
1048 | $output = $OUTPUT->notification($message, $classes); | |
1049 | if ($return) { | |
1050 | return $output; | |
1051 | } else { | |
1052 | echo $output; | |
1053 | } | |
1054 | } | |
1055 | ||
1056 | /** | |
1057 | * Print a continue button that goes to a particular URL. | |
1058 | * | |
05226d76 DP |
1059 | * @deprecated use $OUTPUT->continue_button() instead. |
1060 | * @todo final deprecation of this function in MDL-40607 | |
74623e0a | 1061 | * |
34a2777c | 1062 | * @param string $link The url to create a link to. |
1063 | * @param bool $return If set to true output is returned rather than echoed, default false | |
1064 | * @return string|void HTML String if return=true nothing otherwise | |
1065 | */ | |
1066 | function print_continue($link, $return = false) { | |
1067 | global $CFG, $OUTPUT; | |
1068 | ||
05226d76 DP |
1069 | debugging('print_continue() is deprecated. Please use $OUTPUT->continue_button() instead.', DEBUG_DEVELOPER); |
1070 | ||
34a2777c | 1071 | if ($link == '') { |
1072 | if (!empty($_SERVER['HTTP_REFERER'])) { | |
1073 | $link = $_SERVER['HTTP_REFERER']; | |
1074 | $link = str_replace('&', '&', $link); // make it valid XHTML | |
1075 | } else { | |
1076 | $link = $CFG->wwwroot .'/'; | |
1077 | } | |
1078 | } | |
1079 | ||
1080 | $output = $OUTPUT->continue_button($link); | |
1081 | if ($return) { | |
1082 | return $output; | |
1083 | } else { | |
1084 | echo $output; | |
1085 | } | |
1086 | } | |
1087 | ||
34a2777c | 1088 | /** |
1089 | * Print a standard header | |
1090 | * | |
05226d76 DP |
1091 | * @deprecated use $PAGE methods instead. |
1092 | * @todo final deprecation of this function in MDL-40607 | |
34a2777c | 1093 | * @param string $title Appears at the top of the window |
1094 | * @param string $heading Appears at the top of the page | |
1095 | * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links | |
1096 | * @param string $focus Indicates form element to get cursor focus on load eg inputform.password | |
1097 | * @param string $meta Meta tags to be added to the header | |
1098 | * @param boolean $cache Should this page be cacheable? | |
1099 | * @param string $button HTML code for a button (usually for module editing) | |
1100 | * @param string $menu HTML code for a popup menu | |
1101 | * @param boolean $usexml use XML for this page | |
1102 | * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc) | |
1103 | * @param bool $return If true, return the visible elements of the header instead of echoing them. | |
1104 | * @return string|void If return=true then string else void | |
1105 | */ | |
1106 | function print_header($title='', $heading='', $navigation='', $focus='', | |
e120c61d | 1107 | $meta='', $cache=true, $button=' ', $menu=null, |
34a2777c | 1108 | $usexml=false, $bodytags='', $return=false) { |
1109 | global $PAGE, $OUTPUT; | |
1110 | ||
05226d76 DP |
1111 | debugging('print_header() is deprecated. Please use $PAGE methods instead.', DEBUG_DEVELOPER); |
1112 | ||
34a2777c | 1113 | $PAGE->set_title($title); |
1114 | $PAGE->set_heading($heading); | |
3a11c09f | 1115 | $PAGE->set_cacheable($cache); |
34a2777c | 1116 | if ($button == '') { |
1117 | $button = ' '; | |
1118 | } | |
1119 | $PAGE->set_button($button); | |
e120c61d | 1120 | $PAGE->set_headingmenu($menu); |
34a2777c | 1121 | |
34a2777c | 1122 | // TODO $menu |
1123 | ||
1124 | if ($meta) { | |
1125 | throw new coding_exception('The $meta parameter to print_header is no longer supported. '. | |
e29380f3 | 1126 | 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.'); |
34a2777c | 1127 | } |
1128 | if ($usexml) { | |
1129 | throw new coding_exception('The $usexml parameter to print_header is no longer supported.'); | |
1130 | } | |
1131 | if ($bodytags) { | |
1132 | throw new coding_exception('The $bodytags parameter to print_header is no longer supported.'); | |
1133 | } | |
1134 | ||
e120c61d | 1135 | $output = $OUTPUT->header(); |
34a2777c | 1136 | |
1137 | if ($return) { | |
1138 | return $output; | |
1139 | } else { | |
1140 | echo $output; | |
1141 | } | |
1142 | } | |
1143 | ||
47a1aa45 | 1144 | /** |
1145 | * This version of print_header is simpler because the course name does not have to be | |
1146 | * provided explicitly in the strings. It can be used on the site page as in courses | |
1147 | * Eventually all print_header could be replaced by print_header_simple | |
1148 | * | |
05226d76 DP |
1149 | * @deprecated use $PAGE methods instead. |
1150 | * @todo final deprecation of this function in MDL-40607 | |
47a1aa45 | 1151 | * @param string $title Appears at the top of the window |
1152 | * @param string $heading Appears at the top of the page | |
1153 | * @param string $navigation Premade navigation string (for use as breadcrumbs links) | |
1154 | * @param string $focus Indicates form element to get cursor focus on load eg inputform.password | |
1155 | * @param string $meta Meta tags to be added to the header | |
1156 | * @param boolean $cache Should this page be cacheable? | |
1157 | * @param string $button HTML code for a button (usually for module editing) | |
1158 | * @param string $menu HTML code for a popup menu | |
1159 | * @param boolean $usexml use XML for this page | |
1160 | * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc) | |
1161 | * @param bool $return If true, return the visible elements of the header instead of echoing them. | |
1162 | * @return string|void If $return=true the return string else nothing | |
1163 | */ | |
1164 | function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='', | |
1165 | $cache=true, $button=' ', $menu='', $usexml=false, $bodytags='', $return=false) { | |
1166 | ||
1167 | global $COURSE, $CFG, $PAGE, $OUTPUT; | |
1168 | ||
05226d76 DP |
1169 | debugging('print_header_simple() is deprecated. Please use $PAGE methods instead.', DEBUG_DEVELOPER); |
1170 | ||
47a1aa45 | 1171 | if ($meta) { |
1172 | throw new coding_exception('The $meta parameter to print_header is no longer supported. '. | |
1173 | 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.'); | |
1174 | } | |
1175 | if ($usexml) { | |
1176 | throw new coding_exception('The $usexml parameter to print_header is no longer supported.'); | |
1177 | } | |
1178 | if ($bodytags) { | |
1179 | throw new coding_exception('The $bodytags parameter to print_header is no longer supported.'); | |
1180 | } | |
1181 | ||
1182 | $PAGE->set_title($title); | |
3a11c09f | 1183 | $PAGE->set_heading($heading); |
47a1aa45 | 1184 | $PAGE->set_cacheable(true); |
1185 | $PAGE->set_button($button); | |
1186 | ||
1187 | $output = $OUTPUT->header(); | |
1188 | ||
1189 | if ($return) { | |
1190 | return $output; | |
1191 | } else { | |
1192 | echo $output; | |
1193 | } | |
1194 | } | |
1195 | ||
337965fe DP |
1196 | /** |
1197 | * @deprecated use $OUTPUT->footer() instead. | |
1198 | * @todo remove completely in MDL-40517 | |
1199 | */ | |
34a2777c | 1200 | function print_footer($course = NULL, $usercourse = NULL, $return = false) { |
337965fe | 1201 | throw new coding_exception('print_footer() cant be used anymore. Please use $OUTPUT->footer() instead.'); |
a5cb8d69 | 1202 | } |
1203 | ||
244a32c6 | 1204 | /** |
337965fe DP |
1205 | * @deprecated use theme layouts instead. |
1206 | * @todo remove completely in MDL-40517 | |
244a32c6 PS |
1207 | */ |
1208 | function user_login_string($course='ignored', $user='ignored') { | |
337965fe | 1209 | throw new coding_exception('user_login_info() cant be used anymore. User login info is now handled via themes layouts.'); |
244a32c6 PS |
1210 | } |
1211 | ||
a5cb8d69 | 1212 | /** |
1213 | * Prints a nice side block with an optional header. The content can either | |
1214 | * be a block of HTML or a list of text with optional icons. | |
1215 | * | |
a5cb8d69 | 1216 | * @static int $block_id Increments for each call to the function |
1217 | * @param string $heading HTML for the heading. Can include full HTML or just | |
1218 | * plain text - plain text will automatically be enclosed in the appropriate | |
1219 | * heading tags. | |
1220 | * @param string $content HTML for the content | |
1221 | * @param array $list an alternative to $content, it you want a list of things with optional icons. | |
1222 | * @param array $icons optional icons for the things in $list. | |
1223 | * @param string $footer Extra HTML content that gets output at the end, inside a <div class="footer"> | |
1224 | * @param array $attributes an array of attribute => value pairs that are put on the | |
6605ff8c SH |
1225 | * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't |
1226 | * already a class, class='block' is used. | |
a5cb8d69 | 1227 | * @param string $title Plain text title, as embedded in the $heading. |
05226d76 DP |
1228 | * @deprecated use $OUTPUT->block() instead. |
1229 | * @todo final deprecation of this function in MDL-40607 | |
a5cb8d69 | 1230 | */ |
1231 | function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') { | |
1232 | global $OUTPUT; | |
d4a03c00 | 1233 | |
05226d76 | 1234 | debugging('print_side_block() is deprecated, please use $OUTPUT->block() instead.', DEBUG_DEVELOPER); |
d4a03c00 | 1235 | // We don't use $heading, becuse it often contains HTML that we don't want. |
1236 | // However, sometimes $title is not set, but $heading is. | |
1237 | if (empty($title)) { | |
1238 | $title = strip_tags($heading); | |
1239 | } | |
1240 | ||
1241 | // Render list contents to HTML if required. | |
1242 | if (empty($content) && $list) { | |
1243 | $content = $OUTPUT->list_block_contents($icons, $list); | |
1244 | } | |
1245 | ||
a5cb8d69 | 1246 | $bc = new block_contents(); |
a5cb8d69 | 1247 | $bc->content = $content; |
a5cb8d69 | 1248 | $bc->footer = $footer; |
1249 | $bc->title = $title; | |
1250 | ||
1251 | if (isset($attributes['id'])) { | |
1252 | $bc->id = $attributes['id']; | |
1253 | unset($attributes['id']); | |
1254 | } | |
a5cb8d69 | 1255 | $bc->attributes = $attributes; |
1256 | ||
3ceb6910 | 1257 | echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here. |
a5cb8d69 | 1258 | } |
1259 | ||
d4a03c00 | 1260 | /** |
337965fe DP |
1261 | * @deprecated blocks are now printed by theme. |
1262 | * @todo remove completely in MDL-40517 | |
d4a03c00 | 1263 | */ |
1264 | function blocks_have_content(&$blockmanager, $region) { | |
337965fe | 1265 | throw new coding_exception('blocks_have_content() can no longer be used. Blocks are now printed by the theme.'); |
d4a03c00 | 1266 | } |
1267 | ||
1268 | /** | |
337965fe DP |
1269 | * @deprecated blocks are now printed by the theme. |
1270 | * @todo remove completely in MDL-40517 | |
d4a03c00 | 1271 | */ |
1272 | function blocks_print_group($page, $blockmanager, $region) { | |
337965fe | 1273 | throw new coding_exception('function blocks_print_group() can no longer be used. Blocks are now printed by the theme.'); |
d4a03c00 | 1274 | } |
1275 | ||
1276 | /** | |
337965fe DP |
1277 | * @deprecated blocks are now printed by the theme. |
1278 | * @todo remove completely in MDL-40517 | |
d4a03c00 | 1279 | */ |
1280 | function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) { | |
337965fe | 1281 | throw new coding_exception('blocks_print_group() can no longer be used. Blocks are now printed by the theme.'); |
d4a03c00 | 1282 | } |
1283 | ||
1284 | /** | |
337965fe DP |
1285 | * @deprecated Layout is now controlled by the theme. |
1286 | * @todo remove completely in MDL-40517 | |
d4a03c00 | 1287 | */ |
1288 | function blocks_preferred_width($instances) { | |
337965fe | 1289 | throw new coding_exception('blocks_print_group() can no longer be used. Blocks are now printed by the theme.'); |
d4a03c00 | 1290 | } |
1291 | ||
480b0720 | 1292 | /** |
337965fe DP |
1293 | * @deprecated use html_writer::table() instead. |
1294 | * @todo remove completely in MDL-40517 | |
480b0720 | 1295 | */ |
1296 | function print_table($table, $return=false) { | |
337965fe | 1297 | throw new coding_exception('print_table() can no longer be used. Use html_writer::table() instead.'); |
480b0720 | 1298 | } |
f8065dd2 | 1299 | |
1300 | /** | |
337965fe DP |
1301 | * @deprecated use $OUTPUT->action_link() instead (note: popups are discouraged for accesibility reasons) |
1302 | * @todo remove completely in MDL-40517 | |
f8065dd2 | 1303 | */ |
4bcc5118 | 1304 | function link_to_popup_window ($url, $name=null, $linkname=null, $height=400, $width=500, $title=null, $options=null, $return=false) { |
337965fe | 1305 | throw new coding_exception('link_to_popup_window() can no longer be used. Please to use $OUTPUT->action_link() instead.'); |
f8065dd2 | 1306 | } |
1307 | ||
1308 | /** | |
337965fe DP |
1309 | * @deprecated use $OUTPUT->single_button() instead. |
1310 | * @todo remove completely in MDL-40517 | |
f8065dd2 | 1311 | */ |
1312 | function button_to_popup_window ($url, $name=null, $linkname=null, | |
1313 | $height=400, $width=500, $title=null, $options=null, $return=false, | |
1314 | $id=null, $class=null) { | |
337965fe | 1315 | throw new coding_exception('button_to_popup_window() can no longer be used. Please use $OUTPUT->single_button() instead.'); |
f8065dd2 | 1316 | } |
1317 | ||
1318 | /** | |
337965fe DP |
1319 | * @deprecated use $OUTPUT->single_button() instead. |
1320 | * @todo remove completely in MDL-40517 | |
f8065dd2 | 1321 | */ |
1322 | function print_single_button($link, $options, $label='OK', $method='get', $notusedanymore='', | |
1323 | $return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') { | |
49c8c8d2 | 1324 | |
337965fe | 1325 | throw new coding_exception('print_single_button() can no longer be used. Please use $OUTPUT->single_button() instead.'); |
f8065dd2 | 1326 | } |
1327 | ||
1328 | /** | |
337965fe DP |
1329 | * @deprecated use $OUTPUT->spacer() instead. |
1330 | * @todo remove completely in MDL-40517 | |
f8065dd2 | 1331 | */ |
1332 | function print_spacer($height=1, $width=1, $br=true, $return=false) { | |
337965fe | 1333 | throw new coding_exception('print_spacer() can no longer be used. Please use $OUTPUT->spacer() instead.'); |
f8065dd2 | 1334 | } |
1335 | ||
f8065dd2 | 1336 | /** |
337965fe DP |
1337 | * @deprecated use $OUTPUT->user_picture() instead. |
1338 | * @todo remove completely in MDL-40517 | |
f8065dd2 | 1339 | */ |
1340 | function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) { | |
337965fe | 1341 | throw new coding_exception('print_user_picture() can no longer be used. Please use $OUTPUT->user_picture($user, array(\'courseid\'=>$courseid) instead.'); |
f8065dd2 | 1342 | } |
1343 | ||
f8065dd2 | 1344 | /** |
1345 | * Prints a basic textarea field. | |
1346 | * | |
1347 | * @deprecated since Moodle 2.0 | |
1348 | * | |
1349 | * When using this function, you should | |
1350 | * | |
1351 | * @global object | |
1352 | * @param bool $usehtmleditor Enables the use of the htmleditor for this field. | |
1353 | * @param int $rows Number of rows to display (minimum of 10 when $height is non-null) | |
1354 | * @param int $cols Number of columns to display (minimum of 65 when $width is non-null) | |
1355 | * @param null $width (Deprecated) Width of the element; if a value is passed, the minimum value for $cols will be 65. Value is otherwise ignored. | |
1356 | * @param null $height (Deprecated) Height of the element; if a value is passe, the minimum value for $rows will be 10. Value is otherwise ignored. | |
1357 | * @param string $name Name to use for the textarea element. | |
1358 | * @param string $value Initial content to display in the textarea. | |
1359 | * @param int $obsolete deprecated | |
1360 | * @param bool $return If false, will output string. If true, will return string value. | |
1361 | * @param string $id CSS ID to add to the textarea element. | |
1362 | * @return string|void depending on the value of $return | |
1363 | */ | |
1364 | function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') { | |
1365 | /// $width and height are legacy fields and no longer used as pixels like they used to be. | |
1366 | /// However, you can set them to zero to override the mincols and minrows values below. | |
1367 | ||
3d8a479b MD |
1368 | // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used |
1369 | // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.'); | |
f8065dd2 | 1370 | |
1371 | global $CFG; | |
1372 | ||
1373 | $mincols = 65; | |
1374 | $minrows = 10; | |
1375 | $str = ''; | |
1376 | ||
1377 | if ($id === '') { | |
1378 | $id = 'edit-'.$name; | |
1379 | } | |
1380 | ||
1381 | if ($usehtmleditor) { | |
1382 | if ($height && ($rows < $minrows)) { | |
1383 | $rows = $minrows; | |
1384 | } | |
1385 | if ($width && ($cols < $mincols)) { | |
1386 | $cols = $mincols; | |
1387 | } | |
1388 | } | |
1389 | ||
1390 | if ($usehtmleditor) { | |
1391 | editors_head_setup(); | |
20e5da7d | 1392 | $editor = editors_get_preferred_editor(FORMAT_HTML); |
f8065dd2 | 1393 | $editor->use_editor($id, array('legacy'=>true)); |
1394 | } else { | |
1395 | $editorclass = ''; | |
1396 | } | |
1397 | ||
0ac97084 | 1398 | $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'" spellcheck="true">'."\n"; |
f8065dd2 | 1399 | if ($usehtmleditor) { |
1400 | $str .= htmlspecialchars($value); // needed for editing of cleaned text! | |
1401 | } else { | |
1402 | $str .= s($value); | |
1403 | } | |
1404 | $str .= '</textarea>'."\n"; | |
1405 | ||
1406 | if ($return) { | |
1407 | return $str; | |
1408 | } | |
1409 | echo $str; | |
1410 | } | |
1411 | ||
1412 | ||
1413 | /** | |
1414 | * Print a help button. | |
1415 | * | |
1416 | * @deprecated since Moodle 2.0 | |
f8065dd2 | 1417 | */ |
1418 | function helpbutton($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false, $imagetext='') { | |
a6d81a73 | 1419 | throw new coding_exception('helpbutton() can not be used any more, please see $OUTPUT->help_icon().'); |
4bcc5118 PS |
1420 | } |
1421 | ||
1422 | /** | |
337965fe DP |
1423 | * @deprecated this is now handled by text editors |
1424 | * @todo remove completely in MDL-40517 | |
4bcc5118 PS |
1425 | */ |
1426 | function emoticonhelpbutton($form, $field, $return = false) { | |
337965fe | 1427 | throw new coding_exception('emoticonhelpbutton() was removed, new text editors will implement this feature'); |
4bcc5118 PS |
1428 | } |
1429 | ||
1430 | /** | |
1431 | * Returns a string of html with an image of a help icon linked to a help page on a number of help topics. | |
1432 | * Should be used only with htmleditor or textarea. | |
1433 | * | |
1434 | * @global object | |
1435 | * @global object | |
1436 | * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for | |
1437 | * helpbutton. | |
1438 | * @return string Link to help button | |
1439 | */ | |
1440 | function editorhelpbutton(){ | |
1441 | return ''; | |
1442 | ||
1443 | /// TODO: MDL-21215 | |
f8065dd2 | 1444 | } |
1445 | ||
4bcc5118 PS |
1446 | /** |
1447 | * Print a help button. | |
1448 | * | |
1449 | * Prints a special help button for html editors (htmlarea in this case) | |
1450 | * | |
1451 | * @todo Write code into this function! detect current editor and print correct info | |
1452 | * @global object | |
1453 | * @return string Only returns an empty string at the moment | |
1454 | */ | |
1455 | function editorshortcutshelpbutton() { | |
1456 | /// TODO: MDL-21215 | |
1457 | ||
1458 | global $CFG; | |
1459 | //TODO: detect current editor and print correct info | |
4bcc5118 PS |
1460 | return ''; |
1461 | } | |
1462 | ||
1463 | ||
f8065dd2 | 1464 | /** |
1465 | * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please | |
1466 | * provide this function with the language strings for sortasc and sortdesc. | |
1467 | * | |
05226d76 DP |
1468 | * @deprecated use $OUTPUT->arrow() instead. |
1469 | * @todo final deprecation of this function in MDL-40607 | |
f8065dd2 | 1470 | * |
f8065dd2 | 1471 | * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned. |
1472 | * | |
1473 | * @global object | |
1474 | * @param string $direction 'up' or 'down' | |
1475 | * @param string $strsort The language string used for the alt attribute of this image | |
1476 | * @param bool $return Whether to print directly or return the html string | |
1477 | * @return string|void depending on $return | |
1478 | * | |
1479 | */ | |
1480 | function print_arrow($direction='up', $strsort=null, $return=false) { | |
f8065dd2 | 1481 | global $OUTPUT; |
1482 | ||
05226d76 DP |
1483 | debugging('print_arrow() is deprecated. Please use $OUTPUT->arrow() instead.', DEBUG_DEVELOPER); |
1484 | ||
f8065dd2 | 1485 | if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) { |
1486 | return null; | |
1487 | } | |
1488 | ||
1489 | $return = null; | |
1490 | ||
1491 | switch ($direction) { | |
1492 | case 'up': | |
1493 | $sortdir = 'asc'; | |
1494 | break; | |
1495 | case 'down': | |
1496 | $sortdir = 'desc'; | |
1497 | break; | |
1498 | case 'move': | |
1499 | $sortdir = 'asc'; | |
1500 | break; | |
1501 | default: | |
1502 | $sortdir = null; | |
1503 | break; | |
1504 | } | |
1505 | ||
1506 | // Prepare language string | |
1507 | $strsort = ''; | |
1508 | if (empty($strsort) && !empty($sortdir)) { | |
1509 | $strsort = get_string('sort' . $sortdir, 'grades'); | |
1510 | } | |
1511 | ||
b5d0cafc | 1512 | $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> '; |
f8065dd2 | 1513 | |
1514 | if ($return) { | |
1515 | return $return; | |
1516 | } else { | |
1517 | echo $return; | |
1518 | } | |
1519 | } | |
1520 | ||
1521 | /** | |
1522 | * Returns a string containing a link to the user documentation. | |
1523 | * Also contains an icon by default. Shown to teachers and admin only. | |
1524 | * | |
1525 | * @deprecated since Moodle 2.0 | |
f8065dd2 | 1526 | */ |
8ae8bf8a | 1527 | function doc_link($path='', $text='', $iconpath='ignored') { |
a6d81a73 | 1528 | throw new coding_exception('doc_link() can not be used any more, please see $OUTPUT->doc_link().'); |
f8065dd2 | 1529 | } |
1530 | ||
1531 | /** | |
337965fe DP |
1532 | * @deprecated use $OUTPUT->render($pagingbar) instead. |
1533 | * @todo remove completely in MDL-40517 | |
f8065dd2 | 1534 | */ |
1535 | function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) { | |
337965fe | 1536 | throw new coding_exception('print_paging_bar() can not be used any more. Please use $OUTPUT->render($pagingbar) instead.'); |
f8065dd2 | 1537 | } |
1538 | ||
1539 | /** | |
337965fe DP |
1540 | * @deprecated use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel) instead. |
1541 | * @todo remove completely in MDL-40517 | |
f8065dd2 | 1542 | */ |
1543 | function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') { | |
337965fe | 1544 | throw new coding_exception('notice_yesno() can not be used any more. Please use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel) instead.'); |
f8065dd2 | 1545 | } |
1546 | ||
8100c169 | 1547 | /** |
1548 | * Given an array of values, output the HTML for a select element with those options. | |
1549 | * | |
1550 | * @deprecated since Moodle 2.0 | |
1551 | * | |
1552 | * Normally, you only need to use the first few parameters. | |
1553 | * | |
1554 | * @param array $options The options to offer. An array of the form | |
1555 | * $options[{value}] = {text displayed for that option}; | |
1556 | * @param string $name the name of this form control, as in <select name="..." ... | |
1557 | * @param string $selected the option to select initially, default none. | |
1558 | * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose'). | |
1559 | * Set this to '' if you don't want a 'nothing is selected' option. | |
1560 | * @param string $script if not '', then this is added to the <select> element as an onchange handler. | |
1561 | * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0. | |
1562 | * @param boolean $return if false (the default) the the output is printed directly, If true, the | |
1563 | * generated HTML is returned as a string. | |
1564 | * @param boolean $disabled if true, the select is generated in a disabled state. Default, false. | |
1565 | * @param int $tabindex if give, sets the tabindex attribute on the <select> element. Default none. | |
1566 | * @param string $id value to use for the id attribute of the <select> element. If none is given, | |
1567 | * then a suitable one is constructed. | |
1568 | * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box. | |
1569 | * By default, the list box will have a number of rows equal to min(10, count($options)), but if | |
1570 | * $listbox is an integer, that number is used for size instead. | |
1571 | * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used | |
1572 | * when $listbox display is enabled | |
1573 | * @param string $class value to use for the class attribute of the <select> element. If none is given, | |
1574 | * then a suitable one is constructed. | |
1575 | * @return string|void If $return=true returns string, else echo's and returns void | |
1576 | */ | |
1577 | function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='', | |
1578 | $nothingvalue='0', $return=false, $disabled=false, $tabindex=0, | |
1579 | $id='', $listbox=false, $multiple=false, $class='') { | |
053203a8 | 1580 | |
8100c169 | 1581 | global $OUTPUT; |
4461cc60 | 1582 | debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().'); |
053203a8 | 1583 | |
1584 | if ($script) { | |
1585 | debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER); | |
1586 | } | |
4461cc60 PS |
1587 | $attributes = array(); |
1588 | $attributes['disabled'] = $disabled ? 'disabled' : null; | |
1589 | $attributes['tabindex'] = $tabindex ? $tabindex : null; | |
1590 | $attributes['multiple'] = $multiple ? $multiple : null; | |
1591 | $attributes['class'] = $class ? $class : null; | |
1592 | $attributes['id'] = $id ? $id : null; | |
053203a8 | 1593 | |
4461cc60 | 1594 | $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes); |
053203a8 | 1595 | |
1596 | if ($return) { | |
1597 | return $output; | |
1598 | } else { | |
1599 | echo $output; | |
8100c169 | 1600 | } |
053203a8 | 1601 | } |
1602 | ||
1603 | /** | |
337965fe DP |
1604 | * @deprecated use html_writer::select_yes_no() instead. |
1605 | * @todo remove completely in MDL-40517 | |
053203a8 | 1606 | */ |
28fbce88 | 1607 | function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) { |
337965fe | 1608 | throw new coding_exception('choose_from_menu_yesno() can not be used anymore. Please use html_writerselect_yes_no() instead.'); |
053203a8 | 1609 | } |
1610 | ||
1611 | /** | |
337965fe DP |
1612 | * @deprecated use html_writer::select() instead. |
1613 | * @todo remove completely in MDL-40517 | |
053203a8 | 1614 | */ |
1615 | function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '', | |
1616 | $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) { | |
1617 | ||
337965fe | 1618 | throw new coding_exception('choose_from_menu_nested() can not be used any more. Please use html_writer::select() instead.'); |
8100c169 | 1619 | } |
053203a8 | 1620 | |
c68e4098 | 1621 | /** |
1622 | * Prints a help button about a scale | |
1623 | * | |
05226d76 DP |
1624 | * @deprecated use $OUTPUT->help_icon_scale($courseid, $scale) instead. |
1625 | * @todo final deprecation of this function in MDL-40607 | |
c68e4098 | 1626 | * |
1627 | * @global object | |
1628 | * @param id $courseid | |
1629 | * @param object $scale | |
1630 | * @param boolean $return If set to true returns rather than echo's | |
1631 | * @return string|bool Depending on value of $return | |
1632 | */ | |
1633 | function print_scale_menu_helpbutton($courseid, $scale, $return=false) { | |
c68e4098 | 1634 | global $OUTPUT; |
1635 | ||
05226d76 DP |
1636 | debugging('print_scale_menu_helpbutton() is deprecated. Please use $OUTPUT->help_icon_scale($courseid, $scale) instead.', DEBUG_DEVELOPER); |
1637 | ||
4bcc5118 | 1638 | $output = $OUTPUT->help_icon_scale($courseid, $scale); |
c68e4098 | 1639 | |
1640 | if ($return) { | |
1641 | return $output; | |
1642 | } else { | |
1643 | echo $output; | |
1644 | } | |
1645 | } | |
1646 | ||
c68e4098 | 1647 | /** |
337965fe DP |
1648 | * @deprecated use html_writer::select_time() instead |
1649 | * @todo remove completely in MDL-40517 | |
c68e4098 | 1650 | */ |
1651 | function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) { | |
337965fe | 1652 | throw new moodle_exception('print_time_selector() can not be used any more . Please use html_writer::select_time() instead.'); |
c68e4098 | 1653 | } |
1654 | ||
1655 | /** | |
337965fe DP |
1656 | * @deprecated please use html_writer::select_time instead |
1657 | * @todo remove completely in MDL-40517 | |
c68e4098 | 1658 | */ |
1659 | function print_date_selector($day, $month, $year, $currenttime=0, $return=false) { | |
337965fe | 1660 | throw new coding_exception('print_date_selector() can not be used any more. Please use html_writer::select_time() instead.'); |
49690843 | 1661 | } |
1662 | ||
1663 | /** | |
1664 | * Implements a complete little form with a dropdown menu. | |
1665 | * | |
1666 | * @deprecated since Moodle 2.0 | |
49690843 | 1667 | */ |
1668 | function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false, | |
1669 | $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) { | |
a6d81a73 | 1670 | throw new coding_exception('popup_form() can not be used any more, please see $OUTPUT->single_select or $OUTPUT->url_select().'); |
c68e4098 | 1671 | } |
1672 | ||
ce60cbc8 | 1673 | /** |
337965fe DP |
1674 | * @deprecated use $OUTPUT->close_window_button() instead. |
1675 | * @todo remove completely in MDL-40517 | |
ce60cbc8 | 1676 | */ |
1677 | function close_window_button($name='closewindow', $return=false, $reloadopener = false) { | |
337965fe | 1678 | throw new coding_exception('close_window_button() can not be used any more. Use $OUTPUT->close_window_button() instead.'); |
ce60cbc8 | 1679 | } |
49c8c8d2 | 1680 | |
1681 | /** | |
337965fe DP |
1682 | * @deprecated use html_writer instead. |
1683 | * @todo remove completely in MDL-40517 | |
49c8c8d2 | 1684 | */ |
1685 | function choose_from_radio ($options, $name, $checked='', $return=false) { | |
337965fe | 1686 | throw new coding_exception('choose_from_radio() can not be used any more. Please use html_writer instead.'); |
49c8c8d2 | 1687 | } |
1688 | ||
1689 | /** | |
1690 | * Display an standard html checkbox with an optional label | |
1691 | * | |
05226d76 DP |
1692 | * @deprecated use html_writer::checkbox() instead. |
1693 | * @todo final deprecation of this function in MDL-40607 | |
49c8c8d2 | 1694 | * |
1695 | * @staticvar int $idcounter | |
1696 | * @param string $name The name of the checkbox | |
1697 | * @param string $value The valus that the checkbox will pass when checked | |
1698 | * @param bool $checked The flag to tell the checkbox initial state | |
1699 | * @param string $label The label to be showed near the checkbox | |
1700 | * @param string $alt The info to be inserted in the alt tag | |
1701 | * @param string $script If not '', then this is added to the checkbox element | |
1702 | * as an onchange handler. | |
1703 | * @param bool $return Whether this function should return a string or output | |
1704 | * it (defaults to false) | |
1705 | * @return string|void If $return=true returns string, else echo's and returns void | |
1706 | */ | |
916276fc | 1707 | function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) { |
49c8c8d2 | 1708 | global $OUTPUT; |
6a5c71b9 | 1709 | |
05226d76 DP |
1710 | debugging('print_checkbox() is deprecated. Please use html_writer::checkbox() instead.', DEBUG_DEVELOPER); |
1711 | ||
49c8c8d2 | 1712 | if (!empty($script)) { |
7de13103 | 1713 | debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER); |
49c8c8d2 | 1714 | } |
1715 | ||
2f0e96e4 | 1716 | $output = html_writer::checkbox($name, $value, $checked, $label); |
49c8c8d2 | 1717 | |
1718 | if (empty($return)) { | |
1719 | echo $output; | |
1720 | } else { | |
1721 | return $output; | |
1722 | } | |
1723 | ||
1724 | } | |
6a5c71b9 | 1725 | |
6a5c71b9 | 1726 | /** |
337965fe DP |
1727 | * @deprecated use mforms or html_writer instead. |
1728 | * @todo remove completely in MDL-40517 | |
6a5c71b9 | 1729 | */ |
916276fc | 1730 | function print_textfield($name, $value, $alt = '', $size=50, $maxlength=0, $return=false) { |
337965fe | 1731 | throw new coding_exception('print_textfield() can not be used anymore. Please use mforms or html_writer instead.'); |
6a5c71b9 | 1732 | } |
1733 | ||
e1cc8840 | 1734 | |
1735 | /** | |
337965fe DP |
1736 | * @deprecated use $OUTPUT->heading_with_help() instead |
1737 | * @todo remove completely in MDL-40517 | |
e1cc8840 | 1738 | */ |
1739 | function print_heading_with_help($text, $helppage, $module='moodle', $icon=false, $return=false) { | |
337965fe | 1740 | throw new coding_exception('print_heading_with_help() can not be used anymore. Please use $OUTPUT->heading_with_help() instead.'); |
e1cc8840 | 1741 | } |
7527a2f0 | 1742 | |
c351150f | 1743 | /** |
337965fe DP |
1744 | * @deprecated use $OUTPUT->edit_button() instead. |
1745 | * @todo remove completely in MDL-40517 | |
c351150f | 1746 | */ |
cf132980 | 1747 | function update_tag_button($tagid) { |
337965fe | 1748 | throw new coding_exception('update_tag_button() can not be used any more. Please $OUTPUT->edit_button(moodle_url) instead.'); |
c351150f | 1749 | } |
1750 | ||
1751 | ||
1752 | /** | |
1753 | * Prints the 'update this xxx' button that appears on module pages. | |
1754 | * | |
1755 | * @deprecated since Moodle 2.0 | |
1756 | * | |
1757 | * @param string $cmid the course_module id. | |
1758 | * @param string $ignored not used any more. (Used to be courseid.) | |
1759 | * @param string $string the module name - get_string('modulename', 'xxx') | |
1760 | * @return string the HTML for the button, if this user has permission to edit it, else an empty string. | |
1761 | */ | |
1762 | function update_module_button($cmid, $ignored, $string) { | |
d1f06fb5 | 1763 | global $CFG, $OUTPUT; |
c351150f | 1764 | |
bc2e0484 | 1765 | // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().'); |
c351150f | 1766 | |
d1f06fb5 | 1767 | //NOTE: DO NOT call new output method because it needs the module name we do not have here! |
1768 | ||
b0c6dc1c | 1769 | if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) { |
d1f06fb5 | 1770 | $string = get_string('updatethis', '', $string); |
1771 | ||
5c2ed7e2 PS |
1772 | $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey())); |
1773 | return $OUTPUT->single_button($url, $string); | |
d1f06fb5 | 1774 | } else { |
1775 | return ''; | |
1776 | } | |
c351150f | 1777 | } |
1778 | ||
cf132980 | 1779 | /** |
337965fe DP |
1780 | * @deprecated use $OUTPUT->edit_button() instead. |
1781 | * @todo remove completely in MDL-40517 | |
cf132980 | 1782 | */ |
1783 | function update_course_icon($courseid) { | |
337965fe | 1784 | throw new coding_exception('update_course_button() can not be used anymore. Please use $OUTPUT->edit_button(moodle_url) instead.'); |
cf132980 | 1785 | } |
1786 | ||
7d2a0492 | 1787 | /** |
1788 | * Prints breadcrumb trail of links, called in theme/-/header.html | |
1789 | * | |
1790 | * This function has now been deprecated please use output's navbar method instead | |
1791 | * as shown below | |
1792 | * | |
1793 | * <code php> | |
1794 | * echo $OUTPUT->navbar(); | |
1795 | * </code> | |
1796 | * | |
05226d76 DP |
1797 | * @deprecated use $OUTPUT->navbar() instead |
1798 | * @todo final deprecation of this function in MDL-40607 | |
7d2a0492 | 1799 | * @param mixed $navigation deprecated |
1800 | * @param string $separator OBSOLETE, and now deprecated | |
1801 | * @param boolean $return False to echo the breadcrumb string (default), true to return it. | |
1802 | * @return string|void String or null, depending on $return. | |
1803 | */ | |
1804 | function print_navigation ($navigation, $separator=0, $return=false) { | |
1805 | global $OUTPUT,$PAGE; | |
1806 | ||
05226d76 | 1807 | debugging('print_navigation() is deprecated, please update use $OUTPUT->navbar() instead.', DEBUG_DEVELOPER); |
7d2a0492 | 1808 | |
1809 | $output = $OUTPUT->navbar(); | |
1810 | ||
1811 | if ($return) { | |
1812 | return $output; | |
1813 | } else { | |
1814 | echo $output; | |
1815 | } | |
1816 | } | |
1817 | ||
1818 | /** | |
1819 | * This function will build the navigation string to be used by print_header | |
1820 | * and others. | |
1821 | * | |
1822 | * It automatically generates the site and course level (if appropriate) links. | |
1823 | * | |
1824 | * If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums') | |
1825 | * and activityinstances (e.g. 'General Developer Forum') navigation levels. | |
1826 | * | |
1827 | * If you want to add any further navigation links after the ones this function generates, | |
1828 | * the pass an array of extra link arrays like this: | |
1829 | * array( | |
1830 | * array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1), | |
1831 | * array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2) | |
1832 | * ) | |
1833 | * The normal case is to just add one further link, for example 'Editing forum' after | |
1834 | * 'General Developer Forum', with no link. | |
1835 | * To do that, you need to pass | |
1836 | * array(array('name' => $linktext, 'link' => '', 'type' => 'title')) | |
1837 | * However, becuase this is a very common case, you can use a shortcut syntax, and just | |
1838 | * pass the string 'Editing forum', instead of an array as $extranavlinks. | |
1839 | * | |
1840 | * At the moment, the link types only have limited significance. Type 'activity' is | |
1841 | * recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types | |
1842 | * that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'. | |
1843 | * This really needs to be documented better. In the mean time, try to be consistent, it will | |
1844 | * enable people to customise the navigation more in future. | |
1845 | * | |
1846 | * When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course. | |
1847 | * If you get the $cm object using the function get_coursemodule_from_instance or | |
1848 | * get_coursemodule_from_id (as recommended) then this will be done for you automatically. | |
1849 | * If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using | |
1850 | * the $cm->module and $cm->instance fields, but this takes extra database queries, so a | |
1851 | * warning is printed in developer debug mode. | |
1852 | * | |
05226d76 DP |
1853 | * @deprecated Please use $PAGE->navabar methods instead. |
1854 | * @todo final deprecation of this function in MDL-40607 | |
7d2a0492 | 1855 | * @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you |
1856 | * only want one extra item with no link, you can pass a string instead. If you don't want | |
1857 | * any extra links, pass an empty string. | |
1858 | * @param mixed $cm deprecated | |
1859 | * @return array Navigation array | |
1860 | */ | |
1861 | function build_navigation($extranavlinks, $cm = null) { | |
1862 | global $CFG, $COURSE, $DB, $SITE, $PAGE; | |
1863 | ||
05226d76 | 1864 | debugging('build_navigation() is deprecated, please use $PAGE->navbar methods instead.', DEBUG_DEVELOPER); |
7d2a0492 | 1865 | if (is_array($extranavlinks) && count($extranavlinks)>0) { |
7d2a0492 | 1866 | foreach ($extranavlinks as $nav) { |
1867 | if (array_key_exists('name', $nav)) { | |
a4397489 | 1868 | if (array_key_exists('link', $nav) && !empty($nav['link'])) { |
1869 | $link = $nav['link']; | |
1870 | } else { | |
1871 | $link = null; | |
1872 | } | |
91152a35 | 1873 | $PAGE->navbar->add($nav['name'],$link); |
7d2a0492 | 1874 | } |
1875 | } | |
1876 | } | |
6f5e0852 | 1877 | |
7d2a0492 | 1878 | return(array('newnav' => true, 'navlinks' => array())); |
1879 | } | |
1880 | ||
1881 | /** | |
05226d76 DP |
1882 | * @deprecated not relevant with global navigation in Moodle 2.x+ |
1883 | * @todo remove completely in MDL-40517 | |
7d2a0492 | 1884 | */ |
1885 | function navmenu($course, $cm=NULL, $targetwindow='self') { | |
7d2a0492 | 1886 | // This function has been deprecated with the creation of the global nav in |
1887 | // moodle 2.0 | |
05226d76 | 1888 | debugging('navmenu() is deprecated, it is no longer relevant with global navigation.', DEBUG_DEVELOPER); |
7d2a0492 | 1889 | |
1890 | return ''; | |
f43cdceb | 1891 | } |
76d9df3f | 1892 | |
396898c8 | 1893 | /** |
337965fe DP |
1894 | * @deprecated use the settings block instead. |
1895 | * @todo remove completely in MDL-40517 | |
396898c8 DM |
1896 | */ |
1897 | function switchroles_form($courseid) { | |
337965fe | 1898 | throw new coding_exception('switchroles_form() can not be used any more. The global settings block does this job.'); |
396898c8 | 1899 | } |
01a2ce80 PS |
1900 | |
1901 | /** | |
337965fe DP |
1902 | * @deprecated Please use normal $OUTPUT->header() instead |
1903 | * @todo remove completely in MDL-40517 | |
01a2ce80 PS |
1904 | */ |
1905 | function admin_externalpage_print_header($focus='') { | |
337965fe | 1906 | throw new coding_exception('admin_externalpage_print_header can not be used any more. Please $OUTPUT->header() instead.'); |
01a2ce80 PS |
1907 | } |
1908 | ||
1909 | /** | |
337965fe DP |
1910 | * @deprecated Please use normal $OUTPUT->footer() instead |
1911 | * @todo remove completely in MDL-40517 | |
01a2ce80 PS |
1912 | */ |
1913 | function admin_externalpage_print_footer() { | |
337965fe | 1914 | throw new coding_exception('admin_externalpage_print_footer can not be used anymore Please $OUTPUT->footer() instead.'); |
01a2ce80 PS |
1915 | } |
1916 | ||
76d9df3f SH |
1917 | /// CALENDAR MANAGEMENT //////////////////////////////////////////////////////////////// |
1918 | ||
1919 | ||
1920 | /** | |
1921 | * Call this function to add an event to the calendar table and to call any calendar plugins | |
1922 | * | |
1923 | * @param object $event An object representing an event from the calendar table. | |
1924 | * The event will be identified by the id field. The object event should include the following: | |
1925 | * <ul> | |
1926 | * <li><b>$event->name</b> - Name for the event | |
1927 | * <li><b>$event->description</b> - Description of the event (defaults to '') | |
1928 | * <li><b>$event->format</b> - Format for the description (using formatting types defined at the top of weblib.php) | |
1929 | * <li><b>$event->courseid</b> - The id of the course this event belongs to (0 = all courses) | |
1930 | * <li><b>$event->groupid</b> - The id of the group this event belongs to (0 = no group) | |
1931 | * <li><b>$event->userid</b> - The id of the user this event belongs to (0 = no user) | |
1932 | * <li><b>$event->modulename</b> - Name of the module that creates this event | |
1933 | * <li><b>$event->instance</b> - Instance of the module that owns this event | |
1934 | * <li><b>$event->eventtype</b> - The type info together with the module info could | |
1935 | * be used by calendar plugins to decide how to display event | |
1936 | * <li><b>$event->timestart</b>- Timestamp for start of event | |
1937 | * <li><b>$event->timeduration</b> - Duration (defaults to zero) | |
1938 | * <li><b>$event->visible</b> - 0 if the event should be hidden (e.g. because the activity that created it is hidden) | |
1939 | * </ul> | |
1940 | * @return int|false The id number of the resulting record or false if failed | |
05226d76 DP |
1941 | * @deprecated please use calendar_event::create() instead. |
1942 | * @todo final deprecation of this function in MDL-40607 | |
76d9df3f SH |
1943 | */ |
1944 | function add_event($event) { | |
1945 | global $CFG; | |
1946 | require_once($CFG->dirroot.'/calendar/lib.php'); | |
05226d76 DP |
1947 | |
1948 | debugging('add_event() is deprecated, please use calendar_event::create() instead.', DEBUG_DEVELOPER); | |
76d9df3f SH |
1949 | $event = calendar_event::create($event); |
1950 | if ($event !== false) { | |
1951 | return $event->id; | |
1952 | } | |
1953 | return false; | |
1954 | } | |
1955 | ||
1956 | /** | |
1957 | * Call this function to update an event in the calendar table | |
1958 | * the event will be identified by the id field of the $event object. | |
1959 | * | |
1960 | * @param object $event An object representing an event from the calendar table. The event will be identified by the id field. | |
1961 | * @return bool Success | |
05226d76 | 1962 | * @deprecated please calendar_event->update() instead. |
76d9df3f SH |
1963 | */ |
1964 | function update_event($event) { | |
1965 | global $CFG; | |
1966 | require_once($CFG->dirroot.'/calendar/lib.php'); | |
05226d76 DP |
1967 | |
1968 | debugging('update_event() is deprecated, please use calendar_event->update() instead.', DEBUG_DEVELOPER); | |
76d9df3f SH |
1969 | $event = (object)$event; |
1970 | $calendarevent = calendar_event::load($event->id); | |
1971 | return $calendarevent->update($event); | |
1972 | } | |
1973 | ||
1974 | /** | |
1975 | * Call this function to delete the event with id $id from calendar table. | |
1976 | * | |
1977 | * @param int $id The id of an event from the 'event' table. | |
1978 | * @return bool | |
05226d76 DP |
1979 | * @deprecated please use calendar_event->delete() instead. |
1980 | * @todo final deprecation of this function in MDL-40607 | |
76d9df3f SH |
1981 | */ |
1982 | function delete_event($id) { | |
1983 | global $CFG; | |
1984 | require_once($CFG->dirroot.'/calendar/lib.php'); | |
05226d76 DP |
1985 | |
1986 | debugging('delete_event() is deprecated, please use calendar_event->delete() instead.', DEBUG_DEVELOPER); | |
1987 | ||
76d9df3f SH |
1988 | $event = calendar_event::load($id); |
1989 | return $event->delete(); | |
1990 | } | |
1991 | ||
1992 | /** | |
1993 | * Call this function to hide an event in the calendar table | |
1994 | * the event will be identified by the id field of the $event object. | |
78946b9b | 1995 | * |
76d9df3f SH |
1996 | * @param object $event An object representing an event from the calendar table. The event will be identified by the id field. |
1997 | * @return true | |
05226d76 DP |
1998 | * @deprecated please use calendar_event->toggle_visibility(false) instead. |
1999 | * @todo final deprecation of this function in MDL-40607 | |
76d9df3f SH |
2000 | */ |
2001 | function hide_event($event) { | |
2002 | global $CFG; | |
2003 | require_once($CFG->dirroot.'/calendar/lib.php'); | |
05226d76 DP |
2004 | |
2005 | debugging('hide_event() is deprecated, please use calendar_event->toggle_visibility(false) instead.', DEBUG_DEVELOPER); | |
2006 | ||
76d9df3f SH |
2007 | $event = new calendar_event($event); |
2008 | return $event->toggle_visibility(false); | |
2009 | } | |
2010 | ||
2011 | /** | |
2012 | * Call this function to unhide an event in the calendar table | |
2013 | * the event will be identified by the id field of the $event object. | |
2014 | * | |
2015 | * @param object $event An object representing an event from the calendar table. The event will be identified by the id field. | |
2016 | * @return true | |
05226d76 DP |
2017 | * @deprecated please use calendar_event->toggle_visibility(true) instead. |
2018 | * @todo final deprecation of this function in MDL-40607 | |
76d9df3f SH |
2019 | */ |
2020 | function show_event($event) { | |
2021 | global $CFG; | |
2022 | require_once($CFG->dirroot.'/calendar/lib.php'); | |
05226d76 DP |
2023 | |
2024 | debugging('show_event() is deprecated, please use calendar_event->toggle_visibility(true) instead.', DEBUG_DEVELOPER); | |
2025 | ||
76d9df3f SH |
2026 | $event = new calendar_event($event); |
2027 | return $event->toggle_visibility(true); | |
0189bf77 | 2028 | } |
6f3451e5 PS |
2029 | |
2030 | /** | |
2f1e464a | 2031 | * @deprecated Use core_text::strtolower($text) instead. |
6f3451e5 PS |
2032 | */ |
2033 | function moodle_strtolower($string, $encoding='') { | |
2f1e464a | 2034 | throw new coding_exception('moodle_strtolower() cannot be used any more. Please use core_text::strtolower() instead.'); |
6f3451e5 | 2035 | } |
3fed29a7 PS |
2036 | |
2037 | /** | |
2038 | * Original singleton helper function, please use static methods instead, | |
2f1e464a | 2039 | * ex: core_text::convert() |
3fed29a7 | 2040 | * |
2f1e464a | 2041 | * @deprecated since Moodle 2.2 use core_text::xxxx() instead |
3fed29a7 PS |
2042 | * @see textlib |
2043 | * @return textlib instance | |
2044 | */ | |
2045 | function textlib_get_instance() { | |
2046 | ||
2f1e464a | 2047 | debugging('textlib_get_instance() is deprecated. Please use static calling core_text::functioname() instead.', DEBUG_DEVELOPER); |
3fed29a7 PS |
2048 | |
2049 | return new textlib(); | |
2050 | } | |
2051 | ||
ee7084e9 MG |
2052 | /** |
2053 | * Gets the generic section name for a courses section | |
2054 | * | |
2055 | * The global function is deprecated. Each course format can define their own generic section name | |
2056 | * | |
2057 | * @deprecated since 2.4 | |
2058 | * @see get_section_name() | |
2059 | * @see format_base::get_section_name() | |
2060 | * | |
2061 | * @param string $format Course format ID e.g. 'weeks' $course->format | |
2062 | * @param stdClass $section Section object from database | |
2063 | * @return Display name that the course format prefers, e.g. "Week 2" | |
2064 | */ | |
2065 | function get_generic_section_name($format, stdClass $section) { | |
2066 | debugging('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base', DEBUG_DEVELOPER); | |
2067 | return get_string('sectionname', "format_$format") . ' ' . $section->section; | |
2068 | } | |
99e9f9a6 MG |
2069 | |
2070 | /** | |
2071 | * Returns an array of sections for the requested course id | |
2072 | * | |
2073 | * It is usually not recommended to display the list of sections used | |
2074 | * in course because the course format may have it's own way to do it. | |
2075 | * | |
2076 | * If you need to just display the name of the section please call: | |
2077 | * get_section_name($course, $section) | |
2078 | * {@link get_section_name()} | |
2079 | * from 2.4 $section may also be just the field course_sections.section | |
2080 | * | |
2081 | * If you need the list of all sections it is more efficient to get this data by calling | |
b46be6ad | 2082 | * $modinfo = get_fast_modinfo($courseorid); |
99e9f9a6 MG |
2083 | * $sections = $modinfo->get_section_info_all() |
2084 | * {@link get_fast_modinfo()} | |
2085 | * {@link course_modinfo::get_section_info_all()} | |
2086 | * | |
2087 | * Information about one section (instance of section_info): | |
b46be6ad | 2088 | * get_fast_modinfo($courseorid)->get_sections_info($section) |
99e9f9a6 MG |
2089 | * {@link course_modinfo::get_section_info()} |
2090 | * | |
2091 | * @deprecated since 2.4 | |
2092 | * | |
2093 | * @param int $courseid | |
2094 | * @return array Array of section_info objects | |
2095 | */ | |
2096 | function get_all_sections($courseid) { | |
2097 | global $DB; | |
2098 | debugging('get_all_sections() is deprecated. See phpdocs for this function', DEBUG_DEVELOPER); | |
b46be6ad | 2099 | return get_fast_modinfo($courseid)->get_section_info_all(); |
99e9f9a6 | 2100 | } |
722e6ba9 MG |
2101 | |
2102 | /** | |
2103 | * Given a full mod object with section and course already defined, adds this module to that section. | |
2104 | * | |
2105 | * This function is deprecated, please use {@link course_add_cm_to_section()} | |
2106 | * Note that course_add_cm_to_section() also updates field course_modules.section and | |
2107 | * calls rebuild_course_cache() | |
2108 | * | |
2109 | * @deprecated since 2.4 | |
2110 | * | |
2111 | * @param object $mod | |
2112 | * @param int $beforemod An existing ID which we will insert the new module before | |
2113 | * @return int The course_sections ID where the mod is inserted | |
2114 | */ | |
44aa854e | 2115 | function add_mod_to_section($mod, $beforemod = null) { |
722e6ba9 MG |
2116 | debugging('Function add_mod_to_section() is deprecated, please use course_add_cm_to_section()', DEBUG_DEVELOPER); |
2117 | global $DB; | |
b46be6ad | 2118 | return course_add_cm_to_section($mod->course, $mod->coursemodule, $mod->section, $beforemod); |
722e6ba9 | 2119 | } |
d57aa283 MG |
2120 | |
2121 | /** | |
2122 | * Returns a number of useful structures for course displays | |
2123 | * | |
2124 | * Function get_all_mods() is deprecated in 2.4 | |
2125 | * Instead of: | |
2126 | * <code> | |
b46be6ad | 2127 | * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused); |
d57aa283 MG |
2128 | * </code> |
2129 | * please use: | |
2130 | * <code> | |
b46be6ad | 2131 | * $mods = get_fast_modinfo($courseorid)->get_cms(); |
d57aa283 MG |
2132 | * $modnames = get_module_types_names(); |
2133 | * $modnamesplural = get_module_types_names(true); | |
b46be6ad | 2134 | * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names(); |
d57aa283 MG |
2135 | * </code> |
2136 | * | |
2137 | * @deprecated since 2.4 | |
2138 | * | |
2139 | * @param int $courseid id of the course to get info about | |
2140 | * @param array $mods (return) list of course modules | |
2141 | * @param array $modnames (return) list of names of all module types installed and available | |
2142 | * @param array $modnamesplural (return) list of names of all module types installed and available in the plural form | |
2143 | * @param array $modnamesused (return) list of names of all module types used in the course | |
2144 | */ | |
2145 | function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) { | |
2146 | debugging('Function get_all_mods() is deprecated. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details', DEBUG_DEVELOPER); | |
2147 | ||
2148 | global $COURSE; | |
2149 | $modnames = get_module_types_names(); | |
2150 | $modnamesplural= get_module_types_names(true); | |
b46be6ad | 2151 | $modinfo = get_fast_modinfo($courseid); |
d57aa283 MG |
2152 | $mods = $modinfo->get_cms(); |
2153 | $modnamesused = $modinfo->get_used_module_names(); | |
2154 | } | |
4ede27b2 MG |
2155 | |
2156 | /** | |
2157 | * Returns course section - creates new if does not exist yet | |
2158 | * | |
2159 | * This function is deprecated. To create a course section call: | |
b46be6ad | 2160 | * course_create_sections_if_missing($courseorid, $sections); |
4ede27b2 | 2161 | * to get the section call: |
b46be6ad | 2162 | * get_fast_modinfo($courseorid)->get_section_info($sectionnum); |
4ede27b2 MG |
2163 | * |
2164 | * @see course_create_sections_if_missing() | |
2165 | * @see get_fast_modinfo() | |
2166 | * @deprecated since 2.4 | |
2167 | * | |
2168 | * @param int $section relative section number (field course_sections.section) | |
2169 | * @param int $courseid | |
2170 | * @return stdClass record from table {course_sections} | |
2171 | */ | |
2172 | function get_course_section($section, $courseid) { | |
2173 | global $DB; | |
2174 | debugging('Function get_course_section() is deprecated. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.', DEBUG_DEVELOPER); | |
2175 | ||
2176 | if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) { | |
2177 | return $cw; | |
2178 | } | |
2179 | $cw = new stdClass(); | |
2180 | $cw->course = $courseid; | |
2181 | $cw->section = $section; | |
2182 | $cw->summary = ""; | |
2183 | $cw->summaryformat = FORMAT_HTML; | |
2184 | $cw->sequence = ""; | |
2185 | $id = $DB->insert_record("course_sections", $cw); | |
2186 | rebuild_course_cache($courseid, true); | |
2187 | return $DB->get_record("course_sections", array("id"=>$id)); | |
2188 | } | |
1b2581f4 MG |
2189 | |
2190 | /** | |
2191 | * Return the start and end date of the week in Weekly course format | |
2192 | * | |
2193 | * It is not recommended to use this function outside of format_weeks plugin | |
2194 | * | |
2195 | * @deprecated since 2.4 | |
2196 | * @see format_weeks::get_section_dates() | |
2197 | * | |
2198 | * @param stdClass $section The course_section entry from the DB | |
2199 | * @param stdClass $course The course entry from DB | |
2200 | * @return stdClass property start for startdate, property end for enddate | |
2201 | */ | |
2202 | function format_weeks_get_section_dates($section, $course) { | |
2203 | debugging('Function format_weeks_get_section_dates() is deprecated. It is not recommended to'. | |
2204 | ' use it outside of format_weeks plugin', DEBUG_DEVELOPER); | |
2205 | if (isset($course->format) && $course->format === 'weeks') { | |
2206 | return course_get_format($course)->get_section_dates($section); | |
2207 | } | |
2208 | return null; | |
2209 | } | |
9a36be73 MG |
2210 | |
2211 | /** | |
2212 | * Obtains shared data that is used in print_section when displaying a | |
2213 | * course-module entry. | |
2214 | * | |
2215 | * Deprecated. Instead of: | |
2216 | * list($content, $name) = get_print_section_cm_text($cm, $course); | |
2217 | * use: | |
2218 | * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)); | |
2219 | * $name = $cm->get_formatted_name(); | |
2220 | * | |
2221 | * @deprecated since 2.5 | |
2222 | * @see cm_info::get_formatted_content() | |
2223 | * @see cm_info::get_formatted_name() | |
2224 | * | |
2225 | * This data is also used in other areas of the code. | |
2226 | * @param cm_info $cm Course-module data (must come from get_fast_modinfo) | |
2227 | * @param object $course (argument not used) | |
2228 | * @return array An array with the following values in this order: | |
2229 | * $content (optional extra content for after link), | |
2230 | * $instancename (text of link) | |
2231 | */ | |
2232 | function get_print_section_cm_text(cm_info $cm, $course) { | |
2233 | debugging('Function get_print_section_cm_text() is deprecated. Please use '. | |
2234 | 'cm_info::get_formatted_content() and cm_info::get_formatted_name()', | |
2235 | DEBUG_DEVELOPER); | |
2236 | return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)), | |
2237 | $cm->get_formatted_name()); | |
2238 | } | |
2239 | ||
2240 | /** | |
2241 | * Prints the menus to add activities and resources. | |
2242 | * | |
2243 | * Deprecated. Please use: | |
2244 | * $courserenderer = $PAGE->get_renderer('core', 'course'); | |
2245 | * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn, | |
2246 | * array('inblock' => $vertical)); | |
2247 | * echo $output; // if $return argument in print_section_add_menus() set to false | |
2248 | * | |
2249 | * @deprecated since 2.5 | |
2250 | * @see core_course_renderer::course_section_add_cm_control() | |
2251 | * | |
2252 | * @param stdClass $course course object, must be the same as set on the page | |
2253 | * @param int $section relative section number (field course_sections.section) | |
2254 | * @param null|array $modnames (argument ignored) get_module_types_names() is used instead of argument | |
2255 | * @param bool $vertical Vertical orientation | |
2256 | * @param bool $return Return the menus or send them to output | |
2257 | * @param int $sectionreturn The section to link back to | |
2258 | * @return void|string depending on $return | |
2259 | */ | |
2260 | function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) { | |
2261 | global $PAGE; | |
2262 | debugging('Function print_section_add_menus() is deprecated. Please use course renderer '. | |
2263 | 'function course_section_add_cm_control()', DEBUG_DEVELOPER); | |
2264 | $output = ''; | |
2265 | $courserenderer = $PAGE->get_renderer('core', 'course'); | |
2266 | $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn, | |
2267 | array('inblock' => $vertical)); | |
2268 | if ($return) { | |
2269 | return $output; | |
2270 | } else { | |
2271 | echo $output; | |
2272 | return !empty($output); | |
2273 | } | |
2274 | } | |
2275 | ||
2276 | /** | |
2277 | * Produces the editing buttons for a module | |
2278 | * | |
2279 | * Deprecated. Please use: | |
2280 | * $courserenderer = $PAGE->get_renderer('core', 'course'); | |
2281 | * $actions = course_get_cm_edit_actions($mod, $indent, $section); | |
2282 | * return ' ' . $courserenderer->course_section_cm_edit_actions($actions); | |
2283 | * | |
2284 | * @deprecated since 2.5 | |
2285 | * @see course_get_cm_edit_actions() | |
2286 | * @see core_course_renderer->course_section_cm_edit_actions() | |
2287 | * | |
2288 | * @param stdClass $mod The module to produce editing buttons for | |
2289 | * @param bool $absolute_ignored (argument ignored) - all links are absolute | |
2290 | * @param bool $moveselect (argument ignored) | |
2291 | * @param int $indent The current indenting | |
2292 | * @param int $section The section to link back to | |
2293 | * @return string XHTML for the editing buttons | |
2294 | */ | |
2295 | function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) { | |
2296 | global $PAGE; | |
2297 | debugging('Function make_editing_buttons() is deprecated, please see PHPdocs in '. | |
2298 | 'lib/deprecatedlib.php on how to replace it', DEBUG_DEVELOPER); | |
2299 | if (!($mod instanceof cm_info)) { | |
2300 | $modinfo = get_fast_modinfo($mod->course); | |
2301 | $mod = $modinfo->get_cm($mod->id); | |
2302 | } | |
2303 | $actions = course_get_cm_edit_actions($mod, $indent, $section); | |
2304 | ||
2305 | $courserenderer = $PAGE->get_renderer('core', 'course'); | |
2306 | // The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap | |
2307 | // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of | |
2308 | // the course page HTML will allow this to be removed. | |
2309 | return ' ' . $courserenderer->course_section_cm_edit_actions($actions); | |
2310 | } | |
2311 | ||
2312 | /** | |
2313 | * Prints a section full of activity modules | |
2314 | * | |
2315 | * Deprecated. Please use: | |
2316 | * $courserenderer = $PAGE->get_renderer('core', 'course'); | |
2317 | * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, | |
2318 | * array('hidecompletion' => $hidecompletion)); | |
2319 | * | |
2320 | * @deprecated since 2.5 | |
2321 | * @see core_course_renderer::course_section_cm_list() | |
2322 | * | |
2323 | * @param stdClass $course The course | |
2324 | * @param stdClass|section_info $section The section object containing properties id and section | |
2325 | * @param array $mods (argument not used) | |
2326 | * @param array $modnamesused (argument not used) | |
2327 | * @param bool $absolute (argument not used) | |
2328 | * @param string $width (argument not used) | |
2329 | * @param bool $hidecompletion Hide completion status | |
2330 | * @param int $sectionreturn The section to return to | |
2331 | * @return void | |
2332 | */ | |
2333 | function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) { | |
2334 | global $PAGE; | |
2335 | debugging('Function print_section() is deprecated. Please use course renderer function '. | |
2336 | 'course_section_cm_list() instead.', DEBUG_DEVELOPER); | |
2337 | $displayoptions = array('hidecompletion' => $hidecompletion); | |
2338 | $courserenderer = $PAGE->get_renderer('core', 'course'); | |
2339 | echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions); | |
2340 | } | |
00ba185d | 2341 | |
ff233851 MG |
2342 | /** |
2343 | * Displays the list of courses with user notes | |
2344 | * | |
2345 | * This function is not used in core. It was replaced by block course_overview | |
2346 | * | |
2347 | * @deprecated since 2.5 | |
2348 | * | |
2349 | * @param array $courses | |
2350 | * @param array $remote_courses | |
2351 | */ | |
2352 | function print_overview($courses, array $remote_courses=array()) { | |
2353 | global $CFG, $USER, $DB, $OUTPUT; | |
2354 | debugging('Function print_overview() is deprecated. Use block course_overview to display this information', DEBUG_DEVELOPER); | |
2355 | ||
2356 | $htmlarray = array(); | |
2357 | if ($modules = $DB->get_records('modules')) { | |
2358 | foreach ($modules as $mod) { | |
2359 | if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) { | |
2360 | include_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php'); | |
2361 | $fname = $mod->name.'_print_overview'; | |
2362 | if (function_exists($fname)) { | |
2363 | $fname($courses,$htmlarray); | |
2364 | } | |
2365 | } | |
2366 | } | |
2367 | } | |
2368 | foreach ($courses as $course) { | |
2369 | $fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id))); | |
2370 | echo $OUTPUT->box_start('coursebox'); | |
2371 | $attributes = array('title' => s($fullname)); | |
2372 | if (empty($course->visible)) { | |
2373 | $attributes['class'] = 'dimmed'; | |
2374 | } | |
2375 | echo $OUTPUT->heading(html_writer::link( | |
2376 | new moodle_url('/course/view.php', array('id' => $course->id)), $fullname, $attributes), 3); | |
2377 | if (array_key_exists($course->id,$htmlarray)) { | |
2378 | foreach ($htmlarray[$course->id] as $modname => $html) { | |
2379 | echo $html; | |
2380 | } | |
2381 | } | |
2382 | echo $OUTPUT->box_end(); | |
2383 | } | |
2384 | ||
2385 | if (!empty($remote_courses)) { | |
2386 | echo $OUTPUT->heading(get_string('remotecourses', 'mnet')); | |
2387 | } | |
2388 | foreach ($remote_courses as $course) { | |
2389 | echo $OUTPUT->box_start('coursebox'); | |
2390 | $attributes = array('title' => s($course->fullname)); | |
2391 | echo $OUTPUT->heading(html_writer::link( | |
2392 | new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)), | |
2393 | format_string($course->shortname), | |
2394 | $attributes) . ' (' . format_string($course->hostname) . ')', 3); | |
2395 | echo $OUTPUT->box_end(); | |
2396 | } | |
2397 | } | |
a3f66bde MG |
2398 | |
2399 | /** | |
2400 | * This function trawls through the logs looking for | |
2401 | * anything new since the user's last login | |
2402 | * | |
2403 | * This function was only used to print the content of block recent_activity | |
2404 | * All functionality is moved into class {@link block_recent_activity} | |
2405 | * and renderer {@link block_recent_activity_renderer} | |
2406 | * | |
2407 | * @deprecated since 2.5 | |
2408 | * @param stdClass $course | |
2409 | */ | |
2410 | function print_recent_activity($course) { | |
2411 | // $course is an object | |
2412 | global $CFG, $USER, $SESSION, $DB, $OUTPUT; | |
2413 | debugging('Function print_recent_activity() is deprecated. It is not recommended to'. | |
2414 | ' use it outside of block_recent_activity', DEBUG_DEVELOPER); | |
2415 | ||
2416 | $context = context_course::instance($course->id); | |
2417 | ||
2418 | $viewfullnames = has_capability('moodle/site:viewfullnames', $context); | |
2419 | ||
2420 | $timestart = round(time() - COURSE_MAX_RECENT_PERIOD, -2); // better db caching for guests - 100 seconds | |
2421 | ||
2422 | if (!isguestuser()) { | |
2423 | if (!empty($USER->lastcourseaccess[$course->id])) { | |
2424 | if ($USER->lastcourseaccess[$course->id] > $timestart) { | |
2425 | $timestart = $USER->lastcourseaccess[$course->id]; | |
2426 | } | |
2427 | } | |
2428 | } | |
2429 | ||
2430 | echo '<div class="activitydate">'; | |
2431 | echo get_string('activitysince', '', userdate($timestart)); | |
2432 | echo '</div>'; | |
2433 | echo '<div class="activityhead">'; | |
2434 | ||
2435 | echo '<a href="'.$CFG->wwwroot.'/course/recent.php?id='.$course->id.'">'.get_string('recentactivityreport').'</a>'; | |
2436 | ||
2437 | echo "</div>\n"; | |
2438 | ||
2439 | $content = false; | |
2440 | ||
2441 | /// Firstly, have there been any new enrolments? | |
2442 | ||
2443 | $users = get_recent_enrolments($course->id, $timestart); | |
2444 | ||
2445 | //Accessibility: new users now appear in an <OL> list. | |
2446 | if ($users) { | |
2447 | echo '<div class="newusers">'; | |
2448 | echo $OUTPUT->heading(get_string("newusers").':', 3); | |
2449 | $content = true; | |
2450 | echo "<ol class=\"list\">\n"; | |
2451 | foreach ($users as $user) { | |
2452 | $fullname = fullname($user, $viewfullnames); | |
2453 | echo '<li class="name"><a href="'."$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id\">$fullname</a></li>\n"; | |
2454 | } | |
2455 | echo "</ol>\n</div>\n"; | |
2456 | } | |
2457 | ||
2458 | /// Next, have there been any modifications to the course structure? | |
2459 | ||
2460 | $modinfo = get_fast_modinfo($course); | |
2461 | ||
2462 | $changelist = array(); | |
2463 | ||
2464 | $logs = $DB->get_records_select('log', "time > ? AND course = ? AND | |
2465 | module = 'course' AND | |
2466 | (action = 'add mod' OR action = 'update mod' OR action = 'delete mod')", | |
2467 | array($timestart, $course->id), "id ASC"); | |
2468 | ||
2469 | if ($logs) { | |
2470 | $actions = array('add mod', 'update mod', 'delete mod'); | |
2471 | $newgones = array(); // added and later deleted items | |
2472 | foreach ($logs as $key => $log) { | |
2473 | if (!in_array($log->action, $actions)) { | |
2474 | continue; | |
2475 | } | |
2476 | $info = explode(' ', $log->info); | |
2477 | ||
2478 | // note: in most cases I replaced hardcoding of label with use of | |
2479 | // $cm->has_view() but it was not possible to do this here because | |
2480 | // we don't necessarily have the $cm for it | |
2481 | if ($info[0] == 'label') { // Labels are ignored in recent activity | |
2482 | continue; | |
2483 | } | |
2484 | ||
2485 | if (count($info) != 2) { | |
2486 | debugging("Incorrect log entry info: id = ".$log->id, DEBUG_DEVELOPER); | |
2487 | continue; | |
2488 | } | |
2489 | ||
2490 | $modname = $info[0]; | |
2491 | $instanceid = $info[1]; | |
2492 | ||
2493 | if ($log->action == 'delete mod') { | |
2494 | // unfortunately we do not know if the mod was visible | |
2495 | if (!array_key_exists($log->info, $newgones)) { | |
2496 | $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $modname)); | |
2497 | $changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted); | |
2498 | } | |
2499 | } else { | |
2500 | if (!isset($modinfo->instances[$modname][$instanceid])) { | |
2501 | if ($log->action == 'add mod') { | |
2502 | // do not display added and later deleted activities | |
2503 | $newgones[$log->info] = true; | |
2504 | } | |
2505 | continue; | |
2506 | } | |
2507 | $cm = $modinfo->instances[$modname][$instanceid]; | |
2508 | if (!$cm->uservisible) { | |
2509 | continue; | |
2510 | } | |
2511 | ||
2512 | if ($log->action == 'add mod') { | |
2513 | $stradded = get_string('added', 'moodle', get_string('modulename', $modname)); | |
2514 | $changelist[$log->info] = array('operation' => 'add', 'text' => "$stradded:<br /><a href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id={$cm->id}\">".format_string($cm->name, true)."</a>"); | |
2515 | ||
2516 | } else if ($log->action == 'update mod' and empty($changelist[$log->info])) { | |
2517 | $strupdated = get_string('updated', 'moodle', get_string('modulename', $modname)); | |
2518 | $changelist[$log->info] = array('operation' => 'update', 'text' => "$strupdated:<br /><a href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id={$cm->id}\">".format_string($cm->name, true)."</a>"); | |
2519 | } | |
2520 | } | |
2521 | } | |
2522 | } | |
2523 | ||
2524 | if (!empty($changelist)) { | |
2525 | echo $OUTPUT->heading(get_string("courseupdates").':', 3); | |
2526 | $content = true; | |
2527 | foreach ($changelist as $changeinfo => $change) { | |
2528 | echo '<p class="activity">'.$change['text'].'</p>'; | |
2529 | } | |
2530 | } | |
2531 | ||
2532 | /// Now display new things from each module | |
2533 | ||
2534 | $usedmodules = array(); | |
2535 | foreach($modinfo->cms as $cm) { | |
2536 | if (isset($usedmodules[$cm->modname])) { | |
2537 | continue; | |
2538 | } | |
2539 | if (!$cm->uservisible) { | |
2540 | continue; | |
2541 | } | |
2542 | $usedmodules[$cm->modname] = $cm->modname; | |
2543 | } | |
2544 | ||
2545 | foreach ($usedmodules as $modname) { // Each module gets it's own logs and prints them | |
2546 | if (file_exists($CFG->dirroot.'/mod/'.$modname.'/lib.php')) { | |
2547 | include_once($CFG->dirroot.'/mod/'.$modname.'/lib.php'); | |
2548 | $print_recent_activity = $modname.'_print_recent_activity'; | |
2549 | if (function_exists($print_recent_activity)) { | |
2550 | // NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames! | |
2551 | $content = $print_recent_activity($course, $viewfullnames, $timestart) || $content; | |
2552 | } | |
2553 | } else { | |
2554 | debugging("Missing lib.php in lib/{$modname} - please reinstall files or uninstall the module"); | |
2555 | } | |
2556 | } | |
2557 | ||
2558 | if (! $content) { | |
2559 | echo '<p class="message">'.get_string('nothingnew').'</p>'; | |
2560 | } | |
2561 | } | |
a347aee3 MN |
2562 | |
2563 | /** | |
2564 | * Delete a course module and any associated data at the course level (events) | |
2565 | * Until 1.5 this function simply marked a deleted flag ... now it | |
2566 | * deletes it completely. | |
2567 | * | |
2568 | * @deprecated since 2.5 | |
2569 | * | |
2570 | * @param int $id the course module id | |
2571 | * @return boolean true on success, false on failure | |
2572 | */ | |
2573 | function delete_course_module($id) { | |
2574 | debugging('Function delete_course_module() is deprecated. Please use course_delete_module() instead.', DEBUG_DEVELOPER); | |
2575 | ||
2576 | global $CFG, $DB; | |
2577 | ||
2578 | require_once($CFG->libdir.'/gradelib.php'); | |
2579 | require_once($CFG->dirroot.'/blog/lib.php'); | |
2580 | ||
2581 | if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) { | |
2582 | return true; | |
2583 | } | |
2584 | $modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module)); | |
2585 | //delete events from calendar | |
2586 | if ($events = $DB->get_records('event', array('instance'=>$cm->instance, 'modulename'=>$modulename))) { | |
2587 | foreach($events as $event) { | |
2588 | delete_event($event->id); | |
2589 | } | |
2590 | } | |
2591 | //delete grade items, outcome items and grades attached to modules | |
2592 | if ($grade_items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename, | |
2593 | 'iteminstance'=>$cm->instance, 'courseid'=>$cm->course))) { | |
2594 | foreach ($grade_items as $grade_item) { | |
2595 | $grade_item->delete('moddelete'); | |
2596 | } | |
2597 | } | |
2598 | // Delete completion and availability data; it is better to do this even if the | |
2599 | // features are not turned on, in case they were turned on previously (these will be | |
2600 | // very quick on an empty table) | |
2601 | $DB->delete_records('course_modules_completion', array('coursemoduleid' => $cm->id)); | |
2602 | $DB->delete_records('course_modules_availability', array('coursemoduleid'=> $cm->id)); | |
2603 | $DB->delete_records('course_completion_criteria', array('moduleinstance' => $cm->id, | |
2604 | 'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY)); | |
2605 | ||
2606 | delete_context(CONTEXT_MODULE, $cm->id); | |
2607 | return $DB->delete_records('course_modules', array('id'=>$cm->id)); | |
2608 | } | |
2c49fb4c MG |
2609 | |
2610 | /** | |
2611 | * Prints the turn editing on/off button on course/index.php or course/category.php. | |
2612 | * | |
2613 | * @deprecated since 2.5 | |
2614 | * | |
2615 | * @param integer $categoryid The id of the category we are showing, or 0 for system context. | |
2616 | * @return string HTML of the editing button, or empty string, if this user is not allowed | |
2617 | * to see it. | |
2618 | */ | |
2619 | function update_category_button($categoryid = 0) { | |
2620 | global $CFG, $PAGE, $OUTPUT; | |
2621 | debugging('Function update_category_button() is deprecated. Pages to view '. | |
2622 | 'and edit courses are now separate and no longer depend on editing mode.', | |
2623 | DEBUG_DEVELOPER); | |
2624 | ||
2625 | // Check permissions. | |
2626 | if (!can_edit_in_category($categoryid)) { | |
2627 | return ''; | |
2628 | } | |
2629 | ||
2630 | // Work out the appropriate action. | |
2631 | if ($PAGE->user_is_editing()) { | |
2632 | $label = get_string('turneditingoff'); | |
2633 | $edit = 'off'; | |
2634 | } else { | |
2635 | $label = get_string('turneditingon'); | |
2636 | $edit = 'on'; | |
2637 | } | |
2638 | ||
2639 | // Generate the button HTML. | |
2640 | $options = array('categoryedit' => $edit, 'sesskey' => sesskey()); | |
2641 | if ($categoryid) { | |
2642 | $options['id'] = $categoryid; | |
2643 | $page = 'category.php'; | |
2644 | } else { | |
2645 | $page = 'index.php'; | |
2646 | } | |
2647 | return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get'); | |
2648 | } | |
4e0b6025 MG |
2649 | |
2650 | /** | |
2651 | * This function recursively travels the categories, building up a nice list | |
2652 | * for display. It also makes an array that list all the parents for each | |
2653 | * category. | |
2654 | * | |
2655 | * For example, if you have a tree of categories like: | |
2656 | * Miscellaneous (id = 1) | |
2657 | * Subcategory (id = 2) | |
2658 | * Sub-subcategory (id = 4) | |
2659 | * Other category (id = 3) | |
2660 | * Then after calling this function you will have | |
2661 | * $list = array(1 => 'Miscellaneous', 2 => 'Miscellaneous / Subcategory', | |
2662 | * 4 => 'Miscellaneous / Subcategory / Sub-subcategory', | |
2663 | * 3 => 'Other category'); | |
2664 | * $parents = array(2 => array(1), 4 => array(1, 2)); | |
2665 | * | |
2666 | * If you specify $requiredcapability, then only categories where the current | |
2667 | * user has that capability will be added to $list, although all categories | |
2668 | * will still be added to $parents, and if you only have $requiredcapability | |
2669 | * in a child category, not the parent, then the child catgegory will still be | |
2670 | * included. | |
2671 | * | |
2672 | * If you specify the option $excluded, then that category, and all its children, | |
2673 | * are omitted from the tree. This is useful when you are doing something like | |
2674 | * moving categories, where you do not want to allow people to move a category | |
2675 | * to be the child of itself. | |
2676 | * | |
2677 | * This function is deprecated! For list of categories use | |
2678 | * coursecat::make_all_categories($requiredcapability, $excludeid, $separator) | |
2679 | * For parents of one particular category use | |
2680 | * coursecat::get($id)->get_parents() | |
2681 | * | |
2682 | * @deprecated since 2.5 | |
2683 | * | |
2684 | * @param array $list For output, accumulates an array categoryid => full category path name | |
2685 | * @param array $parents For output, accumulates an array categoryid => list of parent category ids. | |
2686 | * @param string/array $requiredcapability if given, only categories where the current | |
2687 | * user has this capability will be added to $list. Can also be an array of capabilities, | |
2688 | * in which case they are all required. | |
2689 | * @param integer $excludeid Omit this category and its children from the lists built. | |
2690 | * @param object $category Not used | |
2691 | * @param string $path Not used | |
2692 | */ | |
2693 | function make_categories_list(&$list, &$parents, $requiredcapability = '', | |
2694 | $excludeid = 0, $category = NULL, $path = "") { | |
2695 | global $CFG, $DB; | |
2696 | require_once($CFG->libdir.'/coursecatlib.php'); | |
2697 | ||
2698 | debugging('Global function make_categories_list() is deprecated. Please use '. | |
2699 | 'coursecat::make_categories_list() and coursecat::get_parents()', | |
2700 | DEBUG_DEVELOPER); | |
2701 | ||
2702 | // For categories list use just this one function: | |
2703 | if (empty($list)) { | |
2704 | $list = array(); | |
2705 | } | |
2706 | $list += coursecat::make_categories_list($requiredcapability, $excludeid); | |
2707 | ||
2708 | // Building the list of all parents of all categories in the system is highly undesirable and hardly ever needed. | |
2709 | // Usually user needs only parents for one particular category, in which case should be used: | |
2710 | // coursecat::get($categoryid)->get_parents() | |
2711 | if (empty($parents)) { | |
2712 | $parents = array(); | |
2713 | } | |
2714 | $all = $DB->get_records_sql('SELECT id, parent FROM {course_categories} ORDER BY sortorder'); | |
2715 | foreach ($all as $record) { | |
2716 | if ($record->parent) { | |
2717 | $parents[$record->id] = array_merge($parents[$record->parent], array($record->parent)); | |
2718 | } else { | |
2719 | $parents[$record->id] = array(); | |
2720 | } | |
2721 | } | |
2722 | } | |
deb65ced MG |
2723 | |
2724 | /** | |
2725 | * Delete category, but move contents to another category. | |
2726 | * | |
2727 | * This function is deprecated. Please use | |
2728 | * coursecat::get($category->id)->delete_move($newparentid, $showfeedback); | |
2729 | * | |
2730 | * @see coursecat::delete_move() | |
2731 | * @deprecated since 2.5 | |
2732 | * | |
2733 | * @param object $category | |
2734 | * @param int $newparentid category id | |
2735 | * @return bool status | |
2736 | */ | |
2737 | function category_delete_move($category, $newparentid, $showfeedback=true) { | |
2738 | global $CFG; | |
2739 | require_once($CFG->libdir.'/coursecatlib.php'); | |
2740 | ||
2741 | debugging('Function category_delete_move() is deprecated. Please use coursecat::delete_move() instead.'); | |
2742 | ||
2743 | return coursecat::get($category->id)->delete_move($newparentid, $showfeedback); | |
2744 | } | |
2745 | ||
2746 | /** | |
2747 | * Recursively delete category including all subcategories and courses. | |
2748 | * | |
2749 | * This function is deprecated. Please use | |
2750 | * coursecat::get($category->id)->delete_full($showfeedback); | |
2751 | * | |
2752 | * @see coursecat::delete_full() | |
2753 | * @deprecated since 2.5 | |
2754 | * | |
2755 | * @param stdClass $category | |
2756 | * @param boolean $showfeedback display some notices | |
2757 | * @return array return deleted courses | |
2758 | */ | |
2759 | function category_delete_full($category, $showfeedback=true) { | |
2760 | global $CFG, $DB; | |
2761 | require_once($CFG->libdir.'/coursecatlib.php'); | |
2762 | ||
2763 | debugging('Function category_delete_full() is deprecated. Please use coursecat::delete_full() instead.'); | |
2764 | ||
2765 | return coursecat::get($category->id)->delete_full($showfeedback); | |
2766 | } | |
6e1d1ee0 MG |
2767 | |
2768 | /** | |
2769 | * Efficiently moves a category - NOTE that this can have | |
2770 | * a huge impact access-control-wise... | |
2771 | * | |
2772 | * This function is deprecated. Please use | |
2773 | * $coursecat = coursecat::get($category->id); | |
2774 | * if ($coursecat->can_change_parent($newparentcat->id)) { | |
2775 | * $coursecat->change_parent($newparentcat->id); | |
2776 | * } | |
2777 | * | |
2778 | * Alternatively you can use | |
2779 | * $coursecat->update(array('parent' => $newparentcat->id)); | |
2780 | * | |
2781 | * Function update() also updates field course_categories.timemodified | |
2782 | * | |
2783 | * @see coursecat::change_parent() | |
2784 | * @see coursecat::update() | |
2785 | * @deprecated since 2.5 | |
2786 | * | |
2787 | * @param stdClass|coursecat $category | |
2788 | * @param stdClass|coursecat $newparentcat | |
2789 | */ | |
2790 | function move_category($category, $newparentcat) { | |
2791 | global $CFG; | |
2792 | require_once($CFG->libdir.'/coursecatlib.php'); | |
2793 | ||
2794 | debugging('Function move_category() is deprecated. Please use coursecat::change_parent() instead.'); | |
2795 | ||
2796 | return coursecat::get($category->id)->change_parent($newparentcat->id); | |
2797 | } | |
2798 | ||
2799 | /** | |
2800 | * Hide course category and child course and subcategories | |
2801 | * | |
2802 | * This function is deprecated. Please use | |
2803 | * coursecat::get($category->id)->hide(); | |
2804 | * | |
2805 | * @see coursecat::hide() | |
2806 | * @deprecated since 2.5 | |
2807 | * | |
2808 | * @param stdClass $category | |
2809 | * @return void | |
2810 | */ | |
2811 | function course_category_hide($category) { | |
2812 | global $CFG; | |
2813 | require_once($CFG->libdir.'/coursecatlib.php'); | |
2814 | ||
2815 | debugging('Function course_category_hide() is deprecated. Please use coursecat::hide() instead.'); | |
2816 | ||
2817 | coursecat::get($category->id)->hide(); | |
2818 | } | |
2819 | ||
2820 | /** | |
2821 | * Show course category and child course and subcategories | |
2822 | * | |
2823 | * This function is deprecated. Please use | |
2824 | * coursecat::get($category->id)->show(); | |
2825 | * | |
2826 | * @see coursecat::show() | |
2827 | * @deprecated since 2.5 | |
2828 | * | |
2829 | * @param stdClass $category | |
2830 | * @return void | |
2831 | */ | |
2832 | function course_category_show($category) { | |
2833 | global $CFG; | |
2834 | require_once($CFG->libdir.'/coursecatlib.php'); | |
2835 | ||
2836 | debugging('Function course_category_show() is deprecated. Please use coursecat::show() instead.'); | |
2837 | ||
2838 | coursecat::get($category->id)->show(); | |
2839 | } | |
2d8a275b MG |
2840 | |
2841 | /** | |
2842 | * Return specified category, default if given does not exist | |
2843 | * | |
2844 | * This function is deprecated. | |
2845 | * To get the category with the specified it please use: | |
2846 | * coursecat::get($catid, IGNORE_MISSING); | |
2847 | * or | |
2848 | * coursecat::get($catid, MUST_EXIST); | |
2849 | * | |
2850 | * To get the first available category please use | |
2851 | * coursecat::get_default(); | |
2852 | * | |
2853 | * class coursecat will also make sure that at least one category exists in DB | |
2854 | * | |
2855 | * @deprecated since 2.5 | |
2856 | * @see coursecat::get() | |
2857 | * @see coursecat::get_default() | |
2858 | * | |
2859 | * @param int $catid course category id | |
2860 | * @return object caregory | |
2861 | */ | |
2862 | function get_course_category($catid=0) { | |
2863 | global $DB; | |
2864 | ||
2865 | debugging('Function get_course_category() is deprecated. Please use coursecat::get(), see phpdocs for more details'); | |
2866 | ||
2867 | $category = false; | |
2868 | ||
2869 | if (!empty($catid)) { | |
2870 | $category = $DB->get_record('course_categories', array('id'=>$catid)); | |
2871 | } | |
2872 | ||
2873 | if (!$category) { | |
2874 | // the first category is considered default for now | |
2875 | if ($category = $DB->get_records('course_categories', null, 'sortorder', '*', 0, 1)) { | |
2876 | $category = reset($category); | |
2877 | ||
2878 | } else { | |
2879 | $cat = new stdClass(); | |
2880 | $cat->name = get_string('miscellaneous'); | |
2881 | $cat->depth = 1; | |
2882 | $cat->sortorder = MAX_COURSES_IN_CATEGORY; | |
2883 | $cat->timemodified = time(); | |
2884 | $catid = $DB->insert_record('course_categories', $cat); | |
2885 | // make sure category context exists | |
2886 | context_coursecat::instance($catid); | |
2887 | mark_context_dirty('/'.SYSCONTEXTID); | |
2888 | fix_course_sortorder(); // Required to build course_categories.depth and .path. | |
2889 | $category = $DB->get_record('course_categories', array('id'=>$catid)); | |
2890 | } | |
2891 | } | |
2892 | ||
2893 | return $category; | |
2894 | } | |
9bad61db MG |
2895 | |
2896 | /** | |
2897 | * Create a new course category and marks the context as dirty | |
2898 | * | |
2899 | * This function does not set the sortorder for the new category and | |
2900 | * {@link fix_course_sortorder()} should be called after creating a new course | |
2901 | * category | |
2902 | * | |
2903 | * Please note that this function does not verify access control. | |
2904 | * | |
2905 | * This function is deprecated. It is replaced with the method create() in class coursecat. | |
2906 | * {@link coursecat::create()} also verifies the data, fixes sortorder and logs the action | |
2907 | * | |
2908 | * @deprecated since 2.5 | |
2909 | * | |
2910 | * @param object $category All of the data required for an entry in the course_categories table | |
2911 | * @return object new course category | |
2912 | */ | |
2913 | function create_course_category($category) { | |
2914 | global $DB; | |
2915 | ||
2916 | debugging('Function create_course_category() is deprecated. Please use coursecat::create(), see phpdocs for more details', DEBUG_DEVELOPER); | |
2917 | ||
2918 | $category->timemodified = time(); | |
2919 | $category->id = $DB->insert_record('course_categories', $category); | |
2920 | $category = $DB->get_record('course_categories', array('id' => $category->id)); | |
2921 | ||
2922 | // We should mark the context as dirty | |
2923 | $category->context = context_coursecat::instance($category->id); | |
2924 | $category->context->mark_dirty(); | |
2925 | ||
2926 | return $category; | |
2927 | } | |
bc81b006 MG |
2928 | |
2929 | /** | |
2930 | * Returns an array of category ids of all the subcategories for a given | |
2931 | * category. | |
2932 | * | |
2933 | * This function is deprecated. | |
2934 | * | |
2935 | * To get visible children categories of the given category use: | |
2936 | * coursecat::get($categoryid)->get_children(); | |
2937 | * This function will return the array or coursecat objects, on each of them | |
2938 | * you can call get_children() again | |
2939 | * | |
2940 | * @see coursecat::get() | |
2941 | * @see coursecat::get_children() | |
2942 | * | |
2943 | * @deprecated since 2.5 | |
2944 | * | |
2945 | * @global object | |
2946 | * @param int $catid - The id of the category whose subcategories we want to find. | |
2947 | * @return array of category ids. | |
2948 | */ | |
2949 | function get_all_subcategories($catid) { | |
2950 | global $DB; | |
2951 | ||
2952 | debugging('Function get_all_subcategories() is deprecated. Please use appropriate methods() of coursecat class. See phpdocs for more details', | |
2953 | DEBUG_DEVELOPER); | |
2954 | ||
2955 | $subcats = array(); | |
2956 | ||
2957 | if ($categories = $DB->get_records('course_categories', array('parent' => $catid))) { | |
2958 | foreach ($categories as $cat) { | |
2959 | array_push($subcats, $cat->id); | |
2960 | $subcats = array_merge($subcats, get_all_subcategories($cat->id)); | |
2961 | } | |
2962 | } | |
2963 | return $subcats; | |
2964 | } | |
8db5dcb7 MG |
2965 | |
2966 | /** | |
2967 | * Gets the child categories of a given courses category | |
2968 | * | |
2969 | * This function is deprecated. Please use functions in class coursecat: | |
2970 | * - coursecat::get($parentid)->has_children() | |
2971 | * tells if the category has children (visible or not to the current user) | |
2972 | * | |
2973 | * - coursecat::get($parentid)->get_children() | |
2974 | * returns an array of coursecat objects, each of them represents a children category visible | |
2975 | * to the current user (i.e. visible=1 or user has capability to view hidden categories) | |
2976 | * | |
2977 | * - coursecat::get($parentid)->get_children_count() | |
2978 | * returns number of children categories visible to the current user | |
2979 | * | |
2980 | * - coursecat::count_all() | |
2981 | * returns total count of all categories in the system (both visible and not) | |
2982 | * | |
2983 | * - coursecat::get_default() | |
2984 | * returns the first category (usually to be used if count_all() == 1) | |
2985 | * | |
2986 | * @deprecated since 2.5 | |
2987 | * | |
2988 | * @param int $parentid the id of a course category. | |
2989 | * @return array all the child course categories. | |
2990 | */ | |
2991 | function get_child_categories($parentid) { | |
2992 | global $DB; | |
2993 | debugging('Function get_child_categories() is deprecated. Use coursecat::get_children() or see phpdocs for more details.', | |
2994 | DEBUG_DEVELOPER); | |
2995 | ||
2996 | $rv = array(); | |
2997 | $sql = context_helper::get_preload_record_columns_sql('ctx'); | |
2998 | $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ". | |
2999 | "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder", | |
3000 | array(CONTEXT_COURSECAT, $parentid)); | |
3001 | foreach ($records as $category) { | |
3002 | context_helper::preload_from_record($category); | |
3003 | if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) { | |
3004 | continue; | |
3005 | } | |
3006 | $rv[] = $category; | |
3007 | } | |
3008 | return $rv; | |
3009 | } | |
e1d54562 MG |
3010 | |
3011 | /** | |
3012 | * Returns a sorted list of categories. | |
3013 | * | |
3014 | * When asking for $parent='none' it will return all the categories, regardless | |
3015 | * of depth. Wheen asking for a specific parent, the default is to return | |
3016 | * a "shallow" resultset. Pass false to $shallow and it will return all | |
3017 | * the child categories as well. | |
3018 | * | |
3019 | * @deprecated since 2.5 | |
3020 | * | |
3021 | * This function is deprecated. Use appropriate functions from class coursecat. | |
3022 | * Examples: | |
3023 | * | |
3024 | * coursecat::get($categoryid)->get_children() | |
3025 | * - returns all children of the specified category as instances of class | |
3026 | * coursecat, which means on each of them method get_children() can be called again | |
3027 | * | |
3028 | * coursecat::get($categoryid)->get_children(array('recursive' => true)) | |
3029 | * - returns all children of the specified category and all subcategories | |
3030 | * | |
3031 | * coursecat::get(0)->get_children(array('recursive' => true)) | |
3032 | * - returns all categories defined in the system | |
3033 | * | |
3034 | * Sort fields can be specified, see phpdocs to {@link coursecat::get_children()} | |
3035 | * | |
3036 | * Also see functions {@link coursecat::get_children_count()}, {@link coursecat::count_all()}, | |
3037 | * {@link coursecat::get_default()} | |
3038 | * | |
3039 | * The code of this deprecated function is left as it is because coursecat::get_children() | |
3040 | * returns categories as instances of coursecat and not stdClass | |
3041 | * | |
3042 | * @param string $parent The parent category if any | |
3043 | * @param string $sort the sortorder | |
3044 | * @param bool $shallow - set to false to get the children too | |
3045 | * @return array of categories | |
3046 | */ | |
3047 | function get_categories($parent='none', $sort=NULL, $shallow=true) { | |
3048 | global $DB; | |
3049 | ||
3050 | debugging('Function get_categories() is deprecated. Please use coursecat::get_children(). See phpdocs for more details', | |
3051 | DEBUG_DEVELOPER); | |
3052 | ||
3053 | if ($sort === NULL) { | |
3054 | $sort = 'ORDER BY cc.sortorder ASC'; | |
3055 | } elseif ($sort ==='') { | |
3056 | // leave it as empty | |
3057 | } else { | |
3058 | $sort = "ORDER BY $sort"; | |
3059 | } | |
3060 | ||
3061 | list($ccselect, $ccjoin) = context_instance_preload_sql('cc.id', CONTEXT_COURSECAT, 'ctx'); | |
3062 | ||
3063 | if ($parent === 'none') { | |
3064 | $sql = "SELECT cc.* $ccselect | |
3065 | FROM {course_categories} cc | |
3066 | $ccjoin | |
3067 | $sort"; | |
3068 | $params = array(); | |
3069 | ||
3070 | } elseif ($shallow) { | |
3071 | $sql = "SELECT cc.* $ccselect | |
3072 | FROM {course_categories} cc | |
3073 | $ccjoin | |
3074 | WHERE cc.parent=? | |
3075 | $sort"; | |
3076 | $params = array($parent); | |
3077 | ||
3078 | } else { | |
3079 | $sql = "SELECT cc.* $ccselect | |
3080 | FROM {course_categories} cc | |
3081 | $ccjoin | |
3082 | JOIN {course_categories} ccp | |
3083 | ON ((cc.parent = ccp.id) OR (cc.path LIKE ".$DB->sql_concat('ccp.path',"'/%'").")) | |
3084 | WHERE ccp.id=? | |
3085 | $sort"; | |
3086 | $params = array($parent); | |
3087 | } | |
3088 | $categories = array(); | |
3089 | ||
3090 | $rs = $DB->get_recordset_sql($sql, $params); | |
3091 | foreach($rs as $cat) { | |
db314f34 | 3092 | context_helper::preload_from_record($cat); |
e1d54562 MG |
3093 | $catcontext = context_coursecat::instance($cat->id); |
3094 | if ($cat->visible || has_capability('moodle/category:viewhiddencategories', $catcontext)) { | |
3095 | $categories[$cat->id] = $cat; | |
3096 | } | |
3097 | } | |
3098 | $rs->close(); | |
3099 | return $categories; | |
3100 | } | |
a8d683ca MG |
3101 | |
3102 | /** | |
3103 | * Displays a course search form | |
3104 | * | |
3105 | * This function is deprecated, please use course renderer: | |
3106 | * $renderer = $PAGE->get_renderer('core', 'course'); | |
3107 | * echo $renderer->course_search_form($value, $format); | |
3108 | * | |
3109 | * @deprecated since 2.5 | |
3110 | * | |
3111 | * @param string $value default value to populate the search field | |
3112 | * @param bool $return if true returns the value, if false - outputs | |
3113 | * @param string $format display format - 'plain' (default), 'short' or 'navbar' | |
3114 | * @return null|string | |
3115 | */ | |
3116 | function print_course_search($value="", $return=false, $format="plain") { | |
3117 | global $PAGE; | |
3118 | debugging('Function print_course_search() is deprecated, please use course renderer', DEBUG_DEVELOPER); | |
3119 | $renderer = $PAGE->get_renderer('core', 'course'); | |
3120 | if ($return) { | |
3121 | return $renderer->course_search_form($value, $format); | |
3122 | } else { | |
3123 | echo $renderer->course_search_form($value, $format); | |
3124 | } | |
3125 | } | |
09ae7ee0 MG |
3126 | |
3127 | /** | |
3128 | * Prints custom user information on the home page | |
3129 | * | |
3130 | * This function is deprecated, please use: | |
3131 | * $renderer = $PAGE->get_renderer('core', 'course'); | |
3132 | * echo $renderer->frontpage_my_courses() | |
3133 | * | |
3134 | * @deprecated since 2.5 | |
3135 | */ | |
3136 | function print_my_moodle() { | |
3137 | global $PAGE; | |
3138 | debugging('Function print_my_moodle() is deprecated, please use course renderer function frontpage_my_courses()', DEBUG_DEVELOPER); | |
3139 | ||
3140 | $renderer = $PAGE->get_renderer('core', 'course'); | |
3141 | echo $renderer->frontpage_my_courses(); | |
3142 | } | |
3143 | ||
3144 | /** | |
3145 | * Prints information about one remote course | |
3146 | * | |
3147 | * This function is deprecated, it is replaced with protected function | |
3148 | * {@link core_course_renderer::frontpage_remote_course()} | |
3149 | * It is only used from function {@link core_course_renderer::frontpage_my_courses()} | |
3150 | * | |
3151 | * @deprecated since 2.5 | |
3152 | */ | |
3153 | function print_remote_course($course, $width="100%") { | |
3154 | global $CFG, $USER; | |
3155 | debugging('Function print_remote_course() is deprecated, please use course renderer', DEBUG_DEVELOPER); | |
3156 | ||
3157 | $linkcss = ''; | |
3158 | ||
3159 | $url = "{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&wantsurl=/course/view.php?id={$course->remoteid}"; | |
3160 | ||
3161 | echo '<div class="coursebox remotecoursebox clearfix">'; | |
3162 | echo '<div class="info">'; | |
3163 | echo '<div class="name"><a title="'.get_string('entercourse').'"'. | |
3164 | $linkcss.' href="'.$url.'">' | |
3165 | . format_string($course->fullname) .'</a><br />' | |
3166 | . format_string($course->hostname) . ' : ' | |
3167 | . format_string($course->cat_name) . ' : ' | |
3168 | . format_string($course->shortname). '</div>'; | |
3169 | echo '</div><div class="summary">'; | |
3170 | $options = new stdClass(); | |
3171 | $options->noclean = true; | |
3172 | $options->para = false; | |
3173 | $options->overflowdiv = true; | |
3174 | echo format_text($course->summary, $course->summaryformat, $options); | |
3175 | echo '</div>'; | |
3176 | echo '</div>'; | |
3177 | } | |
3178 | ||
3179 | /** | |
3180 | * Prints information about one remote host | |
3181 | * | |
3182 | * This function is deprecated, it is replaced with protected function | |
3183 | * {@link core_course_renderer::frontpage_remote_host()} | |
3184 | * It is only used from function {@link core_course_renderer::frontpage_my_courses()} | |
3185 | * | |
3186 | * @deprecated since 2.5 | |
3187 | */ | |
3188 | function print_remote_host($host, $width="100%") { | |
3189 | global $OUTPUT; | |
3190 | debugging('Function print_remote_host() is deprecated, please use course renderer', DEBUG_DEVELOPER); | |
3191 | ||
3192 | $linkcss = ''; | |
3193 | ||
3194 | echo '<div class="coursebox clearfix">'; | |
3195 | echo '<div class="info">'; | |
3196 | echo '<div class="name">'; | |
3197 | echo '<img src="'.$OUTPUT->pix_url('i/mnethost') . '" class="icon" alt="'.get_string('course').'" />'; | |
3198 | echo '<a title="'.s($host['name']).'" href="'.s($host['url']).'">' | |
3199 | . s($host['name']).'</a> - '; | |
3200 | echo $host['count'] . ' ' . get_string('courses'); | |
3201 | echo '</div>'; | |
3202 | echo '</div>'; | |
3203 | echo '</div>'; | |
3204 | } | |
3205 | ||
3206 | /** | |
3207 | * Recursive function to print out all the categories in a nice format | |
3208 | * with or without courses included | |
3209 | * | |
3210 | * @deprecated since 2.5 | |
3211 | * | |
3212 | * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 | |
3213 | */ | |
3214 | function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) { | |
3215 | global $PAGE; | |
3216 | debugging('Function print_whole_category_list() is deprecated, please use course renderer', DEBUG_DEVELOPER); | |
3217 | ||
3218 | $renderer = $PAGE->get_renderer('core', 'course'); | |
3219 | if ($showcourses && $category) { | |
3220 | echo $renderer->course_category($category); | |
3221 | } else if ($showcourses) { | |
3222 | echo $renderer->frontpage_combo_list(); | |
3223 | } else { | |
3224 | echo $renderer->frontpage_categories_list(); | |
3225 | } | |
3226 | } | |
3227 | ||
3228 | /** | |
3229 | * Prints the category information. | |
3230 | * | |
3231 | * @deprecated since 2.5 | |
3232 | * | |
3233 | * This function was only used by {@link print_whole_category_list()} but now | |
3234 | * all course category rendering is moved to core_course_renderer. | |
3235 | * | |
3236 | * @param stdClass $category | |
3237 | * @param int $depth The depth of the category. | |
3238 | * @param bool $showcourses If set to true course information will also be printed. | |
3239 | * @param array|null $courses An array of courses belonging to the category, or null if you don't have it yet. | |
3240 | */ | |
3241 | function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) { | |
3242 | global $PAGE; | |
3243 | debugging('Function print_category_info() is deprecated, please use course renderer', DEBUG_DEVELOPER); | |
3244 | ||
3245 | $renderer = $PAGE->get_renderer('core', 'course'); | |
3246 | echo $renderer->course_category($category); | |
3247 | } | |
3248 | ||
3249 | /** | |
3250 | * This function generates a structured array of courses and categories. | |
3251 | * | |
3252 | * @deprecated since 2.5 | |
3253 | * | |
3254 | * This function is not used any more in moodle core and course renderer does not have render function for it. | |
3255 | * Combo list on the front page is displayed as: | |
3256 | * $renderer = $PAGE->get_renderer('core', 'course'); | |
3257 | * echo $renderer->frontpage_combo_list() | |
3258 | * | |
3259 | * The new class {@link coursecat} stores the information about course category tree | |
3260 | * To get children categories use: | |
3261 | * coursecat::get($id)->get_children() | |
3262 | * To get list of courses use: | |
3263 | * coursecat::get($id)->get_courses() | |
3264 | * | |
3265 | * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 | |
3266 | * | |
3267 | * @param int $id | |
3268 | * @param int $depth | |
3269 | */ | |
3270 | function get_course_category_tree($id = 0, $depth = 0) { | |
3271 | global $DB, $CFG; | |
3272 | if (!$depth) { | |
3273 | debugging('Function get_course_category_tree() is deprecated, please use course renderer or coursecat class, see function phpdocs for more info', DEBUG_DEVELOPER); | |
3274 | } | |
3275 | ||
3276 | $categories = array(); | |
3277 | $categoryids = array(); | |
3278 | $sql = context_helper::get_preload_record_columns_sql('ctx'); | |
3279 | $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ". | |
3280 | "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder", | |
3281 | array(CONTEXT_COURSECAT, $id)); | |
3282 | foreach ($records as $category) { | |
3283 | context_helper::preload_from_record($category); | |
3284 | if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) { | |
3285 | continue; | |
3286 | } | |
3287 | $categories[] = $category; | |
3288 | $categoryids[$category->id] = $category; | |
3289 | if (empty($CFG->maxcategorydepth) || $depth <= $CFG->maxcategorydepth) { | |
3290 | list($category->categories, $subcategories) = get_course_category_tree($category->id, $depth+1); | |
3291 | foreach ($subcategories as $subid=>$subcat) { | |
3292 | $categoryids[$subid] = $subcat; | |
3293 | } | |
3294 | $category->courses = array(); | |
3295 | } | |
3296 | } | |
3297 | ||
3298 | if ($depth > 0) { | |
3299 | // This is a recursive call so return the required array | |
3300 | return array($categories, $categoryids); | |
3301 | } | |
3302 | ||
3303 | if (empty($categoryids)) { | |
3304 | // No categories available (probably all hidden). | |
3305 | return array(); | |
3306 | } | |
3307 | ||
3308 | // The depth is 0 this function has just been called so we can finish it off | |
3309 | ||
3310 | list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); | |
3311 | list($catsql, $catparams) = $DB->get_in_or_equal(array_keys($categoryids)); | |
3312 | $sql = "SELECT | |
3313 | c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary,c.category | |
3314 | $ccselect | |
3315 | FROM {course} c | |
3316 | $ccjoin | |
3317 | WHERE c.category $catsql ORDER BY c.sortorder ASC"; | |
3318 | if ($courses = $DB->get_records_sql($sql, $catparams)) { | |
3319 | // loop throught them | |
3320 | foreach ($courses as $course) { | |
3321 | if ($course->id == SITEID) { | |
3322 | continue; | |
3323 | } | |
db314f34 | 3324 | context_helper::preload_from_record($course); |
09ae7ee0 MG |
3325 | if (!empty($course->visible) || has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) { |
3326 | $categoryids[$course->category]->courses[$course->id] = $course; | |
3327 | } | |
3328 | } | |
3329 | } | |
3330 | return $categories; | |
3331 | } | |
3332 | ||
3333 | /** | |
3334 | * Print courses in category. If category is 0 then all courses are printed. | |
3335 | * | |
3336 | * @deprecated since 2.5 | |
3337 | * | |
3338 | * To print a generic list of courses use: | |
3339 | * $renderer = $PAGE->get_renderer('core', 'course'); | |
3340 | * echo $renderer->courses_list($courses); | |
3341 | * | |
3342 | * To print list of all courses: | |
3343 | * $renderer = $PAGE->get_renderer('core', 'course'); | |
3344 | * echo $renderer->frontpage_available_courses(); | |
3345 | * | |
3346 | * To print list of courses inside category: | |
3347 | * $renderer = $PAGE->get_renderer('core', 'course'); | |
3348 | * echo $renderer->course_category($category); // this will also print subcategories | |
3349 | * | |
3350 | * @param int|stdClass $category category object or id. | |
3351 | * @return bool true if courses found and printed, else false. | |
3352 | */ | |
3353 | function print_courses($category) { | |
3354 | global $CFG, $OUTPUT, $PAGE; | |
3355 | require_once($CFG->libdir. '/coursecatlib.php'); | |
3356 | debugging('Function print_courses() is deprecated, please use course renderer', DEBUG_DEVELOPER); | |
3357 | ||
3358 | if (!is_object($category) && $category==0) { | |
3359 | $courses = coursecat::get(0)->get_courses(array('recursive' => true, 'summary' => true, 'coursecontacts' => true)); | |
3360 | } else { | |
3361 | $courses = coursecat::get($category->id)->get_courses(array('summary' => true, 'coursecontacts' => true)); | |
3362 | } | |
3363 | ||
3364 | if ($courses) { | |
3365 | $renderer = $PAGE->get_renderer('core', 'course'); | |
3366 | echo $renderer->courses_list($courses); | |
3367 | } else { | |
3368 | echo $OUTPUT->heading(get_string("nocoursesyet")); | |
3369 | $context = context_system::instance(); | |
3370 | if (has_capability('moodle/course:create', $context)) { | |
3371 | $options = array(); | |
3372 | if (!empty($category->id)) { | |
3373 | $options['category'] = $category->id; | |
3374 | } else { | |
3375 | $options['category'] = $CFG->defaultrequestcategory; | |
3376 | } | |
3377 | echo html_writer::start_tag('div', array('class'=>'addcoursebutton')); | |
3378 | echo $OUTPUT->single_button(new moodle_url('/course/edit.php', $options), get_string("addnewcourse")); | |
3379 | echo html_writer::end_tag('div'); | |
3380 | return false; | |
3381 | } | |
3382 | } | |
3383 | return true; | |
3384 | } | |
3385 | ||
3386 | /** | |
3387 | * Print a description of a course, suitable for browsing in a list. | |
3388 | * | |
3389 | * @deprecated since 2.5 | |
3390 | * | |
3391 | * Please use course renderer to display a course information box. | |
3392 | * $renderer = $PAGE->get_renderer('core', 'course'); | |
3393 | * echo $renderer->courses_list($courses); // will print list of courses | |
3394 | * echo $renderer->course_info_box($course); // will print one course wrapped in div.generalbox | |
3395 | * | |
3396 | * @param object $course the course object. | |
3397 | * @param string $highlightterms Ignored in this deprecated function! | |
3398 | */ | |
3399 | function print_course($course, $highlightterms = '') { | |
3400 | global $PAGE; | |
3401 | ||
3402 | debugging('Function print_course() is deprecated, please use course renderer', DEBUG_DEVELOPER); | |
3403 | $renderer = $PAGE->get_renderer('core', 'course'); | |
3404 | // Please note, correct would be to use $renderer->coursecat_coursebox() but this function is protected. | |
3405 | // To print list of courses use $renderer->courses_list(); | |
3406 | echo $renderer->course_info_box($course); | |
3407 | } | |
3408 | ||
3409 | /** | |
3410 | * Gets an array whose keys are category ids and whose values are arrays of courses in the corresponding category. | |
3411 | * | |
3412 | * @deprecated since 2.5 | |
3413 | * | |
3414 | * This function is not used any more in moodle core and course renderer does not have render function for it. | |
3415 | * Combo list on the front page is displayed as: | |
3416 | * $renderer = $PAGE->get_renderer('core', 'course'); | |
3417 | * echo $renderer->frontpage_combo_list() | |
3418 | * | |
3419 | * The new class {@link coursecat} stores the information about course category tree | |
3420 | * To get children categories use: | |
3421 | * coursecat::get($id)->get_children() | |
3422 | * To get list of courses use: | |
3423 | * coursecat::get($id)->get_courses() | |
3424 | * | |
3425 | * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 | |
3426 | * | |
3427 | * @param int $categoryid | |
3428 | * @return array | |
3429 | */ | |
3430 | function get_category_courses_array($categoryid = 0) { | |
3431 | debugging('Function get_category_courses_array() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER); | |
3432 | $tree = get_course_category_tree($categoryid); | |
3433 | $flattened = array(); | |
3434 | foreach ($tree as $category) { | |
3435 | get_category_courses_array_recursively($flattened, $category); | |
3436 | } | |
3437 | return $flattened; | |
3438 | } | |
3439 | ||
3440 | /** | |
3441 | * Recursive function to help flatten the course category tree. | |
3442 | * | |
3443 | * @deprecated since 2.5 | |
3444 | * | |
3445 | * Was intended to be called from {@link get_category_courses_array()} | |
3446 | * | |
3447 | * @param array &$flattened An array passed by reference in which to store courses for each category. | |
3448 | * @param stdClass $category The category to get courses for. | |
3449 | */ | |
3450 | function get_category_courses_array_recursively(array &$flattened, $category) { | |
3451 | debugging('Function get_category_courses_array_recursively() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER); | |
3452 | $flattened[$category->id] = $category->courses; | |
3453 | foreach ($category->categories as $childcategory) { | |
3454 | get_category_courses_array_recursively($flattened, $childcategory); | |
3455 | } | |
3456 | } | |
3457 | ||
7ac18cf9 AA |
3458 | /** |
3459 | * Returns a URL based on the context of the current page. | |
3460 | * This URL points to blog/index.php and includes filter parameters appropriate for the current page. | |
3461 | * | |
3462 | * @param stdclass $context | |
3463 | * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more. | |
3464 | * @todo Remove this in 2.7 | |
3465 | * @return string | |
3466 | */ | |
3467 | function blog_get_context_url($context=null) { | |
3468 | global $CFG; | |
3469 | ||
3470 | debugging('Function blog_get_context_url() is deprecated, getting params from context is not reliable for blogs.', DEBUG_DEVELOPER); | |
3471 | $viewblogentriesurl = new moodle_url('/blog/index.php'); | |
3472 | ||
3473 | if (empty($context)) { | |
3474 | global $PAGE; | |
3475 | $context = $PAGE->context; | |
3476 | } | |
3477 | ||
3478 | // Change contextlevel to SYSTEM if viewing the site course | |
3479 | if ($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID) { | |
3480 | $context = context_system::instance(); | |
3481 | } | |
3482 | ||
3483 | $filterparam = ''; | |
3484 | $strlevel = ''; | |
3485 | ||
3486 | switch ($context->contextlevel) { | |
3487 | case CONTEXT_SYSTEM: | |
3488 | case CONTEXT_BLOCK: | |
3489 | case CONTEXT_COURSECAT: | |
3490 | break; | |
3491 | case CONTEXT_COURSE: | |
3492 | $filterparam = 'courseid'; | |
3493 | $strlevel = get_string('course'); | |
3494 | break; | |
3495 | case CONTEXT_MODULE: | |
3496 | $filterparam = 'modid'; | |
329846f1 | 3497 | $strlevel = $context->get_context_name(); |
7ac18cf9 AA |
3498 | break; |
3499 | case CONTEXT_USER: | |
3500 | $filterparam = 'userid'; | |
3501 | $strlevel = get_string('user'); | |
3502 | break; | |
3503 | } | |
3504 | ||
3505 | if (!empty($filterparam)) { | |
3506 | $viewblogentriesurl->param($filterparam, $context->instanceid); | |
3507 | } | |
3508 | ||
3509 | return $viewblogentriesurl; | |
3510 | } | |
3511 | ||
09ae7ee0 MG |
3512 | /** |
3513 | * Retrieve course records with the course managers and other related records | |
3514 | * that we need for print_course(). This allows print_courses() to do its job | |
3515 | * in a constant number of DB queries, regardless of the number of courses, | |
3516 | * role assignments, etc. | |
3517 | * | |
3518 | * The returned array is indexed on c.id, and each course will have | |
3519 | * - $course->managers - array containing RA objects that include a $user obj | |
3520 | * with the minimal fields needed for fullname() | |
3521 | * | |
3522 | * @deprecated since 2.5 | |
3523 | * | |
3524 | * To get list of all courses with course contacts ('managers') use | |
3525 | * coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true)); | |
3526 | * | |
3527 | * To get list of courses inside particular category use | |
3528 | * coursecat::get($id)->get_courses(array('coursecontacts' => true)); | |
3529 | * | |
3530 | * Additionally you can specify sort order, offset and maximum number of courses, | |
3531 | * see {@link coursecat::get_courses()} | |
3532 | * | |
3533 | * Please note that code of this function is not changed to use coursecat class because | |
3534 | * coursecat::get_courses() returns result in slightly different format. Also note that | |
3535 | * get_courses_wmanagers() DOES NOT check that users are enrolled in the course and | |
3536 | * coursecat::get_courses() does. | |
3537 | * | |
3538 | * @global object | |
3539 | * @global object | |
3540 | * @global object | |
3541 | * @uses CONTEXT_COURSE | |
3542 | * @uses CONTEXT_SYSTEM | |
3543 | * @uses CONTEXT_COURSECAT | |
3544 | * @uses SITEID | |
3545 | * @param int|string $categoryid Either the categoryid for the courses or 'all' | |
3546 | * @param string $sort A SQL sort field and direction | |
3547 | * @param array $fields An array of additional fields to fetch | |
3548 | * @return array | |
3549 | */ | |
3550 | function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) { | |
3551 | /* | |
3552 | * The plan is to | |
3553 | * | |
3554 | * - Grab the courses JOINed w/context | |
3555 | * | |
3556 | * - Grab the interesting course-manager RAs | |
3557 | * JOINed with a base user obj and add them to each course | |
3558 | * | |
3559 | * So as to do all the work in 2 DB queries. The RA+user JOIN | |
3560 | * ends up being pretty expensive if it happens over _all_ | |
3561 | * courses on a large site. (Are we surprised!?) | |
3562 | * | |
3563 | * So this should _never_ get called with 'all' on a large site. | |
3564 | * | |
3565 | */ | |
3566 | global $USER, $CFG, $DB; | |
3567 | debugging('Function get_courses_wmanagers() is deprecated, please use coursecat::get_courses()', DEBUG_DEVELOPER); | |
3568 | ||
3569 | $params = array(); | |
3570 | $allcats = false; // bool flag | |
3571 | if ($categoryid === 'all') { | |
3572 | $categoryclause = ''; | |
3573 | $allcats = true; | |
3574 | } elseif (is_numeric($categoryid)) { | |
3575 | $categoryclause = "c.category = :catid"; | |
3576 | $params['catid'] = $categoryid; | |
3577 | } else { | |
3578 | debugging("Could not recognise categoryid = $categoryid"); | |
3579 | $categoryclause = ''; | |
3580 | } | |
3581 | ||
3582 | $basefields = array('id', 'category', 'sortorder', | |
3583 | 'shortname', 'fullname', 'idnumber', | |
3584 | 'startdate', 'visible', | |
3585 | 'newsitems', 'groupmode', 'groupmodeforce'); | |
3586 | ||
3587 | if (!is_null($fields) && is_string($fields)) { | |
3588 | if (empty($fields)) { | |
3589 | $fields = $basefields; | |
3590 | } else { | |
3591 | // turn the fields from a string to an array that | |
3592 | // get_user_courses_bycap() will like... | |
3593 | $fields = explode(',',$fields); | |
3594 | $fields = array_map('trim', $fields); | |
3595 | $fields = array_unique(array_merge($basefields, $fields)); | |
3596 | } | |
3597 | } elseif (is_array($fields)) { | |
3598 | $fields = array_merge($basefields,$fields); | |
3599 | } | |
3600 | $coursefields = 'c.' .join(',c.', $fields); | |
3601 | ||
3602 | if (empty($sort)) { | |
3603 | $sortstatement = ""; | |
3604 | } else { | |
3605 | $sortstatement = "ORDER BY $sort"; | |
3606 | } | |
3607 | ||
3608 | $where = 'WHERE c.id != ' . SITEID; | |
3609 | if ($categoryclause !== ''){ | |
3610 | $where = "$where AND $categoryclause"; | |
3611 | } | |
3612 | ||
3613 | // pull out all courses matching the cat | |
3614 | list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); | |
3615 | $sql = "SELECT $coursefields $ccselect | |
3616 | FROM {course} c | |
3617 | $ccjoin | |
3618 | $where | |
3619 | $sortstatement"; | |
3620 | ||
3621 | $catpaths = array(); | |
3622 | $catpath = NULL; | |
3623 | if ($courses = $DB->get_records_sql($sql, $params)) { | |
3624 | // loop on courses materialising | |
3625 | // the context, and prepping data to fetch the | |
3626 | // managers efficiently later... | |
3627 | foreach ($courses as $k => $course) { | |
db314f34 | 3628 | context_helper::preload_from_record($course); |
09ae7ee0 MG |
3629 | $coursecontext = context_course::instance($course->id); |
3630 | $courses[$k] = $course; | |
3631 | $courses[$k]->managers = array(); | |
3632 | if ($allcats === false) { | |
3633 | // single cat, so take just the first one... | |
3634 | if ($catpath === NULL) { | |
3635 | $catpath = preg_replace(':/\d+$:', '', $coursecontext->path); | |
3636 | } | |
3637 | } else { | |
3638 | // chop off the contextid of the course itself | |
3639 | // like dirname() does... | |
3640 | $catpaths[] = preg_replace(':/\d+$:', '', $coursecontext->path); | |
3641 | } | |
3642 | } | |
3643 | } else { | |
3644 | return array(); // no courses! | |
3645 | } | |
3646 | ||
3647 | $CFG->coursecontact = trim($CFG->coursecontact); | |
3648 | if (empty($CFG->coursecontact)) { | |
3649 | return $courses; | |
3650 | } | |
3651 | ||
3652 | $managerroles = explode(',', $CFG->coursecontact); | |
3653 | $catctxids = ''; | |
3654 | if (count($managerroles)) { | |
3655 | if ($allcats === true) { | |
3656 | $catpaths = array_unique($catpaths); | |
3657 | $ctxids = array(); | |
3658 | foreach ($catpaths as $cpath) { | |
3659 | $ctxids = array_merge($ctxids, explode('/',substr($cpath,1))); | |
3660 | } | |
3661 | $ctxids = array_unique($ctxids); | |
3662 | $catctxids = implode( ',' , $ctxids); | |
3663 | unset($catpaths); | |
3664 | unset($cpath); | |
3665 | } else { | |
3666 | // take the ctx path from the first course | |
3667 | // as all categories will be the same... | |
3668 | $catpath = substr($catpath,1); | |
3669 | $catpath = preg_replace(':/\d+$:','',$catpath); | |
3670 | $catctxids = str_replace('/',',',$catpath); | |
3671 | } | |
3672 | if ($categoryclause !== '') { | |
3673 | $categoryclause = "AND $categoryclause"; | |
3674 | } | |
3675 | /* | |
3676 | * Note: Here we use a LEFT OUTER JOIN that can | |
3677 | * "optionally" match to avoid passing a ton of context | |
3678 | * ids in an IN() clause. Perhaps a subselect is faster. | |
3679 |