Merge branch 'MDL-42392-26' of git://github.com/andrewnicols/moodle into MOODLE_26_STABLE
[moodle.git] / lib / deprecatedlib.php
blobb58d1ee69bbb8dd3600376fd363e194c0884904f
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
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.
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/>.
18 /**
19 * deprecatedlib.php - Old functions retained only for backward compatibility
21 * Old functions retained only for backward compatibility. New code should not
22 * use any of these functions.
24 * @package core
25 * @subpackage deprecated
26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 * @deprecated
31 defined('MOODLE_INTERNAL') || die();
33 /**
34 * Factory method that was returning moodle_session object.
36 * @deprecated since 2.6
37 * @return \core\session\manager
39 function session_get_instance() {
40 // Note: the new session manager includes all methods from the original session class.
41 static $deprecatedinstance = null;
43 debugging('session_get_instance() is deprecated, use \core\session\manager instead', DEBUG_DEVELOPER);
45 if (!$deprecatedinstance) {
46 $deprecatedinstance = new \core\session\manager();
49 return $deprecatedinstance;
52 /**
53 * Returns true if legacy session used.
55 * @deprecated since 2.6
56 * @return bool
58 function session_is_legacy() {
59 debugging('session_is_legacy() is deprecated, do not use any more', DEBUG_DEVELOPER);
60 return false;
63 /**
64 * Terminates all sessions, auth hooks are not executed.
65 * Useful in upgrade scripts.
67 * @deprecated since 2.6
69 function session_kill_all() {
70 debugging('session_kill_all() is deprecated, use \core\session\manager::kill_all_sessions() instead', DEBUG_DEVELOPER);
71 \core\session\manager::kill_all_sessions();
74 /**
75 * Mark session as accessed, prevents timeouts.
77 * @deprecated since 2.6
78 * @param string $sid
80 function session_touch($sid) {
81 debugging('session_touch() is deprecated, use \core\session\manager::touch_session() instead', DEBUG_DEVELOPER);
82 \core\session\manager::touch_session($sid);
85 /**
86 * Terminates one sessions, auth hooks are not executed.
88 * @deprecated since 2.6
89 * @param string $sid session id
91 function session_kill($sid) {
92 debugging('session_kill() is deprecated, use \core\session\manager::kill_session() instead', DEBUG_DEVELOPER);
93 \core\session\manager::kill_session($sid);
96 /**
97 * Terminates all sessions of one user, auth hooks are not executed.
98 * NOTE: This can not work for file based sessions!
100 * @deprecated since 2.6
101 * @param int $userid user id
103 function session_kill_user($userid) {
104 debugging('session_kill_user() is deprecated, use \core\session\manager::kill_user_sessions() instead', DEBUG_DEVELOPER);
105 \core\session\manager::kill_user_sessions($userid);
109 * Session garbage collection
110 * - verify timeout for all users
111 * - kill sessions of all deleted users
112 * - kill sessions of users with disabled plugins or 'nologin' plugin
114 * @deprecated since 2.6
116 function session_gc() {
117 debugging('session_gc() is deprecated, use \core\session\manager::gc() instead', DEBUG_DEVELOPER);
118 \core\session\manager::gc();
122 * Setup $USER object - called during login, loginas, etc.
124 * Call sync_user_enrolments() manually after log-in, or log-in-as.
126 * @deprecated since 2.6
127 * @param stdClass $user full user record object
128 * @return void
130 function session_set_user($user) {
131 debugging('session_set_user() is deprecated, use \core\session\manager::set_user() instead', DEBUG_DEVELOPER);
132 \core\session\manager::set_user($user);
136 * Is current $USER logged-in-as somebody else?
137 * @deprecated since 2.6
138 * @return bool
140 function session_is_loggedinas() {
141 debugging('session_is_loggedinas() is deprecated, use \core\session\manager::is_loggedinas() instead', DEBUG_DEVELOPER);
142 return \core\session\manager::is_loggedinas();
146 * Returns the $USER object ignoring current login-as session
147 * @deprecated since 2.6
148 * @return stdClass user object
150 function session_get_realuser() {
151 debugging('session_get_realuser() is deprecated, use \core\session\manager::get_realuser() instead', DEBUG_DEVELOPER);
152 return \core\session\manager::get_realuser();
156 * Login as another user - no security checks here.
157 * @deprecated since 2.6
158 * @param int $userid
159 * @param stdClass $context
160 * @return void
162 function session_loginas($userid, $context) {
163 debugging('session_loginas() is deprecated, use \core\session\manager::loginas() instead', DEBUG_DEVELOPER);
164 \core\session\manager::loginas($userid, $context);
168 * Minify JavaScript files.
170 * @deprecated since 2.6
172 * @param array $files
173 * @return string
175 function js_minify($files) {
176 debugging('js_minify() is deprecated, use core_minify::js_files() or core_minify::js() instead.');
177 return core_minify::js_files($files);
181 * Minify CSS files.
183 * @deprecated since 2.6
185 * @param array $files
186 * @return string
188 function css_minify_css($files) {
189 debugging('css_minify_css() is deprecated, use core_minify::css_files() or core_minify::css() instead.');
190 return core_minify::css_files($files);
194 * Function to call all event handlers when triggering an event
196 * @deprecated since 2.6
198 * @param string $eventname name of the event
199 * @param mixed $eventdata event data object
200 * @return int number of failed events
202 function events_trigger($eventname, $eventdata) {
203 // TODO: uncomment after conversion of all events in standard distribution
204 // debugging('events_trigger() is deprecated, please use new events instead', DEBUG_DEVELOPER);
205 return events_trigger_legacy($eventname, $eventdata);
209 * List all core subsystems and their location
211 * This is a whitelist of components that are part of the core and their
212 * language strings are defined in /lang/en/<<subsystem>>.php. If a given
213 * plugin is not listed here and it does not have proper plugintype prefix,
214 * then it is considered as course activity module.
216 * The location is optionally dirroot relative path. NULL means there is no special
217 * directory for this subsystem. If the location is set, the subsystem's
218 * renderer.php is expected to be there.
220 * @deprecated since 2.6, use core_component::get_core_subsystems()
222 * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons
223 * @return array of (string)name => (string|null)location
225 function get_core_subsystems($fullpaths = false) {
226 global $CFG;
228 // NOTE: do not add any other debugging here, keep forever.
230 $subsystems = core_component::get_core_subsystems();
232 if ($fullpaths) {
233 return $subsystems;
236 debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
238 $dlength = strlen($CFG->dirroot);
240 foreach ($subsystems as $k => $v) {
241 if ($v === null) {
242 continue;
244 $subsystems[$k] = substr($v, $dlength+1);
247 return $subsystems;
251 * Lists all plugin types.
253 * @deprecated since 2.6, use core_component::get_plugin_types()
255 * @param bool $fullpaths false means relative paths from dirroot
256 * @return array Array of strings - name=>location
258 function get_plugin_types($fullpaths = true) {
259 global $CFG;
261 // NOTE: do not add any other debugging here, keep forever.
263 $types = core_component::get_plugin_types();
265 if ($fullpaths) {
266 return $types;
269 debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
271 $dlength = strlen($CFG->dirroot);
273 foreach ($types as $k => $v) {
274 if ($k === 'theme') {
275 $types[$k] = 'theme';
276 continue;
278 $types[$k] = substr($v, $dlength+1);
281 return $types;
285 * Use when listing real plugins of one type.
287 * @deprecated since 2.6, use core_component::get_plugin_list()
289 * @param string $plugintype type of plugin
290 * @return array name=>fulllocation pairs of plugins of given type
292 function get_plugin_list($plugintype) {
294 // NOTE: do not add any other debugging here, keep forever.
296 if ($plugintype === '') {
297 $plugintype = 'mod';
300 return core_component::get_plugin_list($plugintype);
304 * Get a list of all the plugins of a given type that define a certain class
305 * in a certain file. The plugin component names and class names are returned.
307 * @deprecated since 2.6, use core_component::get_plugin_list_with_class()
309 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
310 * @param string $class the part of the name of the class after the
311 * frankenstyle prefix. e.g 'thing' if you are looking for classes with
312 * names like report_courselist_thing. If you are looking for classes with
313 * the same name as the plugin name (e.g. qtype_multichoice) then pass ''.
314 * @param string $file the name of file within the plugin that defines the class.
315 * @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum')
316 * and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice').
318 function get_plugin_list_with_class($plugintype, $class, $file) {
320 // NOTE: do not add any other debugging here, keep forever.
322 return core_component::get_plugin_list_with_class($plugintype, $class, $file);
326 * Returns the exact absolute path to plugin directory.
328 * @deprecated since 2.6, use core_component::get_plugin_directory()
330 * @param string $plugintype type of plugin
331 * @param string $name name of the plugin
332 * @return string full path to plugin directory; NULL if not found
334 function get_plugin_directory($plugintype, $name) {
336 // NOTE: do not add any other debugging here, keep forever.
338 if ($plugintype === '') {
339 $plugintype = 'mod';
342 return core_component::get_plugin_directory($plugintype, $name);
346 * Normalize the component name using the "frankenstyle" names.
348 * @deprecated since 2.6, use core_component::normalize_component()
350 * @param string $component
351 * @return array as (string)$type => (string)$plugin
353 function normalize_component($component) {
355 // NOTE: do not add any other debugging here, keep forever.
357 return core_component::normalize_component($component);
361 * Return exact absolute path to a plugin directory.
363 * @deprecated since 2.6, use core_component::normalize_component()
365 * @param string $component name such as 'moodle', 'mod_forum'
366 * @return string full path to component directory; NULL if not found
368 function get_component_directory($component) {
370 // NOTE: do not add any other debugging here, keep forever.
372 return core_component::get_component_directory($component);
376 // === Deprecated before 2.6.0 ===
379 * Hack to find out the GD version by parsing phpinfo output
381 * @return int GD version (1, 2, or 0)
383 function check_gd_version() {
384 // TODO: delete function in Moodle 2.7
385 debugging('check_gd_version() is deprecated, GD extension is always available now');
387 $gdversion = 0;
389 if (function_exists('gd_info')){
390 $gd_info = gd_info();
391 if (substr_count($gd_info['GD Version'], '2.')) {
392 $gdversion = 2;
393 } else if (substr_count($gd_info['GD Version'], '1.')) {
394 $gdversion = 1;
397 } else {
398 ob_start();
399 phpinfo(INFO_MODULES);
400 $phpinfo = ob_get_contents();
401 ob_end_clean();
403 $phpinfo = explode("\n", $phpinfo);
406 foreach ($phpinfo as $text) {
407 $parts = explode('</td>', $text);
408 foreach ($parts as $key => $val) {
409 $parts[$key] = trim(strip_tags($val));
411 if ($parts[0] == 'GD Version') {
412 if (substr_count($parts[1], '2.0')) {
413 $parts[1] = '2.0';
415 $gdversion = intval($parts[1]);
420 return $gdversion; // 1, 2 or 0
424 * Not used any more, the account lockout handling is now
425 * part of authenticate_user_login().
426 * @deprecated
428 function update_login_count() {
429 // TODO: delete function in Moodle 2.6
430 debugging('update_login_count() is deprecated, all calls need to be removed');
434 * Not used any more, replaced by proper account lockout.
435 * @deprecated
437 function reset_login_count() {
438 // TODO: delete function in Moodle 2.6
439 debugging('reset_login_count() is deprecated, all calls need to be removed');
443 * Insert or update log display entry. Entry may already exist.
444 * $module, $action must be unique
445 * @deprecated
447 * @param string $module
448 * @param string $action
449 * @param string $mtable
450 * @param string $field
451 * @return void
454 function update_log_display_entry($module, $action, $mtable, $field) {
455 global $DB;
457 debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
461 * Given some text in HTML format, this function will pass it
462 * through any filters that have been configured for this context.
464 * @deprecated use the text formatting in a standard way instead (http://docs.moodle.org/dev/Output_functions)
465 * this was abused mostly for embedding of attachments
466 * @todo final deprecation of this function in MDL-40607
467 * @param string $text The text to be passed through format filters
468 * @param int $courseid The current course.
469 * @return string the filtered string.
471 function filter_text($text, $courseid = NULL) {
472 global $CFG, $COURSE;
474 debugging('filter_text() is deprecated, use format_text(), format_string() etc instead.', DEBUG_DEVELOPER);
476 if (!$courseid) {
477 $courseid = $COURSE->id;
480 if (!$context = context_course::instance($courseid, IGNORE_MISSING)) {
481 return $text;
484 return filter_manager::instance()->filter_text($text, $context);
488 * This function indicates that current page requires the https
489 * when $CFG->loginhttps enabled.
491 * By using this function properly, we can ensure 100% https-ized pages
492 * at our entire discretion (login, forgot_password, change_password)
493 * @deprecated use $PAGE->https_required() instead
494 * @todo final deprecation of this function in MDL-40607
496 function httpsrequired() {
497 global $PAGE;
498 debugging('httpsrequired() is deprecated use $PAGE->https_required() instead.', DEBUG_DEVELOPER);
499 $PAGE->https_required();
503 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
505 * @deprecated use moodle_url factory methods instead
507 * @param string $path Physical path to a file
508 * @param array $options associative array of GET variables to append to the URL
509 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
510 * @return string URL to file
512 function get_file_url($path, $options=null, $type='coursefile') {
513 global $CFG;
515 $path = str_replace('//', '/', $path);
516 $path = trim($path, '/'); // no leading and trailing slashes
518 // type of file
519 switch ($type) {
520 case 'questionfile':
521 $url = $CFG->wwwroot."/question/exportfile.php";
522 break;
523 case 'rssfile':
524 $url = $CFG->wwwroot."/rss/file.php";
525 break;
526 case 'httpscoursefile':
527 $url = $CFG->httpswwwroot."/file.php";
528 break;
529 case 'coursefile':
530 default:
531 $url = $CFG->wwwroot."/file.php";
534 if ($CFG->slasharguments) {
535 $parts = explode('/', $path);
536 foreach ($parts as $key => $part) {
537 /// anchor dash character should not be encoded
538 $subparts = explode('#', $part);
539 $subparts = array_map('rawurlencode', $subparts);
540 $parts[$key] = implode('#', $subparts);
542 $path = implode('/', $parts);
543 $ffurl = $url.'/'.$path;
544 $separator = '?';
545 } else {
546 $path = rawurlencode('/'.$path);
547 $ffurl = $url.'?file='.$path;
548 $separator = '&amp;';
551 if ($options) {
552 foreach ($options as $name=>$value) {
553 $ffurl = $ffurl.$separator.$name.'='.$value;
554 $separator = '&amp;';
558 return $ffurl;
562 * @deprecated use get_string("pluginname", "auth_[PLUINNAME]") instead.
563 * @todo remove completely in MDL-40517
565 function auth_get_plugin_title($authtype) {
566 throw new coding_exception('Function auth_get_plugin_title() is deprecated, please use standard get_string("pluginname", "auth_'.$authtype.'")!');
570 * @deprecated use indivividual enrol plugin settings instead
571 * @todo remove completely in MDL-40517
573 function get_default_course_role($course) {
574 throw new coding_exception('get_default_course_role() can not be used any more, please use enrol plugin settings instead!');
578 * @deprecated use get_string_manager()->get_list_of_translations() instead.
579 * @todo remove completely in MDL-40517
581 function get_list_of_languages($refreshcache=false, $returnall=false) {
582 throw new coding_exception('get_list_of_languages() can not be used any more, please use get_string_manager()->get_list_of_translations() instead.');
586 * @deprecated use get_string_manager()->get_list_of_currencies() instead.
587 * @todo remove completely in MDL-40517
589 function get_list_of_currencies() {
590 throw new coding_exception('get_list_of_currencies() can not be used any more, please use get_string_manager()->get_list_of_currencies() instead.');
594 * @deprecated use get_string_manager()->get_list_of_countries() instead.
595 * @todo remove completely in MDL-40517
597 function get_list_of_countries() {
598 throw new coding_exception('get_list_of_countries() can not be used any more, please use get_string_manager()->get_list_of_countries() instead.');
602 * Return all course participant for a given course
604 * @deprecated use get_enrolled_users($context) instead.
605 * @todo final deprecation of this function in MDL-40607
606 * @param integer $courseid
607 * @return array of user
609 function get_course_participants($courseid) {
610 debugging('get_course_participants() is deprecated, use get_enrolled_users() instead.', DEBUG_DEVELOPER);
611 return get_enrolled_users(context_course::instance($courseid));
615 * Return true if the user is a participant for a given course
617 * @deprecated use is_enrolled($context, $userid) instead.
618 * @todo final deprecation of this function in MDL-40607
619 * @param integer $userid
620 * @param integer $courseid
621 * @return boolean
623 function is_course_participant($userid, $courseid) {
624 debugging('is_course_participant() is deprecated, use is_enrolled() instead.', DEBUG_DEVELOPER);
625 return is_enrolled(context_course::instance($courseid), $userid);
629 * Searches logs to find all enrolments since a certain date
631 * used to print recent activity
633 * @param int $courseid The course in question.
634 * @param int $timestart The date to check forward of
635 * @return object|false {@link $USER} records or false if error.
637 function get_recent_enrolments($courseid, $timestart) {
638 global $DB;
640 debugging('get_recent_enrolments() is deprecated as it returned inaccurate results.', DEBUG_DEVELOPER);
642 $context = context_course::instance($courseid);
643 $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
644 FROM {user} u, {role_assignments} ra, {log} l
645 WHERE l.time > ?
646 AND l.course = ?
647 AND l.module = 'course'
648 AND l.action = 'enrol'
649 AND ".$DB->sql_cast_char2int('l.info')." = u.id
650 AND u.id = ra.userid
651 AND ra.contextid ".get_related_contexts_string($context)."
652 GROUP BY u.id, u.firstname, u.lastname
653 ORDER BY MAX(l.time) ASC";
654 $params = array($timestart, $courseid);
655 return $DB->get_records_sql($sql, $params);
658 ########### FROM weblib.php ##########################################################################
661 * @deprecated use $OUTPUT->box() instead.
662 * @todo remove completely in MDL-40517
664 function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
665 throw new coding_exception('print_simple_box can not be used any more. Please use $OUTPUT->box() instead');
669 * @deprecated use $OUTPUT->box_start instead.
670 * @todo remove completely in MDL-40517
672 function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
673 throw new coding_exception('print_simple_box_start can not be used any more. Please use $OUTPUT->box_start instead');
677 * @deprecated use $OUTPUT->box_end instead.
678 * @todo remove completely in MDL-40517
680 function print_simple_box_end($return=false) {
681 throw new coding_exception('print_simple_box_end can not be used any more. Please use $OUTPUT->box_end instead');
685 * @deprecated the urltolink filter now does this job.
686 * @todo remove completely in MDL-40517
688 function convert_urls_into_links($text) {
689 throw new coding_exception('convert_urls_into_links() can not be used any more and replaced by the urltolink filter');
693 * @deprecated use the emoticon_manager class instead.
694 * @todo remove completely in MDL-40517
696 function get_emoticons_list_for_help_file() {
697 throw new coding_exception('get_emoticons_list_for_help_file() can not be used any more, use the new emoticon_manager API instead');
701 * @deprecated use emoticon filter now does this job.
702 * @todo remove completely in MDL-40517
704 function replace_smilies(&$text) {
705 throw new coding_exception('replace_smilies() can not be used any more and replaced with the emoticon filter.');
709 * @deprecated use clean_param($string, PARAM_FILE) instead.
710 * @todo final deprecation of this function in MDL-40607
712 * @param string $string ?
713 * @param int $allowdots ?
714 * @return bool
716 function detect_munged_arguments($string, $allowdots=1) {
717 debugging('detect_munged_arguments() is deprecated, please use clean_param(,PARAM_FILE) instead.', DEBUG_DEVELOPER);
718 if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
719 return true;
721 if (preg_match('/[\|\`]/', $string)) { // check for other bad characters
722 return true;
724 if (empty($string) or $string == '/') {
725 return true;
728 return false;
733 * Unzip one zip file to a destination dir
734 * Both parameters must be FULL paths
735 * If destination isn't specified, it will be the
736 * SAME directory where the zip file resides.
738 * @global object
739 * @param string $zipfile The zip file to unzip
740 * @param string $destination The location to unzip to
741 * @param bool $showstatus_ignored Unused
743 function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
744 global $CFG;
746 //Extract everything from zipfile
747 $path_parts = pathinfo(cleardoubleslashes($zipfile));
748 $zippath = $path_parts["dirname"]; //The path of the zip file
749 $zipfilename = $path_parts["basename"]; //The name of the zip file
750 $extension = $path_parts["extension"]; //The extension of the file
752 //If no file, error
753 if (empty($zipfilename)) {
754 return false;
757 //If no extension, error
758 if (empty($extension)) {
759 return false;
762 //Clear $zipfile
763 $zipfile = cleardoubleslashes($zipfile);
765 //Check zipfile exists
766 if (!file_exists($zipfile)) {
767 return false;
770 //If no destination, passed let's go with the same directory
771 if (empty($destination)) {
772 $destination = $zippath;
775 //Clear $destination
776 $destpath = rtrim(cleardoubleslashes($destination), "/");
778 //Check destination path exists
779 if (!is_dir($destpath)) {
780 return false;
783 $packer = get_file_packer('application/zip');
785 $result = $packer->extract_to_pathname($zipfile, $destpath);
787 if ($result === false) {
788 return false;
791 foreach ($result as $status) {
792 if ($status !== true) {
793 return false;
797 return true;
801 * Zip an array of files/dirs to a destination zip file
802 * Both parameters must be FULL paths to the files/dirs
804 * @global object
805 * @param array $originalfiles Files to zip
806 * @param string $destination The destination path
807 * @return bool Outcome
809 function zip_files ($originalfiles, $destination) {
810 global $CFG;
812 //Extract everything from destination
813 $path_parts = pathinfo(cleardoubleslashes($destination));
814 $destpath = $path_parts["dirname"]; //The path of the zip file
815 $destfilename = $path_parts["basename"]; //The name of the zip file
816 $extension = $path_parts["extension"]; //The extension of the file
818 //If no file, error
819 if (empty($destfilename)) {
820 return false;
823 //If no extension, add it
824 if (empty($extension)) {
825 $extension = 'zip';
826 $destfilename = $destfilename.'.'.$extension;
829 //Check destination path exists
830 if (!is_dir($destpath)) {
831 return false;
834 //Check destination path is writable. TODO!!
836 //Clean destination filename
837 $destfilename = clean_filename($destfilename);
839 //Now check and prepare every file
840 $files = array();
841 $origpath = NULL;
843 foreach ($originalfiles as $file) { //Iterate over each file
844 //Check for every file
845 $tempfile = cleardoubleslashes($file); // no doubleslashes!
846 //Calculate the base path for all files if it isn't set
847 if ($origpath === NULL) {
848 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
850 //See if the file is readable
851 if (!is_readable($tempfile)) { //Is readable
852 continue;
854 //See if the file/dir is in the same directory than the rest
855 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
856 continue;
858 //Add the file to the array
859 $files[] = $tempfile;
862 $zipfiles = array();
863 $start = strlen($origpath)+1;
864 foreach($files as $file) {
865 $zipfiles[substr($file, $start)] = $file;
868 $packer = get_file_packer('application/zip');
870 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
874 * Get the IDs for the user's groups in the given course.
876 * @global object
877 * @param int $courseid The course being examined - the 'course' table id field.
878 * @return array|bool An _array_ of groupids, or false
879 * (Was return $groupids[0] - consequences!)
880 * @deprecated use groups_get_all_groups() instead.
881 * @todo final deprecation of this function in MDL-40607
883 function mygroupid($courseid) {
884 global $USER;
886 debugging('mygroupid() is deprecated, please use groups_get_all_groups() instead.', DEBUG_DEVELOPER);
888 if ($groups = groups_get_all_groups($courseid, $USER->id)) {
889 return array_keys($groups);
890 } else {
891 return false;
897 * Returns the current group mode for a given course or activity module
899 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
901 * @param object $course Course Object
902 * @param object $cm Course Manager Object
903 * @return mixed $course->groupmode
905 function groupmode($course, $cm=null) {
907 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
908 return $cm->groupmode;
910 return $course->groupmode;
914 * Sets the current group in the session variable
915 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
916 * Sets currentgroup[$courseid] in the session variable appropriately.
917 * Does not do any permission checking.
919 * @global object
920 * @param int $courseid The course being examined - relates to id field in
921 * 'course' table.
922 * @param int $groupid The group being examined.
923 * @return int Current group id which was set by this function
925 function set_current_group($courseid, $groupid) {
926 global $SESSION;
927 return $SESSION->currentgroup[$courseid] = $groupid;
932 * Gets the current group - either from the session variable or from the database.
934 * @global object
935 * @param int $courseid The course being examined - relates to id field in
936 * 'course' table.
937 * @param bool $full If true, the return value is a full record object.
938 * If false, just the id of the record.
939 * @return int|bool
941 function get_current_group($courseid, $full = false) {
942 global $SESSION;
944 if (isset($SESSION->currentgroup[$courseid])) {
945 if ($full) {
946 return groups_get_group($SESSION->currentgroup[$courseid]);
947 } else {
948 return $SESSION->currentgroup[$courseid];
952 $mygroupid = mygroupid($courseid);
953 if (is_array($mygroupid)) {
954 $mygroupid = array_shift($mygroupid);
955 set_current_group($courseid, $mygroupid);
956 if ($full) {
957 return groups_get_group($mygroupid);
958 } else {
959 return $mygroupid;
963 if ($full) {
964 return false;
965 } else {
966 return 0;
972 * Inndicates fatal error. This function was originally printing the
973 * error message directly, since 2.0 it is throwing exception instead.
974 * The error printing is handled in default exception handler.
976 * Old method, don't call directly in new code - use print_error instead.
978 * @param string $message The message to display to the user about the error.
979 * @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.
980 * @return void, always throws moodle_exception
982 function error($message, $link='') {
983 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
988 * @deprecated use $PAGE->requires->js_module() instead.
990 function require_js($lib) {
991 throw new coding_exception('require_js() was removed, use new JS api');
995 * @deprecated use $PAGE->theme->name instead.
996 * @todo final deprecation of this function in MDL-40607
997 * @return string the name of the current theme.
999 function current_theme() {
1000 global $PAGE;
1002 debugging('current_theme() is deprecated, please use $PAGE->theme->name instead', DEBUG_DEVELOPER);
1003 return $PAGE->theme->name;
1007 * Prints some red text using echo
1009 * @deprecated
1010 * @param string $error The text to be displayed in red
1012 function formerr($error) {
1013 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
1014 global $OUTPUT;
1015 echo $OUTPUT->error_text($error);
1019 * Return the markup for the destination of the 'Skip to main content' links.
1020 * Accessibility improvement for keyboard-only users.
1022 * Used in course formats, /index.php and /course/index.php
1024 * @deprecated use $OUTPUT->skip_link_target() in instead.
1025 * @todo final deprecation of this function in MDL-40607
1026 * @return string HTML element.
1028 function skip_main_destination() {
1029 global $OUTPUT;
1031 debugging('skip_main_destination() is deprecated, please use $OUTPUT->skip_link_target() instead.', DEBUG_DEVELOPER);
1032 return $OUTPUT->skip_link_target();
1036 * @deprecated use $OUTPUT->heading() instead.
1037 * @todo remove completely in MDL-40517
1039 function print_headline($text, $size=2, $return=false) {
1040 throw new coding_exception('print_headline() can not be used any more. Please use $OUTPUT->heading() instead.');
1044 * @deprecated use $OUTPUT->heading() instead.
1045 * @todo remove completely in MDL-40517
1047 function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
1048 throw new coding_exception('print_heading() can not be used any more. Please use $OUTPUT->heading() instead.');
1052 * @deprecated use $OUTPUT->heading() instead.
1053 * @todo remove completely in MDL-40517
1055 function print_heading_block($heading, $class='', $return=false) {
1056 throw new coding_exception('print_heading_with_block() can not be used any more. Please use $OUTPUT->heading() instead.');
1060 * @deprecated use $OUTPUT->box() instead.
1061 * @todo remove completely in MDL-40517
1063 function print_box($message, $classes='generalbox', $ids='', $return=false) {
1064 throw new coding_exception('print_box() can not be used any more. Please use $OUTPUT->box() instead.');
1068 * @deprecated use $OUTPUT->box_start() instead.
1069 * @todo remove completely in MDL-40517
1071 function print_box_start($classes='generalbox', $ids='', $return=false) {
1072 throw new coding_exception('print_box_start() can not be used any more. Please use $OUTPUT->box_start() instead.');
1076 * @deprecated use $OUTPUT->box_end() instead.
1077 * @todo remove completely in MDL-40517
1079 function print_box_end($return=false) {
1080 throw new coding_exception('print_box_end() can not be used any more. Please use $OUTPUT->box_end() instead.');
1084 * Print a message in a standard themed container.
1086 * @deprecated use $OUTPUT->container() instead.
1087 * @todo final deprecation of this function in MDL-40607
1088 * @param string $message, the content of the container
1089 * @param boolean $clearfix clear both sides
1090 * @param string $classes, space-separated class names.
1091 * @param string $idbase
1092 * @param boolean $return, return as string or just print it
1093 * @return string|void Depending on value of $return
1095 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
1096 global $OUTPUT;
1098 debugging('print_container() is deprecated. Please use $OUTPUT->container() instead.', DEBUG_DEVELOPER);
1099 if ($clearfix) {
1100 $classes .= ' clearfix';
1102 $output = $OUTPUT->container($message, $classes, $idbase);
1103 if ($return) {
1104 return $output;
1105 } else {
1106 echo $output;
1111 * Starts a container using divs
1113 * @deprecated use $OUTPUT->container_start() instead.
1114 * @todo final deprecation of this function in MDL-40607
1115 * @param boolean $clearfix clear both sides
1116 * @param string $classes, space-separated class names.
1117 * @param string $idbase
1118 * @param boolean $return, return as string or just print it
1119 * @return string|void Based on value of $return
1121 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
1122 global $OUTPUT;
1124 debugging('print_container_start() is deprecated. Please use $OUTPUT->container_start() instead.', DEBUG_DEVELOPER);
1126 if ($clearfix) {
1127 $classes .= ' clearfix';
1129 $output = $OUTPUT->container_start($classes, $idbase);
1130 if ($return) {
1131 return $output;
1132 } else {
1133 echo $output;
1138 * @deprecated do not use any more, is not automatic
1139 * @todo remove completely in MDL-40517
1141 function check_theme_arrows() {
1142 throw new coding_exception('check_theme_arrows() has been deprecated, do not use it anymore, it is now automatic.');
1146 * Simple function to end a container (see above)
1148 * @deprecated use $OUTPUT->container_end() instead.
1149 * @todo final deprecation of this function in MDL-40607
1150 * @param boolean $return, return as string or just print it
1151 * @return string|void Based on $return
1153 function print_container_end($return=false) {
1154 global $OUTPUT;
1155 debugging('print_container_end() is deprecated. Please use $OUTPUT->container_end() instead.', DEBUG_DEVELOPER);
1156 $output = $OUTPUT->container_end();
1157 if ($return) {
1158 return $output;
1159 } else {
1160 echo $output;
1165 * Print a bold message in an optional color.
1167 * @deprecated use $OUTPUT->notification instead.
1168 * @param string $message The message to print out
1169 * @param string $style Optional style to display message text in
1170 * @param string $align Alignment option
1171 * @param bool $return whether to return an output string or echo now
1172 * @return string|bool Depending on $result
1174 function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
1175 global $OUTPUT;
1177 if ($classes == 'green') {
1178 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
1179 $classes = 'notifysuccess'; // Backward compatible with old color system
1182 $output = $OUTPUT->notification($message, $classes);
1183 if ($return) {
1184 return $output;
1185 } else {
1186 echo $output;
1191 * Print a continue button that goes to a particular URL.
1193 * @deprecated use $OUTPUT->continue_button() instead.
1194 * @todo final deprecation of this function in MDL-40607
1196 * @param string $link The url to create a link to.
1197 * @param bool $return If set to true output is returned rather than echoed, default false
1198 * @return string|void HTML String if return=true nothing otherwise
1200 function print_continue($link, $return = false) {
1201 global $CFG, $OUTPUT;
1203 debugging('print_continue() is deprecated. Please use $OUTPUT->continue_button() instead.', DEBUG_DEVELOPER);
1205 if ($link == '') {
1206 if (!empty($_SERVER['HTTP_REFERER'])) {
1207 $link = $_SERVER['HTTP_REFERER'];
1208 $link = str_replace('&', '&amp;', $link); // make it valid XHTML
1209 } else {
1210 $link = $CFG->wwwroot .'/';
1214 $output = $OUTPUT->continue_button($link);
1215 if ($return) {
1216 return $output;
1217 } else {
1218 echo $output;
1223 * Print a standard header
1225 * @deprecated use $PAGE methods instead.
1226 * @todo final deprecation of this function in MDL-40607
1227 * @param string $title Appears at the top of the window
1228 * @param string $heading Appears at the top of the page
1229 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
1230 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1231 * @param string $meta Meta tags to be added to the header
1232 * @param boolean $cache Should this page be cacheable?
1233 * @param string $button HTML code for a button (usually for module editing)
1234 * @param string $menu HTML code for a popup menu
1235 * @param boolean $usexml use XML for this page
1236 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1237 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1238 * @return string|void If return=true then string else void
1240 function print_header($title='', $heading='', $navigation='', $focus='',
1241 $meta='', $cache=true, $button='&nbsp;', $menu=null,
1242 $usexml=false, $bodytags='', $return=false) {
1243 global $PAGE, $OUTPUT;
1245 debugging('print_header() is deprecated. Please use $PAGE methods instead.', DEBUG_DEVELOPER);
1247 $PAGE->set_title($title);
1248 $PAGE->set_heading($heading);
1249 $PAGE->set_cacheable($cache);
1250 if ($button == '') {
1251 $button = '&nbsp;';
1253 $PAGE->set_button($button);
1254 $PAGE->set_headingmenu($menu);
1256 // TODO $menu
1258 if ($meta) {
1259 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1260 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1262 if ($usexml) {
1263 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1265 if ($bodytags) {
1266 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1269 $output = $OUTPUT->header();
1271 if ($return) {
1272 return $output;
1273 } else {
1274 echo $output;
1279 * This version of print_header is simpler because the course name does not have to be
1280 * provided explicitly in the strings. It can be used on the site page as in courses
1281 * Eventually all print_header could be replaced by print_header_simple
1283 * @deprecated use $PAGE methods instead.
1284 * @todo final deprecation of this function in MDL-40607
1285 * @param string $title Appears at the top of the window
1286 * @param string $heading Appears at the top of the page
1287 * @param string $navigation Premade navigation string (for use as breadcrumbs links)
1288 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1289 * @param string $meta Meta tags to be added to the header
1290 * @param boolean $cache Should this page be cacheable?
1291 * @param string $button HTML code for a button (usually for module editing)
1292 * @param string $menu HTML code for a popup menu
1293 * @param boolean $usexml use XML for this page
1294 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1295 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1296 * @return string|void If $return=true the return string else nothing
1298 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
1299 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
1301 global $COURSE, $CFG, $PAGE, $OUTPUT;
1303 debugging('print_header_simple() is deprecated. Please use $PAGE methods instead.', DEBUG_DEVELOPER);
1305 if ($meta) {
1306 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1307 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1309 if ($usexml) {
1310 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1312 if ($bodytags) {
1313 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1316 $PAGE->set_title($title);
1317 $PAGE->set_heading($heading);
1318 $PAGE->set_cacheable(true);
1319 $PAGE->set_button($button);
1321 $output = $OUTPUT->header();
1323 if ($return) {
1324 return $output;
1325 } else {
1326 echo $output;
1331 * @deprecated use $OUTPUT->footer() instead.
1332 * @todo remove completely in MDL-40517
1334 function print_footer($course = NULL, $usercourse = NULL, $return = false) {
1335 throw new coding_exception('print_footer() cant be used anymore. Please use $OUTPUT->footer() instead.');
1339 * @deprecated use theme layouts instead.
1340 * @todo remove completely in MDL-40517
1342 function user_login_string($course='ignored', $user='ignored') {
1343 throw new coding_exception('user_login_info() cant be used anymore. User login info is now handled via themes layouts.');
1347 * Prints a nice side block with an optional header. The content can either
1348 * be a block of HTML or a list of text with optional icons.
1350 * @static int $block_id Increments for each call to the function
1351 * @param string $heading HTML for the heading. Can include full HTML or just
1352 * plain text - plain text will automatically be enclosed in the appropriate
1353 * heading tags.
1354 * @param string $content HTML for the content
1355 * @param array $list an alternative to $content, it you want a list of things with optional icons.
1356 * @param array $icons optional icons for the things in $list.
1357 * @param string $footer Extra HTML content that gets output at the end, inside a &lt;div class="footer">
1358 * @param array $attributes an array of attribute => value pairs that are put on the
1359 * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
1360 * already a class, class='block' is used.
1361 * @param string $title Plain text title, as embedded in the $heading.
1362 * @deprecated use $OUTPUT->block() instead.
1363 * @todo final deprecation of this function in MDL-40607
1365 function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
1366 global $OUTPUT;
1368 debugging('print_side_block() is deprecated, please use $OUTPUT->block() instead.', DEBUG_DEVELOPER);
1369 // We don't use $heading, becuse it often contains HTML that we don't want.
1370 // However, sometimes $title is not set, but $heading is.
1371 if (empty($title)) {
1372 $title = strip_tags($heading);
1375 // Render list contents to HTML if required.
1376 if (empty($content) && $list) {
1377 $content = $OUTPUT->list_block_contents($icons, $list);
1380 $bc = new block_contents();
1381 $bc->content = $content;
1382 $bc->footer = $footer;
1383 $bc->title = $title;
1385 if (isset($attributes['id'])) {
1386 $bc->id = $attributes['id'];
1387 unset($attributes['id']);
1389 $bc->attributes = $attributes;
1391 echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
1395 * @deprecated blocks are now printed by theme.
1396 * @todo remove completely in MDL-40517
1398 function blocks_have_content(&$blockmanager, $region) {
1399 throw new coding_exception('blocks_have_content() can no longer be used. Blocks are now printed by the theme.');
1403 * @deprecated blocks are now printed by the theme.
1404 * @todo remove completely in MDL-40517
1406 function blocks_print_group($page, $blockmanager, $region) {
1407 throw new coding_exception('function blocks_print_group() can no longer be used. Blocks are now printed by the theme.');
1411 * @deprecated blocks are now printed by the theme.
1412 * @todo remove completely in MDL-40517
1414 function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
1415 throw new coding_exception('blocks_print_group() can no longer be used. Blocks are now printed by the theme.');
1419 * @deprecated Layout is now controlled by the theme.
1420 * @todo remove completely in MDL-40517
1422 function blocks_preferred_width($instances) {
1423 throw new coding_exception('blocks_print_group() can no longer be used. Blocks are now printed by the theme.');
1427 * @deprecated use html_writer::table() instead.
1428 * @todo remove completely in MDL-40517
1430 function print_table($table, $return=false) {
1431 throw new coding_exception('print_table() can no longer be used. Use html_writer::table() instead.');
1435 * @deprecated use $OUTPUT->action_link() instead (note: popups are discouraged for accesibility reasons)
1436 * @todo remove completely in MDL-40517
1438 function link_to_popup_window ($url, $name=null, $linkname=null, $height=400, $width=500, $title=null, $options=null, $return=false) {
1439 throw new coding_exception('link_to_popup_window() can no longer be used. Please to use $OUTPUT->action_link() instead.');
1443 * @deprecated use $OUTPUT->single_button() instead.
1444 * @todo remove completely in MDL-40517
1446 function button_to_popup_window ($url, $name=null, $linkname=null,
1447 $height=400, $width=500, $title=null, $options=null, $return=false,
1448 $id=null, $class=null) {
1449 throw new coding_exception('button_to_popup_window() can no longer be used. Please use $OUTPUT->single_button() instead.');
1453 * @deprecated use $OUTPUT->single_button() instead.
1454 * @todo remove completely in MDL-40517
1456 function print_single_button($link, $options, $label='OK', $method='get', $notusedanymore='',
1457 $return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
1459 throw new coding_exception('print_single_button() can no longer be used. Please use $OUTPUT->single_button() instead.');
1463 * @deprecated use $OUTPUT->spacer() instead.
1464 * @todo remove completely in MDL-40517
1466 function print_spacer($height=1, $width=1, $br=true, $return=false) {
1467 throw new coding_exception('print_spacer() can no longer be used. Please use $OUTPUT->spacer() instead.');
1471 * @deprecated use $OUTPUT->user_picture() instead.
1472 * @todo remove completely in MDL-40517
1474 function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
1475 throw new coding_exception('print_user_picture() can no longer be used. Please use $OUTPUT->user_picture($user, array(\'courseid\'=>$courseid) instead.');
1479 * Prints a basic textarea field.
1481 * @deprecated since Moodle 2.0
1483 * When using this function, you should
1485 * @global object
1486 * @param bool $unused No longer used.
1487 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
1488 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
1489 * @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.
1490 * @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.
1491 * @param string $name Name to use for the textarea element.
1492 * @param string $value Initial content to display in the textarea.
1493 * @param int $obsolete deprecated
1494 * @param bool $return If false, will output string. If true, will return string value.
1495 * @param string $id CSS ID to add to the textarea element.
1496 * @return string|void depending on the value of $return
1498 function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
1499 /// $width and height are legacy fields and no longer used as pixels like they used to be.
1500 /// However, you can set them to zero to override the mincols and minrows values below.
1502 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
1503 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
1505 global $CFG;
1507 $mincols = 65;
1508 $minrows = 10;
1509 $str = '';
1511 if ($id === '') {
1512 $id = 'edit-'.$name;
1515 if ($height && ($rows < $minrows)) {
1516 $rows = $minrows;
1518 if ($width && ($cols < $mincols)) {
1519 $cols = $mincols;
1522 editors_head_setup();
1523 $editor = editors_get_preferred_editor(FORMAT_HTML);
1524 $editor->use_editor($id, array('legacy'=>true));
1526 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'" spellcheck="true">'."\n";
1527 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
1528 $str .= '</textarea>'."\n";
1530 if ($return) {
1531 return $str;
1533 echo $str;
1538 * Print a help button.
1540 * @deprecated since Moodle 2.0
1542 function helpbutton($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false, $imagetext='') {
1543 throw new coding_exception('helpbutton() can not be used any more, please see $OUTPUT->help_icon().');
1547 * @deprecated this is now handled by text editors
1548 * @todo remove completely in MDL-40517
1550 function emoticonhelpbutton($form, $field, $return = false) {
1551 throw new coding_exception('emoticonhelpbutton() was removed, new text editors will implement this feature');
1555 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
1556 * Should be used only with htmleditor or textarea.
1558 * @global object
1559 * @global object
1560 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
1561 * helpbutton.
1562 * @return string Link to help button
1564 function editorhelpbutton(){
1565 return '';
1567 /// TODO: MDL-21215
1571 * Print a help button.
1573 * Prints a special help button for html editors (htmlarea in this case)
1575 * @todo Write code into this function! detect current editor and print correct info
1576 * @global object
1577 * @return string Only returns an empty string at the moment
1579 function editorshortcutshelpbutton() {
1580 /// TODO: MDL-21215
1582 global $CFG;
1583 //TODO: detect current editor and print correct info
1584 return '';
1589 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
1590 * provide this function with the language strings for sortasc and sortdesc.
1592 * @deprecated use $OUTPUT->arrow() instead.
1593 * @todo final deprecation of this function in MDL-40607
1595 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
1597 * @global object
1598 * @param string $direction 'up' or 'down'
1599 * @param string $strsort The language string used for the alt attribute of this image
1600 * @param bool $return Whether to print directly or return the html string
1601 * @return string|void depending on $return
1604 function print_arrow($direction='up', $strsort=null, $return=false) {
1605 global $OUTPUT;
1607 debugging('print_arrow() is deprecated. Please use $OUTPUT->arrow() instead.', DEBUG_DEVELOPER);
1609 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
1610 return null;
1613 $return = null;
1615 switch ($direction) {
1616 case 'up':
1617 $sortdir = 'asc';
1618 break;
1619 case 'down':
1620 $sortdir = 'desc';
1621 break;
1622 case 'move':
1623 $sortdir = 'asc';
1624 break;
1625 default:
1626 $sortdir = null;
1627 break;
1630 // Prepare language string
1631 $strsort = '';
1632 if (empty($strsort) && !empty($sortdir)) {
1633 $strsort = get_string('sort' . $sortdir, 'grades');
1636 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
1638 if ($return) {
1639 return $return;
1640 } else {
1641 echo $return;
1646 * Returns a string containing a link to the user documentation.
1647 * Also contains an icon by default. Shown to teachers and admin only.
1649 * @deprecated since Moodle 2.0
1651 function doc_link($path='', $text='', $iconpath='ignored') {
1652 throw new coding_exception('doc_link() can not be used any more, please see $OUTPUT->doc_link().');
1656 * @deprecated use $OUTPUT->render($pagingbar) instead.
1657 * @todo remove completely in MDL-40517
1659 function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) {
1660 throw new coding_exception('print_paging_bar() can not be used any more. Please use $OUTPUT->render($pagingbar) instead.');
1664 * @deprecated use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel) instead.
1665 * @todo remove completely in MDL-40517
1667 function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
1668 throw new coding_exception('notice_yesno() can not be used any more. Please use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel) instead.');
1672 * Given an array of values, output the HTML for a select element with those options.
1674 * @deprecated since Moodle 2.0
1676 * Normally, you only need to use the first few parameters.
1678 * @param array $options The options to offer. An array of the form
1679 * $options[{value}] = {text displayed for that option};
1680 * @param string $name the name of this form control, as in &lt;select name="..." ...
1681 * @param string $selected the option to select initially, default none.
1682 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
1683 * Set this to '' if you don't want a 'nothing is selected' option.
1684 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
1685 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
1686 * @param boolean $return if false (the default) the the output is printed directly, If true, the
1687 * generated HTML is returned as a string.
1688 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
1689 * @param int $tabindex if give, sets the tabindex attribute on the &lt;select> element. Default none.
1690 * @param string $id value to use for the id attribute of the &lt;select> element. If none is given,
1691 * then a suitable one is constructed.
1692 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
1693 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
1694 * $listbox is an integer, that number is used for size instead.
1695 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
1696 * when $listbox display is enabled
1697 * @param string $class value to use for the class attribute of the &lt;select> element. If none is given,
1698 * then a suitable one is constructed.
1699 * @return string|void If $return=true returns string, else echo's and returns void
1701 function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
1702 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
1703 $id='', $listbox=false, $multiple=false, $class='') {
1705 global $OUTPUT;
1706 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
1708 if ($script) {
1709 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
1711 $attributes = array();
1712 $attributes['disabled'] = $disabled ? 'disabled' : null;
1713 $attributes['tabindex'] = $tabindex ? $tabindex : null;
1714 $attributes['multiple'] = $multiple ? $multiple : null;
1715 $attributes['class'] = $class ? $class : null;
1716 $attributes['id'] = $id ? $id : null;
1718 $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
1720 if ($return) {
1721 return $output;
1722 } else {
1723 echo $output;
1728 * @deprecated use html_writer::select_yes_no() instead.
1729 * @todo remove completely in MDL-40517
1731 function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) {
1732 throw new coding_exception('choose_from_menu_yesno() can not be used anymore. Please use html_writerselect_yes_no() instead.');
1736 * @deprecated use html_writer::select() instead.
1737 * @todo remove completely in MDL-40517
1739 function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '',
1740 $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) {
1742 throw new coding_exception('choose_from_menu_nested() can not be used any more. Please use html_writer::select() instead.');
1746 * Prints a help button about a scale
1748 * @deprecated use $OUTPUT->help_icon_scale($courseid, $scale) instead.
1749 * @todo final deprecation of this function in MDL-40607
1751 * @global object
1752 * @param id $courseid
1753 * @param object $scale
1754 * @param boolean $return If set to true returns rather than echo's
1755 * @return string|bool Depending on value of $return
1757 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
1758 global $OUTPUT;
1760 debugging('print_scale_menu_helpbutton() is deprecated. Please use $OUTPUT->help_icon_scale($courseid, $scale) instead.', DEBUG_DEVELOPER);
1762 $output = $OUTPUT->help_icon_scale($courseid, $scale);
1764 if ($return) {
1765 return $output;
1766 } else {
1767 echo $output;
1772 * @deprecated use html_writer::select_time() instead
1773 * @todo remove completely in MDL-40517
1775 function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
1776 throw new moodle_exception('print_time_selector() can not be used any more . Please use html_writer::select_time() instead.');
1780 * @deprecated please use html_writer::select_time instead
1781 * @todo remove completely in MDL-40517
1783 function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
1784 throw new coding_exception('print_date_selector() can not be used any more. Please use html_writer::select_time() instead.');
1788 * Implements a complete little form with a dropdown menu.
1790 * @deprecated since Moodle 2.0
1792 function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false,
1793 $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) {
1794 throw new coding_exception('popup_form() can not be used any more, please see $OUTPUT->single_select or $OUTPUT->url_select().');
1798 * @deprecated use $OUTPUT->close_window_button() instead.
1799 * @todo remove completely in MDL-40517
1801 function close_window_button($name='closewindow', $return=false, $reloadopener = false) {
1802 throw new coding_exception('close_window_button() can not be used any more. Use $OUTPUT->close_window_button() instead.');
1806 * @deprecated use html_writer instead.
1807 * @todo remove completely in MDL-40517
1809 function choose_from_radio ($options, $name, $checked='', $return=false) {
1810 throw new coding_exception('choose_from_radio() can not be used any more. Please use html_writer instead.');
1814 * Display an standard html checkbox with an optional label
1816 * @deprecated use html_writer::checkbox() instead.
1817 * @todo final deprecation of this function in MDL-40607
1819 * @staticvar int $idcounter
1820 * @param string $name The name of the checkbox
1821 * @param string $value The valus that the checkbox will pass when checked
1822 * @param bool $checked The flag to tell the checkbox initial state
1823 * @param string $label The label to be showed near the checkbox
1824 * @param string $alt The info to be inserted in the alt tag
1825 * @param string $script If not '', then this is added to the checkbox element
1826 * as an onchange handler.
1827 * @param bool $return Whether this function should return a string or output
1828 * it (defaults to false)
1829 * @return string|void If $return=true returns string, else echo's and returns void
1831 function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
1832 global $OUTPUT;
1834 debugging('print_checkbox() is deprecated. Please use html_writer::checkbox() instead.', DEBUG_DEVELOPER);
1836 if (!empty($script)) {
1837 debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER);
1840 $output = html_writer::checkbox($name, $value, $checked, $label);
1842 if (empty($return)) {
1843 echo $output;
1844 } else {
1845 return $output;
1851 * @deprecated use mforms or html_writer instead.
1852 * @todo remove completely in MDL-40517
1854 function print_textfield($name, $value, $alt = '', $size=50, $maxlength=0, $return=false) {
1855 throw new coding_exception('print_textfield() can not be used anymore. Please use mforms or html_writer instead.');
1860 * @deprecated use $OUTPUT->heading_with_help() instead
1861 * @todo remove completely in MDL-40517
1863 function print_heading_with_help($text, $helppage, $module='moodle', $icon=false, $return=false) {
1864 throw new coding_exception('print_heading_with_help() can not be used anymore. Please use $OUTPUT->heading_with_help() instead.');
1868 * @deprecated use $OUTPUT->edit_button() instead.
1869 * @todo remove completely in MDL-40517
1871 function update_tag_button($tagid) {
1872 throw new coding_exception('update_tag_button() can not be used any more. Please $OUTPUT->edit_button(moodle_url) instead.');
1877 * Prints the 'update this xxx' button that appears on module pages.
1879 * @deprecated since Moodle 2.0
1881 * @param string $cmid the course_module id.
1882 * @param string $ignored not used any more. (Used to be courseid.)
1883 * @param string $string the module name - get_string('modulename', 'xxx')
1884 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
1886 function update_module_button($cmid, $ignored, $string) {
1887 global $CFG, $OUTPUT;
1889 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
1891 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
1893 if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) {
1894 $string = get_string('updatethis', '', $string);
1896 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
1897 return $OUTPUT->single_button($url, $string);
1898 } else {
1899 return '';
1904 * @deprecated use $OUTPUT->edit_button() instead.
1905 * @todo remove completely in MDL-40517
1907 function update_course_icon($courseid) {
1908 throw new coding_exception('update_course_button() can not be used anymore. Please use $OUTPUT->edit_button(moodle_url) instead.');
1912 * Prints breadcrumb trail of links, called in theme/-/header.html
1914 * This function has now been deprecated please use output's navbar method instead
1915 * as shown below
1917 * <code php>
1918 * echo $OUTPUT->navbar();
1919 * </code>
1921 * @deprecated use $OUTPUT->navbar() instead
1922 * @todo final deprecation of this function in MDL-40607
1923 * @param mixed $navigation deprecated
1924 * @param string $separator OBSOLETE, and now deprecated
1925 * @param boolean $return False to echo the breadcrumb string (default), true to return it.
1926 * @return string|void String or null, depending on $return.
1928 function print_navigation ($navigation, $separator=0, $return=false) {
1929 global $OUTPUT,$PAGE;
1931 debugging('print_navigation() is deprecated, please update use $OUTPUT->navbar() instead.', DEBUG_DEVELOPER);
1933 $output = $OUTPUT->navbar();
1935 if ($return) {
1936 return $output;
1937 } else {
1938 echo $output;
1943 * This function will build the navigation string to be used by print_header
1944 * and others.
1946 * It automatically generates the site and course level (if appropriate) links.
1948 * If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums')
1949 * and activityinstances (e.g. 'General Developer Forum') navigation levels.
1951 * If you want to add any further navigation links after the ones this function generates,
1952 * the pass an array of extra link arrays like this:
1953 * array(
1954 * array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1),
1955 * array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2)
1957 * The normal case is to just add one further link, for example 'Editing forum' after
1958 * 'General Developer Forum', with no link.
1959 * To do that, you need to pass
1960 * array(array('name' => $linktext, 'link' => '', 'type' => 'title'))
1961 * However, becuase this is a very common case, you can use a shortcut syntax, and just
1962 * pass the string 'Editing forum', instead of an array as $extranavlinks.
1964 * At the moment, the link types only have limited significance. Type 'activity' is
1965 * recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types
1966 * that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'.
1967 * This really needs to be documented better. In the mean time, try to be consistent, it will
1968 * enable people to customise the navigation more in future.
1970 * When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course.
1971 * If you get the $cm object using the function get_coursemodule_from_instance or
1972 * get_coursemodule_from_id (as recommended) then this will be done for you automatically.
1973 * If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using
1974 * the $cm->module and $cm->instance fields, but this takes extra database queries, so a
1975 * warning is printed in developer debug mode.
1977 * @deprecated Please use $PAGE->navabar methods instead.
1978 * @todo final deprecation of this function in MDL-40607
1979 * @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you
1980 * only want one extra item with no link, you can pass a string instead. If you don't want
1981 * any extra links, pass an empty string.
1982 * @param mixed $cm deprecated
1983 * @return array Navigation array
1985 function build_navigation($extranavlinks, $cm = null) {
1986 global $CFG, $COURSE, $DB, $SITE, $PAGE;
1988 debugging('build_navigation() is deprecated, please use $PAGE->navbar methods instead.', DEBUG_DEVELOPER);
1989 if (is_array($extranavlinks) && count($extranavlinks)>0) {
1990 foreach ($extranavlinks as $nav) {
1991 if (array_key_exists('name', $nav)) {
1992 if (array_key_exists('link', $nav) && !empty($nav['link'])) {
1993 $link = $nav['link'];
1994 } else {
1995 $link = null;
1997 $PAGE->navbar->add($nav['name'],$link);
2002 return(array('newnav' => true, 'navlinks' => array()));
2006 * @deprecated not relevant with global navigation in Moodle 2.x+
2007 * @todo remove completely in MDL-40517
2009 function navmenu($course, $cm=NULL, $targetwindow='self') {
2010 // This function has been deprecated with the creation of the global nav in
2011 // moodle 2.0
2012 debugging('navmenu() is deprecated, it is no longer relevant with global navigation.', DEBUG_DEVELOPER);
2014 return '';
2018 * @deprecated use the settings block instead.
2019 * @todo remove completely in MDL-40517
2021 function switchroles_form($courseid) {
2022 throw new coding_exception('switchroles_form() can not be used any more. The global settings block does this job.');
2026 * @deprecated Please use normal $OUTPUT->header() instead
2027 * @todo remove completely in MDL-40517
2029 function admin_externalpage_print_header($focus='') {
2030 throw new coding_exception('admin_externalpage_print_header can not be used any more. Please $OUTPUT->header() instead.');
2034 * @deprecated Please use normal $OUTPUT->footer() instead
2035 * @todo remove completely in MDL-40517
2037 function admin_externalpage_print_footer() {
2038 throw new coding_exception('admin_externalpage_print_footer can not be used anymore Please $OUTPUT->footer() instead.');
2041 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
2045 * Call this function to add an event to the calendar table and to call any calendar plugins
2047 * @param object $event An object representing an event from the calendar table.
2048 * The event will be identified by the id field. The object event should include the following:
2049 * <ul>
2050 * <li><b>$event->name</b> - Name for the event
2051 * <li><b>$event->description</b> - Description of the event (defaults to '')
2052 * <li><b>$event->format</b> - Format for the description (using formatting types defined at the top of weblib.php)
2053 * <li><b>$event->courseid</b> - The id of the course this event belongs to (0 = all courses)
2054 * <li><b>$event->groupid</b> - The id of the group this event belongs to (0 = no group)
2055 * <li><b>$event->userid</b> - The id of the user this event belongs to (0 = no user)
2056 * <li><b>$event->modulename</b> - Name of the module that creates this event
2057 * <li><b>$event->instance</b> - Instance of the module that owns this event
2058 * <li><b>$event->eventtype</b> - The type info together with the module info could
2059 * be used by calendar plugins to decide how to display event
2060 * <li><b>$event->timestart</b>- Timestamp for start of event
2061 * <li><b>$event->timeduration</b> - Duration (defaults to zero)
2062 * <li><b>$event->visible</b> - 0 if the event should be hidden (e.g. because the activity that created it is hidden)
2063 * </ul>
2064 * @return int|false The id number of the resulting record or false if failed
2065 * @deprecated please use calendar_event::create() instead.
2066 * @todo final deprecation of this function in MDL-40607
2068 function add_event($event) {
2069 global $CFG;
2070 require_once($CFG->dirroot.'/calendar/lib.php');
2072 debugging('add_event() is deprecated, please use calendar_event::create() instead.', DEBUG_DEVELOPER);
2073 $event = calendar_event::create($event);
2074 if ($event !== false) {
2075 return $event->id;
2077 return false;
2081 * Call this function to update an event in the calendar table
2082 * the event will be identified by the id field of the $event object.
2084 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2085 * @return bool Success
2086 * @deprecated please calendar_event->update() instead.
2088 function update_event($event) {
2089 global $CFG;
2090 require_once($CFG->dirroot.'/calendar/lib.php');
2092 debugging('update_event() is deprecated, please use calendar_event->update() instead.', DEBUG_DEVELOPER);
2093 $event = (object)$event;
2094 $calendarevent = calendar_event::load($event->id);
2095 return $calendarevent->update($event);
2099 * Call this function to delete the event with id $id from calendar table.
2101 * @param int $id The id of an event from the 'event' table.
2102 * @return bool
2103 * @deprecated please use calendar_event->delete() instead.
2104 * @todo final deprecation of this function in MDL-40607
2106 function delete_event($id) {
2107 global $CFG;
2108 require_once($CFG->dirroot.'/calendar/lib.php');
2110 debugging('delete_event() is deprecated, please use calendar_event->delete() instead.', DEBUG_DEVELOPER);
2112 $event = calendar_event::load($id);
2113 return $event->delete();
2117 * Call this function to hide an event in the calendar table
2118 * the event will be identified by the id field of the $event object.
2120 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2121 * @return true
2122 * @deprecated please use calendar_event->toggle_visibility(false) instead.
2123 * @todo final deprecation of this function in MDL-40607
2125 function hide_event($event) {
2126 global $CFG;
2127 require_once($CFG->dirroot.'/calendar/lib.php');
2129 debugging('hide_event() is deprecated, please use calendar_event->toggle_visibility(false) instead.', DEBUG_DEVELOPER);
2131 $event = new calendar_event($event);
2132 return $event->toggle_visibility(false);
2136 * Call this function to unhide an event in the calendar table
2137 * the event will be identified by the id field of the $event object.
2139 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2140 * @return true
2141 * @deprecated please use calendar_event->toggle_visibility(true) instead.
2142 * @todo final deprecation of this function in MDL-40607
2144 function show_event($event) {
2145 global $CFG;
2146 require_once($CFG->dirroot.'/calendar/lib.php');
2148 debugging('show_event() is deprecated, please use calendar_event->toggle_visibility(true) instead.', DEBUG_DEVELOPER);
2150 $event = new calendar_event($event);
2151 return $event->toggle_visibility(true);
2155 * @deprecated Use core_text::strtolower($text) instead.
2157 function moodle_strtolower($string, $encoding='') {
2158 throw new coding_exception('moodle_strtolower() cannot be used any more. Please use core_text::strtolower() instead.');
2162 * Original singleton helper function, please use static methods instead,
2163 * ex: core_text::convert()
2165 * @deprecated since Moodle 2.2 use core_text::xxxx() instead
2166 * @see textlib
2167 * @return textlib instance
2169 function textlib_get_instance() {
2171 debugging('textlib_get_instance() is deprecated. Please use static calling core_text::functioname() instead.', DEBUG_DEVELOPER);
2173 return new textlib();
2177 * Gets the generic section name for a courses section
2179 * The global function is deprecated. Each course format can define their own generic section name
2181 * @deprecated since 2.4
2182 * @see get_section_name()
2183 * @see format_base::get_section_name()
2185 * @param string $format Course format ID e.g. 'weeks' $course->format
2186 * @param stdClass $section Section object from database
2187 * @return Display name that the course format prefers, e.g. "Week 2"
2189 function get_generic_section_name($format, stdClass $section) {
2190 debugging('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base', DEBUG_DEVELOPER);
2191 return get_string('sectionname', "format_$format") . ' ' . $section->section;
2195 * Returns an array of sections for the requested course id
2197 * It is usually not recommended to display the list of sections used
2198 * in course because the course format may have it's own way to do it.
2200 * If you need to just display the name of the section please call:
2201 * get_section_name($course, $section)
2202 * {@link get_section_name()}
2203 * from 2.4 $section may also be just the field course_sections.section
2205 * If you need the list of all sections it is more efficient to get this data by calling
2206 * $modinfo = get_fast_modinfo($courseorid);
2207 * $sections = $modinfo->get_section_info_all()
2208 * {@link get_fast_modinfo()}
2209 * {@link course_modinfo::get_section_info_all()}
2211 * Information about one section (instance of section_info):
2212 * get_fast_modinfo($courseorid)->get_sections_info($section)
2213 * {@link course_modinfo::get_section_info()}
2215 * @deprecated since 2.4
2217 * @param int $courseid
2218 * @return array Array of section_info objects
2220 function get_all_sections($courseid) {
2221 global $DB;
2222 debugging('get_all_sections() is deprecated. See phpdocs for this function', DEBUG_DEVELOPER);
2223 return get_fast_modinfo($courseid)->get_section_info_all();
2227 * Given a full mod object with section and course already defined, adds this module to that section.
2229 * This function is deprecated, please use {@link course_add_cm_to_section()}
2230 * Note that course_add_cm_to_section() also updates field course_modules.section and
2231 * calls rebuild_course_cache()
2233 * @deprecated since 2.4
2235 * @param object $mod
2236 * @param int $beforemod An existing ID which we will insert the new module before
2237 * @return int The course_sections ID where the mod is inserted
2239 function add_mod_to_section($mod, $beforemod = null) {
2240 debugging('Function add_mod_to_section() is deprecated, please use course_add_cm_to_section()', DEBUG_DEVELOPER);
2241 global $DB;
2242 return course_add_cm_to_section($mod->course, $mod->coursemodule, $mod->section, $beforemod);
2246 * Returns a number of useful structures for course displays
2248 * Function get_all_mods() is deprecated in 2.4
2249 * Instead of:
2250 * <code>
2251 * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
2252 * </code>
2253 * please use:
2254 * <code>
2255 * $mods = get_fast_modinfo($courseorid)->get_cms();
2256 * $modnames = get_module_types_names();
2257 * $modnamesplural = get_module_types_names(true);
2258 * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names();
2259 * </code>
2261 * @deprecated since 2.4
2263 * @param int $courseid id of the course to get info about
2264 * @param array $mods (return) list of course modules
2265 * @param array $modnames (return) list of names of all module types installed and available
2266 * @param array $modnamesplural (return) list of names of all module types installed and available in the plural form
2267 * @param array $modnamesused (return) list of names of all module types used in the course
2269 function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
2270 debugging('Function get_all_mods() is deprecated. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details', DEBUG_DEVELOPER);
2272 global $COURSE;
2273 $modnames = get_module_types_names();
2274 $modnamesplural= get_module_types_names(true);
2275 $modinfo = get_fast_modinfo($courseid);
2276 $mods = $modinfo->get_cms();
2277 $modnamesused = $modinfo->get_used_module_names();
2281 * Returns course section - creates new if does not exist yet
2283 * This function is deprecated. To create a course section call:
2284 * course_create_sections_if_missing($courseorid, $sections);
2285 * to get the section call:
2286 * get_fast_modinfo($courseorid)->get_section_info($sectionnum);
2288 * @see course_create_sections_if_missing()
2289 * @see get_fast_modinfo()
2290 * @deprecated since 2.4
2292 * @param int $section relative section number (field course_sections.section)
2293 * @param int $courseid
2294 * @return stdClass record from table {course_sections}
2296 function get_course_section($section, $courseid) {
2297 global $DB;
2298 debugging('Function get_course_section() is deprecated. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.', DEBUG_DEVELOPER);
2300 if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) {
2301 return $cw;
2303 $cw = new stdClass();
2304 $cw->course = $courseid;
2305 $cw->section = $section;
2306 $cw->summary = "";
2307 $cw->summaryformat = FORMAT_HTML;
2308 $cw->sequence = "";
2309 $id = $DB->insert_record("course_sections", $cw);
2310 rebuild_course_cache($courseid, true);
2311 return $DB->get_record("course_sections", array("id"=>$id));
2315 * Return the start and end date of the week in Weekly course format
2317 * It is not recommended to use this function outside of format_weeks plugin
2319 * @deprecated since 2.4
2320 * @see format_weeks::get_section_dates()
2322 * @param stdClass $section The course_section entry from the DB
2323 * @param stdClass $course The course entry from DB
2324 * @return stdClass property start for startdate, property end for enddate
2326 function format_weeks_get_section_dates($section, $course) {
2327 debugging('Function format_weeks_get_section_dates() is deprecated. It is not recommended to'.
2328 ' use it outside of format_weeks plugin', DEBUG_DEVELOPER);
2329 if (isset($course->format) && $course->format === 'weeks') {
2330 return course_get_format($course)->get_section_dates($section);
2332 return null;
2336 * Obtains shared data that is used in print_section when displaying a
2337 * course-module entry.
2339 * Deprecated. Instead of:
2340 * list($content, $name) = get_print_section_cm_text($cm, $course);
2341 * use:
2342 * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
2343 * $name = $cm->get_formatted_name();
2345 * @deprecated since 2.5
2346 * @see cm_info::get_formatted_content()
2347 * @see cm_info::get_formatted_name()
2349 * This data is also used in other areas of the code.
2350 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
2351 * @param object $course (argument not used)
2352 * @return array An array with the following values in this order:
2353 * $content (optional extra content for after link),
2354 * $instancename (text of link)
2356 function get_print_section_cm_text(cm_info $cm, $course) {
2357 debugging('Function get_print_section_cm_text() is deprecated. Please use '.
2358 'cm_info::get_formatted_content() and cm_info::get_formatted_name()',
2359 DEBUG_DEVELOPER);
2360 return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)),
2361 $cm->get_formatted_name());
2365 * Prints the menus to add activities and resources.
2367 * Deprecated. Please use:
2368 * $courserenderer = $PAGE->get_renderer('core', 'course');
2369 * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
2370 * array('inblock' => $vertical));
2371 * echo $output; // if $return argument in print_section_add_menus() set to false
2373 * @deprecated since 2.5
2374 * @see core_course_renderer::course_section_add_cm_control()
2376 * @param stdClass $course course object, must be the same as set on the page
2377 * @param int $section relative section number (field course_sections.section)
2378 * @param null|array $modnames (argument ignored) get_module_types_names() is used instead of argument
2379 * @param bool $vertical Vertical orientation
2380 * @param bool $return Return the menus or send them to output
2381 * @param int $sectionreturn The section to link back to
2382 * @return void|string depending on $return
2384 function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
2385 global $PAGE;
2386 debugging('Function print_section_add_menus() is deprecated. Please use course renderer '.
2387 'function course_section_add_cm_control()', DEBUG_DEVELOPER);
2388 $output = '';
2389 $courserenderer = $PAGE->get_renderer('core', 'course');
2390 $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
2391 array('inblock' => $vertical));
2392 if ($return) {
2393 return $output;
2394 } else {
2395 echo $output;
2396 return !empty($output);
2401 * Produces the editing buttons for a module
2403 * Deprecated. Please use:
2404 * $courserenderer = $PAGE->get_renderer('core', 'course');
2405 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
2406 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
2408 * @deprecated since 2.5
2409 * @see course_get_cm_edit_actions()
2410 * @see core_course_renderer->course_section_cm_edit_actions()
2412 * @param stdClass $mod The module to produce editing buttons for
2413 * @param bool $absolute_ignored (argument ignored) - all links are absolute
2414 * @param bool $moveselect (argument ignored)
2415 * @param int $indent The current indenting
2416 * @param int $section The section to link back to
2417 * @return string XHTML for the editing buttons
2419 function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
2420 global $PAGE;
2421 debugging('Function make_editing_buttons() is deprecated, please see PHPdocs in '.
2422 'lib/deprecatedlib.php on how to replace it', DEBUG_DEVELOPER);
2423 if (!($mod instanceof cm_info)) {
2424 $modinfo = get_fast_modinfo($mod->course);
2425 $mod = $modinfo->get_cm($mod->id);
2427 $actions = course_get_cm_edit_actions($mod, $indent, $section);
2429 $courserenderer = $PAGE->get_renderer('core', 'course');
2430 // The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap
2431 // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
2432 // the course page HTML will allow this to be removed.
2433 return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
2437 * Prints a section full of activity modules
2439 * Deprecated. Please use:
2440 * $courserenderer = $PAGE->get_renderer('core', 'course');
2441 * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn,
2442 * array('hidecompletion' => $hidecompletion));
2444 * @deprecated since 2.5
2445 * @see core_course_renderer::course_section_cm_list()
2447 * @param stdClass $course The course
2448 * @param stdClass|section_info $section The section object containing properties id and section
2449 * @param array $mods (argument not used)
2450 * @param array $modnamesused (argument not used)
2451 * @param bool $absolute (argument not used)
2452 * @param string $width (argument not used)
2453 * @param bool $hidecompletion Hide completion status
2454 * @param int $sectionreturn The section to return to
2455 * @return void
2457 function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
2458 global $PAGE;
2459 debugging('Function print_section() is deprecated. Please use course renderer function '.
2460 'course_section_cm_list() instead.', DEBUG_DEVELOPER);
2461 $displayoptions = array('hidecompletion' => $hidecompletion);
2462 $courserenderer = $PAGE->get_renderer('core', 'course');
2463 echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions);
2467 * Displays the list of courses with user notes
2469 * This function is not used in core. It was replaced by block course_overview
2471 * @deprecated since 2.5
2473 * @param array $courses
2474 * @param array $remote_courses
2476 function print_overview($courses, array $remote_courses=array()) {
2477 global $CFG, $USER, $DB, $OUTPUT;
2478 debugging('Function print_overview() is deprecated. Use block course_overview to display this information', DEBUG_DEVELOPER);
2480 $htmlarray = array();
2481 if ($modules = $DB->get_records('modules')) {
2482 foreach ($modules as $mod) {
2483 if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) {
2484 include_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php');
2485 $fname = $mod->name.'_print_overview';
2486 if (function_exists($fname)) {
2487 $fname($courses,$htmlarray);
2492 foreach ($courses as $course) {
2493 $fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
2494 echo $OUTPUT->box_start('coursebox');
2495 $attributes = array('title' => s($fullname));
2496 if (empty($course->visible)) {
2497 $attributes['class'] = 'dimmed';
2499 echo $OUTPUT->heading(html_writer::link(
2500 new moodle_url('/course/view.php', array('id' => $course->id)), $fullname, $attributes), 3);
2501 if (array_key_exists($course->id,$htmlarray)) {
2502 foreach ($htmlarray[$course->id] as $modname => $html) {
2503 echo $html;
2506 echo $OUTPUT->box_end();
2509 if (!empty($remote_courses)) {
2510 echo $OUTPUT->heading(get_string('remotecourses', 'mnet'));
2512 foreach ($remote_courses as $course) {
2513 echo $OUTPUT->box_start('coursebox');
2514 $attributes = array('title' => s($course->fullname));
2515 echo $OUTPUT->heading(html_writer::link(
2516 new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)),
2517 format_string($course->shortname),
2518 $attributes) . ' (' . format_string($course->hostname) . ')', 3);
2519 echo $OUTPUT->box_end();
2524 * This function trawls through the logs looking for
2525 * anything new since the user's last login
2527 * This function was only used to print the content of block recent_activity
2528 * All functionality is moved into class {@link block_recent_activity}
2529 * and renderer {@link block_recent_activity_renderer}
2531 * @deprecated since 2.5
2532 * @param stdClass $course
2534 function print_recent_activity($course) {
2535 // $course is an object
2536 global $CFG, $USER, $SESSION, $DB, $OUTPUT;
2537 debugging('Function print_recent_activity() is deprecated. It is not recommended to'.
2538 ' use it outside of block_recent_activity', DEBUG_DEVELOPER);
2540 $context = context_course::instance($course->id);
2542 $viewfullnames = has_capability('moodle/site:viewfullnames', $context);
2544 $timestart = round(time() - COURSE_MAX_RECENT_PERIOD, -2); // better db caching for guests - 100 seconds
2546 if (!isguestuser()) {
2547 if (!empty($USER->lastcourseaccess[$course->id])) {
2548 if ($USER->lastcourseaccess[$course->id] > $timestart) {
2549 $timestart = $USER->lastcourseaccess[$course->id];
2554 echo '<div class="activitydate">';
2555 echo get_string('activitysince', '', userdate($timestart));
2556 echo '</div>';
2557 echo '<div class="activityhead">';
2559 echo '<a href="'.$CFG->wwwroot.'/course/recent.php?id='.$course->id.'">'.get_string('recentactivityreport').'</a>';
2561 echo "</div>\n";
2563 $content = false;
2565 /// Firstly, have there been any new enrolments?
2567 $users = get_recent_enrolments($course->id, $timestart);
2569 //Accessibility: new users now appear in an <OL> list.
2570 if ($users) {
2571 echo '<div class="newusers">';
2572 echo $OUTPUT->heading(get_string("newusers").':', 3);
2573 $content = true;
2574 echo "<ol class=\"list\">\n";
2575 foreach ($users as $user) {
2576 $fullname = fullname($user, $viewfullnames);
2577 echo '<li class="name"><a href="'."$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a></li>\n";
2579 echo "</ol>\n</div>\n";
2582 /// Next, have there been any modifications to the course structure?
2584 $modinfo = get_fast_modinfo($course);
2586 $changelist = array();
2588 $logs = $DB->get_records_select('log', "time > ? AND course = ? AND
2589 module = 'course' AND
2590 (action = 'add mod' OR action = 'update mod' OR action = 'delete mod')",
2591 array($timestart, $course->id), "id ASC");
2593 if ($logs) {
2594 $actions = array('add mod', 'update mod', 'delete mod');
2595 $newgones = array(); // added and later deleted items
2596 foreach ($logs as $key => $log) {
2597 if (!in_array($log->action, $actions)) {
2598 continue;
2600 $info = explode(' ', $log->info);
2602 // note: in most cases I replaced hardcoding of label with use of
2603 // $cm->has_view() but it was not possible to do this here because
2604 // we don't necessarily have the $cm for it
2605 if ($info[0] == 'label') { // Labels are ignored in recent activity
2606 continue;
2609 if (count($info) != 2) {
2610 debugging("Incorrect log entry info: id = ".$log->id, DEBUG_DEVELOPER);
2611 continue;
2614 $modname = $info[0];
2615 $instanceid = $info[1];
2617 if ($log->action == 'delete mod') {
2618 // unfortunately we do not know if the mod was visible
2619 if (!array_key_exists($log->info, $newgones)) {
2620 $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $modname));
2621 $changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted);
2623 } else {
2624 if (!isset($modinfo->instances[$modname][$instanceid])) {
2625 if ($log->action == 'add mod') {
2626 // do not display added and later deleted activities
2627 $newgones[$log->info] = true;
2629 continue;
2631 $cm = $modinfo->instances[$modname][$instanceid];
2632 if (!$cm->uservisible) {
2633 continue;
2636 if ($log->action == 'add mod') {
2637 $stradded = get_string('added', 'moodle', get_string('modulename', $modname));
2638 $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>");
2640 } else if ($log->action == 'update mod' and empty($changelist[$log->info])) {
2641 $strupdated = get_string('updated', 'moodle', get_string('modulename', $modname));
2642 $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>");
2648 if (!empty($changelist)) {
2649 echo $OUTPUT->heading(get_string("courseupdates").':', 3);
2650 $content = true;
2651 foreach ($changelist as $changeinfo => $change) {
2652 echo '<p class="activity">'.$change['text'].'</p>';
2656 /// Now display new things from each module
2658 $usedmodules = array();
2659 foreach($modinfo->cms as $cm) {
2660 if (isset($usedmodules[$cm->modname])) {
2661 continue;
2663 if (!$cm->uservisible) {
2664 continue;
2666 $usedmodules[$cm->modname] = $cm->modname;
2669 foreach ($usedmodules as $modname) { // Each module gets it's own logs and prints them
2670 if (file_exists($CFG->dirroot.'/mod/'.$modname.'/lib.php')) {
2671 include_once($CFG->dirroot.'/mod/'.$modname.'/lib.php');
2672 $print_recent_activity = $modname.'_print_recent_activity';
2673 if (function_exists($print_recent_activity)) {
2674 // NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames!
2675 $content = $print_recent_activity($course, $viewfullnames, $timestart) || $content;
2677 } else {
2678 debugging("Missing lib.php in lib/{$modname} - please reinstall files or uninstall the module");
2682 if (! $content) {
2683 echo '<p class="message">'.get_string('nothingnew').'</p>';
2688 * Delete a course module and any associated data at the course level (events)
2689 * Until 1.5 this function simply marked a deleted flag ... now it
2690 * deletes it completely.
2692 * @deprecated since 2.5
2694 * @param int $id the course module id
2695 * @return boolean true on success, false on failure
2697 function delete_course_module($id) {
2698 debugging('Function delete_course_module() is deprecated. Please use course_delete_module() instead.', DEBUG_DEVELOPER);
2700 global $CFG, $DB;
2702 require_once($CFG->libdir.'/gradelib.php');
2703 require_once($CFG->dirroot.'/blog/lib.php');
2705 if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) {
2706 return true;
2708 $modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module));
2709 //delete events from calendar
2710 if ($events = $DB->get_records('event', array('instance'=>$cm->instance, 'modulename'=>$modulename))) {
2711 foreach($events as $event) {
2712 delete_event($event->id);
2715 //delete grade items, outcome items and grades attached to modules
2716 if ($grade_items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename,
2717 'iteminstance'=>$cm->instance, 'courseid'=>$cm->course))) {
2718 foreach ($grade_items as $grade_item) {
2719 $grade_item->delete('moddelete');
2722 // Delete completion and availability data; it is better to do this even if the
2723 // features are not turned on, in case they were turned on previously (these will be
2724 // very quick on an empty table)
2725 $DB->delete_records('course_modules_completion', array('coursemoduleid' => $cm->id));
2726 $DB->delete_records('course_modules_availability', array('coursemoduleid'=> $cm->id));
2727 $DB->delete_records('course_completion_criteria', array('moduleinstance' => $cm->id,
2728 'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY));
2730 delete_context(CONTEXT_MODULE, $cm->id);
2731 return $DB->delete_records('course_modules', array('id'=>$cm->id));
2735 * Prints the turn editing on/off button on course/index.php or course/category.php.
2737 * @deprecated since 2.5
2739 * @param integer $categoryid The id of the category we are showing, or 0 for system context.
2740 * @return string HTML of the editing button, or empty string, if this user is not allowed
2741 * to see it.
2743 function update_category_button($categoryid = 0) {
2744 global $CFG, $PAGE, $OUTPUT;
2745 debugging('Function update_category_button() is deprecated. Pages to view '.
2746 'and edit courses are now separate and no longer depend on editing mode.',
2747 DEBUG_DEVELOPER);
2749 // Check permissions.
2750 if (!can_edit_in_category($categoryid)) {
2751 return '';
2754 // Work out the appropriate action.
2755 if ($PAGE->user_is_editing()) {
2756 $label = get_string('turneditingoff');
2757 $edit = 'off';
2758 } else {
2759 $label = get_string('turneditingon');
2760 $edit = 'on';
2763 // Generate the button HTML.
2764 $options = array('categoryedit' => $edit, 'sesskey' => sesskey());
2765 if ($categoryid) {
2766 $options['id'] = $categoryid;
2767 $page = 'category.php';
2768 } else {
2769 $page = 'index.php';
2771 return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get');
2775 * This function recursively travels the categories, building up a nice list
2776 * for display. It also makes an array that list all the parents for each
2777 * category.
2779 * For example, if you have a tree of categories like:
2780 * Miscellaneous (id = 1)
2781 * Subcategory (id = 2)
2782 * Sub-subcategory (id = 4)
2783 * Other category (id = 3)
2784 * Then after calling this function you will have
2785 * $list = array(1 => 'Miscellaneous', 2 => 'Miscellaneous / Subcategory',
2786 * 4 => 'Miscellaneous / Subcategory / Sub-subcategory',
2787 * 3 => 'Other category');
2788 * $parents = array(2 => array(1), 4 => array(1, 2));
2790 * If you specify $requiredcapability, then only categories where the current
2791 * user has that capability will be added to $list, although all categories
2792 * will still be added to $parents, and if you only have $requiredcapability
2793 * in a child category, not the parent, then the child catgegory will still be
2794 * included.
2796 * If you specify the option $excluded, then that category, and all its children,
2797 * are omitted from the tree. This is useful when you are doing something like
2798 * moving categories, where you do not want to allow people to move a category
2799 * to be the child of itself.
2801 * This function is deprecated! For list of categories use
2802 * coursecat::make_all_categories($requiredcapability, $excludeid, $separator)
2803 * For parents of one particular category use
2804 * coursecat::get($id)->get_parents()
2806 * @deprecated since 2.5
2808 * @param array $list For output, accumulates an array categoryid => full category path name
2809 * @param array $parents For output, accumulates an array categoryid => list of parent category ids.
2810 * @param string/array $requiredcapability if given, only categories where the current
2811 * user has this capability will be added to $list. Can also be an array of capabilities,
2812 * in which case they are all required.
2813 * @param integer $excludeid Omit this category and its children from the lists built.
2814 * @param object $category Not used
2815 * @param string $path Not used
2817 function make_categories_list(&$list, &$parents, $requiredcapability = '',
2818 $excludeid = 0, $category = NULL, $path = "") {
2819 global $CFG, $DB;
2820 require_once($CFG->libdir.'/coursecatlib.php');
2822 debugging('Global function make_categories_list() is deprecated. Please use '.
2823 'coursecat::make_categories_list() and coursecat::get_parents()',
2824 DEBUG_DEVELOPER);
2826 // For categories list use just this one function:
2827 if (empty($list)) {
2828 $list = array();
2830 $list += coursecat::make_categories_list($requiredcapability, $excludeid);
2832 // Building the list of all parents of all categories in the system is highly undesirable and hardly ever needed.
2833 // Usually user needs only parents for one particular category, in which case should be used:
2834 // coursecat::get($categoryid)->get_parents()
2835 if (empty($parents)) {
2836 $parents = array();
2838 $all = $DB->get_records_sql('SELECT id, parent FROM {course_categories} ORDER BY sortorder');
2839 foreach ($all as $record) {
2840 if ($record->parent) {
2841 $parents[$record->id] = array_merge($parents[$record->parent], array($record->parent));
2842 } else {
2843 $parents[$record->id] = array();
2849 * Delete category, but move contents to another category.
2851 * This function is deprecated. Please use
2852 * coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2854 * @see coursecat::delete_move()
2855 * @deprecated since 2.5
2857 * @param object $category
2858 * @param int $newparentid category id
2859 * @return bool status
2861 function category_delete_move($category, $newparentid, $showfeedback=true) {
2862 global $CFG;
2863 require_once($CFG->libdir.'/coursecatlib.php');
2865 debugging('Function category_delete_move() is deprecated. Please use coursecat::delete_move() instead.');
2867 return coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2871 * Recursively delete category including all subcategories and courses.
2873 * This function is deprecated. Please use
2874 * coursecat::get($category->id)->delete_full($showfeedback);
2876 * @see coursecat::delete_full()
2877 * @deprecated since 2.5
2879 * @param stdClass $category
2880 * @param boolean $showfeedback display some notices
2881 * @return array return deleted courses
2883 function category_delete_full($category, $showfeedback=true) {
2884 global $CFG, $DB;
2885 require_once($CFG->libdir.'/coursecatlib.php');
2887 debugging('Function category_delete_full() is deprecated. Please use coursecat::delete_full() instead.');
2889 return coursecat::get($category->id)->delete_full($showfeedback);
2893 * Efficiently moves a category - NOTE that this can have
2894 * a huge impact access-control-wise...
2896 * This function is deprecated. Please use
2897 * $coursecat = coursecat::get($category->id);
2898 * if ($coursecat->can_change_parent($newparentcat->id)) {
2899 * $coursecat->change_parent($newparentcat->id);
2902 * Alternatively you can use
2903 * $coursecat->update(array('parent' => $newparentcat->id));
2905 * Function update() also updates field course_categories.timemodified
2907 * @see coursecat::change_parent()
2908 * @see coursecat::update()
2909 * @deprecated since 2.5
2911 * @param stdClass|coursecat $category
2912 * @param stdClass|coursecat $newparentcat
2914 function move_category($category, $newparentcat) {
2915 global $CFG;
2916 require_once($CFG->libdir.'/coursecatlib.php');
2918 debugging('Function move_category() is deprecated. Please use coursecat::change_parent() instead.');
2920 return coursecat::get($category->id)->change_parent($newparentcat->id);
2924 * Hide course category and child course and subcategories
2926 * This function is deprecated. Please use
2927 * coursecat::get($category->id)->hide();
2929 * @see coursecat::hide()
2930 * @deprecated since 2.5
2932 * @param stdClass $category
2933 * @return void
2935 function course_category_hide($category) {
2936 global $CFG;
2937 require_once($CFG->libdir.'/coursecatlib.php');
2939 debugging('Function course_category_hide() is deprecated. Please use coursecat::hide() instead.');
2941 coursecat::get($category->id)->hide();
2945 * Show course category and child course and subcategories
2947 * This function is deprecated. Please use
2948 * coursecat::get($category->id)->show();
2950 * @see coursecat::show()
2951 * @deprecated since 2.5
2953 * @param stdClass $category
2954 * @return void
2956 function course_category_show($category) {
2957 global $CFG;
2958 require_once($CFG->libdir.'/coursecatlib.php');
2960 debugging('Function course_category_show() is deprecated. Please use coursecat::show() instead.');
2962 coursecat::get($category->id)->show();
2966 * Return specified category, default if given does not exist
2968 * This function is deprecated.
2969 * To get the category with the specified it please use:
2970 * coursecat::get($catid, IGNORE_MISSING);
2971 * or
2972 * coursecat::get($catid, MUST_EXIST);
2974 * To get the first available category please use
2975 * coursecat::get_default();
2977 * class coursecat will also make sure that at least one category exists in DB
2979 * @deprecated since 2.5
2980 * @see coursecat::get()
2981 * @see coursecat::get_default()
2983 * @param int $catid course category id
2984 * @return object caregory
2986 function get_course_category($catid=0) {
2987 global $DB;
2989 debugging('Function get_course_category() is deprecated. Please use coursecat::get(), see phpdocs for more details');
2991 $category = false;
2993 if (!empty($catid)) {
2994 $category = $DB->get_record('course_categories', array('id'=>$catid));
2997 if (!$category) {
2998 // the first category is considered default for now
2999 if ($category = $DB->get_records('course_categories', null, 'sortorder', '*', 0, 1)) {
3000 $category = reset($category);
3002 } else {
3003 $cat = new stdClass();
3004 $cat->name = get_string('miscellaneous');
3005 $cat->depth = 1;
3006 $cat->sortorder = MAX_COURSES_IN_CATEGORY;
3007 $cat->timemodified = time();
3008 $catid = $DB->insert_record('course_categories', $cat);
3009 // make sure category context exists
3010 context_coursecat::instance($catid);
3011 mark_context_dirty('/'.SYSCONTEXTID);
3012 fix_course_sortorder(); // Required to build course_categories.depth and .path.
3013 $category = $DB->get_record('course_categories', array('id'=>$catid));
3017 return $category;
3021 * Create a new course category and marks the context as dirty
3023 * This function does not set the sortorder for the new category and
3024 * {@link fix_course_sortorder()} should be called after creating a new course
3025 * category
3027 * Please note that this function does not verify access control.
3029 * This function is deprecated. It is replaced with the method create() in class coursecat.
3030 * {@link coursecat::create()} also verifies the data, fixes sortorder and logs the action
3032 * @deprecated since 2.5
3034 * @param object $category All of the data required for an entry in the course_categories table
3035 * @return object new course category
3037 function create_course_category($category) {
3038 global $DB;
3040 debugging('Function create_course_category() is deprecated. Please use coursecat::create(), see phpdocs for more details', DEBUG_DEVELOPER);
3042 $category->timemodified = time();
3043 $category->id = $DB->insert_record('course_categories', $category);
3044 $category = $DB->get_record('course_categories', array('id' => $category->id));
3046 // We should mark the context as dirty
3047 $category->context = context_coursecat::instance($category->id);
3048 $category->context->mark_dirty();
3050 return $category;
3054 * Returns an array of category ids of all the subcategories for a given
3055 * category.
3057 * This function is deprecated.
3059 * To get visible children categories of the given category use:
3060 * coursecat::get($categoryid)->get_children();
3061 * This function will return the array or coursecat objects, on each of them
3062 * you can call get_children() again
3064 * @see coursecat::get()
3065 * @see coursecat::get_children()
3067 * @deprecated since 2.5
3069 * @global object
3070 * @param int $catid - The id of the category whose subcategories we want to find.
3071 * @return array of category ids.
3073 function get_all_subcategories($catid) {
3074 global $DB;
3076 debugging('Function get_all_subcategories() is deprecated. Please use appropriate methods() of coursecat class. See phpdocs for more details',
3077 DEBUG_DEVELOPER);
3079 $subcats = array();
3081 if ($categories = $DB->get_records('course_categories', array('parent' => $catid))) {
3082 foreach ($categories as $cat) {
3083 array_push($subcats, $cat->id);
3084 $subcats = array_merge($subcats, get_all_subcategories($cat->id));
3087 return $subcats;
3091 * Gets the child categories of a given courses category
3093 * This function is deprecated. Please use functions in class coursecat:
3094 * - coursecat::get($parentid)->has_children()
3095 * tells if the category has children (visible or not to the current user)
3097 * - coursecat::get($parentid)->get_children()
3098 * returns an array of coursecat objects, each of them represents a children category visible
3099 * to the current user (i.e. visible=1 or user has capability to view hidden categories)
3101 * - coursecat::get($parentid)->get_children_count()
3102 * returns number of children categories visible to the current user
3104 * - coursecat::count_all()
3105 * returns total count of all categories in the system (both visible and not)
3107 * - coursecat::get_default()
3108 * returns the first category (usually to be used if count_all() == 1)
3110 * @deprecated since 2.5
3112 * @param int $parentid the id of a course category.
3113 * @return array all the child course categories.
3115 function get_child_categories($parentid) {
3116 global $DB;
3117 debugging('Function get_child_categories() is deprecated. Use coursecat::get_children() or see phpdocs for more details.',
3118 DEBUG_DEVELOPER);
3120 $rv = array();
3121 $sql = context_helper::get_preload_record_columns_sql('ctx');
3122 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
3123 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
3124 array(CONTEXT_COURSECAT, $parentid));
3125 foreach ($records as $category) {
3126 context_helper::preload_from_record($category);
3127 if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) {
3128 continue;
3130 $rv[] = $category;
3132 return $rv;
3136 * Returns a sorted list of categories.
3138 * When asking for $parent='none' it will return all the categories, regardless
3139 * of depth. Wheen asking for a specific parent, the default is to return
3140 * a "shallow" resultset. Pass false to $shallow and it will return all
3141 * the child categories as well.
3143 * @deprecated since 2.5
3145 * This function is deprecated. Use appropriate functions from class coursecat.
3146 * Examples:
3148 * coursecat::get($categoryid)->get_children()
3149 * - returns all children of the specified category as instances of class
3150 * coursecat, which means on each of them method get_children() can be called again.
3151 * Only categories visible to the current user are returned.
3153 * coursecat::get(0)->get_children()
3154 * - returns all top-level categories visible to the current user.
3156 * Sort fields can be specified, see phpdocs to {@link coursecat::get_children()}
3158 * coursecat::make_categories_list()
3159 * - returns an array of all categories id/names in the system.
3160 * Also only returns categories visible to current user and can additionally be
3161 * filetered by capability, see phpdocs to {@link coursecat::make_categories_list()}
3163 * make_categories_options()
3164 * - Returns full course categories tree to be used in html_writer::select()
3166 * Also see functions {@link coursecat::get_children_count()}, {@link coursecat::count_all()},
3167 * {@link coursecat::get_default()}
3169 * The code of this deprecated function is left as it is because coursecat::get_children()
3170 * returns categories as instances of coursecat and not stdClass. Also there is no
3171 * substitute for retrieving the category with all it's subcategories. Plugin developers
3172 * may re-use the code/queries from this function in their plugins if really necessary.
3174 * @param string $parent The parent category if any
3175 * @param string $sort the sortorder
3176 * @param bool $shallow - set to false to get the children too
3177 * @return array of categories
3179 function get_categories($parent='none', $sort=NULL, $shallow=true) {
3180 global $DB;
3182 debugging('Function get_categories() is deprecated. Please use coursecat::get_children() or see phpdocs for other alternatives',
3183 DEBUG_DEVELOPER);
3185 if ($sort === NULL) {
3186 $sort = 'ORDER BY cc.sortorder ASC';
3187 } elseif ($sort ==='') {
3188 // leave it as empty
3189 } else {
3190 $sort = "ORDER BY $sort";
3193 list($ccselect, $ccjoin) = context_instance_preload_sql('cc.id', CONTEXT_COURSECAT, 'ctx');
3195 if ($parent === 'none') {
3196 $sql = "SELECT cc.* $ccselect
3197 FROM {course_categories} cc
3198 $ccjoin
3199 $sort";
3200 $params = array();
3202 } elseif ($shallow) {
3203 $sql = "SELECT cc.* $ccselect
3204 FROM {course_categories} cc
3205 $ccjoin
3206 WHERE cc.parent=?
3207 $sort";
3208 $params = array($parent);
3210 } else {
3211 $sql = "SELECT cc.* $ccselect
3212 FROM {course_categories} cc
3213 $ccjoin
3214 JOIN {course_categories} ccp
3215 ON ((cc.parent = ccp.id) OR (cc.path LIKE ".$DB->sql_concat('ccp.path',"'/%'")."))
3216 WHERE ccp.id=?
3217 $sort";
3218 $params = array($parent);
3220 $categories = array();
3222 $rs = $DB->get_recordset_sql($sql, $params);
3223 foreach($rs as $cat) {
3224 context_helper::preload_from_record($cat);
3225 $catcontext = context_coursecat::instance($cat->id);
3226 if ($cat->visible || has_capability('moodle/category:viewhiddencategories', $catcontext)) {
3227 $categories[$cat->id] = $cat;
3230 $rs->close();
3231 return $categories;
3235 * Displays a course search form
3237 * This function is deprecated, please use course renderer:
3238 * $renderer = $PAGE->get_renderer('core', 'course');
3239 * echo $renderer->course_search_form($value, $format);
3241 * @deprecated since 2.5
3243 * @param string $value default value to populate the search field
3244 * @param bool $return if true returns the value, if false - outputs
3245 * @param string $format display format - 'plain' (default), 'short' or 'navbar'
3246 * @return null|string
3248 function print_course_search($value="", $return=false, $format="plain") {
3249 global $PAGE;
3250 debugging('Function print_course_search() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3251 $renderer = $PAGE->get_renderer('core', 'course');
3252 if ($return) {
3253 return $renderer->course_search_form($value, $format);
3254 } else {
3255 echo $renderer->course_search_form($value, $format);
3260 * Prints custom user information on the home page
3262 * This function is deprecated, please use:
3263 * $renderer = $PAGE->get_renderer('core', 'course');
3264 * echo $renderer->frontpage_my_courses()
3266 * @deprecated since 2.5
3268 function print_my_moodle() {
3269 global $PAGE;
3270 debugging('Function print_my_moodle() is deprecated, please use course renderer function frontpage_my_courses()', DEBUG_DEVELOPER);
3272 $renderer = $PAGE->get_renderer('core', 'course');
3273 echo $renderer->frontpage_my_courses();
3277 * Prints information about one remote course
3279 * This function is deprecated, it is replaced with protected function
3280 * {@link core_course_renderer::frontpage_remote_course()}
3281 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
3283 * @deprecated since 2.5
3285 function print_remote_course($course, $width="100%") {
3286 global $CFG, $USER;
3287 debugging('Function print_remote_course() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3289 $linkcss = '';
3291 $url = "{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&amp;wantsurl=/course/view.php?id={$course->remoteid}";
3293 echo '<div class="coursebox remotecoursebox clearfix">';
3294 echo '<div class="info">';
3295 echo '<div class="name"><a title="'.get_string('entercourse').'"'.
3296 $linkcss.' href="'.$url.'">'
3297 . format_string($course->fullname) .'</a><br />'
3298 . format_string($course->hostname) . ' : '
3299 . format_string($course->cat_name) . ' : '
3300 . format_string($course->shortname). '</div>';
3301 echo '</div><div class="summary">';
3302 $options = new stdClass();
3303 $options->noclean = true;
3304 $options->para = false;
3305 $options->overflowdiv = true;
3306 echo format_text($course->summary, $course->summaryformat, $options);
3307 echo '</div>';
3308 echo '</div>';
3312 * Prints information about one remote host
3314 * This function is deprecated, it is replaced with protected function
3315 * {@link core_course_renderer::frontpage_remote_host()}
3316 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
3318 * @deprecated since 2.5
3320 function print_remote_host($host, $width="100%") {
3321 global $OUTPUT;
3322 debugging('Function print_remote_host() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3324 $linkcss = '';
3326 echo '<div class="coursebox clearfix">';
3327 echo '<div class="info">';
3328 echo '<div class="name">';
3329 echo '<img src="'.$OUTPUT->pix_url('i/mnethost') . '" class="icon" alt="'.get_string('course').'" />';
3330 echo '<a title="'.s($host['name']).'" href="'.s($host['url']).'">'
3331 . s($host['name']).'</a> - ';
3332 echo $host['count'] . ' ' . get_string('courses');
3333 echo '</div>';
3334 echo '</div>';
3335 echo '</div>';
3339 * Recursive function to print out all the categories in a nice format
3340 * with or without courses included
3342 * @deprecated since 2.5
3344 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3346 function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) {
3347 global $PAGE;
3348 debugging('Function print_whole_category_list() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3350 $renderer = $PAGE->get_renderer('core', 'course');
3351 if ($showcourses && $category) {
3352 echo $renderer->course_category($category);
3353 } else if ($showcourses) {
3354 echo $renderer->frontpage_combo_list();
3355 } else {
3356 echo $renderer->frontpage_categories_list();
3361 * Prints the category information.
3363 * @deprecated since 2.5
3365 * This function was only used by {@link print_whole_category_list()} but now
3366 * all course category rendering is moved to core_course_renderer.
3368 * @param stdClass $category
3369 * @param int $depth The depth of the category.
3370 * @param bool $showcourses If set to true course information will also be printed.
3371 * @param array|null $courses An array of courses belonging to the category, or null if you don't have it yet.
3373 function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) {
3374 global $PAGE;
3375 debugging('Function print_category_info() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3377 $renderer = $PAGE->get_renderer('core', 'course');
3378 echo $renderer->course_category($category);
3382 * This function generates a structured array of courses and categories.
3384 * @deprecated since 2.5
3386 * This function is not used any more in moodle core and course renderer does not have render function for it.
3387 * Combo list on the front page is displayed as:
3388 * $renderer = $PAGE->get_renderer('core', 'course');
3389 * echo $renderer->frontpage_combo_list()
3391 * The new class {@link coursecat} stores the information about course category tree
3392 * To get children categories use:
3393 * coursecat::get($id)->get_children()
3394 * To get list of courses use:
3395 * coursecat::get($id)->get_courses()
3397 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3399 * @param int $id
3400 * @param int $depth
3402 function get_course_category_tree($id = 0, $depth = 0) {
3403 global $DB, $CFG;
3404 if (!$depth) {
3405 debugging('Function get_course_category_tree() is deprecated, please use course renderer or coursecat class, see function phpdocs for more info', DEBUG_DEVELOPER);
3408 $categories = array();
3409 $categoryids = array();
3410 $sql = context_helper::get_preload_record_columns_sql('ctx');
3411 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
3412 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
3413 array(CONTEXT_COURSECAT, $id));
3414 foreach ($records as $category) {
3415 context_helper::preload_from_record($category);
3416 if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) {
3417 continue;
3419 $categories[] = $category;
3420 $categoryids[$category->id] = $category;
3421 if (empty($CFG->maxcategorydepth) || $depth <= $CFG->maxcategorydepth) {
3422 list($category->categories, $subcategories) = get_course_category_tree($category->id, $depth+1);
3423 foreach ($subcategories as $subid=>$subcat) {
3424 $categoryids[$subid] = $subcat;
3426 $category->courses = array();
3430 if ($depth > 0) {
3431 // This is a recursive call so return the required array
3432 return array($categories, $categoryids);
3435 if (empty($categoryids)) {
3436 // No categories available (probably all hidden).
3437 return array();
3440 // The depth is 0 this function has just been called so we can finish it off
3442 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
3443 list($catsql, $catparams) = $DB->get_in_or_equal(array_keys($categoryids));
3444 $sql = "SELECT
3445 c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary,c.category
3446 $ccselect
3447 FROM {course} c
3448 $ccjoin
3449 WHERE c.category $catsql ORDER BY c.sortorder ASC";
3450 if ($courses = $DB->get_records_sql($sql, $catparams)) {
3451 // loop throught them
3452 foreach ($courses as $course) {
3453 if ($course->id == SITEID) {
3454 continue;
3456 context_helper::preload_from_record($course);
3457 if (!empty($course->visible) || has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
3458 $categoryids[$course->category]->courses[$course->id] = $course;
3462 return $categories;
3466 * Print courses in category. If category is 0 then all courses are printed.
3468 * @deprecated since 2.5
3470 * To print a generic list of courses use:
3471 * $renderer = $PAGE->get_renderer('core', 'course');
3472 * echo $renderer->courses_list($courses);
3474 * To print list of all courses:
3475 * $renderer = $PAGE->get_renderer('core', 'course');
3476 * echo $renderer->frontpage_available_courses();
3478 * To print list of courses inside category:
3479 * $renderer = $PAGE->get_renderer('core', 'course');
3480 * echo $renderer->course_category($category); // this will also print subcategories
3482 * @param int|stdClass $category category object or id.
3483 * @return bool true if courses found and printed, else false.
3485 function print_courses($category) {
3486 global $CFG, $OUTPUT, $PAGE;
3487 require_once($CFG->libdir. '/coursecatlib.php');
3488 debugging('Function print_courses() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3490 if (!is_object($category) && $category==0) {
3491 $courses = coursecat::get(0)->get_courses(array('recursive' => true, 'summary' => true, 'coursecontacts' => true));
3492 } else {
3493 $courses = coursecat::get($category->id)->get_courses(array('summary' => true, 'coursecontacts' => true));
3496 if ($courses) {
3497 $renderer = $PAGE->get_renderer('core', 'course');
3498 echo $renderer->courses_list($courses);
3499 } else {
3500 echo $OUTPUT->heading(get_string("nocoursesyet"));
3501 $context = context_system::instance();
3502 if (has_capability('moodle/course:create', $context)) {
3503 $options = array();
3504 if (!empty($category->id)) {
3505 $options['category'] = $category->id;
3506 } else {
3507 $options['category'] = $CFG->defaultrequestcategory;
3509 echo html_writer::start_tag('div', array('class'=>'addcoursebutton'));
3510 echo $OUTPUT->single_button(new moodle_url('/course/edit.php', $options), get_string("addnewcourse"));
3511 echo html_writer::end_tag('div');
3512 return false;
3515 return true;
3519 * Print a description of a course, suitable for browsing in a list.
3521 * @deprecated since 2.5
3523 * Please use course renderer to display a course information box.
3524 * $renderer = $PAGE->get_renderer('core', 'course');
3525 * echo $renderer->courses_list($courses); // will print list of courses
3526 * echo $renderer->course_info_box($course); // will print one course wrapped in div.generalbox
3528 * @param object $course the course object.
3529 * @param string $highlightterms Ignored in this deprecated function!
3531 function print_course($course, $highlightterms = '') {
3532 global $PAGE;
3534 debugging('Function print_course() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3535 $renderer = $PAGE->get_renderer('core', 'course');
3536 // Please note, correct would be to use $renderer->coursecat_coursebox() but this function is protected.
3537 // To print list of courses use $renderer->courses_list();
3538 echo $renderer->course_info_box($course);
3542 * Gets an array whose keys are category ids and whose values are arrays of courses in the corresponding category.
3544 * @deprecated since 2.5
3546 * This function is not used any more in moodle core and course renderer does not have render function for it.
3547 * Combo list on the front page is displayed as:
3548 * $renderer = $PAGE->get_renderer('core', 'course');
3549 * echo $renderer->frontpage_combo_list()
3551 * The new class {@link coursecat} stores the information about course category tree
3552 * To get children categories use:
3553 * coursecat::get($id)->get_children()
3554 * To get list of courses use:
3555 * coursecat::get($id)->get_courses()
3557 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3559 * @param int $categoryid
3560 * @return array
3562 function get_category_courses_array($categoryid = 0) {
3563 debugging('Function get_category_courses_array() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
3564 $tree = get_course_category_tree($categoryid);
3565 $flattened = array();
3566 foreach ($tree as $category) {
3567 get_category_courses_array_recursively($flattened, $category);
3569 return $flattened;
3573 * Recursive function to help flatten the course category tree.
3575 * @deprecated since 2.5
3577 * Was intended to be called from {@link get_category_courses_array()}
3579 * @param array &$flattened An array passed by reference in which to store courses for each category.
3580 * @param stdClass $category The category to get courses for.
3582 function get_category_courses_array_recursively(array &$flattened, $category) {
3583 debugging('Function get_category_courses_array_recursively() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
3584 $flattened[$category->id] = $category->courses;
3585 foreach ($category->categories as $childcategory) {
3586 get_category_courses_array_recursively($flattened, $childcategory);
3591 * Returns a URL based on the context of the current page.
3592 * This URL points to blog/index.php and includes filter parameters appropriate for the current page.
3594 * @param stdclass $context
3595 * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more.
3596 * @todo Remove this in 2.7
3597 * @return string
3599 function blog_get_context_url($context=null) {
3600 global $CFG;
3602 debugging('Function blog_get_context_url() is deprecated, getting params from context is not reliable for blogs.', DEBUG_DEVELOPER);
3603 $viewblogentriesurl = new moodle_url('/blog/index.php');
3605 if (empty($context)) {
3606 global $PAGE;
3607 $context = $PAGE->context;
3610 // Change contextlevel to SYSTEM if viewing the site course
3611 if ($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID) {
3612 $context = context_system::instance();
3615 $filterparam = '';
3616 $strlevel = '';
3618 switch ($context->contextlevel) {
3619 case CONTEXT_SYSTEM:
3620 case CONTEXT_BLOCK:
3621 case CONTEXT_COURSECAT:
3622 break;
3623 case CONTEXT_COURSE:
3624 $filterparam = 'courseid';
3625 $strlevel = get_string('course');
3626 break;
3627 case CONTEXT_MODULE:
3628 $filterparam = 'modid';
3629 $strlevel = $context->get_context_name();
3630 break;
3631 case CONTEXT_USER:
3632 $filterparam = 'userid';
3633 $strlevel = get_string('user');
3634 break;
3637 if (!empty($filterparam)) {
3638 $viewblogentriesurl->param($filterparam, $context->instanceid);
3641 return $viewblogentriesurl;
3645 * Retrieve course records with the course managers and other related records
3646 * that we need for print_course(). This allows print_courses() to do its job
3647 * in a constant number of DB queries, regardless of the number of courses,
3648 * role assignments, etc.
3650 * The returned array is indexed on c.id, and each course will have
3651 * - $course->managers - array containing RA objects that include a $user obj
3652 * with the minimal fields needed for fullname()
3654 * @deprecated since 2.5
3656 * To get list of all courses with course contacts ('managers') use
3657 * coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true));
3659 * To get list of courses inside particular category use
3660 * coursecat::get($id)->get_courses(array('coursecontacts' => true));
3662 * Additionally you can specify sort order, offset and maximum number of courses,
3663 * see {@link coursecat::get_courses()}
3665 * Please note that code of this function is not changed to use coursecat class because
3666 * coursecat::get_courses() returns result in slightly different format. Also note that
3667 * get_courses_wmanagers() DOES NOT check that users are enrolled in the course and
3668 * coursecat::get_courses() does.
3670 * @global object
3671 * @global object
3672 * @global object
3673 * @uses CONTEXT_COURSE
3674 * @uses CONTEXT_SYSTEM
3675 * @uses CONTEXT_COURSECAT
3676 * @uses SITEID
3677 * @param int|string $categoryid Either the categoryid for the courses or 'all'
3678 * @param string $sort A SQL sort field and direction
3679 * @param array $fields An array of additional fields to fetch
3680 * @return array
3682 function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) {
3684 * The plan is to
3686 * - Grab the courses JOINed w/context
3688 * - Grab the interesting course-manager RAs
3689 * JOINed with a base user obj and add them to each course
3691 * So as to do all the work in 2 DB queries. The RA+user JOIN
3692 * ends up being pretty expensive if it happens over _all_
3693 * courses on a large site. (Are we surprised!?)
3695 * So this should _never_ get called with 'all' on a large site.
3698 global $USER, $CFG, $DB;
3699 debugging('Function get_courses_wmanagers() is deprecated, please use coursecat::get_courses()', DEBUG_DEVELOPER);
3701 $params = array();
3702 $allcats = false; // bool flag
3703 if ($categoryid === 'all') {
3704 $categoryclause = '';
3705 $allcats = true;
3706 } elseif (is_numeric($categoryid)) {
3707 $categoryclause = "c.category = :catid";
3708 $params['catid'] = $categoryid;
3709 } else {
3710 debugging("Could not recognise categoryid = $categoryid");
3711 $categoryclause = '';
3714 $basefields = array('id', 'category', 'sortorder',
3715 'shortname', 'fullname', 'idnumber',
3716 'startdate', 'visible',
3717 'newsitems', 'groupmode', 'groupmodeforce');
3719 if (!is_null($fields) && is_string($fields)) {
3720 if (empty($fields)) {
3721 $fields = $basefields;
3722 } else {
3723 // turn the fields from a string to an array that
3724 // get_user_courses_bycap() will like...
3725 $fields = explode(',',$fields);
3726 $fields = array_map('trim', $fields);
3727 $fields = array_unique(array_merge($basefields, $fields));
3729 } elseif (is_array($fields)) {
3730 $fields = array_merge($basefields,$fields);
3732 $coursefields = 'c.' .join(',c.', $fields);
3734 if (empty($sort)) {
3735 $sortstatement = "";
3736 } else {
3737 $sortstatement = "ORDER BY $sort";
3740 $where = 'WHERE c.id != ' . SITEID;
3741 if ($categoryclause !== ''){
3742 $where = "$where AND $categoryclause";
3745 // pull out all courses matching the cat
3746 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
3747 $sql = "SELECT $coursefields $ccselect
3748 FROM {course} c
3749 $ccjoin
3750 $where
3751 $sortstatement";
3753 $catpaths = array();
3754 $catpath = NULL;
3755 if ($courses = $DB->get_records_sql($sql, $params)) {
3756 // loop on courses materialising
3757 // the context, and prepping data to fetch the
3758 // managers efficiently later...
3759 foreach ($courses as $k => $course) {
3760 context_helper::preload_from_record($course);
3761 $coursecontext = context_course::instance($course->id);
3762 $courses[$k] = $course;
3763 $courses[$k]->managers = array();
3764 if ($allcats === false) {
3765 // single cat, so take just the first one...
3766 if ($catpath === NULL) {
3767 $catpath = preg_replace(':/\d+$:', '', $coursecontext->path);
3769 } else {
3770 // chop off the contextid of the course itself
3771 // like dirname() does...
3772 $catpaths[] = preg_replace(':/\d+$:', '', $coursecontext->path);
3775 } else {
3776 return array(); // no courses!
3779 $CFG->coursecontact = trim($CFG->coursecontact);
3780 if (empty($CFG->coursecontact)) {
3781 return $courses;
3784 $managerroles = explode(',', $CFG->coursecontact);
3785 $catctxids = '';
3786 if (count($managerroles)) {
3787 if ($allcats === true) {
3788 $catpaths = array_unique($catpaths);
3789 $ctxids = array();
3790 foreach ($catpaths as $cpath) {
3791 $ctxids = array_merge($ctxids, explode('/',substr($cpath,1)));
3793 $ctxids = array_unique($ctxids);
3794 $catctxids = implode( ',' , $ctxids);
3795 unset($catpaths);
3796 unset($cpath);
3797 } else {
3798 // take the ctx path from the first course
3799 // as all categories will be the same...
3800 $catpath = substr($catpath,1);
3801 $catpath = preg_replace(':/\d+$:','',$catpath);
3802 $catctxids = str_replace('/',',',$catpath);
3804 if ($categoryclause !== '') {
3805 $categoryclause = "AND $categoryclause";
3808 * Note: Here we use a LEFT OUTER JOIN that can
3809 * "optionally" match to avoid passing a ton of context
3810 * ids in an IN() clause. Perhaps a subselect is faster.
3812 * In any case, this SQL is not-so-nice over large sets of
3813 * courses with no $categoryclause.
3816 $sql = "SELECT ctx.path, ctx.instanceid, ctx.contextlevel,
3817 r.id AS roleid, r.name AS rolename, r.shortname AS roleshortname,
3818 rn.name AS rolecoursealias, u.id AS userid, u.firstname, u.lastname
3819 FROM {role_assignments} ra
3820 JOIN {context} ctx ON ra.contextid = ctx.id
3821 JOIN {user} u ON ra.userid = u.id
3822 JOIN {role} r ON ra.roleid = r.id
3823 LEFT JOIN {role_names} rn ON (rn.contextid = ctx.id AND rn.roleid = r.id)
3824 LEFT OUTER JOIN {course} c
3825 ON (ctx.instanceid=c.id AND ctx.contextlevel=".CONTEXT_COURSE.")
3826 WHERE ( c.id IS NOT NULL";
3827 // under certain conditions, $catctxids is NULL
3828 if($catctxids == NULL){
3829 $sql .= ") ";
3830 }else{
3831 $sql .= " OR ra.contextid IN ($catctxids) )";
3834 $sql .= "AND ra.roleid IN ({$CFG->coursecontact})
3835 $categoryclause
3836 ORDER BY r.sortorder ASC, ctx.contextlevel ASC, ra.sortorder ASC";
3837 $rs = $DB->get_recordset_sql($sql, $params);
3839 // This loop is fairly stupid as it stands - might get better
3840 // results doing an initial pass clustering RAs by path.
3841 foreach($rs as $ra) {
3842 $user = new stdClass;
3843 $user->id = $ra->userid; unset($ra->userid);
3844 $user->firstname = $ra->firstname; unset($ra->firstname);
3845 $user->lastname = $ra->lastname; unset($ra->lastname);
3846 $ra->user = $user;
3847 if ($ra->contextlevel == CONTEXT_SYSTEM) {
3848 foreach ($courses as $k => $course) {
3849 $courses[$k]->managers[] = $ra;
3851 } else if ($ra->contextlevel == CONTEXT_COURSECAT) {
3852 if ($allcats === false) {
3853 // It always applies
3854 foreach ($courses as $k => $course) {
3855 $courses[$k]->managers[] = $ra;
3857 } else {
3858 foreach ($courses as $k => $course) {
3859 $coursecontext = context_course::instance($course->id);
3860 // Note that strpos() returns 0 as "matched at pos 0"
3861 if (strpos($coursecontext->path, $ra->path.'/') === 0) {
3862 // Only add it to subpaths
3863 $courses[$k]->managers[] = $ra;
3867 } else { // course-level
3868 if (!array_key_exists($ra->instanceid, $courses)) {
3869 //this course is not in a list, probably a frontpage course
3870 continue;
3872 $courses[$ra->instanceid]->managers[] = $ra;
3875 $rs->close();
3878 return $courses;
3882 * Converts a nested array tree into HTML ul:li [recursive]
3884 * @deprecated since 2.5
3886 * @param array $tree A tree array to convert
3887 * @param int $row Used in identifying the iteration level and in ul classes
3888 * @return string HTML structure
3890 function convert_tree_to_html($tree, $row=0) {
3891 debugging('Function convert_tree_to_html() is deprecated since Moodle 2.5. Consider using class tabtree and core_renderer::render_tabtree()', DEBUG_DEVELOPER);
3893 $str = "\n".'<ul class="tabrow'.$row.'">'."\n";
3895 $first = true;
3896 $count = count($tree);
3898 foreach ($tree as $tab) {
3899 $count--; // countdown to zero
3901 $liclass = '';
3903 if ($first && ($count == 0)) { // Just one in the row
3904 $liclass = 'first last';
3905 $first = false;
3906 } else if ($first) {
3907 $liclass = 'first';
3908 $first = false;
3909 } else if ($count == 0) {
3910 $liclass = 'last';
3913 if ((empty($tab->subtree)) && (!empty($tab->selected))) {
3914 $liclass .= (empty($liclass)) ? 'onerow' : ' onerow';
3917 if ($tab->inactive || $tab->active || $tab->selected) {
3918 if ($tab->selected) {
3919 $liclass .= (empty($liclass)) ? 'here selected' : ' here selected';
3920 } else if ($tab->active) {
3921 $liclass .= (empty($liclass)) ? 'here active' : ' here active';
3925 $str .= (!empty($liclass)) ? '<li class="'.$liclass.'">' : '<li>';
3927 if ($tab->inactive || $tab->active || ($tab->selected && !$tab->linkedwhenselected)) {
3928 // The a tag is used for styling
3929 $str .= '<a class="nolink"><span>'.$tab->text.'</span></a>';
3930 } else {
3931 $str .= '<a href="'.$tab->link.'" title="'.$tab->title.'"><span>'.$tab->text.'</span></a>';
3934 if (!empty($tab->subtree)) {
3935 $str .= convert_tree_to_html($tab->subtree, $row+1);
3936 } else if ($tab->selected) {
3937 $str .= '<div class="tabrow'.($row+1).' empty">&nbsp;</div>'."\n";
3940 $str .= ' </li>'."\n";
3942 $str .= '</ul>'."\n";
3944 return $str;
3948 * Convert nested tabrows to a nested array
3950 * @deprecated since 2.5
3952 * @param array $tabrows A [nested] array of tab row objects
3953 * @param string $selected The tabrow to select (by id)
3954 * @param array $inactive An array of tabrow id's to make inactive
3955 * @param array $activated An array of tabrow id's to make active
3956 * @return array The nested array
3958 function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) {
3960 debugging('Function convert_tabrows_to_tree() is deprecated since Moodle 2.5. Consider using class tabtree', DEBUG_DEVELOPER);
3962 // Work backwards through the rows (bottom to top) collecting the tree as we go.
3963 $tabrows = array_reverse($tabrows);
3965 $subtree = array();
3967 foreach ($tabrows as $row) {
3968 $tree = array();
3970 foreach ($row as $tab) {
3971 $tab->inactive = in_array((string)$tab->id, $inactive);
3972 $tab->active = in_array((string)$tab->id, $activated);
3973 $tab->selected = (string)$tab->id == $selected;
3975 if ($tab->active || $tab->selected) {
3976 if ($subtree) {
3977 $tab->subtree = $subtree;
3980 $tree[] = $tab;
3982 $subtree = $tree;
3985 return $subtree;
3989 * @deprecated since Moodle 2.3
3991 function move_section($course, $section, $move) {
3992 throw new coding_exception('move_section() can not be used any more, please see move_section_to().');
3995 * Can handle rotated text. Whether it is safe to use the trickery in textrotate.js.
3997 * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically
3998 * @return bool True for yes, false for no
4000 function can_use_rotated_text() {
4001 debugging('can_use_rotated_text() is deprecated since Moodle 2.5. JS feature detection is used automatically.', DEBUG_DEVELOPER);
4002 return true;
4006 * Get the context instance as an object. This function will create the
4007 * context instance if it does not exist yet.
4009 * @deprecated since 2.2, use context_course::instance() or other relevant class instead
4010 * @todo This will be deleted in Moodle 2.8, refer MDL-34472
4011 * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
4012 * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
4013 * for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
4014 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
4015 * MUST_EXIST means throw exception if no record or multiple records found
4016 * @return context The context object.
4018 function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
4020 debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER);
4022 $instances = (array)$instance;
4023 $contexts = array();
4025 $classname = context_helper::get_class_for_level($contextlevel);
4027 // we do not load multiple contexts any more, PAGE should be responsible for any preloading
4028 foreach ($instances as $inst) {
4029 $contexts[$inst] = $classname::instance($inst, $strictness);
4032 if (is_array($instance)) {
4033 return $contexts;
4034 } else {
4035 return $contexts[$instance];
4040 * Get a context instance as an object, from a given context id.
4042 * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more.
4043 * @todo MDL-34550 This will be deleted in Moodle 2.8
4044 * @see context::instance_by_id($id)
4045 * @param int $id context id
4046 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
4047 * MUST_EXIST means throw exception if no record or multiple records found
4048 * @return context|bool the context object or false if not found.
4050 function get_context_instance_by_id($id, $strictness = IGNORE_MISSING) {
4051 debugging('get_context_instance_by_id() is deprecated, please use context::instance_by_id($id) instead.', DEBUG_DEVELOPER);
4052 return context::instance_by_id($id, $strictness);
4056 * @deprecated since Moodle 2.2
4057 * @see load_temp_course_role()
4059 function load_temp_role($context, $roleid, array $accessdata) {
4060 throw new coding_exception('load_temp_role() can not be used any more, please use load_temp_course_role()');
4064 * @deprecated since Moodle 2.2
4065 * @see remove_temp_course_roles()
4067 function remove_temp_roles($context, array $accessdata) {
4068 throw new coding_exception('remove_temp_roles() can not be used any more, please use remove_temp_course_roles()');
4072 * Returns system context or null if can not be created yet.
4074 * @see context_system::instance()
4075 * @deprecated since 2.2
4076 * @param bool $cache use caching
4077 * @return context system context (null if context table not created yet)
4079 function get_system_context($cache = true) {
4080 debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER);
4081 return context_system::instance(0, IGNORE_MISSING, $cache);
4085 * Recursive function which, given a context, find all parent context ids,
4086 * and return the array in reverse order, i.e. parent first, then grand
4087 * parent, etc.
4089 * @see context::get_parent_context_ids()
4090 * @deprecated since 2.2, use $context->get_parent_context_ids() instead
4091 * @param context $context
4092 * @param bool $includeself optional, defaults to false
4093 * @return array
4095 function get_parent_contexts(context $context, $includeself = false) {
4096 debugging('get_parent_contexts() is deprecated, please use $context->get_parent_context_ids() instead.', DEBUG_DEVELOPER);
4097 return $context->get_parent_context_ids($includeself);
4101 * Return the id of the parent of this context, or false if there is no parent (only happens if this
4102 * is the site context.)
4104 * @deprecated since Moodle 2.2
4105 * @see context::get_parent_context()
4106 * @param context $context
4107 * @return integer the id of the parent context.
4109 function get_parent_contextid(context $context) {
4110 debugging('get_parent_contextid() is deprecated, please use $context->get_parent_context() instead.', DEBUG_DEVELOPER);
4112 if ($parent = $context->get_parent_context()) {
4113 return $parent->id;
4114 } else {
4115 return false;
4120 * Recursive function which, given a context, find all its children contexts.
4122 * For course category contexts it will return immediate children only categories and courses.
4123 * It will NOT recurse into courses or child categories.
4124 * If you want to do that, call it on the returned courses/categories.
4126 * When called for a course context, it will return the modules and blocks
4127 * displayed in the course page.
4129 * If called on a user/course/module context it _will_ populate the cache with the appropriate
4130 * contexts ;-)
4132 * @see context::get_child_contexts()
4133 * @deprecated since 2.2
4134 * @param context $context
4135 * @return array Array of child records
4137 function get_child_contexts(context $context) {
4138 debugging('get_child_contexts() is deprecated, please use $context->get_child_contexts() instead.', DEBUG_DEVELOPER);
4139 return $context->get_child_contexts();
4143 * Precreates all contexts including all parents.
4145 * @see context_helper::create_instances()
4146 * @deprecated since 2.2
4147 * @param int $contextlevel empty means all
4148 * @param bool $buildpaths update paths and depths
4149 * @return void
4151 function create_contexts($contextlevel = null, $buildpaths = true) {
4152 debugging('create_contexts() is deprecated, please use context_helper::create_instances() instead.', DEBUG_DEVELOPER);
4153 context_helper::create_instances($contextlevel, $buildpaths);
4157 * Remove stale context records.
4159 * @see context_helper::cleanup_instances()
4160 * @deprecated since 2.2
4161 * @return bool
4163 function cleanup_contexts() {
4164 debugging('cleanup_contexts() is deprecated, please use context_helper::cleanup_instances() instead.', DEBUG_DEVELOPER);
4165 context_helper::cleanup_instances();
4166 return true;
4170 * Populate context.path and context.depth where missing.
4172 * @see context_helper::build_all_paths()
4173 * @deprecated since 2.2
4174 * @param bool $force force a complete rebuild of the path and depth fields, defaults to false
4175 * @return void
4177 function build_context_path($force = false) {
4178 debugging('build_context_path() is deprecated, please use context_helper::build_all_paths() instead.', DEBUG_DEVELOPER);
4179 context_helper::build_all_paths($force);
4183 * Rebuild all related context depth and path caches.
4185 * @see context::reset_paths()
4186 * @deprecated since 2.2
4187 * @param array $fixcontexts array of contexts, strongtyped
4188 * @return void
4190 function rebuild_contexts(array $fixcontexts) {
4191 debugging('rebuild_contexts() is deprecated, please use $context->reset_paths(true) instead.', DEBUG_DEVELOPER);
4192 foreach ($fixcontexts as $fixcontext) {
4193 $fixcontext->reset_paths(false);
4195 context_helper::build_all_paths(false);
4199 * Preloads all contexts relating to a course: course, modules. Block contexts
4200 * are no longer loaded here. The contexts for all the blocks on the current
4201 * page are now efficiently loaded by {@link block_manager::load_blocks()}.
4203 * @deprecated since Moodle 2.2
4204 * @see context_helper::preload_course()
4205 * @param int $courseid Course ID
4206 * @return void
4208 function preload_course_contexts($courseid) {
4209 debugging('preload_course_contexts() is deprecated, please use context_helper::preload_course() instead.', DEBUG_DEVELOPER);
4210 context_helper::preload_course($courseid);
4214 * Update the path field of the context and all dep. subcontexts that follow
4216 * Update the path field of the context and
4217 * all the dependent subcontexts that follow
4218 * the move.
4220 * The most important thing here is to be as
4221 * DB efficient as possible. This op can have a
4222 * massive impact in the DB.
4224 * @deprecated since Moodle 2.2
4225 * @see context::update_moved()
4226 * @param context $context context obj
4227 * @param context $newparent new parent obj
4228 * @return void
4230 function context_moved(context $context, context $newparent) {
4231 debugging('context_moved() is deprecated, please use context::update_moved() instead.', DEBUG_DEVELOPER);
4232 $context->update_moved($newparent);
4236 * Extracts the relevant capabilities given a contextid.
4237 * All case based, example an instance of forum context.
4238 * Will fetch all forum related capabilities, while course contexts
4239 * Will fetch all capabilities
4241 * capabilities
4242 * `name` varchar(150) NOT NULL,
4243 * `captype` varchar(50) NOT NULL,
4244 * `contextlevel` int(10) NOT NULL,
4245 * `component` varchar(100) NOT NULL,
4247 * @see context::get_capabilities()
4248 * @deprecated since 2.2
4249 * @param context $context
4250 * @return array
4252 function fetch_context_capabilities(context $context) {
4253 debugging('fetch_context_capabilities() is deprecated, please use $context->get_capabilities() instead.', DEBUG_DEVELOPER);
4254 return $context->get_capabilities();
4258 * Preloads context information from db record and strips the cached info.
4259 * The db request has to contain both the $join and $select from context_instance_preload_sql()
4261 * @deprecated since 2.2
4262 * @see context_helper::preload_from_record()
4263 * @param stdClass $rec
4264 * @return void (modifies $rec)
4266 function context_instance_preload(stdClass $rec) {
4267 debugging('context_instance_preload() is deprecated, please use context_helper::preload_from_record() instead.', DEBUG_DEVELOPER);
4268 context_helper::preload_from_record($rec);
4272 * Returns context level name
4274 * @deprecated since 2.2
4275 * @see context_helper::get_level_name()
4276 * @param integer $contextlevel $context->context level. One of the CONTEXT_... constants.
4277 * @return string the name for this type of context.
4279 function get_contextlevel_name($contextlevel) {
4280 debugging('get_contextlevel_name() is deprecated, please use context_helper::get_level_name() instead.', DEBUG_DEVELOPER);
4281 return context_helper::get_level_name($contextlevel);
4285 * Prints human readable context identifier.
4287 * @deprecated since 2.2
4288 * @see context::get_context_name()
4289 * @param context $context the context.
4290 * @param boolean $withprefix whether to prefix the name of the context with the
4291 * type of context, e.g. User, Course, Forum, etc.
4292 * @param boolean $short whether to user the short name of the thing. Only applies
4293 * to course contexts
4294 * @return string the human readable context name.
4296 function print_context_name(context $context, $withprefix = true, $short = false) {
4297 debugging('print_context_name() is deprecated, please use $context->get_context_name() instead.', DEBUG_DEVELOPER);
4298 return $context->get_context_name($withprefix, $short);
4302 * Mark a context as dirty (with timestamp) so as to force reloading of the context.
4304 * @deprecated since 2.2, use $context->mark_dirty() instead
4305 * @see context::mark_dirty()
4306 * @param string $path context path
4308 function mark_context_dirty($path) {
4309 global $CFG, $USER, $ACCESSLIB_PRIVATE;
4310 debugging('mark_context_dirty() is deprecated, please use $context->mark_dirty() instead.', DEBUG_DEVELOPER);
4312 if (during_initial_install()) {
4313 return;
4316 // only if it is a non-empty string
4317 if (is_string($path) && $path !== '') {
4318 set_cache_flag('accesslib/dirtycontexts', $path, 1, time()+$CFG->sessiontimeout);
4319 if (isset($ACCESSLIB_PRIVATE->dirtycontexts)) {
4320 $ACCESSLIB_PRIVATE->dirtycontexts[$path] = 1;
4321 } else {
4322 if (CLI_SCRIPT) {
4323 $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1);
4324 } else {
4325 if (isset($USER->access['time'])) {
4326 $ACCESSLIB_PRIVATE->dirtycontexts = get_cache_flags('accesslib/dirtycontexts', $USER->access['time']-2);
4327 } else {
4328 $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1);
4330 // flags not loaded yet, it will be done later in $context->reload_if_dirty()
4337 * Remove a context record and any dependent entries,
4338 * removes context from static context cache too
4340 * @deprecated since Moodle 2.2
4341 * @see context_helper::delete_instance() or context::delete_content()
4342 * @param int $contextlevel
4343 * @param int $instanceid
4344 * @param bool $deleterecord false means keep record for now
4345 * @return bool returns true or throws an exception
4347 function delete_context($contextlevel, $instanceid, $deleterecord = true) {
4348 if ($deleterecord) {
4349 debugging('delete_context() is deprecated, please use context_helper::delete_instance() instead.', DEBUG_DEVELOPER);
4350 context_helper::delete_instance($contextlevel, $instanceid);
4351 } else {
4352 debugging('delete_context() is deprecated, please use $context->delete_content() instead.', DEBUG_DEVELOPER);
4353 $classname = context_helper::get_class_for_level($contextlevel);
4354 if ($context = $classname::instance($instanceid, IGNORE_MISSING)) {
4355 $context->delete_content();
4359 return true;
4363 * Get a URL for a context, if there is a natural one. For example, for
4364 * CONTEXT_COURSE, this is the course page. For CONTEXT_USER it is the
4365 * user profile page.
4367 * @deprecated since 2.2
4368 * @see context::get_url()
4369 * @param context $context the context
4370 * @return moodle_url
4372 function get_context_url(context $context) {
4373 debugging('get_context_url() is deprecated, please use $context->get_url() instead.', DEBUG_DEVELOPER);
4374 return $context->get_url();
4378 * Is this context part of any course? if yes return course context,
4379 * if not return null or throw exception.
4381 * @deprecated since 2.2
4382 * @see context::get_course_context()
4383 * @param context $context
4384 * @return course_context context of the enclosing course, null if not found or exception
4386 function get_course_context(context $context) {
4387 debugging('get_course_context() is deprecated, please use $context->get_course_context(true) instead.', DEBUG_DEVELOPER);
4388 return $context->get_course_context(true);
4392 * Get an array of courses where cap requested is available
4393 * and user is enrolled, this can be relatively slow.
4395 * @deprecated since 2.2
4396 * @see enrol_get_users_courses()
4397 * @param int $userid A user id. By default (null) checks the permissions of the current user.
4398 * @param string $cap - name of the capability
4399 * @param array $accessdata_ignored
4400 * @param bool $doanything_ignored
4401 * @param string $sort - sorting fields - prefix each fieldname with "c."
4402 * @param array $fields - additional fields you are interested in...
4403 * @param int $limit_ignored
4404 * @return array $courses - ordered array of course objects - see notes above
4406 function get_user_courses_bycap($userid, $cap, $accessdata_ignored, $doanything_ignored, $sort = 'c.sortorder ASC', $fields = null, $limit_ignored = 0) {
4408 debugging('get_user_courses_bycap() is deprecated, please use enrol_get_users_courses() instead.', DEBUG_DEVELOPER);
4409 $courses = enrol_get_users_courses($userid, true, $fields, $sort);
4410 foreach ($courses as $id=>$course) {
4411 $context = context_course::instance($id);
4412 if (!has_capability($cap, $context, $userid)) {
4413 unset($courses[$id]);
4417 return $courses;
4421 * This is really slow!!! do not use above course context level
4423 * @deprecated since Moodle 2.2
4424 * @param int $roleid
4425 * @param context $context
4426 * @return array
4428 function get_role_context_caps($roleid, context $context) {
4429 global $DB;
4430 debugging('get_role_context_caps() is deprecated, it is really slow. Don\'t use it.', DEBUG_DEVELOPER);
4432 // This is really slow!!!! - do not use above course context level.
4433 $result = array();
4434 $result[$context->id] = array();
4436 // First emulate the parent context capabilities merging into context.
4437 $searchcontexts = array_reverse($context->get_parent_context_ids(true));
4438 foreach ($searchcontexts as $cid) {
4439 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
4440 foreach ($capabilities as $cap) {
4441 if (!array_key_exists($cap->capability, $result[$context->id])) {
4442 $result[$context->id][$cap->capability] = 0;
4444 $result[$context->id][$cap->capability] += $cap->permission;
4449 // Now go through the contexts below given context.
4450 $searchcontexts = array_keys($context->get_child_contexts());
4451 foreach ($searchcontexts as $cid) {
4452 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
4453 foreach ($capabilities as $cap) {
4454 if (!array_key_exists($cap->contextid, $result)) {
4455 $result[$cap->contextid] = array();
4457 $result[$cap->contextid][$cap->capability] = $cap->permission;
4462 return $result;
4466 * Returns current course id or false if outside of course based on context parameter.
4468 * @see context::get_course_context()
4469 * @deprecated since 2.2
4470 * @param context $context
4471 * @return int|bool related course id or false
4473 function get_courseid_from_context(context $context) {
4474 debugging('get_courseid_from_context() is deprecated, please use $context->get_course_context(false) instead.', DEBUG_DEVELOPER);
4475 if ($coursecontext = $context->get_course_context(false)) {
4476 return $coursecontext->instanceid;
4477 } else {
4478 return false;
4483 * Preloads context information together with instances.
4484 * Use context_instance_preload() to strip the context info from the record and cache the context instance.
4486 * If you are using this methid, you should have something like this:
4488 * list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
4490 * To prevent the use of this deprecated function, replace the line above with something similar to this:
4492 * $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
4494 * $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
4495 * ^ ^ ^ ^
4496 * $params = array('contextlevel' => CONTEXT_COURSE);
4498 * @see context_helper:;get_preload_record_columns_sql()
4499 * @deprecated since 2.2
4500 * @param string $joinon for example 'u.id'
4501 * @param string $contextlevel context level of instance in $joinon
4502 * @param string $tablealias context table alias
4503 * @return array with two values - select and join part
4505 function context_instance_preload_sql($joinon, $contextlevel, $tablealias) {
4506 debugging('context_instance_preload_sql() is deprecated, please use context_helper::get_preload_record_columns_sql() instead.', DEBUG_DEVELOPER);
4507 $select = ", " . context_helper::get_preload_record_columns_sql($tablealias);
4508 $join = "LEFT JOIN {context} $tablealias ON ($tablealias.instanceid = $joinon AND $tablealias.contextlevel = $contextlevel)";
4509 return array($select, $join);
4513 * Gets a string for sql calls, searching for stuff in this context or above.
4515 * @deprecated since 2.2
4516 * @see context::get_parent_context_ids()
4517 * @param context $context
4518 * @return string
4520 function get_related_contexts_string(context $context) {
4521 debugging('get_related_contexts_string() is deprecated, please use $context->get_parent_context_ids(true) instead.', DEBUG_DEVELOPER);
4522 if ($parents = $context->get_parent_context_ids()) {
4523 return (' IN ('.$context->id.','.implode(',', $parents).')');
4524 } else {
4525 return (' ='.$context->id);
4530 * @deprecated since Moodle 2.0 - use $PAGE->user_is_editing() instead.
4531 * @see moodle_page->user_is_editing()
4533 function isediting() {
4534 throw new coding_exception('isediting() can not be used any more, please use $PAGE->user_is_editing() instead.');
4538 * Get a list of all the plugins of a given type that contain a particular file.
4540 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
4541 * @param string $file the name of file that must be present in the plugin.
4542 * (e.g. 'view.php', 'db/install.xml').
4543 * @param bool $include if true (default false), the file will be include_once-ed if found.
4544 * @return array with plugin name as keys (e.g. 'forum', 'courselist') and the path
4545 * to the file relative to dirroot as value (e.g. "$CFG->dirroot/mod/forum/view.php").
4546 * @deprecated since 2.6
4547 * @see core_component::get_plugin_list_with_file()
4549 function get_plugin_list_with_file($plugintype, $file, $include = false) {
4550 debugging('get_plugin_list_with_file() is deprecated, please use core_component::get_plugin_list_with_file() instead.',
4551 DEBUG_DEVELOPER);
4552 return core_component::get_plugin_list_with_file($plugintype, $file, $include);
4556 * Checks to see if is the browser operating system matches the specified brand.
4558 * Known brand: 'Windows','Linux','Macintosh','SGI','SunOS','HP-UX'
4560 * @deprecated since 2.6
4561 * @param string $brand The operating system identifier being tested
4562 * @return bool true if the given brand below to the detected operating system
4564 function check_browser_operating_system($brand) {
4565 debugging('check_browser_operating_system has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4566 return core_useragent::check_browser_operating_system($brand);
4570 * Checks to see if is a browser matches the specified
4571 * brand and is equal or better version.
4573 * @deprecated since 2.6
4574 * @param string $brand The browser identifier being tested
4575 * @param int $version The version of the browser, if not specified any version (except 5.5 for IE for BC reasons)
4576 * @return bool true if the given version is below that of the detected browser
4578 function check_browser_version($brand, $version = null) {
4579 debugging('check_browser_version has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4580 return core_useragent::check_browser_version($brand, $version);
4584 * Returns whether a device/browser combination is mobile, tablet, legacy, default or the result of
4585 * an optional admin specified regular expression. If enabledevicedetection is set to no or not set
4586 * it returns default
4588 * @deprecated since 2.6
4589 * @return string device type
4591 function get_device_type() {
4592 debugging('get_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4593 return core_useragent::get_device_type();
4597 * Returns a list of the device types supporting by Moodle
4599 * @deprecated since 2.6
4600 * @param boolean $incusertypes includes types specified using the devicedetectregex admin setting
4601 * @return array $types
4603 function get_device_type_list($incusertypes = true) {
4604 debugging('get_device_type_list has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4605 return core_useragent::get_device_type_list($incusertypes);
4609 * Returns the theme selected for a particular device or false if none selected.
4611 * @deprecated since 2.6
4612 * @param string $devicetype
4613 * @return string|false The name of the theme to use for the device or the false if not set
4615 function get_selected_theme_for_device_type($devicetype = null) {
4616 debugging('get_selected_theme_for_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4617 return core_useragent::get_device_type_theme($devicetype);
4621 * Returns the name of the device type theme var in $CFG because there is not a convention to allow backwards compatibility.
4623 * @deprecated since 2.6
4624 * @param string $devicetype
4625 * @return string The config variable to use to determine the theme
4627 function get_device_cfg_var_name($devicetype = null) {
4628 debugging('get_device_cfg_var_name has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4629 return core_useragent::get_device_type_cfg_var_name($devicetype);
4633 * Allows the user to switch the device they are seeing the theme for.
4634 * This allows mobile users to switch back to the default theme, or theme for any other device.
4636 * @deprecated since 2.6
4637 * @param string $newdevice The device the user is currently using.
4638 * @return string The device the user has switched to
4640 function set_user_device_type($newdevice) {
4641 debugging('set_user_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4642 return core_useragent::set_user_device_type($newdevice);
4646 * Returns the device the user is currently using, or if the user has chosen to switch devices
4647 * for the current device type the type they have switched to.
4649 * @deprecated since 2.6
4650 * @return string The device the user is currently using or wishes to use
4652 function get_user_device_type() {
4653 debugging('get_user_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4654 return core_useragent::get_user_device_type();
4658 * Returns one or several CSS class names that match the user's browser. These can be put
4659 * in the body tag of the page to apply browser-specific rules without relying on CSS hacks
4661 * @deprecated since 2.6
4662 * @return array An array of browser version classes
4664 function get_browser_version_classes() {
4665 debugging('get_browser_version_classes has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4666 return core_useragent::get_browser_version_classes();
4670 * Generate a fake user for emails based on support settings
4672 * @deprecated since Moodle 2.6
4673 * @see core_user::get_support_user()
4674 * @return stdClass user info
4676 function generate_email_supportuser() {
4677 debugging('generate_email_supportuser is deprecated, please use core_user::get_support_user');
4678 return core_user::get_support_user();
4682 * Get issued badge details for assertion URL
4684 * @deprecated since Moodle 2.6
4685 * @param string $hash Unique hash of a badge
4686 * @return array Information about issued badge.
4688 function badges_get_issued_badge_info($hash) {
4689 debugging('Function badges_get_issued_badge_info() is deprecated. Please use core_badges_assertion class and methods to generate badge assertion.', DEBUG_DEVELOPER);
4690 $assertion = new core_badges_assertion($hash);
4691 return $assertion->get_badge_assertion();
4695 * Does the user want and can edit using rich text html editor?
4696 * This function does not make sense anymore because a user can directly choose their preferred editor.
4698 * @deprecated since 2.6
4699 * @return bool
4701 function can_use_html_editor() {
4702 debugging('can_use_html_editor has been deprecated please update your code to assume it returns true.', DEBUG_DEVELOPER);
4703 return true;