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