3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
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.
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
31 defined('MOODLE_INTERNAL') || die();
34 * List all core subsystems and their location
36 * This is a whitelist of components that are part of the core and their
37 * language strings are defined in /lang/en/<<subsystem>>.php. If a given
38 * plugin is not listed here and it does not have proper plugintype prefix,
39 * then it is considered as course activity module.
41 * The location is optionally dirroot relative path. NULL means there is no special
42 * directory for this subsystem. If the location is set, the subsystem's
43 * renderer.php is expected to be there.
45 * @deprecated since 2.6, use core_component::get_core_subsystems()
47 * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons
48 * @return array of (string)name => (string|null)location
50 function get_core_subsystems($fullpaths = false) {
53 // NOTE: do not add any other debugging here, keep forever.
55 $subsystems = core_component::get_core_subsystems();
61 debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
63 $dlength = strlen($CFG->dirroot);
65 foreach ($subsystems as $k => $v) {
69 $subsystems[$k] = substr($v, $dlength+1);
76 * Lists all plugin types.
78 * @deprecated since 2.6, use core_component::get_plugin_types()
80 * @param bool $fullpaths false means relative paths from dirroot
81 * @return array Array of strings - name=>location
83 function get_plugin_types($fullpaths = true) {
86 // NOTE: do not add any other debugging here, keep forever.
88 $types = core_component::get_plugin_types();
94 debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
96 $dlength = strlen($CFG->dirroot);
98 foreach ($types as $k => $v) {
100 $types[$k] = 'theme';
103 $types[$k] = substr($v, $dlength+1);
110 * Use when listing real plugins of one type.
112 * @deprecated since 2.6, use core_component::get_plugin_list()
114 * @param string $plugintype type of plugin
115 * @return array name=>fulllocation pairs of plugins of given type
117 function get_plugin_list($plugintype) {
119 // NOTE: do not add any other debugging here, keep forever.
121 if ($plugintype === '') {
125 return core_component::get_plugin_list($plugintype);
129 * Get a list of all the plugins of a given type that define a certain class
130 * in a certain file. The plugin component names and class names are returned.
132 * @deprecated since 2.6, use core_component::get_plugin_list_with_class()
134 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
135 * @param string $class the part of the name of the class after the
136 * frankenstyle prefix. e.g 'thing' if you are looking for classes with
137 * names like report_courselist_thing. If you are looking for classes with
138 * the same name as the plugin name (e.g. qtype_multichoice) then pass ''.
139 * @param string $file the name of file within the plugin that defines the class.
140 * @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum')
141 * and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice').
143 function get_plugin_list_with_class($plugintype, $class, $file) {
145 // NOTE: do not add any other debugging here, keep forever.
147 return core_component::get_plugin_list_with_class($plugintype, $class, $file);
151 * Returns the exact absolute path to plugin directory.
153 * @deprecated since 2.6, use core_component::get_plugin_directory()
155 * @param string $plugintype type of plugin
156 * @param string $name name of the plugin
157 * @return string full path to plugin directory; NULL if not found
159 function get_plugin_directory($plugintype, $name) {
161 // NOTE: do not add any other debugging here, keep forever.
163 if ($plugintype === '') {
167 return core_component::get_plugin_directory($plugintype, $name);
171 * Normalize the component name using the "frankenstyle" names.
173 * @deprecated since 2.6, use core_component::normalize_component()
175 * @param string $component
176 * @return array as (string)$type => (string)$plugin
178 function normalize_component($component) {
180 // NOTE: do not add any other debugging here, keep forever.
182 return core_component::normalize_component($component);
186 * Return exact absolute path to a plugin directory.
188 * @deprecated since 2.6, use core_component::normalize_component()
190 * @param string $component name such as 'moodle', 'mod_forum'
191 * @return string full path to component directory; NULL if not found
193 function get_component_directory($component) {
195 // NOTE: do not add any other debugging here, keep forever.
197 return core_component::get_component_directory($component);
201 // === Deprecated before 2.6.0 ===
204 * Hack to find out the GD version by parsing phpinfo output
206 * @return int GD version (1, 2, or 0)
208 function check_gd_version() {
209 // TODO: delete function in Moodle 2.7
210 debugging('check_gd_version() is deprecated, GD extension is always available now');
214 if (function_exists('gd_info')){
215 $gd_info = gd_info();
216 if (substr_count($gd_info['GD Version'], '2.')) {
218 } else if (substr_count($gd_info['GD Version'], '1.')) {
224 phpinfo(INFO_MODULES);
225 $phpinfo = ob_get_contents();
228 $phpinfo = explode("\n", $phpinfo);
231 foreach ($phpinfo as $text) {
232 $parts = explode('</td>', $text);
233 foreach ($parts as $key => $val) {
234 $parts[$key] = trim(strip_tags($val));
236 if ($parts[0] == 'GD Version') {
237 if (substr_count($parts[1], '2.0')) {
240 $gdversion = intval($parts[1]);
245 return $gdversion; // 1, 2 or 0
249 * Not used any more, the account lockout handling is now
250 * part of authenticate_user_login().
253 function update_login_count() {
254 // TODO: delete function in Moodle 2.6
255 debugging('update_login_count() is deprecated, all calls need to be removed');
259 * Not used any more, replaced by proper account lockout.
262 function reset_login_count() {
263 // TODO: delete function in Moodle 2.6
264 debugging('reset_login_count() is deprecated, all calls need to be removed');
268 * Insert or update log display entry. Entry may already exist.
269 * $module, $action must be unique
272 * @param string $module
273 * @param string $action
274 * @param string $mtable
275 * @param string $field
279 function update_log_display_entry($module, $action, $mtable, $field) {
282 debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
286 * Given some text in HTML format, this function will pass it
287 * through any filters that have been configured for this context.
289 * @deprecated use the text formatting in a standard way instead,
290 * this was abused mostly for embedding of attachments
292 * @param string $text The text to be passed through format filters
293 * @param int $courseid The current course.
294 * @return string the filtered string.
296 function filter_text($text, $courseid = NULL) {
297 global $CFG, $COURSE;
300 $courseid = $COURSE->id;
303 if (!$context = context_course::instance($courseid, IGNORE_MISSING)) {
307 return filter_manager::instance()->filter_text($text, $context);
311 * This function indicates that current page requires the https
312 * when $CFG->loginhttps enabled.
314 * By using this function properly, we can ensure 100% https-ized pages
315 * at our entire discretion (login, forgot_password, change_password)
316 * @deprecated use $PAGE->https_required() instead
318 function httpsrequired() {
320 $PAGE->https_required();
324 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
326 * @deprecated use moodle_url factory methods instead
328 * @param string $path Physical path to a file
329 * @param array $options associative array of GET variables to append to the URL
330 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
331 * @return string URL to file
333 function get_file_url($path, $options=null, $type='coursefile') {
336 $path = str_replace('//', '/', $path);
337 $path = trim($path, '/'); // no leading and trailing slashes
342 $url = $CFG->wwwroot."/question/exportfile.php";
345 $url = $CFG->wwwroot."/rss/file.php";
347 case 'httpscoursefile':
348 $url = $CFG->httpswwwroot."/file.php";
352 $url = $CFG->wwwroot."/file.php";
355 if ($CFG->slasharguments) {
356 $parts = explode('/', $path);
357 foreach ($parts as $key => $part) {
358 /// anchor dash character should not be encoded
359 $subparts = explode('#', $part);
360 $subparts = array_map('rawurlencode', $subparts);
361 $parts[$key] = implode('#', $subparts);
363 $path = implode('/', $parts);
364 $ffurl = $url.'/'.$path;
367 $path = rawurlencode('/'.$path);
368 $ffurl = $url.'?file='.$path;
369 $separator = '&';
373 foreach ($options as $name=>$value) {
374 $ffurl = $ffurl.$separator.$name.'='.$value;
375 $separator = '&';
383 * @deprecated use get_string("pluginname", "auth_[PLUINNAME]") instead.
384 * @todo remove completely in MDL-40517
386 function auth_get_plugin_title($authtype) {
387 throw new coding_exception('Function auth_get_plugin_title() is deprecated, please use standard get_string("pluginname", "auth_'.$authtype.'")!');
391 * @deprecated use indivividual enrol plugin settings instead
392 * @todo remove completely in MDL-40517
394 function get_default_course_role($course) {
395 throw new coding_exception('get_default_course_role() can not be used any more, please use enrol plugin settings instead!');
399 * @deprecated use get_string_manager()->get_list_of_translations() instead.
400 * @todo remove completely in MDL-40517
402 function get_list_of_languages($refreshcache=false, $returnall=false) {
403 throw new coding_exception('get_list_of_languages() can not be used any more, please use get_string_manager()->get_list_of_translations() instead.');
407 * @deprecated use get_string_manager()->get_list_of_currencies() instead.
408 * @todo remove completely in MDL-40517
410 function get_list_of_currencies() {
411 throw new coding_exception('get_list_of_currencies() can not be used any more, please use get_string_manager()->get_list_of_currencies() instead.');
415 * @deprecated use get_string_manager()->get_list_of_countries() instead.
416 * @todo remove completely in MDL-40517
418 function get_list_of_countries() {
419 throw new coding_exception('get_list_of_countries() can not be used any more, please use get_string_manager()->get_list_of_countries() instead.');
423 * Return all course participant for a given course
426 * @param integer $courseid
427 * @return array of user
429 function get_course_participants($courseid) {
430 return get_enrolled_users(context_course::instance($courseid));
434 * Return true if the user is a participant for a given course
437 * @param integer $userid
438 * @param integer $courseid
441 function is_course_participant($userid, $courseid) {
442 return is_enrolled(context_course::instance($courseid), $userid);
446 * Searches logs to find all enrolments since a certain date
448 * used to print recent activity
450 * @todo MDL-36993 this function is still used in block_recent_activity, deprecate properly
452 * @uses CONTEXT_COURSE
453 * @param int $courseid The course in question.
454 * @param int $timestart The date to check forward of
455 * @return object|false {@link $USER} records or false if error.
457 function get_recent_enrolments($courseid, $timestart) {
460 $context = context_course::instance($courseid);
462 $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
463 FROM {user} u, {role_assignments} ra, {log} l
466 AND l.module = 'course'
467 AND l.action = 'enrol'
468 AND ".$DB->sql_cast_char2int('l.info')." = u.id
470 AND ra.contextid ".get_related_contexts_string($context)."
471 GROUP BY u.id, u.firstname, u.lastname
472 ORDER BY MAX(l.time) ASC";
473 $params = array($timestart, $courseid);
474 return $DB->get_records_sql($sql, $params);
477 ########### FROM weblib.php ##########################################################################
480 * @deprecated use $OUTPUT->box() instead.
481 * @todo remove completely in MDL-40517
483 function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
484 throw new coding_exception('print_simple_box can not be used any more. Please use $OUTPUT->box() instead');
488 * @deprecated use $OUTPUT->box_start instead.
489 * @todo remove completely in MDL-40517
491 function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
492 throw new coding_exception('print_simple_box_start can not be used any more. Please use $OUTPUT->box_start instead');
496 * @deprecated use $OUTPUT->box_end instead.
497 * @todo remove completely in MDL-40517
499 function print_simple_box_end($return=false) {
500 throw new coding_exception('print_simple_box_end can not be used any more. Please use $OUTPUT->box_end instead');
504 * @deprecated the urltolink filter now does this job.
505 * @todo remove completely in MDL-40517
507 function convert_urls_into_links($text) {
508 throw new coding_exception('convert_urls_into_links() can not be used any more and replaced by the urltolink filter');
512 * @deprecated use the emoticon_manager class instead.
513 * @todo remove completely in MDL-40517
515 function get_emoticons_list_for_help_file() {
516 throw new coding_exception('get_emoticons_list_for_help_file() can not be used any more, use the new emoticon_manager API instead');
520 * @deprecated use emoticon filter now does this job.
521 * @todo remove completely in MDL-40517
523 function replace_smilies(&$text) {
524 throw new coding_exception('replace_smilies() can not be used any more and replaced with the emoticon filter.');
528 * deprecated - use clean_param($string, PARAM_FILE); instead
529 * Check for bad characters ?
531 * @todo Finish documenting this function - more detail needed in description as well as details on arguments
533 * @param string $string ?
534 * @param int $allowdots ?
537 function detect_munged_arguments($string, $allowdots=1) {
538 if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
541 if (preg_match('/[\|\`]/', $string)) { // check for other bad characters
544 if (empty($string) or $string == '/') {
553 * Unzip one zip file to a destination dir
554 * Both parameters must be FULL paths
555 * If destination isn't specified, it will be the
556 * SAME directory where the zip file resides.
559 * @param string $zipfile The zip file to unzip
560 * @param string $destination The location to unzip to
561 * @param bool $showstatus_ignored Unused
563 function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
566 //Extract everything from zipfile
567 $path_parts = pathinfo(cleardoubleslashes($zipfile));
568 $zippath = $path_parts["dirname"]; //The path of the zip file
569 $zipfilename = $path_parts["basename"]; //The name of the zip file
570 $extension = $path_parts["extension"]; //The extension of the file
573 if (empty($zipfilename)) {
577 //If no extension, error
578 if (empty($extension)) {
583 $zipfile = cleardoubleslashes($zipfile);
585 //Check zipfile exists
586 if (!file_exists($zipfile)) {
590 //If no destination, passed let's go with the same directory
591 if (empty($destination)) {
592 $destination = $zippath;
596 $destpath = rtrim(cleardoubleslashes($destination), "/");
598 //Check destination path exists
599 if (!is_dir($destpath)) {
603 $packer = get_file_packer('application/zip');
605 $result = $packer->extract_to_pathname($zipfile, $destpath);
607 if ($result === false) {
611 foreach ($result as $status) {
612 if ($status !== true) {
621 * Zip an array of files/dirs to a destination zip file
622 * Both parameters must be FULL paths to the files/dirs
625 * @param array $originalfiles Files to zip
626 * @param string $destination The destination path
627 * @return bool Outcome
629 function zip_files ($originalfiles, $destination) {
632 //Extract everything from destination
633 $path_parts = pathinfo(cleardoubleslashes($destination));
634 $destpath = $path_parts["dirname"]; //The path of the zip file
635 $destfilename = $path_parts["basename"]; //The name of the zip file
636 $extension = $path_parts["extension"]; //The extension of the file
639 if (empty($destfilename)) {
643 //If no extension, add it
644 if (empty($extension)) {
646 $destfilename = $destfilename.'.'.$extension;
649 //Check destination path exists
650 if (!is_dir($destpath)) {
654 //Check destination path is writable. TODO!!
656 //Clean destination filename
657 $destfilename = clean_filename($destfilename);
659 //Now check and prepare every file
663 foreach ($originalfiles as $file) { //Iterate over each file
664 //Check for every file
665 $tempfile = cleardoubleslashes($file); // no doubleslashes!
666 //Calculate the base path for all files if it isn't set
667 if ($origpath === NULL) {
668 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
670 //See if the file is readable
671 if (!is_readable($tempfile)) { //Is readable
674 //See if the file/dir is in the same directory than the rest
675 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
678 //Add the file to the array
679 $files[] = $tempfile;
683 $start = strlen($origpath)+1;
684 foreach($files as $file) {
685 $zipfiles[substr($file, $start)] = $file;
688 $packer = get_file_packer('application/zip');
690 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
693 /////////////////////////////////////////////////////////////
694 /// Old functions not used anymore - candidates for removal
695 /////////////////////////////////////////////////////////////
698 /** various deprecated groups function **/
702 * Get the IDs for the user's groups in the given course.
705 * @param int $courseid The course being examined - the 'course' table id field.
706 * @return array|bool An _array_ of groupids, or false
707 * (Was return $groupids[0] - consequences!)
709 function mygroupid($courseid) {
711 if ($groups = groups_get_all_groups($courseid, $USER->id)) {
712 return array_keys($groups);
720 * Returns the current group mode for a given course or activity module
722 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
724 * @param object $course Course Object
725 * @param object $cm Course Manager Object
726 * @return mixed $course->groupmode
728 function groupmode($course, $cm=null) {
730 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
731 return $cm->groupmode;
733 return $course->groupmode;
737 * Sets the current group in the session variable
738 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
739 * Sets currentgroup[$courseid] in the session variable appropriately.
740 * Does not do any permission checking.
743 * @param int $courseid The course being examined - relates to id field in
745 * @param int $groupid The group being examined.
746 * @return int Current group id which was set by this function
748 function set_current_group($courseid, $groupid) {
750 return $SESSION->currentgroup[$courseid] = $groupid;
755 * Gets the current group - either from the session variable or from the database.
758 * @param int $courseid The course being examined - relates to id field in
760 * @param bool $full If true, the return value is a full record object.
761 * If false, just the id of the record.
764 function get_current_group($courseid, $full = false) {
767 if (isset($SESSION->currentgroup[$courseid])) {
769 return groups_get_group($SESSION->currentgroup[$courseid]);
771 return $SESSION->currentgroup[$courseid];
775 $mygroupid = mygroupid($courseid);
776 if (is_array($mygroupid)) {
777 $mygroupid = array_shift($mygroupid);
778 set_current_group($courseid, $mygroupid);
780 return groups_get_group($mygroupid);
795 * Inndicates fatal error. This function was originally printing the
796 * error message directly, since 2.0 it is throwing exception instead.
797 * The error printing is handled in default exception handler.
799 * Old method, don't call directly in new code - use print_error instead.
801 * @param string $message The message to display to the user about the error.
802 * @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.
803 * @return void, always throws moodle_exception
805 function error($message, $link='') {
806 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
810 //////////////////////////
811 /// removed functions ////
812 //////////////////////////
815 * The old method that was used to include JavaScript libraries.
816 * Please use $PAGE->requires->js_module() instead.
818 * @param mixed $lib The library or libraries to load (a string or array of strings)
819 * There are three way to specify the library:
820 * 1. a shorname like 'yui_yahoo'. This translates into a call to $PAGE->requires->yui2_lib('yahoo');
821 * 2. the path to the library relative to wwwroot, for example 'lib/javascript-static.js'
822 * 3. (legacy) a full URL like $CFG->wwwroot . '/lib/javascript-static.js'.
823 * 2. and 3. lead to a call $PAGE->requires->js('/lib/javascript-static.js').
825 function require_js($lib) {
826 throw new coding_exception('require_js() was removed, use new JS api');
830 * @deprecated use $PAGE->theme->name instead.
831 * @return string the name of the current theme.
833 function current_theme() {
835 // TODO, uncomment this once we have eliminated all references to current_theme in core code.
836 // debugging('current_theme is deprecated, use $PAGE->theme->name instead', DEBUG_DEVELOPER);
837 return $PAGE->theme->name;
841 * Prints some red text using echo
844 * @param string $error The text to be displayed in red
846 function formerr($error) {
847 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
849 echo $OUTPUT->error_text($error);
853 * Return the markup for the destination of the 'Skip to main content' links.
854 * Accessibility improvement for keyboard-only users.
856 * Used in course formats, /index.php and /course/index.php
858 * @deprecated use $OUTPUT->skip_link_target() in instead.
859 * @return string HTML element.
861 function skip_main_destination() {
863 return $OUTPUT->skip_link_target();
867 * @deprecated use $OUTPUT->heading() instead.
868 * @todo remove completely in MDL-40517
870 function print_headline($text, $size=2, $return=false) {
871 throw new coding_exception('print_headline() can not be used any more. Please use $OUTPUT->heading() instead.');
875 * @deprecated use $OUTPUT->heading() instead.
876 * @todo remove completely in MDL-40517
878 function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
879 throw new coding_exception('print_heading() can not be used any more. Please use $OUTPUT->heading() instead.');
883 * @deprecated use $OUTPUT->heading() instead.
884 * @todo remove completely in MDL-40517
886 function print_heading_block($heading, $class='', $return=false) {
887 throw new coding_exception('print_heading_with_block() can not be used any more. Please use $OUTPUT->heading() instead.');
891 * @deprecated use $OUTPUT->box() instead.
892 * @todo remove completely in MDL-40517
894 function print_box($message, $classes='generalbox', $ids='', $return=false) {
895 throw new coding_exception('print_box() can not be used any more. Please use $OUTPUT->box() instead.');
899 * @deprecated use $OUTPUT->box_start() instead.
900 * @todo remove completely in MDL-40517
902 function print_box_start($classes='generalbox', $ids='', $return=false) {
903 throw new coding_exception('print_box_start() can not be used any more. Please use $OUTPUT->box_start() instead.');
907 * @deprecated use $OUTPUT->box_end() instead.
908 * @todo remove completely in MDL-40517
910 function print_box_end($return=false) {
911 throw new coding_exception('print_box_end() can not be used any more. Please use $OUTPUT->box_end() instead.');
915 * Print a message in a standard themed container.
918 * @param string $message, the content of the container
919 * @param boolean $clearfix clear both sides
920 * @param string $classes, space-separated class names.
921 * @param string $idbase
922 * @param boolean $return, return as string or just print it
923 * @return string|void Depending on value of $return
925 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
928 $classes .= ' clearfix';
930 $output = $OUTPUT->container($message, $classes, $idbase);
939 * Starts a container using divs
942 * @param boolean $clearfix clear both sides
943 * @param string $classes, space-separated class names.
944 * @param string $idbase
945 * @param boolean $return, return as string or just print it
946 * @return string|void Based on value of $return
948 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
951 $classes .= ' clearfix';
953 $output = $OUTPUT->container_start($classes, $idbase);
962 * @deprecated do not use any more, is not automatic
963 * @todo remove completely in MDL-40517
965 function check_theme_arrows() {
966 throw new coding_exception('check_theme_arrows() has been deprecated, do not use it anymore, it is now automatic.');
970 * Simple function to end a container (see above)
973 * @param boolean $return, return as string or just print it
974 * @return string|void Based on $return
976 function print_container_end($return=false) {
978 $output = $OUTPUT->container_end();
987 * Print a bold message in an optional color.
989 * @deprecated use $OUTPUT->notification instead.
990 * @param string $message The message to print out
991 * @param string $style Optional style to display message text in
992 * @param string $align Alignment option
993 * @param bool $return whether to return an output string or echo now
994 * @return string|bool Depending on $result
996 function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
999 if ($classes == 'green') {
1000 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
1001 $classes = 'notifysuccess'; // Backward compatible with old color system
1004 $output = $OUTPUT->notification($message, $classes);
1013 * Print a continue button that goes to a particular URL.
1015 * @deprecated since Moodle 2.0
1017 * @param string $link The url to create a link to.
1018 * @param bool $return If set to true output is returned rather than echoed, default false
1019 * @return string|void HTML String if return=true nothing otherwise
1021 function print_continue($link, $return = false) {
1022 global $CFG, $OUTPUT;
1025 if (!empty($_SERVER['HTTP_REFERER'])) {
1026 $link = $_SERVER['HTTP_REFERER'];
1027 $link = str_replace('&', '&', $link); // make it valid XHTML
1029 $link = $CFG->wwwroot .'/';
1033 $output = $OUTPUT->continue_button($link);
1042 * Print a standard header
1044 * @param string $title Appears at the top of the window
1045 * @param string $heading Appears at the top of the page
1046 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
1047 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1048 * @param string $meta Meta tags to be added to the header
1049 * @param boolean $cache Should this page be cacheable?
1050 * @param string $button HTML code for a button (usually for module editing)
1051 * @param string $menu HTML code for a popup menu
1052 * @param boolean $usexml use XML for this page
1053 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1054 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1055 * @return string|void If return=true then string else void
1057 function print_header($title='', $heading='', $navigation='', $focus='',
1058 $meta='', $cache=true, $button=' ', $menu=null,
1059 $usexml=false, $bodytags='', $return=false) {
1060 global $PAGE, $OUTPUT;
1062 $PAGE->set_title($title);
1063 $PAGE->set_heading($heading);
1064 $PAGE->set_cacheable($cache);
1065 if ($button == '') {
1068 $PAGE->set_button($button);
1069 $PAGE->set_headingmenu($menu);
1074 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1075 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1078 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1081 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1084 $output = $OUTPUT->header();
1094 * This version of print_header is simpler because the course name does not have to be
1095 * provided explicitly in the strings. It can be used on the site page as in courses
1096 * Eventually all print_header could be replaced by print_header_simple
1098 * @deprecated since Moodle 2.0
1099 * @param string $title Appears at the top of the window
1100 * @param string $heading Appears at the top of the page
1101 * @param string $navigation Premade navigation string (for use as breadcrumbs links)
1102 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1103 * @param string $meta Meta tags to be added to the header
1104 * @param boolean $cache Should this page be cacheable?
1105 * @param string $button HTML code for a button (usually for module editing)
1106 * @param string $menu HTML code for a popup menu
1107 * @param boolean $usexml use XML for this page
1108 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1109 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1110 * @return string|void If $return=true the return string else nothing
1112 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
1113 $cache=true, $button=' ', $menu='', $usexml=false, $bodytags='', $return=false) {
1115 global $COURSE, $CFG, $PAGE, $OUTPUT;
1118 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1119 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1122 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1125 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1128 $PAGE->set_title($title);
1129 $PAGE->set_heading($heading);
1130 $PAGE->set_cacheable(true);
1131 $PAGE->set_button($button);
1133 $output = $OUTPUT->header();
1143 * @deprecated use $OUTPUT->footer() instead.
1144 * @todo remove completely in MDL-40517
1146 function print_footer($course = NULL, $usercourse = NULL, $return = false) {
1147 throw new coding_exception('print_footer() cant be used anymore. Please use $OUTPUT->footer() instead.');
1151 * @deprecated use theme layouts instead.
1152 * @todo remove completely in MDL-40517
1154 function user_login_string($course='ignored', $user='ignored') {
1155 throw new coding_exception('user_login_info() cant be used anymore. User login info is now handled via themes layouts.');
1159 * Prints a nice side block with an optional header. The content can either
1160 * be a block of HTML or a list of text with optional icons.
1162 * @todo Finish documenting this function. Show example of various attributes, etc.
1164 * @static int $block_id Increments for each call to the function
1165 * @param string $heading HTML for the heading. Can include full HTML or just
1166 * plain text - plain text will automatically be enclosed in the appropriate
1168 * @param string $content HTML for the content
1169 * @param array $list an alternative to $content, it you want a list of things with optional icons.
1170 * @param array $icons optional icons for the things in $list.
1171 * @param string $footer Extra HTML content that gets output at the end, inside a <div class="footer">
1172 * @param array $attributes an array of attribute => value pairs that are put on the
1173 * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
1174 * already a class, class='block' is used.
1175 * @param string $title Plain text title, as embedded in the $heading.
1178 function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
1181 // We don't use $heading, becuse it often contains HTML that we don't want.
1182 // However, sometimes $title is not set, but $heading is.
1183 if (empty($title)) {
1184 $title = strip_tags($heading);
1187 // Render list contents to HTML if required.
1188 if (empty($content) && $list) {
1189 $content = $OUTPUT->list_block_contents($icons, $list);
1192 $bc = new block_contents();
1193 $bc->content = $content;
1194 $bc->footer = $footer;
1195 $bc->title = $title;
1197 if (isset($attributes['id'])) {
1198 $bc->id = $attributes['id'];
1199 unset($attributes['id']);
1201 $bc->attributes = $attributes;
1203 echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
1207 * @deprecated blocks are now printed by theme.
1208 * @todo remove completely in MDL-40517
1210 function blocks_have_content(&$blockmanager, $region) {
1211 throw new coding_exception('blocks_have_content() can no longer be used. Blocks are now printed by the theme.');
1215 * @deprecated blocks are now printed by the theme.
1216 * @todo remove completely in MDL-40517
1218 function blocks_print_group($page, $blockmanager, $region) {
1219 throw new coding_exception('function blocks_print_group() can no longer be used. Blocks are now printed by the theme.');
1223 * @deprecated blocks are now printed by the theme.
1224 * @todo remove completely in MDL-40517
1226 function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
1227 throw new coding_exception('blocks_print_group() can no longer be used. Blocks are now printed by the theme.');
1231 * @deprecated Layout is now controlled by the theme.
1232 * @todo remove completely in MDL-40517
1234 function blocks_preferred_width($instances) {
1235 throw new coding_exception('blocks_print_group() can no longer be used. Blocks are now printed by the theme.');
1239 * @deprecated use html_writer::table() instead.
1240 * @todo remove completely in MDL-40517
1242 function print_table($table, $return=false) {
1243 throw new coding_exception('print_table() can no longer be used. Use html_writer::table() instead.');
1247 * @deprecated use $OUTPUT->action_link() instead (note: popups are discouraged for accesibility reasons)
1248 * @todo remove completely in MDL-40517
1250 function link_to_popup_window ($url, $name=null, $linkname=null, $height=400, $width=500, $title=null, $options=null, $return=false) {
1251 throw new coding_exception('link_to_popup_window() can no longer be used. Please to use $OUTPUT->action_link() instead.');
1255 * @deprecated use $OUTPUT->single_button() instead.
1256 * @todo remove completely in MDL-40517
1258 function button_to_popup_window ($url, $name=null, $linkname=null,
1259 $height=400, $width=500, $title=null, $options=null, $return=false,
1260 $id=null, $class=null) {
1261 throw new coding_exception('button_to_popup_window() can no longer be used. Please use $OUTPUT->single_button() instead.');
1265 * @deprecated use $OUTPUT->single_button() instead.
1266 * @todo remove completely in MDL-40517
1268 function print_single_button($link, $options, $label='OK', $method='get', $notusedanymore='',
1269 $return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
1271 throw new coding_exception('print_single_button() can no longer be used. Please use $OUTPUT->single_button() instead.');
1275 * @deprecated use $OUTPUT->spacer() instead.
1276 * @todo remove completely in MDL-40517
1278 function print_spacer($height=1, $width=1, $br=true, $return=false) {
1279 throw new coding_exception('print_spacer() can no longer be used. Please use $OUTPUT->spacer() instead.');
1283 * @deprecated use $OUTPUT->user_picture() instead.
1284 * @todo remove completely in MDL-40517
1286 function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
1287 throw new coding_exception('print_user_picture() can no longer be used. Please use $OUTPUT->user_picture($user, array(\'courseid\'=>$courseid) instead.');
1291 * Prints a basic textarea field.
1293 * @deprecated since Moodle 2.0
1295 * When using this function, you should
1298 * @param bool $usehtmleditor Enables the use of the htmleditor for this field.
1299 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
1300 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
1301 * @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.
1302 * @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.
1303 * @param string $name Name to use for the textarea element.
1304 * @param string $value Initial content to display in the textarea.
1305 * @param int $obsolete deprecated
1306 * @param bool $return If false, will output string. If true, will return string value.
1307 * @param string $id CSS ID to add to the textarea element.
1308 * @return string|void depending on the value of $return
1310 function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
1311 /// $width and height are legacy fields and no longer used as pixels like they used to be.
1312 /// However, you can set them to zero to override the mincols and minrows values below.
1314 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
1315 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
1324 $id = 'edit-'.$name;
1327 if ($usehtmleditor) {
1328 if ($height && ($rows < $minrows)) {
1331 if ($width && ($cols < $mincols)) {
1336 if ($usehtmleditor) {
1337 editors_head_setup();
1338 $editor = editors_get_preferred_editor(FORMAT_HTML);
1339 $editor->use_editor($id, array('legacy'=>true));
1344 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'" spellcheck="true">'."\n";
1345 if ($usehtmleditor) {
1346 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
1350 $str .= '</textarea>'."\n";
1360 * Print a help button.
1362 * @deprecated since Moodle 2.0
1364 function helpbutton($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false, $imagetext='') {
1365 throw new coding_exception('helpbutton() can not be used any more, please see $OUTPUT->help_icon().');
1369 * @deprecated this is now handled by text editors
1370 * @todo remove completely in MDL-40517
1372 function emoticonhelpbutton($form, $field, $return = false) {
1373 throw new coding_exception('emoticonhelpbutton() was removed, new text editors will implement this feature');
1377 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
1378 * Should be used only with htmleditor or textarea.
1382 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
1384 * @return string Link to help button
1386 function editorhelpbutton(){
1393 * Print a help button.
1395 * Prints a special help button for html editors (htmlarea in this case)
1397 * @todo Write code into this function! detect current editor and print correct info
1399 * @return string Only returns an empty string at the moment
1401 function editorshortcutshelpbutton() {
1405 //TODO: detect current editor and print correct info
1411 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
1412 * provide this function with the language strings for sortasc and sortdesc.
1414 * @deprecated since Moodle 2.0
1416 * TODO migrate to outputlib
1417 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
1420 * @param string $direction 'up' or 'down'
1421 * @param string $strsort The language string used for the alt attribute of this image
1422 * @param bool $return Whether to print directly or return the html string
1423 * @return string|void depending on $return
1426 function print_arrow($direction='up', $strsort=null, $return=false) {
1427 // debugging('print_arrow() has been deprecated. Please change your code to use $OUTPUT->arrow().');
1431 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
1437 switch ($direction) {
1452 // Prepare language string
1454 if (empty($strsort) && !empty($sortdir)) {
1455 $strsort = get_string('sort' . $sortdir, 'grades');
1458 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
1468 * Returns a string containing a link to the user documentation.
1469 * Also contains an icon by default. Shown to teachers and admin only.
1471 * @deprecated since Moodle 2.0
1473 function doc_link($path='', $text='', $iconpath='ignored') {
1474 throw new coding_exception('doc_link() can not be used any more, please see $OUTPUT->doc_link().');
1478 * @deprecated use $OUTPUT->render($pagingbar) instead.
1479 * @todo remove completely in MDL-40517
1481 function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) {
1482 throw new coding_exception('print_paging_bar() can not be used any more. Please use $OUTPUT->render($pagingbar) instead.');
1486 * @deprecated use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel) instead.
1487 * @todo remove completely in MDL-40517
1489 function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
1490 throw new coding_exception('notice_yesno() can not be used any more. Please use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel) instead.');
1494 * Given an array of values, output the HTML for a select element with those options.
1496 * @deprecated since Moodle 2.0
1498 * Normally, you only need to use the first few parameters.
1500 * @param array $options The options to offer. An array of the form
1501 * $options[{value}] = {text displayed for that option};
1502 * @param string $name the name of this form control, as in <select name="..." ...
1503 * @param string $selected the option to select initially, default none.
1504 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
1505 * Set this to '' if you don't want a 'nothing is selected' option.
1506 * @param string $script if not '', then this is added to the <select> element as an onchange handler.
1507 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
1508 * @param boolean $return if false (the default) the the output is printed directly, If true, the
1509 * generated HTML is returned as a string.
1510 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
1511 * @param int $tabindex if give, sets the tabindex attribute on the <select> element. Default none.
1512 * @param string $id value to use for the id attribute of the <select> element. If none is given,
1513 * then a suitable one is constructed.
1514 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
1515 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
1516 * $listbox is an integer, that number is used for size instead.
1517 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
1518 * when $listbox display is enabled
1519 * @param string $class value to use for the class attribute of the <select> element. If none is given,
1520 * then a suitable one is constructed.
1521 * @return string|void If $return=true returns string, else echo's and returns void
1523 function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
1524 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
1525 $id='', $listbox=false, $multiple=false, $class='') {
1528 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
1531 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
1533 $attributes = array();
1534 $attributes['disabled'] = $disabled ? 'disabled' : null;
1535 $attributes['tabindex'] = $tabindex ? $tabindex : null;
1536 $attributes['multiple'] = $multiple ? $multiple : null;
1537 $attributes['class'] = $class ? $class : null;
1538 $attributes['id'] = $id ? $id : null;
1540 $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
1550 * @deprecated use html_writer::select_yes_no() instead.
1551 * @todo remove completely in MDL-40517
1553 function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) {
1554 throw new coding_exception('choose_from_menu_yesno() can not be used anymore. Please use html_writerselect_yes_no() instead.');
1558 * @deprecated use html_writer::select() instead.
1559 * @todo remove completely in MDL-40517
1561 function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '',
1562 $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) {
1564 throw new coding_exception('choose_from_menu_nested() can not be used any more. Please use html_writer::select() instead.');
1568 * Prints a help button about a scale
1570 * @deprecated since Moodle 2.0
1573 * @param id $courseid
1574 * @param object $scale
1575 * @param boolean $return If set to true returns rather than echo's
1576 * @return string|bool Depending on value of $return
1578 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
1579 // debugging('print_scale_menu_helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_scale($courseid, $scale).');
1582 $output = $OUTPUT->help_icon_scale($courseid, $scale);
1592 * @deprecated use html_writer::select_time() instead
1593 * @todo remove completely in MDL-40517
1595 function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
1596 throw new moodle_exception('print_time_selector() can not be used any more . Please use html_writer::select_time() instead.');
1600 * @deprecated please use html_writer::select_time instead
1601 * @todo remove completely in MDL-40517
1603 function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
1604 throw new coding_exception('print_date_selector() can not be used any more. Please use html_writer::select_time() instead.');
1608 * Implements a complete little form with a dropdown menu.
1610 * @deprecated since Moodle 2.0
1612 function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false,
1613 $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) {
1614 throw new coding_exception('popup_form() can not be used any more, please see $OUTPUT->single_select or $OUTPUT->url_select().');
1618 * @deprecated use $OUTPUT->close_window_button() instead.
1619 * @todo remove completely in MDL-40517
1621 function close_window_button($name='closewindow', $return=false, $reloadopener = false) {
1622 throw new coding_exception('close_window_button() can not be used any more. Use $OUTPUT->close_window_button() instead.');
1626 * @deprecated use html_writer instead.
1627 * @todo remove completely in MDL-40517
1629 function choose_from_radio ($options, $name, $checked='', $return=false) {
1630 throw new coding_exception('choose_from_radio() can not be used any more. Please use html_writer instead.');
1634 * Display an standard html checkbox with an optional label
1636 * @deprecated since Moodle 2.0
1638 * @staticvar int $idcounter
1639 * @param string $name The name of the checkbox
1640 * @param string $value The valus that the checkbox will pass when checked
1641 * @param bool $checked The flag to tell the checkbox initial state
1642 * @param string $label The label to be showed near the checkbox
1643 * @param string $alt The info to be inserted in the alt tag
1644 * @param string $script If not '', then this is added to the checkbox element
1645 * as an onchange handler.
1646 * @param bool $return Whether this function should return a string or output
1647 * it (defaults to false)
1648 * @return string|void If $return=true returns string, else echo's and returns void
1650 function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
1652 // debugging('print_checkbox() has been deprecated. Please change your code to use html_writer::checkbox().');
1655 if (!empty($script)) {
1656 debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER);
1659 $output = html_writer::checkbox($name, $value, $checked, $label);
1661 if (empty($return)) {
1670 * @deprecated use mforms or html_writer instead.
1671 * @todo remove completely in MDL-40517
1673 function print_textfield($name, $value, $alt = '', $size=50, $maxlength=0, $return=false) {
1674 throw new coding_exception('print_textfield() can not be used anymore. Please use mforms or html_writer instead.');
1679 * @deprecated use $OUTPUT->heading_with_help() instead
1680 * @todo remove completely in MDL-40517
1682 function print_heading_with_help($text, $helppage, $module='moodle', $icon=false, $return=false) {
1683 throw new coding_exception('print_heading_with_help() can not be used anymore. Please use $OUTPUT->heading_with_help() instead.');
1687 * @deprecated use $OUTPUT->edit_button() instead.
1688 * @todo remove completely in MDL-40517
1690 function update_tag_button($tagid) {
1691 throw new coding_exception('update_tag_button() can not be used any more. Please $OUTPUT->edit_button(moodle_url) instead.');
1696 * Prints the 'update this xxx' button that appears on module pages.
1698 * @deprecated since Moodle 2.0
1700 * @param string $cmid the course_module id.
1701 * @param string $ignored not used any more. (Used to be courseid.)
1702 * @param string $string the module name - get_string('modulename', 'xxx')
1703 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
1705 function update_module_button($cmid, $ignored, $string) {
1706 global $CFG, $OUTPUT;
1708 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
1710 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
1712 if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) {
1713 $string = get_string('updatethis', '', $string);
1715 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
1716 return $OUTPUT->single_button($url, $string);
1723 * @deprecated use $OUTPUT->edit_button() instead.
1724 * @todo remove completely in MDL-40517
1726 function update_course_icon($courseid) {
1727 throw new coding_exception('update_course_button() can not be used anymore. Please use $OUTPUT->edit_button(moodle_url) instead.');
1731 * Prints breadcrumb trail of links, called in theme/-/header.html
1733 * This function has now been deprecated please use output's navbar method instead
1737 * echo $OUTPUT->navbar();
1740 * @deprecated since 2.0
1741 * @param mixed $navigation deprecated
1742 * @param string $separator OBSOLETE, and now deprecated
1743 * @param boolean $return False to echo the breadcrumb string (default), true to return it.
1744 * @return string|void String or null, depending on $return.
1746 function print_navigation ($navigation, $separator=0, $return=false) {
1747 global $OUTPUT,$PAGE;
1749 # debugging('print_navigation has been deprecated please update your theme to use $OUTPUT->navbar() instead', DEBUG_DEVELOPER);
1751 $output = $OUTPUT->navbar();
1761 * This function will build the navigation string to be used by print_header
1764 * It automatically generates the site and course level (if appropriate) links.
1766 * If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums')
1767 * and activityinstances (e.g. 'General Developer Forum') navigation levels.
1769 * If you want to add any further navigation links after the ones this function generates,
1770 * the pass an array of extra link arrays like this:
1772 * array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1),
1773 * array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2)
1775 * The normal case is to just add one further link, for example 'Editing forum' after
1776 * 'General Developer Forum', with no link.
1777 * To do that, you need to pass
1778 * array(array('name' => $linktext, 'link' => '', 'type' => 'title'))
1779 * However, becuase this is a very common case, you can use a shortcut syntax, and just
1780 * pass the string 'Editing forum', instead of an array as $extranavlinks.
1782 * At the moment, the link types only have limited significance. Type 'activity' is
1783 * recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types
1784 * that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'.
1785 * This really needs to be documented better. In the mean time, try to be consistent, it will
1786 * enable people to customise the navigation more in future.
1788 * When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course.
1789 * If you get the $cm object using the function get_coursemodule_from_instance or
1790 * get_coursemodule_from_id (as recommended) then this will be done for you automatically.
1791 * If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using
1792 * the $cm->module and $cm->instance fields, but this takes extra database queries, so a
1793 * warning is printed in developer debug mode.
1795 * @deprecated since 2.0
1796 * @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you
1797 * only want one extra item with no link, you can pass a string instead. If you don't want
1798 * any extra links, pass an empty string.
1799 * @param mixed $cm deprecated
1800 * @return array Navigation array
1802 function build_navigation($extranavlinks, $cm = null) {
1803 global $CFG, $COURSE, $DB, $SITE, $PAGE;
1805 if (is_array($extranavlinks) && count($extranavlinks)>0) {
1806 # debugging('build_navigation() has been deprecated, please replace with $PAGE->navbar methods', DEBUG_DEVELOPER);
1807 foreach ($extranavlinks as $nav) {
1808 if (array_key_exists('name', $nav)) {
1809 if (array_key_exists('link', $nav) && !empty($nav['link'])) {
1810 $link = $nav['link'];
1814 $PAGE->navbar->add($nav['name'],$link);
1819 return(array('newnav' => true, 'navlinks' => array()));
1823 * Returns a small popup menu of course activity modules
1825 * Given a course and a (current) coursemodule
1826 * his function returns a small popup menu with all the
1827 * course activity modules in it, as a navigation menu
1828 * The data is taken from the serialised array stored in
1835 * @uses CONTEXT_COURSE
1836 * @param object $course A {@link $COURSE} object.
1837 * @param object $cm A {@link $COURSE} object.
1838 * @param string $targetwindow The target window attribute to us
1841 function navmenu($course, $cm=NULL, $targetwindow='self') {
1842 // This function has been deprecated with the creation of the global nav in
1849 * @deprecated use the settings block instead.
1850 * @todo remove completely in MDL-40517
1852 function switchroles_form($courseid) {
1853 throw new coding_exception('switchroles_form() can not be used any more. The global settings block does this job.');
1857 * @deprecated Please use normal $OUTPUT->header() instead
1858 * @todo remove completely in MDL-40517
1860 function admin_externalpage_print_header($focus='') {
1861 throw new coding_exception('admin_externalpage_print_header can not be used any more. Please $OUTPUT->header() instead.');
1865 * @deprecated Please use normal $OUTPUT->footer() instead
1866 * @todo remove completely in MDL-40517
1868 function admin_externalpage_print_footer() {
1869 throw new coding_exception('admin_externalpage_print_footer can not be used anymore Please $OUTPUT->footer() instead.');
1872 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
1876 * Call this function to add an event to the calendar table and to call any calendar plugins
1878 * @param object $event An object representing an event from the calendar table.
1879 * The event will be identified by the id field. The object event should include the following:
1881 * <li><b>$event->name</b> - Name for the event
1882 * <li><b>$event->description</b> - Description of the event (defaults to '')
1883 * <li><b>$event->format</b> - Format for the description (using formatting types defined at the top of weblib.php)
1884 * <li><b>$event->courseid</b> - The id of the course this event belongs to (0 = all courses)
1885 * <li><b>$event->groupid</b> - The id of the group this event belongs to (0 = no group)
1886 * <li><b>$event->userid</b> - The id of the user this event belongs to (0 = no user)
1887 * <li><b>$event->modulename</b> - Name of the module that creates this event
1888 * <li><b>$event->instance</b> - Instance of the module that owns this event
1889 * <li><b>$event->eventtype</b> - The type info together with the module info could
1890 * be used by calendar plugins to decide how to display event
1891 * <li><b>$event->timestart</b>- Timestamp for start of event
1892 * <li><b>$event->timeduration</b> - Duration (defaults to zero)
1893 * <li><b>$event->visible</b> - 0 if the event should be hidden (e.g. because the activity that created it is hidden)
1895 * @return int|false The id number of the resulting record or false if failed
1897 function add_event($event) {
1899 require_once($CFG->dirroot.'/calendar/lib.php');
1900 $event = calendar_event::create($event);
1901 if ($event !== false) {
1908 * Call this function to update an event in the calendar table
1909 * the event will be identified by the id field of the $event object.
1911 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
1912 * @return bool Success
1914 function update_event($event) {
1916 require_once($CFG->dirroot.'/calendar/lib.php');
1917 $event = (object)$event;
1918 $calendarevent = calendar_event::load($event->id);
1919 return $calendarevent->update($event);
1923 * Call this function to delete the event with id $id from calendar table.
1925 * @param int $id The id of an event from the 'event' table.
1928 function delete_event($id) {
1930 require_once($CFG->dirroot.'/calendar/lib.php');
1931 $event = calendar_event::load($id);
1932 return $event->delete();
1936 * Call this function to hide an event in the calendar table
1937 * the event will be identified by the id field of the $event object.
1939 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
1942 function hide_event($event) {
1944 require_once($CFG->dirroot.'/calendar/lib.php');
1945 $event = new calendar_event($event);
1946 return $event->toggle_visibility(false);
1950 * Call this function to unhide an event in the calendar table
1951 * the event will be identified by the id field of the $event object.
1953 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
1956 function show_event($event) {
1958 require_once($CFG->dirroot.'/calendar/lib.php');
1959 $event = new calendar_event($event);
1960 return $event->toggle_visibility(true);
1964 * @deprecated Use textlib::strtolower($text) instead.
1966 function moodle_strtolower($string, $encoding='') {
1967 throw new coding_exception('moodle_strtolower() cannot be used any more. Please use textlib::strtolower() instead.');
1971 * Original singleton helper function, please use static methods instead,
1972 * ex: textlib::convert()
1974 * @deprecated since Moodle 2.2 use textlib::xxxx() instead
1976 * @return textlib instance
1978 function textlib_get_instance() {
1980 debugging('textlib_get_instance() is deprecated. Please use static calling textlib::functioname() instead.', DEBUG_DEVELOPER);
1982 return new textlib();
1986 * Gets the generic section name for a courses section
1988 * The global function is deprecated. Each course format can define their own generic section name
1990 * @deprecated since 2.4
1991 * @see get_section_name()
1992 * @see format_base::get_section_name()
1994 * @param string $format Course format ID e.g. 'weeks' $course->format
1995 * @param stdClass $section Section object from database
1996 * @return Display name that the course format prefers, e.g. "Week 2"
1998 function get_generic_section_name($format, stdClass $section) {
1999 debugging('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base', DEBUG_DEVELOPER);
2000 return get_string('sectionname', "format_$format") . ' ' . $section->section;
2004 * Returns an array of sections for the requested course id
2006 * It is usually not recommended to display the list of sections used
2007 * in course because the course format may have it's own way to do it.
2009 * If you need to just display the name of the section please call:
2010 * get_section_name($course, $section)
2011 * {@link get_section_name()}
2012 * from 2.4 $section may also be just the field course_sections.section
2014 * If you need the list of all sections it is more efficient to get this data by calling
2015 * $modinfo = get_fast_modinfo($courseorid);
2016 * $sections = $modinfo->get_section_info_all()
2017 * {@link get_fast_modinfo()}
2018 * {@link course_modinfo::get_section_info_all()}
2020 * Information about one section (instance of section_info):
2021 * get_fast_modinfo($courseorid)->get_sections_info($section)
2022 * {@link course_modinfo::get_section_info()}
2024 * @deprecated since 2.4
2026 * @param int $courseid
2027 * @return array Array of section_info objects
2029 function get_all_sections($courseid) {
2031 debugging('get_all_sections() is deprecated. See phpdocs for this function', DEBUG_DEVELOPER);
2032 return get_fast_modinfo($courseid)->get_section_info_all();
2036 * Given a full mod object with section and course already defined, adds this module to that section.
2038 * This function is deprecated, please use {@link course_add_cm_to_section()}
2039 * Note that course_add_cm_to_section() also updates field course_modules.section and
2040 * calls rebuild_course_cache()
2042 * @deprecated since 2.4
2044 * @param object $mod
2045 * @param int $beforemod An existing ID which we will insert the new module before
2046 * @return int The course_sections ID where the mod is inserted
2048 function add_mod_to_section($mod, $beforemod = null) {
2049 debugging('Function add_mod_to_section() is deprecated, please use course_add_cm_to_section()', DEBUG_DEVELOPER);
2051 return course_add_cm_to_section($mod->course, $mod->coursemodule, $mod->section, $beforemod);
2055 * Returns a number of useful structures for course displays
2057 * Function get_all_mods() is deprecated in 2.4
2060 * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
2064 * $mods = get_fast_modinfo($courseorid)->get_cms();
2065 * $modnames = get_module_types_names();
2066 * $modnamesplural = get_module_types_names(true);
2067 * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names();
2070 * @deprecated since 2.4
2072 * @param int $courseid id of the course to get info about
2073 * @param array $mods (return) list of course modules
2074 * @param array $modnames (return) list of names of all module types installed and available
2075 * @param array $modnamesplural (return) list of names of all module types installed and available in the plural form
2076 * @param array $modnamesused (return) list of names of all module types used in the course
2078 function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
2079 debugging('Function get_all_mods() is deprecated. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details', DEBUG_DEVELOPER);
2082 $modnames = get_module_types_names();
2083 $modnamesplural= get_module_types_names(true);
2084 $modinfo = get_fast_modinfo($courseid);
2085 $mods = $modinfo->get_cms();
2086 $modnamesused = $modinfo->get_used_module_names();
2090 * Returns course section - creates new if does not exist yet
2092 * This function is deprecated. To create a course section call:
2093 * course_create_sections_if_missing($courseorid, $sections);
2094 * to get the section call:
2095 * get_fast_modinfo($courseorid)->get_section_info($sectionnum);
2097 * @see course_create_sections_if_missing()
2098 * @see get_fast_modinfo()
2099 * @deprecated since 2.4
2101 * @param int $section relative section number (field course_sections.section)
2102 * @param int $courseid
2103 * @return stdClass record from table {course_sections}
2105 function get_course_section($section, $courseid) {
2107 debugging('Function get_course_section() is deprecated. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.', DEBUG_DEVELOPER);
2109 if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) {
2112 $cw = new stdClass();
2113 $cw->course = $courseid;
2114 $cw->section = $section;
2116 $cw->summaryformat = FORMAT_HTML;
2118 $id = $DB->insert_record("course_sections", $cw);
2119 rebuild_course_cache($courseid, true);
2120 return $DB->get_record("course_sections", array("id"=>$id));
2124 * Return the start and end date of the week in Weekly course format
2126 * It is not recommended to use this function outside of format_weeks plugin
2128 * @deprecated since 2.4
2129 * @see format_weeks::get_section_dates()
2131 * @param stdClass $section The course_section entry from the DB
2132 * @param stdClass $course The course entry from DB
2133 * @return stdClass property start for startdate, property end for enddate
2135 function format_weeks_get_section_dates($section, $course) {
2136 debugging('Function format_weeks_get_section_dates() is deprecated. It is not recommended to'.
2137 ' use it outside of format_weeks plugin', DEBUG_DEVELOPER);
2138 if (isset($course->format) && $course->format === 'weeks') {
2139 return course_get_format($course)->get_section_dates($section);
2145 * Obtains shared data that is used in print_section when displaying a
2146 * course-module entry.
2148 * Deprecated. Instead of:
2149 * list($content, $name) = get_print_section_cm_text($cm, $course);
2151 * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
2152 * $name = $cm->get_formatted_name();
2154 * @deprecated since 2.5
2155 * @see cm_info::get_formatted_content()
2156 * @see cm_info::get_formatted_name()
2158 * This data is also used in other areas of the code.
2159 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
2160 * @param object $course (argument not used)
2161 * @return array An array with the following values in this order:
2162 * $content (optional extra content for after link),
2163 * $instancename (text of link)
2165 function get_print_section_cm_text(cm_info $cm, $course) {
2166 debugging('Function get_print_section_cm_text() is deprecated. Please use '.
2167 'cm_info::get_formatted_content() and cm_info::get_formatted_name()',
2169 return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)),
2170 $cm->get_formatted_name());
2174 * Prints the menus to add activities and resources.
2176 * Deprecated. Please use:
2177 * $courserenderer = $PAGE->get_renderer('core', 'course');
2178 * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
2179 * array('inblock' => $vertical));
2180 * echo $output; // if $return argument in print_section_add_menus() set to false
2182 * @deprecated since 2.5
2183 * @see core_course_renderer::course_section_add_cm_control()
2185 * @param stdClass $course course object, must be the same as set on the page
2186 * @param int $section relative section number (field course_sections.section)
2187 * @param null|array $modnames (argument ignored) get_module_types_names() is used instead of argument
2188 * @param bool $vertical Vertical orientation
2189 * @param bool $return Return the menus or send them to output
2190 * @param int $sectionreturn The section to link back to
2191 * @return void|string depending on $return
2193 function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
2195 debugging('Function print_section_add_menus() is deprecated. Please use course renderer '.
2196 'function course_section_add_cm_control()', DEBUG_DEVELOPER);
2198 $courserenderer = $PAGE->get_renderer('core', 'course');
2199 $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
2200 array('inblock' => $vertical));
2205 return !empty($output);
2210 * Produces the editing buttons for a module
2212 * Deprecated. Please use:
2213 * $courserenderer = $PAGE->get_renderer('core', 'course');
2214 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
2215 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
2217 * @deprecated since 2.5
2218 * @see course_get_cm_edit_actions()
2219 * @see core_course_renderer->course_section_cm_edit_actions()
2221 * @param stdClass $mod The module to produce editing buttons for
2222 * @param bool $absolute_ignored (argument ignored) - all links are absolute
2223 * @param bool $moveselect (argument ignored)
2224 * @param int $indent The current indenting
2225 * @param int $section The section to link back to
2226 * @return string XHTML for the editing buttons
2228 function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
2230 debugging('Function make_editing_buttons() is deprecated, please see PHPdocs in '.
2231 'lib/deprecatedlib.php on how to replace it', DEBUG_DEVELOPER);
2232 if (!($mod instanceof cm_info)) {
2233 $modinfo = get_fast_modinfo($mod->course);
2234 $mod = $modinfo->get_cm($mod->id);
2236 $actions = course_get_cm_edit_actions($mod, $indent, $section);
2238 $courserenderer = $PAGE->get_renderer('core', 'course');
2239 // The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap
2240 // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
2241 // the course page HTML will allow this to be removed.
2242 return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
2246 * Prints a section full of activity modules
2248 * Deprecated. Please use:
2249 * $courserenderer = $PAGE->get_renderer('core', 'course');
2250 * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn,
2251 * array('hidecompletion' => $hidecompletion));
2253 * @deprecated since 2.5
2254 * @see core_course_renderer::course_section_cm_list()
2256 * @param stdClass $course The course
2257 * @param stdClass|section_info $section The section object containing properties id and section
2258 * @param array $mods (argument not used)
2259 * @param array $modnamesused (argument not used)
2260 * @param bool $absolute (argument not used)
2261 * @param string $width (argument not used)
2262 * @param bool $hidecompletion Hide completion status
2263 * @param int $sectionreturn The section to return to
2266 function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
2268 debugging('Function print_section() is deprecated. Please use course renderer function '.
2269 'course_section_cm_list() instead.', DEBUG_DEVELOPER);
2270 $displayoptions = array('hidecompletion' => $hidecompletion);
2271 $courserenderer = $PAGE->get_renderer('core', 'course');
2272 echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions);
2276 * Displays the list of courses with user notes
2278 * This function is not used in core. It was replaced by block course_overview
2280 * @deprecated since 2.5
2282 * @param array $courses
2283 * @param array $remote_courses
2285 function print_overview($courses, array $remote_courses=array()) {
2286 global $CFG, $USER, $DB, $OUTPUT;
2287 debugging('Function print_overview() is deprecated. Use block course_overview to display this information', DEBUG_DEVELOPER);
2289 $htmlarray = array();
2290 if ($modules = $DB->get_records('modules')) {
2291 foreach ($modules as $mod) {
2292 if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) {
2293 include_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php');
2294 $fname = $mod->name.'_print_overview';
2295 if (function_exists($fname)) {
2296 $fname($courses,$htmlarray);
2301 foreach ($courses as $course) {
2302 $fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
2303 echo $OUTPUT->box_start('coursebox');
2304 $attributes = array('title' => s($fullname));
2305 if (empty($course->visible)) {
2306 $attributes['class'] = 'dimmed';
2308 echo $OUTPUT->heading(html_writer::link(
2309 new moodle_url('/course/view.php', array('id' => $course->id)), $fullname, $attributes), 3);
2310 if (array_key_exists($course->id,$htmlarray)) {
2311 foreach ($htmlarray[$course->id] as $modname => $html) {
2315 echo $OUTPUT->box_end();
2318 if (!empty($remote_courses)) {
2319 echo $OUTPUT->heading(get_string('remotecourses', 'mnet'));
2321 foreach ($remote_courses as $course) {
2322 echo $OUTPUT->box_start('coursebox');
2323 $attributes = array('title' => s($course->fullname));
2324 echo $OUTPUT->heading(html_writer::link(
2325 new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)),
2326 format_string($course->shortname),
2327 $attributes) . ' (' . format_string($course->hostname) . ')', 3);
2328 echo $OUTPUT->box_end();
2333 * This function trawls through the logs looking for
2334 * anything new since the user's last login
2336 * This function was only used to print the content of block recent_activity
2337 * All functionality is moved into class {@link block_recent_activity}
2338 * and renderer {@link block_recent_activity_renderer}
2340 * @deprecated since 2.5
2341 * @param stdClass $course
2343 function print_recent_activity($course) {
2344 // $course is an object
2345 global $CFG, $USER, $SESSION, $DB, $OUTPUT;
2346 debugging('Function print_recent_activity() is deprecated. It is not recommended to'.
2347 ' use it outside of block_recent_activity', DEBUG_DEVELOPER);
2349 $context = context_course::instance($course->id);
2351 $viewfullnames = has_capability('moodle/site:viewfullnames', $context);
2353 $timestart = round(time() - COURSE_MAX_RECENT_PERIOD, -2); // better db caching for guests - 100 seconds
2355 if (!isguestuser()) {
2356 if (!empty($USER->lastcourseaccess[$course->id])) {
2357 if ($USER->lastcourseaccess[$course->id] > $timestart) {
2358 $timestart = $USER->lastcourseaccess[$course->id];
2363 echo '<div class="activitydate">';
2364 echo get_string('activitysince', '', userdate($timestart));
2366 echo '<div class="activityhead">';
2368 echo '<a href="'.$CFG->wwwroot.'/course/recent.php?id='.$course->id.'">'.get_string('recentactivityreport').'</a>';
2374 /// Firstly, have there been any new enrolments?
2376 $users = get_recent_enrolments($course->id, $timestart);
2378 //Accessibility: new users now appear in an <OL> list.
2380 echo '<div class="newusers">';
2381 echo $OUTPUT->heading(get_string("newusers").':', 3);
2383 echo "<ol class=\"list\">\n";
2384 foreach ($users as $user) {
2385 $fullname = fullname($user, $viewfullnames);
2386 echo '<li class="name"><a href="'."$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id\">$fullname</a></li>\n";
2388 echo "</ol>\n</div>\n";
2391 /// Next, have there been any modifications to the course structure?
2393 $modinfo = get_fast_modinfo($course);
2395 $changelist = array();
2397 $logs = $DB->get_records_select('log', "time > ? AND course = ? AND
2398 module = 'course' AND
2399 (action = 'add mod' OR action = 'update mod' OR action = 'delete mod')",
2400 array($timestart, $course->id), "id ASC");
2403 $actions = array('add mod', 'update mod', 'delete mod');
2404 $newgones = array(); // added and later deleted items
2405 foreach ($logs as $key => $log) {
2406 if (!in_array($log->action, $actions)) {
2409 $info = explode(' ', $log->info);
2411 // note: in most cases I replaced hardcoding of label with use of
2412 // $cm->has_view() but it was not possible to do this here because
2413 // we don't necessarily have the $cm for it
2414 if ($info[0] == 'label') { // Labels are ignored in recent activity
2418 if (count($info) != 2) {
2419 debugging("Incorrect log entry info: id = ".$log->id, DEBUG_DEVELOPER);
2423 $modname = $info[0];
2424 $instanceid = $info[1];
2426 if ($log->action == 'delete mod') {
2427 // unfortunately we do not know if the mod was visible
2428 if (!array_key_exists($log->info, $newgones)) {
2429 $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $modname));
2430 $changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted);
2433 if (!isset($modinfo->instances[$modname][$instanceid])) {
2434 if ($log->action == 'add mod') {
2435 // do not display added and later deleted activities
2436 $newgones[$log->info] = true;
2440 $cm = $modinfo->instances[$modname][$instanceid];
2441 if (!$cm->uservisible) {
2445 if ($log->action == 'add mod') {
2446 $stradded = get_string('added', 'moodle', get_string('modulename', $modname));
2447 $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>");
2449 } else if ($log->action == 'update mod' and empty($changelist[$log->info])) {
2450 $strupdated = get_string('updated', 'moodle', get_string('modulename', $modname));
2451 $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>");
2457 if (!empty($changelist)) {
2458 echo $OUTPUT->heading(get_string("courseupdates").':', 3);
2460 foreach ($changelist as $changeinfo => $change) {
2461 echo '<p class="activity">'.$change['text'].'</p>';
2465 /// Now display new things from each module
2467 $usedmodules = array();
2468 foreach($modinfo->cms as $cm) {
2469 if (isset($usedmodules[$cm->modname])) {
2472 if (!$cm->uservisible) {
2475 $usedmodules[$cm->modname] = $cm->modname;
2478 foreach ($usedmodules as $modname) { // Each module gets it's own logs and prints them
2479 if (file_exists($CFG->dirroot.'/mod/'.$modname.'/lib.php')) {
2480 include_once($CFG->dirroot.'/mod/'.$modname.'/lib.php');
2481 $print_recent_activity = $modname.'_print_recent_activity';
2482 if (function_exists($print_recent_activity)) {
2483 // NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames!
2484 $content = $print_recent_activity($course, $viewfullnames, $timestart) || $content;
2487 debugging("Missing lib.php in lib/{$modname} - please reinstall files or uninstall the module");
2492 echo '<p class="message">'.get_string('nothingnew').'</p>';
2497 * Delete a course module and any associated data at the course level (events)
2498 * Until 1.5 this function simply marked a deleted flag ... now it
2499 * deletes it completely.
2501 * @deprecated since 2.5
2503 * @param int $id the course module id
2504 * @return boolean true on success, false on failure
2506 function delete_course_module($id) {
2507 debugging('Function delete_course_module() is deprecated. Please use course_delete_module() instead.', DEBUG_DEVELOPER);
2511 require_once($CFG->libdir.'/gradelib.php');
2512 require_once($CFG->dirroot.'/blog/lib.php');
2514 if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) {
2517 $modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module));
2518 //delete events from calendar
2519 if ($events = $DB->get_records('event', array('instance'=>$cm->instance, 'modulename'=>$modulename))) {
2520 foreach($events as $event) {
2521 delete_event($event->id);
2524 //delete grade items, outcome items and grades attached to modules
2525 if ($grade_items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename,
2526 'iteminstance'=>$cm->instance, 'courseid'=>$cm->course))) {
2527 foreach ($grade_items as $grade_item) {
2528 $grade_item->delete('moddelete');
2531 // Delete completion and availability data; it is better to do this even if the
2532 // features are not turned on, in case they were turned on previously (these will be
2533 // very quick on an empty table)
2534 $DB->delete_records('course_modules_completion', array('coursemoduleid' => $cm->id));
2535 $DB->delete_records('course_modules_availability', array('coursemoduleid'=> $cm->id));
2536 $DB->delete_records('course_completion_criteria', array('moduleinstance' => $cm->id,
2537 'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY));
2539 delete_context(CONTEXT_MODULE, $cm->id);
2540 return $DB->delete_records('course_modules', array('id'=>$cm->id));
2544 * Prints the turn editing on/off button on course/index.php or course/category.php.
2546 * @deprecated since 2.5
2548 * @param integer $categoryid The id of the category we are showing, or 0 for system context.
2549 * @return string HTML of the editing button, or empty string, if this user is not allowed
2552 function update_category_button($categoryid = 0) {
2553 global $CFG, $PAGE, $OUTPUT;
2554 debugging('Function update_category_button() is deprecated. Pages to view '.
2555 'and edit courses are now separate and no longer depend on editing mode.',
2558 // Check permissions.
2559 if (!can_edit_in_category($categoryid)) {
2563 // Work out the appropriate action.
2564 if ($PAGE->user_is_editing()) {
2565 $label = get_string('turneditingoff');
2568 $label = get_string('turneditingon');
2572 // Generate the button HTML.
2573 $options = array('categoryedit' => $edit, 'sesskey' => sesskey());
2575 $options['id'] = $categoryid;
2576 $page = 'category.php';
2578 $page = 'index.php';
2580 return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get');
2584 * This function recursively travels the categories, building up a nice list
2585 * for display. It also makes an array that list all the parents for each
2588 * For example, if you have a tree of categories like:
2589 * Miscellaneous (id = 1)
2590 * Subcategory (id = 2)
2591 * Sub-subcategory (id = 4)
2592 * Other category (id = 3)
2593 * Then after calling this function you will have
2594 * $list = array(1 => 'Miscellaneous', 2 => 'Miscellaneous / Subcategory',
2595 * 4 => 'Miscellaneous / Subcategory / Sub-subcategory',
2596 * 3 => 'Other category');
2597 * $parents = array(2 => array(1), 4 => array(1, 2));
2599 * If you specify $requiredcapability, then only categories where the current
2600 * user has that capability will be added to $list, although all categories
2601 * will still be added to $parents, and if you only have $requiredcapability
2602 * in a child category, not the parent, then the child catgegory will still be
2605 * If you specify the option $excluded, then that category, and all its children,
2606 * are omitted from the tree. This is useful when you are doing something like
2607 * moving categories, where you do not want to allow people to move a category
2608 * to be the child of itself.
2610 * This function is deprecated! For list of categories use
2611 * coursecat::make_all_categories($requiredcapability, $excludeid, $separator)
2612 * For parents of one particular category use
2613 * coursecat::get($id)->get_parents()
2615 * @deprecated since 2.5
2617 * @param array $list For output, accumulates an array categoryid => full category path name
2618 * @param array $parents For output, accumulates an array categoryid => list of parent category ids.
2619 * @param string/array $requiredcapability if given, only categories where the current
2620 * user has this capability will be added to $list. Can also be an array of capabilities,
2621 * in which case they are all required.
2622 * @param integer $excludeid Omit this category and its children from the lists built.
2623 * @param object $category Not used
2624 * @param string $path Not used
2626 function make_categories_list(&$list, &$parents, $requiredcapability = '',
2627 $excludeid = 0, $category = NULL, $path = "") {
2629 require_once($CFG->libdir.'/coursecatlib.php');
2631 debugging('Global function make_categories_list() is deprecated. Please use '.
2632 'coursecat::make_categories_list() and coursecat::get_parents()',
2635 // For categories list use just this one function:
2639 $list += coursecat::make_categories_list($requiredcapability, $excludeid);
2641 // Building the list of all parents of all categories in the system is highly undesirable and hardly ever needed.
2642 // Usually user needs only parents for one particular category, in which case should be used:
2643 // coursecat::get($categoryid)->get_parents()
2644 if (empty($parents)) {
2647 $all = $DB->get_records_sql('SELECT id, parent FROM {course_categories} ORDER BY sortorder');
2648 foreach ($all as $record) {
2649 if ($record->parent) {
2650 $parents[$record->id] = array_merge($parents[$record->parent], array($record->parent));
2652 $parents[$record->id] = array();
2658 * Delete category, but move contents to another category.
2660 * This function is deprecated. Please use
2661 * coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2663 * @see coursecat::delete_move()
2664 * @deprecated since 2.5
2666 * @param object $category
2667 * @param int $newparentid category id
2668 * @return bool status
2670 function category_delete_move($category, $newparentid, $showfeedback=true) {
2672 require_once($CFG->libdir.'/coursecatlib.php');
2674 debugging('Function category_delete_move() is deprecated. Please use coursecat::delete_move() instead.');
2676 return coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2680 * Recursively delete category including all subcategories and courses.
2682 * This function is deprecated. Please use
2683 * coursecat::get($category->id)->delete_full($showfeedback);
2685 * @see coursecat::delete_full()
2686 * @deprecated since 2.5
2688 * @param stdClass $category
2689 * @param boolean $showfeedback display some notices
2690 * @return array return deleted courses
2692 function category_delete_full($category, $showfeedback=true) {
2694 require_once($CFG->libdir.'/coursecatlib.php');
2696 debugging('Function category_delete_full() is deprecated. Please use coursecat::delete_full() instead.');
2698 return coursecat::get($category->id)->delete_full($showfeedback);
2702 * Efficiently moves a category - NOTE that this can have
2703 * a huge impact access-control-wise...
2705 * This function is deprecated. Please use
2706 * $coursecat = coursecat::get($category->id);
2707 * if ($coursecat->can_change_parent($newparentcat->id)) {
2708 * $coursecat->change_parent($newparentcat->id);
2711 * Alternatively you can use
2712 * $coursecat->update(array('parent' => $newparentcat->id));
2714 * Function update() also updates field course_categories.timemodified
2716 * @see coursecat::change_parent()
2717 * @see coursecat::update()
2718 * @deprecated since 2.5
2720 * @param stdClass|coursecat $category
2721 * @param stdClass|coursecat $newparentcat
2723 function move_category($category, $newparentcat) {
2725 require_once($CFG->libdir.'/coursecatlib.php');
2727 debugging('Function move_category() is deprecated. Please use coursecat::change_parent() instead.');
2729 return coursecat::get($category->id)->change_parent($newparentcat->id);
2733 * Hide course category and child course and subcategories
2735 * This function is deprecated. Please use
2736 * coursecat::get($category->id)->hide();
2738 * @see coursecat::hide()
2739 * @deprecated since 2.5
2741 * @param stdClass $category
2744 function course_category_hide($category) {
2746 require_once($CFG->libdir.'/coursecatlib.php');
2748 debugging('Function course_category_hide() is deprecated. Please use coursecat::hide() instead.');
2750 coursecat::get($category->id)->hide();
2754 * Show course category and child course and subcategories
2756 * This function is deprecated. Please use
2757 * coursecat::get($category->id)->show();
2759 * @see coursecat::show()
2760 * @deprecated since 2.5
2762 * @param stdClass $category
2765 function course_category_show($category) {
2767 require_once($CFG->libdir.'/coursecatlib.php');
2769 debugging('Function course_category_show() is deprecated. Please use coursecat::show() instead.');
2771 coursecat::get($category->id)->show();
2775 * Return specified category, default if given does not exist
2777 * This function is deprecated.
2778 * To get the category with the specified it please use:
2779 * coursecat::get($catid, IGNORE_MISSING);
2781 * coursecat::get($catid, MUST_EXIST);
2783 * To get the first available category please use
2784 * coursecat::get_default();
2786 * class coursecat will also make sure that at least one category exists in DB
2788 * @deprecated since 2.5
2789 * @see coursecat::get()
2790 * @see coursecat::get_default()
2792 * @param int $catid course category id
2793 * @return object caregory
2795 function get_course_category($catid=0) {
2798 debugging('Function get_course_category() is deprecated. Please use coursecat::get(), see phpdocs for more details');
2802 if (!empty($catid)) {
2803 $category = $DB->get_record('course_categories', array('id'=>$catid));
2807 // the first category is considered default for now
2808 if ($category = $DB->get_records('course_categories', null, 'sortorder', '*', 0, 1)) {
2809 $category = reset($category);
2812 $cat = new stdClass();
2813 $cat->name = get_string('miscellaneous');
2815 $cat->sortorder = MAX_COURSES_IN_CATEGORY;
2816 $cat->timemodified = time();
2817 $catid = $DB->insert_record('course_categories', $cat);
2818 // make sure category context exists
2819 context_coursecat::instance($catid);
2820 mark_context_dirty('/'.SYSCONTEXTID);
2821 fix_course_sortorder(); // Required to build course_categories.depth and .path.
2822 $category = $DB->get_record('course_categories', array('id'=>$catid));
2830 * Create a new course category and marks the context as dirty
2832 * This function does not set the sortorder for the new category and
2833 * {@link fix_course_sortorder()} should be called after creating a new course
2836 * Please note that this function does not verify access control.
2838 * This function is deprecated. It is replaced with the method create() in class coursecat.
2839 * {@link coursecat::create()} also verifies the data, fixes sortorder and logs the action
2841 * @deprecated since 2.5
2843 * @param object $category All of the data required for an entry in the course_categories table
2844 * @return object new course category
2846 function create_course_category($category) {
2849 debugging('Function create_course_category() is deprecated. Please use coursecat::create(), see phpdocs for more details', DEBUG_DEVELOPER);
2851 $category->timemodified = time();
2852 $category->id = $DB->insert_record('course_categories', $category);
2853 $category = $DB->get_record('course_categories', array('id' => $category->id));
2855 // We should mark the context as dirty
2856 $category->context = context_coursecat::instance($category->id);
2857 $category->context->mark_dirty();
2863 * Returns an array of category ids of all the subcategories for a given
2866 * This function is deprecated.
2868 * To get visible children categories of the given category use:
2869 * coursecat::get($categoryid)->get_children();
2870 * This function will return the array or coursecat objects, on each of them
2871 * you can call get_children() again
2873 * @see coursecat::get()
2874 * @see coursecat::get_children()
2876 * @deprecated since 2.5
2879 * @param int $catid - The id of the category whose subcategories we want to find.
2880 * @return array of category ids.
2882 function get_all_subcategories($catid) {
2885 debugging('Function get_all_subcategories() is deprecated. Please use appropriate methods() of coursecat class. See phpdocs for more details',
2890 if ($categories = $DB->get_records('course_categories', array('parent' => $catid))) {
2891 foreach ($categories as $cat) {
2892 array_push($subcats, $cat->id);
2893 $subcats = array_merge($subcats, get_all_subcategories($cat->id));
2900 * Gets the child categories of a given courses category
2902 * This function is deprecated. Please use functions in class coursecat:
2903 * - coursecat::get($parentid)->has_children()
2904 * tells if the category has children (visible or not to the current user)
2906 * - coursecat::get($parentid)->get_children()
2907 * returns an array of coursecat objects, each of them represents a children category visible
2908 * to the current user (i.e. visible=1 or user has capability to view hidden categories)
2910 * - coursecat::get($parentid)->get_children_count()
2911 * returns number of children categories visible to the current user
2913 * - coursecat::count_all()
2914 * returns total count of all categories in the system (both visible and not)
2916 * - coursecat::get_default()
2917 * returns the first category (usually to be used if count_all() == 1)
2919 * @deprecated since 2.5
2921 * @param int $parentid the id of a course category.
2922 * @return array all the child course categories.
2924 function get_child_categories($parentid) {
2926 debugging('Function get_child_categories() is deprecated. Use coursecat::get_children() or see phpdocs for more details.',
2930 $sql = context_helper::get_preload_record_columns_sql('ctx');
2931 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
2932 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
2933 array(CONTEXT_COURSECAT, $parentid));
2934 foreach ($records as $category) {
2935 context_helper::preload_from_record($category);
2936 if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) {
2945 * Returns a sorted list of categories.
2947 * When asking for $parent='none' it will return all the categories, regardless
2948 * of depth. Wheen asking for a specific parent, the default is to return
2949 * a "shallow" resultset. Pass false to $shallow and it will return all
2950 * the child categories as well.
2952 * @deprecated since 2.5
2954 * This function is deprecated. Use appropriate functions from class coursecat.
2957 * coursecat::get($categoryid)->get_children()
2958 * - returns all children of the specified category as instances of class
2959 * coursecat, which means on each of them method get_children() can be called again
2961 * coursecat::get($categoryid)->get_children(array('recursive' => true))
2962 * - returns all children of the specified category and all subcategories
2964 * coursecat::get(0)->get_children(array('recursive' => true))
2965 * - returns all categories defined in the system
2967 * Sort fields can be specified, see phpdocs to {@link coursecat::get_children()}
2969 * Also see functions {@link coursecat::get_children_count()}, {@link coursecat::count_all()},
2970 * {@link coursecat::get_default()}
2972 * The code of this deprecated function is left as it is because coursecat::get_children()
2973 * returns categories as instances of coursecat and not stdClass
2975 * @param string $parent The parent category if any
2976 * @param string $sort the sortorder
2977 * @param bool $shallow - set to false to get the children too
2978 * @return array of categories
2980 function get_categories($parent='none', $sort=NULL, $shallow=true) {
2983 debugging('Function get_categories() is deprecated. Please use coursecat::get_children(). See phpdocs for more details',
2986 if ($sort === NULL) {
2987 $sort = 'ORDER BY cc.sortorder ASC';
2988 } elseif ($sort ==='') {
2989 // leave it as empty
2991 $sort = "ORDER BY $sort";
2994 list($ccselect, $ccjoin) = context_instance_preload_sql('cc.id', CONTEXT_COURSECAT, 'ctx');
2996 if ($parent === 'none') {
2997 $sql = "SELECT cc.* $ccselect
2998 FROM {course_categories} cc
3003 } elseif ($shallow) {
3004 $sql = "SELECT cc.* $ccselect
3005 FROM {course_categories} cc
3009 $params = array($parent);
3012 $sql = "SELECT cc.* $ccselect
3013 FROM {course_categories} cc
3015 JOIN {course_categories} ccp
3016 ON ((cc.parent = ccp.id) OR (cc.path LIKE ".$DB->sql_concat('ccp.path',"'/%'")."))
3019 $params = array($parent);
3021 $categories = array();
3023 $rs = $DB->get_recordset_sql($sql, $params);
3024 foreach($rs as $cat) {
3025 context_helper::preload_from_record($cat);
3026 $catcontext = context_coursecat::instance($cat->id);
3027 if ($cat->visible || has_capability('moodle/category:viewhiddencategories', $catcontext)) {
3028 $categories[$cat->id] = $cat;
3036 * Displays a course search form
3038 * This function is deprecated, please use course renderer:
3039 * $renderer = $PAGE->get_renderer('core', 'course');
3040 * echo $renderer->course_search_form($value, $format);
3042 * @deprecated since 2.5
3044 * @param string $value default value to populate the search field
3045 * @param bool $return if true returns the value, if false - outputs
3046 * @param string $format display format - 'plain' (default), 'short' or 'navbar'
3047 * @return null|string
3049 function print_course_search($value="", $return=false, $format="plain") {
3051 debugging('Function print_course_search() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3052 $renderer = $PAGE->get_renderer('core', 'course');
3054 return $renderer->course_search_form($value, $format);
3056 echo $renderer->course_search_form($value, $format);
3061 * Prints custom user information on the home page
3063 * This function is deprecated, please use:
3064 * $renderer = $PAGE->get_renderer('core', 'course');
3065 * echo $renderer->frontpage_my_courses()
3067 * @deprecated since 2.5
3069 function print_my_moodle() {
3071 debugging('Function print_my_moodle() is deprecated, please use course renderer function frontpage_my_courses()', DEBUG_DEVELOPER);
3073 $renderer = $PAGE->get_renderer('core', 'course');
3074 echo $renderer->frontpage_my_courses();
3078 * Prints information about one remote course
3080 * This function is deprecated, it is replaced with protected function
3081 * {@link core_course_renderer::frontpage_remote_course()}
3082 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
3084 * @deprecated since 2.5
3086 function print_remote_course($course, $width="100%") {
3088 debugging('Function print_remote_course() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3092 $url = "{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&wantsurl=/course/view.php?id={$course->remoteid}";
3094 echo '<div class="coursebox remotecoursebox clearfix">';
3095 echo '<div class="info">';
3096 echo '<div class="name"><a title="'.get_string('entercourse').'"'.
3097 $linkcss.' href="'.$url.'">'
3098 . format_string($course->fullname) .'</a><br />'
3099 . format_string($course->hostname) . ' : '
3100 . format_string($course->cat_name) . ' : '
3101 . format_string($course->shortname). '</div>';
3102 echo '</div><div class="summary">';
3103 $options = new stdClass();
3104 $options->noclean = true;
3105 $options->para = false;
3106 $options->overflowdiv = true;
3107 echo format_text($course->summary, $course->summaryformat, $options);
3113 * Prints information about one remote host
3115 * This function is deprecated, it is replaced with protected function
3116 * {@link core_course_renderer::frontpage_remote_host()}
3117 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
3119 * @deprecated since 2.5
3121 function print_remote_host($host, $width="100%") {
3123 debugging('Function print_remote_host() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3127 echo '<div class="coursebox clearfix">';
3128 echo '<div class="info">';
3129 echo '<div class="name">';
3130 echo '<img src="'.$OUTPUT->pix_url('i/mnethost') . '" class="icon" alt="'.get_string('course').'" />';
3131 echo '<a title="'.s($host['name']).'" href="'.s($host['url']).'">'
3132 . s($host['name']).'</a> - ';
3133 echo $host['count'] . ' ' . get_string('courses');
3140 * Recursive function to print out all the categories in a nice format
3141 * with or without courses included
3143 * @deprecated since 2.5
3145 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3147 function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) {
3149 debugging('Function print_whole_category_list() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3151 $renderer = $PAGE->get_renderer('core', 'course');
3152 if ($showcourses && $category) {
3153 echo $renderer->course_category($category);
3154 } else if ($showcourses) {
3155 echo $renderer->frontpage_combo_list();
3157 echo $renderer->frontpage_categories_list();
3162 * Prints the category information.
3164 * @deprecated since 2.5
3166 * This function was only used by {@link print_whole_category_list()} but now
3167 * all course category rendering is moved to core_course_renderer.
3169 * @param stdClass $category
3170 * @param int $depth The depth of the category.
3171 * @param bool $showcourses If set to true course information will also be printed.
3172 * @param array|null $courses An array of courses belonging to the category, or null if you don't have it yet.
3174 function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) {
3176 debugging('Function print_category_info() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3178 $renderer = $PAGE->get_renderer('core', 'course');
3179 echo $renderer->course_category($category);
3183 * This function generates a structured array of courses and categories.
3185 * @deprecated since 2.5
3187 * This function is not used any more in moodle core and course renderer does not have render function for it.
3188 * Combo list on the front page is displayed as:
3189 * $renderer = $PAGE->get_renderer('core', 'course');
3190 * echo $renderer->frontpage_combo_list()
3192 * The new class {@link coursecat} stores the information about course category tree
3193 * To get children categories use:
3194 * coursecat::get($id)->get_children()
3195 * To get list of courses use:
3196 * coursecat::get($id)->get_courses()
3198 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3203 function get_course_category_tree($id = 0, $depth = 0) {
3206 debugging('Function get_course_category_tree() is deprecated, please use course renderer or coursecat class, see function phpdocs for more info', DEBUG_DEVELOPER);
3209 $categories = array();
3210 $categoryids = array();
3211 $sql = context_helper::get_preload_record_columns_sql('ctx');
3212 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
3213 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
3214 array(CONTEXT_COURSECAT, $id));
3215 foreach ($records as $category) {
3216 context_helper::preload_from_record($category);
3217 if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) {
3220 $categories[] = $category;
3221 $categoryids[$category->id] = $category;
3222 if (empty($CFG->maxcategorydepth) || $depth <= $CFG->maxcategorydepth) {
3223 list($category->categories, $subcategories) = get_course_category_tree($category->id, $depth+1);
3224 foreach ($subcategories as $subid=>$subcat) {
3225 $categoryids[$subid] = $subcat;
3227 $category->courses = array();
3232 // This is a recursive call so return the required array
3233 return array($categories, $categoryids);
3236 if (empty($categoryids)) {
3237 // No categories available (probably all hidden).
3241 // The depth is 0 this function has just been called so we can finish it off
3243 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
3244 list($catsql, $catparams) = $DB->get_in_or_equal(array_keys($categoryids));
3246 c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary,c.category
3250 WHERE c.category $catsql ORDER BY c.sortorder ASC";
3251 if ($courses = $DB->get_records_sql($sql, $catparams)) {
3252 // loop throught them
3253 foreach ($courses as $course) {
3254 if ($course->id == SITEID) {
3257 context_helper::preload_from_record($course);
3258 if (!empty($course->visible) || has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
3259 $categoryids[$course->category]->courses[$course->id] = $course;
3267 * Print courses in category. If category is 0 then all courses are printed.
3269 * @deprecated since 2.5
3271 * To print a generic list of courses use:
3272 * $renderer = $PAGE->get_renderer('core', 'course');
3273 * echo $renderer->courses_list($courses);
3275 * To print list of all courses:
3276 * $renderer = $PAGE->get_renderer('core', 'course');
3277 * echo $renderer->frontpage_available_courses();
3279 * To print list of courses inside category:
3280 * $renderer = $PAGE->get_renderer('core', 'course');
3281 * echo $renderer->course_category($category); // this will also print subcategories
3283 * @param int|stdClass $category category object or id.
3284 * @return bool true if courses found and printed, else false.
3286 function print_courses($category) {
3287 global $CFG, $OUTPUT, $PAGE;
3288 require_once($CFG->libdir. '/coursecatlib.php');
3289 debugging('Function print_courses() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3291 if (!is_object($category) && $category==0) {
3292 $courses = coursecat::get(0)->get_courses(array('recursive' => true, 'summary' => true, 'coursecontacts' => true));
3294 $courses = coursecat::get($category->id)->get_courses(array('summary' => true, 'coursecontacts' => true));
3298 $renderer = $PAGE->get_renderer('core', 'course');
3299 echo $renderer->courses_list($courses);
3301 echo $OUTPUT->heading(get_string("nocoursesyet"));
3302 $context = context_system::instance();
3303 if (has_capability('moodle/course:create', $context)) {
3305 if (!empty($category->id)) {
3306 $options['category'] = $category->id;
3308 $options['category'] = $CFG->defaultrequestcategory;
3310 echo html_writer::start_tag('div', array('class'=>'addcoursebutton'));
3311 echo $OUTPUT->single_button(new moodle_url('/course/edit.php', $options), get_string("addnewcourse"));
3312 echo html_writer::end_tag('div');
3320 * Print a description of a course, suitable for browsing in a list.
3322 * @deprecated since 2.5
3324 * Please use course renderer to display a course information box.
3325 * $renderer = $PAGE->get_renderer('core', 'course');
3326 * echo $renderer->courses_list($courses); // will print list of courses
3327 * echo $renderer->course_info_box($course); // will print one course wrapped in div.generalbox
3329 * @param object $course the course object.
3330 * @param string $highlightterms Ignored in this deprecated function!
3332 function print_course($course, $highlightterms = '') {
3335 debugging('Function print_course() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3336 $renderer = $PAGE->get_renderer('core', 'course');
3337 // Please note, correct would be to use $renderer->coursecat_coursebox() but this function is protected.
3338 // To print list of courses use $renderer->courses_list();
3339 echo $renderer->course_info_box($course);
3343 * Gets an array whose keys are category ids and whose values are arrays of courses in the corresponding category.
3345 * @deprecated since 2.5
3347 * This function is not used any more in moodle core and course renderer does not have render function for it.
3348 * Combo list on the front page is displayed as:
3349 * $renderer = $PAGE->get_renderer('core', 'course');
3350 * echo $renderer->frontpage_combo_list()
3352 * The new class {@link coursecat} stores the information about course category tree
3353 * To get children categories use:
3354 * coursecat::get($id)->get_children()
3355 * To get list of courses use:
3356 * coursecat::get($id)->get_courses()
3358 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3360 * @param int $categoryid
3363 function get_category_courses_array($categoryid = 0) {
3364 debugging('Function get_category_courses_array() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
3365 $tree = get_course_category_tree($categoryid);
3366 $flattened = array();
3367 foreach ($tree as $category) {
3368 get_category_courses_array_recursively($flattened, $category);
3374 * Recursive function to help flatten the course category tree.
3376 * @deprecated since 2.5
3378 * Was intended to be called from {@link get_category_courses_array()}
3380 * @param array &$flattened An array passed by reference in which to store courses for each category.
3381 * @param stdClass $category The category to get courses for.
3383 function get_category_courses_array_recursively(array &$flattened, $category) {
3384 debugging('Function get_category_courses_array_recursively() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
3385 $flattened[$category->id] = $category->courses;
3386 foreach ($category->categories as $childcategory) {
3387 get_category_courses_array_recursively($flattened, $childcategory);
3392 * Returns a URL based on the context of the current page.
3393 * This URL points to blog/index.php and includes filter parameters appropriate for the current page.
3395 * @param stdclass $context
3396 * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more.
3397 * @todo Remove this in 2.7
3400 function blog_get_context_url($context=null) {
3403 debugging('Function blog_get_context_url() is deprecated, getting params from context is not reliable for blogs.', DEBUG_DEVELOPER);
3404 $viewblogentriesurl = new moodle_url('/blog/index.php');
3406 if (empty($context)) {
3408 $context = $PAGE->context;
3411 // Change contextlevel to SYSTEM if viewing the site course
3412 if ($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID) {
3413 $context = context_system::instance();
3419 switch ($context->contextlevel) {
3420 case CONTEXT_SYSTEM:
3422 case CONTEXT_COURSECAT:
3424 case CONTEXT_COURSE:
3425 $filterparam = 'courseid';
3426 $strlevel = get_string('course');
3428 case CONTEXT_MODULE:
3429 $filterparam = 'modid';
3430 $strlevel = $context->get_context_name();
3433 $filterparam = 'userid';
3434 $strlevel = get_string('user');
3438 if (!empty($filterparam)) {
3439 $viewblogentriesurl->param($filterparam, $context->instanceid);
3442 return $viewblogentriesurl;
3446 * Retrieve course records with the course managers and other related records
3447 * that we need for print_course(). This allows print_courses() to do its job
3448 * in a constant number of DB queries, regardless of the number of courses,
3449 * role assignments, etc.
3451 * The returned array is indexed on c.id, and each course will have
3452 * - $course->managers - array containing RA objects that include a $user obj
3453 * with the minimal fields needed for fullname()
3455 * @deprecated since 2.5
3457 * To get list of all courses with course contacts ('managers') use
3458 * coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true));
3460 * To get list of courses inside particular category use
3461 * coursecat::get($id)->get_courses(array('coursecontacts' => true));
3463 * Additionally you can specify sort order, offset and maximum number of courses,
3464 * see {@link coursecat::get_courses()}
3466 * Please note that code of this function is not changed to use coursecat class because
3467 * coursecat::get_courses() returns result in slightly different format. Also note that
3468 * get_courses_wmanagers() DOES NOT check that users are enrolled in the course and
3469 * coursecat::get_courses() does.
3474 * @uses CONTEXT_COURSE
3475 * @uses CONTEXT_SYSTEM
3476 * @uses CONTEXT_COURSECAT
3478 * @param int|string $categoryid Either the categoryid for the courses or 'all'
3479 * @param string $sort A SQL sort field and direction
3480 * @param array $fields An array of additional fields to fetch
3483 function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) {
3487 * - Grab the courses JOINed w/context
3489 * - Grab the interesting course-manager RAs
3490 * JOINed with a base user obj and add them to each course
3492 * So as to do all the work in 2 DB queries. The RA+user JOIN
3493 * ends up being pretty expensive if it happens over _all_
3494 * courses on a large site. (Are we surprised!?)
3496 * So this should _never_ get called with 'all' on a large site.
3499 global $USER, $CFG, $DB;
3500 debugging('Function get_courses_wmanagers() is deprecated, please use coursecat::get_courses()', DEBUG_DEVELOPER);
3503 $allcats = false; // bool flag
3504 if ($categoryid === 'all') {
3505 $categoryclause = '';
3507 } elseif (is_numeric($categoryid)) {
3508 $categoryclause = "c.category = :catid";
3509 $params['catid'] = $categoryid;
3511 debugging("Could not recognise categoryid = $categoryid");
3512 $categoryclause = '';
3515 $basefields = array('id', 'category', 'sortorder',
3516 'shortname', 'fullname', 'idnumber',
3517 'startdate', 'visible',
3518 'newsitems', 'groupmode', 'groupmodeforce');
3520 if (!is_null($fields) && is_string($fields)) {
3521 if (empty($fields)) {
3522 $fields = $basefields;
3524 // turn the fields from a string to an array that
3525 // get_user_courses_bycap() will like...
3526 $fields = explode(',',$fields);
3527 $fields = array_map('trim', $fields);
3528 $fields = array_unique(array_merge($basefields, $fields));
3530 } elseif (is_array($fields)) {
3531 $fields = array_merge($basefields,$fields);
3533 $coursefields = 'c.' .join(',c.', $fields);
3536 $sortstatement = "";
3538 $sortstatement = "ORDER BY $sort";
3541 $where = 'WHERE c.id != ' . SITEID;
3542 if ($categoryclause !== ''){
3543 $where = "$where AND $categoryclause";
3546 // pull out all courses matching the cat
3547 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
3548 $sql = "SELECT $coursefields $ccselect
3554 $catpaths = array();
3556 if ($courses = $DB->get_records_sql($sql, $params)) {
3557 // loop on courses materialising
3558 // the context, and prepping data to fetch the
3559 // managers efficiently later...
3560 foreach ($courses as $k => $course) {
3561 context_helper::preload_from_record($course);
3562 $coursecontext = context_course::instance($course->id);
3563 $courses[$k] = $course;
3564 $courses[$k]->managers = array();
3565 if ($allcats === false) {
3566 // single cat, so take just the first one...
3567 if ($catpath === NULL) {
3568 $catpath = preg_replace(':/\d+$:', '', $coursecontext->path);
3571 // chop off the contextid of the course itself
3572 // like dirname() does...
3573 $catpaths[] = preg_replace(':/\d+$:', '', $coursecontext->path);
3577 return array(); // no courses!
3580 $CFG->coursecontact = trim($CFG->coursecontact);
3581 if (empty($CFG->coursecontact)) {
3585 $managerroles = explode(',', $CFG->coursecontact);
3587 if (count($managerroles)) {
3588 if ($allcats === true) {
3589 $catpaths = array_unique($catpaths);
3591 foreach ($catpaths as $cpath) {
3592 $ctxids = array_merge($ctxids, explode('/',substr($cpath,1)));
3594 $ctxids = array_unique($ctxids);
3595 $catctxids = implode( ',' , $ctxids);
3599 // take the ctx path from the first course
3600 // as all categories will be the same...
3601 $catpath = substr($catpath,1);
3602 $catpath = preg_replace(':/\d+$:','',$catpath);
3603 $catctxids = str_replace('/',',',$catpath);
3605 if ($categoryclause !== '') {
3606 $categoryclause = "AND $categoryclause";
3609 * Note: Here we use a LEFT OUTER JOIN that can
3610 * "optionally" match to avoid passing a ton of context
3611 * ids in an IN() clause. Perhaps a subselect is faster.
3613 * In any case, this SQL is not-so-nice over large sets of
3614 * courses with no $categoryclause.
3617 $sql = "SELECT ctx.path, ctx.instanceid, ctx.contextlevel,
3618 r.id AS roleid, r.name AS rolename, r.shortname AS roleshortname,
3619 rn.name AS rolecoursealias, u.id AS userid, u.firstname, u.lastname
3620 FROM {role_assignments} ra
3621 JOIN {context} ctx ON ra.contextid = ctx.id
3622 JOIN {user} u ON ra.userid = u.id
3623 JOIN {role} r ON ra.roleid = r.id
3624 LEFT JOIN {role_names} rn ON (rn.contextid = ctx.id AND rn.roleid = r.id)
3625 LEFT OUTER JOIN {course} c
3626 ON (ctx.instanceid=c.id AND ctx.contextlevel=".CONTEXT_COURSE.")
3627 WHERE ( c.id IS NOT NULL";
3628 // under certain conditions, $catctxids is NULL
3629 if($catctxids == NULL){
3632 $sql .= " OR ra.contextid IN ($catctxids) )";
3635 $sql .= "AND ra.roleid IN ({$CFG->coursecontact})
3637 ORDER BY r.sortorder ASC, ctx.contextlevel ASC, ra.sortorder ASC";
3638 $rs = $DB->get_recordset_sql($sql, $params);
3640 // This loop is fairly stupid as it stands - might get better
3641 // results doing an initial pass clustering RAs by path.
3642 foreach($rs as $ra) {
3643 $user = new stdClass;
3644 $user->id = $ra->userid; unset($ra->userid);
3645 $user->firstname = $ra->firstname; unset($ra->firstname);
3646 $user->lastname = $ra->lastname; unset($ra->lastname);
3648 if ($ra->contextlevel == CONTEXT_SYSTEM) {
3649 foreach ($courses as $k => $course) {
3650 $courses[$k]->managers[] = $ra;
3652 } else if ($ra->contextlevel == CONTEXT_COURSECAT) {
3653 if ($allcats === false) {
3654 // It always applies
3655 foreach ($courses as $k => $course) {
3656 $courses[$k]->managers[] = $ra;
3659 foreach ($courses as $k => $course) {
3660 $coursecontext = context_course::instance($course->id);
3661 // Note that strpos() returns 0 as "matched at pos 0"
3662 if (strpos($coursecontext->path, $ra->path.'/') === 0) {
3663 // Only add it to subpaths
3664 $courses[$k]->managers[] = $ra;
3668 } else { // course-level
3669 if (!array_key_exists($ra->instanceid, $courses)) {
3670 //this course is not in a list, probably a frontpage course
3673 $courses[$ra->instanceid]->managers[] = $ra;
3683 * Converts a nested array tree into HTML ul:li [recursive]
3685 * @deprecated since 2.5
3687 * @param array $tree A tree array to convert
3688 * @param int $row Used in identifying the iteration level and in ul classes
3689 * @return string HTML structure
3691 function convert_tree_to_html($tree, $row=0) {
3692 debugging('Function convert_tree_to_html() is deprecated since Moodle 2.5. Consider using class tabtree and core_renderer::render_tabtree()', DEBUG_DEVELOPER);
3694 $str = "\n".'<ul class="tabrow'.$row.'">'."\n";
3697 $count = count($tree);
3699 foreach ($tree as $tab) {
3700 $count--; // countdown to zero
3704 if ($first && ($count == 0)) { // Just one in the row
3705 $liclass = 'first last';
3707 } else if ($first) {
3710 } else if ($count == 0) {
3714 if ((empty($tab->subtree)) && (!empty($tab->selected))) {
3715 $liclass .= (empty($liclass)) ? 'onerow' : ' onerow';
3718 if ($tab->inactive || $tab->active || $tab->selected) {
3719 if ($tab->selected) {
3720 $liclass .= (empty($liclass)) ? 'here selected' : ' here selected';
3721 } else if ($tab->active) {
3722 $liclass .= (empty($liclass)) ? 'here active' : ' here active';
3726 $str .= (!empty($liclass)) ? '<li class="'.$liclass.'">' : '<li>';
3728 if ($tab->inactive || $tab->active || ($tab->selected && !$tab->linkedwhenselected)) {
3729 // The a tag is used for styling
3730 $str .= '<a class="nolink"><span>'.$tab->text.'</span></a>';
3732 $str .= '<a href="'.$tab->link.'" title="'.$tab->title.'"><span>'.$tab->text.'</span></a>';
3735 if (!empty($tab->subtree)) {
3736 $str .= convert_tree_to_html($tab->subtree, $row+1);
3737 } else if ($tab->selected) {
3738 $str .= '<div class="tabrow'.($row+1).' empty"> </div>'."\n";
3741 $str .= ' </li>'."\n";
3743 $str .= '</ul>'."\n";
3749 * Convert nested tabrows to a nested array
3751 * @deprecated since 2.5
3753 * @param array $tabrows A [nested] array of tab row objects
3754 * @param string $selected The tabrow to select (by id)
3755 * @param array $inactive An array of tabrow id's to make inactive
3756 * @param array $activated An array of tabrow id's to make active
3757 * @return array The nested array
3759 function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) {
3761 debugging('Function convert_tabrows_to_tree() is deprecated since Moodle 2.5. Consider using class tabtree', DEBUG_DEVELOPER);
3763 // Work backwards through the rows (bottom to top) collecting the tree as we go.
3764 $tabrows = array_reverse($tabrows);
3768 foreach ($tabrows as $row) {
3771 foreach ($row as $tab) {
3772 $tab->inactive = in_array((string)$tab->id, $inactive);
3773 $tab->active = in_array((string)$tab->id, $activated);
3774 $tab->selected = (string)$tab->id == $selected;
3776 if ($tab->active || $tab->selected) {
3778 $tab->subtree = $subtree;
3790 * @deprecated since Moodle 2.3
3792 function move_section($course, $section, $move) {
3793 throw new coding_exception('move_section() can not be used any more, please see move_section_to().');
3796 * Can handle rotated text. Whether it is safe to use the trickery in textrotate.js.
3798 * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically
3799 * @return bool True for yes, false for no
3801 function can_use_rotated_text() {
3802 debugging('can_use_rotated_text() is deprecated since Moodle 2.5. JS feature detection is used automatically.', DEBUG_DEVELOPER);
3807 * Get the context instance as an object. This function will create the
3808 * context instance if it does not exist yet.
3810 * @deprecated since 2.2, use context_course::instance() or other relevant class instead
3811 * @todo This will be deleted in Moodle 2.8, refer MDL-34472
3812 * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
3813 * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
3814 * for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
3815 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
3816 * MUST_EXIST means throw exception if no record or multiple records found
3817 * @return context The context object.
3819 function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
3821 debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER);
3823 $instances = (array)$instance;
3824 $contexts = array();
3826 $classname = context_helper::get_class_for_level($contextlevel);
3828 // we do not load multiple contexts any more, PAGE should be responsible for any preloading
3829 foreach ($instances as $inst) {
3830 $contexts[$inst] = $classname::instance($inst, $strictness);
3833 if (is_array($instance)) {
3836 return $contexts[$instance];
3841 * Get a context instance as an object, from a given context id.
3843 * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more.
3844 * @todo MDL-34550 This will be deleted in Moodle 2.8
3845 * @see context::instance_by_id($id)
3846 * @param int $id context id
3847 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
3848 * MUST_EXIST means throw exception if no record or multiple records found
3849 * @return context|bool the context object or false if not found.
3851 function get_context_instance_by_id($id, $strictness = IGNORE_MISSING) {
3852 debugging('get_context_instance_by_id() is deprecated, please use context::instance_by_id($id) instead.', DEBUG_DEVELOPER);
3853 return context::instance_by_id($id, $strictness);
3857 * @deprecated since Moodle 2.2
3858 * @see load_temp_course_role()
3860 function load_temp_role($context, $roleid, array $accessdata) {
3861 throw new coding_exception('load_temp_role() can not be used any more, please use load_temp_course_role()');
3865 * @deprecated since Moodle 2.2
3866 * @see remove_temp_course_roles()
3868 function remove_temp_roles($context, array $accessdata) {
3869 throw new coding_exception('remove_temp_roles() can not be used any more, please use remove_temp_course_roles()');
3873 * Returns system context or null if can not be created yet.
3875 * @see context_system::instance()
3876 * @deprecated since 2.2
3877 * @param bool $cache use caching
3878 * @return context system context (null if context table not created yet)
3880 function get_system_context($cache = true) {
3881 debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER);
3882 return context_system::instance(0, IGNORE_MISSING, $cache);
3886 * Recursive function which, given a context, find all parent context ids,
3887 * and return the array in reverse order, i.e. parent first, then grand
3890 * @see context::get_parent_context_ids()
3891 * @deprecated since 2.2, use $context->get_parent_context_ids() instead
3892 * @param context $context
3893 * @param bool $includeself optional, defaults to false
3896 function get_parent_contexts(context $context, $includeself = false) {
3897 debugging('get_parent_contexts() is deprecated, please use $context->get_parent_context_ids() instead.', DEBUG_DEVELOPER);
3898 return $context->get_parent_context_ids($includeself);
3902 * Return the id of the parent of this context, or false if there is no parent (only happens if this
3903 * is the site context.)
3905 * @deprecated since Moodle 2.2
3906 * @see context::get_parent_context()
3907 * @param context $context
3908 * @return integer the id of the parent context.
3910 function get_parent_contextid(context $context) {
3911 debugging('get_parent_contextid() is deprecated, please use $context->get_parent_context() instead.', DEBUG_DEVELOPER);
3913 if ($parent = $context->get_parent_context()) {
3921 * Recursive function which, given a context, find all its children contexts.
3923 * For course category contexts it will return immediate children only categories and courses.
3924 * It will NOT recurse into courses or child categories.
3925 * If you want to do that, call it on the returned courses/categories.
3927 * When called for a course context, it will return the modules and blocks
3928 * displayed in the course page.
3930 * If called on a user/course/module context it _will_ populate the cache with the appropriate
3933 * @see context::get_child_contexts()
3934 * @deprecated since 2.2
3935 * @param context $context
3936 * @return array Array of child records
3938 function get_child_contexts(context $context) {
3939 debugging('get_child_contexts() is deprecated, please use $context->get_child_contexts() instead.', DEBUG_DEVELOPER);
3940 return $context->get_child_contexts();
3944 * Precreates all contexts including all parents.
3946 * @see context_helper::create_instances()
3947 * @deprecated since 2.2
3948 * @param int $contextlevel empty means all
3949 * @param bool $buildpaths update paths and depths
3952 function create_contexts($contextlevel = null, $buildpaths = true) {
3953 debugging('create_contexts() is deprecated, please use context_helper::create_instances() instead.', DEBUG_DEVELOPER);
3954 context_helper::create_instances($contextlevel, $buildpaths);
3958 * Remove stale context records.
3960 * @see context_helper::cleanup_instances()
3961 * @deprecated since 2.2
3964 function cleanup_contexts() {
3965 debugging('cleanup_contexts() is deprecated, please use context_helper::cleanup_instances() instead.', DEBUG_DEVELOPER);
3966 context_helper::cleanup_instances();
3971 * Populate context.path and context.depth where missing.
3973 * @see context_helper::build_all_paths()
3974 * @deprecated since 2.2
3975 * @param bool $force force a complete rebuild of the path and depth fields, defaults to false
3978 function build_context_path($force = false) {
3979 debugging('build_context_path() is deprecated, please use context_helper::build_all_paths() instead.', DEBUG_DEVELOPER);
3980 context_helper::build_all_paths($force);
3984 * Rebuild all related context depth and path caches.
3986 * @see context::reset_paths()
3987 * @deprecated since 2.2
3988 * @param array $fixcontexts array of contexts, strongtyped
3991 function rebuild_contexts(array $fixcontexts) {
3992 debugging('rebuild_contexts() is deprecated, please use $context->reset_paths(true) instead.', DEBUG_DEVELOPER);
3993 foreach ($fixcontexts as $fixcontext) {
3994 $fixcontext->reset_paths(false);
3996 context_helper::build_all_paths(false);
4000 * Preloads all contexts relating to a course: course, modules. Block contexts
4001 * are no longer loaded here. The contexts for all the blocks on the current
4002 * page are now efficiently loaded by {@link block_manager::load_blocks()}.
4004 * @deprecated since Moodle 2.2
4005 * @see context_helper::preload_course()
4006 * @param int $courseid Course ID
4009 function preload_course_contexts($courseid) {
4010 debugging('preload_course_contexts() is deprecated, please use context_helper::preload_course() instead.', DEBUG_DEVELOPER);
4011 context_helper::preload_course($courseid);
4015 * Update the path field of the context and all dep. subcontexts that follow
4017 * Update the path field of the context and
4018 * all the dependent subcontexts that follow
4021 * The most important thing here is to be as
4022 * DB efficient as possible. This op can have a
4023 * massive impact in the DB.
4025 * @deprecated since Moodle 2.2
4026 * @see context::update_moved()
4027 * @param context $context context obj
4028 * @param context $newparent new parent obj
4031 function context_moved(context $context, context $newparent) {
4032 debugging('context_moved() is deprecated, please use context::update_moved() instead.', DEBUG_DEVELOPER);
4033 $context->update_moved($newparent);
4037 * Extracts the relevant capabilities given a contextid.
4038 * All case based, example an instance of forum context.
4039 * Will fetch all forum related capabilities, while course contexts
4040 * Will fetch all capabilities
4043 * `name` varchar(150) NOT NULL,
4044 * `captype` varchar(50) NOT NULL,
4045 * `contextlevel` int(10) NOT NULL,
4046 * `component` varchar(100) NOT NULL,
4048 * @see context::get_capabilities()
4049 * @deprecated since 2.2
4050 * @param context $context
4053 function fetch_context_capabilities(context $context) {
4054 debugging('fetch_context_capabilities() is deprecated, please use $context->get_capabilities() instead.', DEBUG_DEVELOPER);
4055 return $context->get_capabilities();
4059 * Preloads context information from db record and strips the cached info.
4060 * The db request has to contain both the $join and $select from context_instance_preload_sql()
4062 * @deprecated since 2.2
4063 * @see context_helper::preload_from_record()
4064 * @param stdClass $rec
4065 * @return void (modifies $rec)
4067 function context_instance_preload(stdClass $rec) {
4068 debugging('context_instance_preload() is deprecated, please use context_helper::preload_from_record() instead.', DEBUG_DEVELOPER);
4069 context_helper::preload_from_record($rec);
4073 * Returns context level name
4075 * @deprecated since 2.2
4076 * @see context_helper::get_level_name()
4077 * @param integer $contextlevel $context->context level. One of the CONTEXT_... constants.
4078 * @return string the name for this type of context.
4080 function get_contextlevel_name($contextlevel) {
4081 debugging('get_contextlevel_name() is deprecated, please use context_helper::get_level_name() instead.', DEBUG_DEVELOPER);
4082 return context_helper::get_level_name($contextlevel);
4086 * Prints human readable context identifier.
4088 * @deprecated since 2.2
4089 * @see context::get_context_name()
4090 * @param context $context the context.
4091 * @param boolean $withprefix whether to prefix the name of the context with the
4092 * type of context, e.g. User, Course, Forum, etc.
4093 * @param boolean $short whether to user the short name of the thing. Only applies
4094 * to course contexts
4095 * @return string the human readable context name.
4097 function print_context_name(context $context, $withprefix = true, $short = false) {
4098 debugging('print_context_name() is deprecated, please use $context->get_context_name() instead.', DEBUG_DEVELOPER);
4099 return $context->get_context_name($withprefix, $short);
4103 * Mark a context as dirty (with timestamp) so as to force reloading of the context.
4105 * @deprecated since 2.2, use $context->mark_dirty() instead
4106 * @see context::mark_dirty()
4107 * @param string $path context path
4109 function mark_context_dirty($path) {
4110 global $CFG, $USER, $ACCESSLIB_PRIVATE;
4111 debugging('mark_context_dirty() is deprecated, please use $context->mark_dirty() instead.', DEBUG_DEVELOPER);
4113 if (during_initial_install()) {
4117 // only if it is a non-empty string
4118 if (is_string($path) && $path !== '') {
4119 set_cache_flag('accesslib/dirtycontexts', $path, 1, time()+$CFG->sessiontimeout);
4120 if (isset($ACCESSLIB_PRIVATE->dirtycontexts)) {
4121 $ACCESSLIB_PRIVATE->dirtycontexts[$path] = 1;
4124 $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1);
4126 if (isset($USER->access['time'])) {
4127 $ACCESSLIB_PRIVATE->dirtycontexts = get_cache_flags('accesslib/dirtycontexts', $USER->access['time']-2);
4129 $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1);
4131 // flags not loaded yet, it will be done later in $context->reload_if_dirty()
4138 * Remove a context record and any dependent entries,
4139 * removes context from static context cache too
4141 * @deprecated since Moodle 2.2
4142 * @see context_helper::delete_instance() or context::delete_content()
4143 * @param int $contextlevel
4144 * @param int $instanceid
4145 * @param bool $deleterecord false means keep record for now
4146 * @return bool returns true or throws an exception
4148 function delete_context($contextlevel, $instanceid, $deleterecord = true) {
4149 if ($deleterecord) {
4150 debugging('delete_context() is deprecated, please use context_helper::delete_instance() instead.', DEBUG_DEVELOPER);
4151 context_helper::delete_instance($contextlevel, $instanceid);
4153 debugging('delete_context() is deprecated, please use $context->delete_content() instead.', DEBUG_DEVELOPER);
4154 $classname = context_helper::get_class_for_level($contextlevel);
4155 if ($context = $classname::instance($instanceid, IGNORE_MISSING)) {
4156 $context->delete_content();
4164 * Get a URL for a context, if there is a natural one. For example, for
4165 * CONTEXT_COURSE, this is the course page. For CONTEXT_USER it is the
4166 * user profile page.
4168 * @deprecated since 2.2
4169 * @see context::get_url()
4170 * @param context $context the context
4171 * @return moodle_url
4173 function get_context_url(context $context) {
4174 debugging('get_context_url() is deprecated, please use $context->get_url() instead.', DEBUG_DEVELOPER);
4175 return $context->get_url();
4179 * Is this context part of any course? if yes return course context,
4180 * if not return null or throw exception.
4182 * @deprecated since 2.2
4183 * @see context::get_course_context()
4184 * @param context $context
4185 * @return course_context context of the enclosing course, null if not found or exception
4187 function get_course_context(context $context) {
4188 debugging('get_course_context() is deprecated, please use $context->get_course_context(true) instead.', DEBUG_DEVELOPER);
4189 return $context->get_course_context(true);
4193 * Get an array of courses where cap requested is available
4194 * and user is enrolled, this can be relatively slow.
4196 * @deprecated since 2.2
4197 * @see enrol_get_users_courses()
4198 * @param int $userid A user id. By default (null) checks the permissions of the current user.
4199 * @param string $cap - name of the capability
4200 * @param array $accessdata_ignored
4201 * @param bool $doanything_ignored
4202 * @param string $sort - sorting fields - prefix each fieldname with "c."
4203 * @param array $fields - additional fields you are interested in...
4204 * @param int $limit_ignored
4205 * @return array $courses - ordered array of course objects - see notes above
4207 function get_user_courses_bycap($userid, $cap, $accessdata_ignored, $doanything_ignored, $sort = 'c.sortorder ASC', $fields = null, $limit_ignored = 0) {
4209 debugging('get_user_courses_bycap() is deprecated, please use enrol_get_users_courses() instead.', DEBUG_DEVELOPER);
4210 $courses = enrol_get_users_courses($userid, true, $fields, $sort);
4211 foreach ($courses as $id=>$course) {
4212 $context = context_course::instance($id);
4213 if (!has_capability($cap, $context, $userid)) {
4214 unset($courses[$id]);
4222 * This is really slow!!! do not use above course context level
4224 * @deprecated since Moodle 2.2
4225 * @param int $roleid
4226 * @param context $context
4229 function get_role_context_caps($roleid, context $context) {
4231 debugging('get_role_context_caps() is deprecated, it is really slow. Don\'t use it.', DEBUG_DEVELOPER);
4233 // This is really slow!!!! - do not use above course context level.
4235 $result[$context->id] = array();
4237 // First emulate the parent context capabilities merging into context.
4238 $searchcontexts = array_reverse($context->get_parent_context_ids(true));
4239 foreach ($searchcontexts as $cid) {
4240 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
4241 foreach ($capabilities as $cap) {
4242 if (!array_key_exists($cap->capability, $result[$context->id])) {
4243 $result[$context->id][$cap->capability] = 0;
4245 $result[$context->id][$cap->capability] += $cap->permission;
4250 // Now go through the contexts below given context.
4251 $searchcontexts = array_keys($context->get_child_contexts());
4252 foreach ($searchcontexts as $cid) {
4253 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
4254 foreach ($capabilities as $cap) {
4255 if (!array_key_exists($cap->contextid, $result)) {
4256 $result[$cap->contextid] = array();
4258 $result[$cap->contextid][$cap->capability] = $cap->permission;
4267 * Returns current course id or false if outside of course based on context parameter.
4269 * @see context::get_course_context()
4270 * @deprecated since 2.2
4271 * @param context $context
4272 * @return int|bool related course id or false
4274 function get_courseid_from_context(context $context) {
4275 debugging('get_courseid_from_context() is deprecated, please use $context->get_course_context(false) instead.', DEBUG_DEVELOPER);
4276 if ($coursecontext = $context->get_course_context(false)) {
4277 return $coursecontext->instanceid;