Merge branch 'wip-MDL-44362-master' of git://github.com/marinaglancy/moodle
[moodle.git] / lib / deprecatedlib.php
blob7368dc840ca8903ee6583bba87e60a027d549c63
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * deprecatedlib.php - Old functions retained only for backward compatibility
21 * Old functions retained only for backward compatibility. New code should not
22 * use any of these functions.
24 * @package core
25 * @subpackage deprecated
26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 * @deprecated
31 defined('MOODLE_INTERNAL') || die();
33 /**
34 * Adds a file upload to the log table so that clam can resolve the filename to the user later if necessary
36 * @deprecated since 2.7 - use new file picker instead
38 * @param string $newfilepath
39 * @param stdClass $course
40 * @param bool $nourl
42 function clam_log_upload($newfilepath, $course=null, $nourl=false) {
43 debugging('clam_log_upload() is not supposed to be used any more, use new file picker instead', DEBUG_DEVELOPER);
46 /**
47 * This function logs to error_log and to the log table that an infected file has been found and what's happened to it.
49 * @deprecated since 2.7 - use new file picker instead
51 * @param string $oldfilepath
52 * @param string $newfilepath
53 * @param int $userid The user
55 function clam_log_infected($oldfilepath='', $newfilepath='', $userid=0) {
56 debugging('clam_log_infected() is not supposed to be used any more, use new file picker instead', DEBUG_DEVELOPER);
59 /**
60 * Some of the modules allow moving attachments (glossary), in which case we need to hunt down an original log and change the path.
62 * @deprecated since 2.7 - use new file picker instead
64 * @param string $oldpath
65 * @param string $newpath
66 * @param boolean $update
68 function clam_change_log($oldpath, $newpath, $update=true) {
69 debugging('clam_change_log() is not supposed to be used any more, use new file picker instead', DEBUG_DEVELOPER);
72 /**
73 * Replaces the given file with a string.
75 * @deprecated since 2.7 - infected files are now deleted in file picker
77 * @param string $file
78 * @return boolean
80 function clam_replace_infected_file($file) {
81 debugging('clam_change_log() is not supposed to be used any more', DEBUG_DEVELOPER);
82 return false;
85 /**
86 * Checks whether the password compatibility library will work with the current
87 * version of PHP. This cannot be done using PHP version numbers since the fix
88 * has been backported to earlier versions in some distributions.
90 * See https://github.com/ircmaxell/password_compat/issues/10 for more details.
92 * @deprecated since 2.7 PHP 5.4.x should be always compatible.
94 * @return bool always returns false
96 function password_compat_not_supported() {
97 debugging('Do not use password_compat_not_supported() - bcrypt is now always available', DEBUG_DEVELOPER);
98 return false;
102 * Factory method that was returning moodle_session object.
104 * @deprecated since 2.6
105 * @return \core\session\manager
107 function session_get_instance() {
108 // Note: the new session manager includes all methods from the original session class.
109 static $deprecatedinstance = null;
111 debugging('session_get_instance() is deprecated, use \core\session\manager instead', DEBUG_DEVELOPER);
113 if (!$deprecatedinstance) {
114 $deprecatedinstance = new \core\session\manager();
117 return $deprecatedinstance;
121 * Returns true if legacy session used.
123 * @deprecated since 2.6
124 * @return bool
126 function session_is_legacy() {
127 debugging('session_is_legacy() is deprecated, do not use any more', DEBUG_DEVELOPER);
128 return false;
132 * Terminates all sessions, auth hooks are not executed.
133 * Useful in upgrade scripts.
135 * @deprecated since 2.6
137 function session_kill_all() {
138 debugging('session_kill_all() is deprecated, use \core\session\manager::kill_all_sessions() instead', DEBUG_DEVELOPER);
139 \core\session\manager::kill_all_sessions();
143 * Mark session as accessed, prevents timeouts.
145 * @deprecated since 2.6
146 * @param string $sid
148 function session_touch($sid) {
149 debugging('session_touch() is deprecated, use \core\session\manager::touch_session() instead', DEBUG_DEVELOPER);
150 \core\session\manager::touch_session($sid);
154 * Terminates one sessions, auth hooks are not executed.
156 * @deprecated since 2.6
157 * @param string $sid session id
159 function session_kill($sid) {
160 debugging('session_kill() is deprecated, use \core\session\manager::kill_session() instead', DEBUG_DEVELOPER);
161 \core\session\manager::kill_session($sid);
165 * Terminates all sessions of one user, auth hooks are not executed.
166 * NOTE: This can not work for file based sessions!
168 * @deprecated since 2.6
169 * @param int $userid user id
171 function session_kill_user($userid) {
172 debugging('session_kill_user() is deprecated, use \core\session\manager::kill_user_sessions() instead', DEBUG_DEVELOPER);
173 \core\session\manager::kill_user_sessions($userid);
177 * Session garbage collection
178 * - verify timeout for all users
179 * - kill sessions of all deleted users
180 * - kill sessions of users with disabled plugins or 'nologin' plugin
182 * @deprecated since 2.6
184 function session_gc() {
185 debugging('session_gc() is deprecated, use \core\session\manager::gc() instead', DEBUG_DEVELOPER);
186 \core\session\manager::gc();
190 * Setup $USER object - called during login, loginas, etc.
192 * Call sync_user_enrolments() manually after log-in, or log-in-as.
194 * @deprecated since 2.6
195 * @param stdClass $user full user record object
196 * @return void
198 function session_set_user($user) {
199 debugging('session_set_user() is deprecated, use \core\session\manager::set_user() instead', DEBUG_DEVELOPER);
200 \core\session\manager::set_user($user);
204 * Is current $USER logged-in-as somebody else?
205 * @deprecated since 2.6
206 * @return bool
208 function session_is_loggedinas() {
209 debugging('session_is_loggedinas() is deprecated, use \core\session\manager::is_loggedinas() instead', DEBUG_DEVELOPER);
210 return \core\session\manager::is_loggedinas();
214 * Returns the $USER object ignoring current login-as session
215 * @deprecated since 2.6
216 * @return stdClass user object
218 function session_get_realuser() {
219 debugging('session_get_realuser() is deprecated, use \core\session\manager::get_realuser() instead', DEBUG_DEVELOPER);
220 return \core\session\manager::get_realuser();
224 * Login as another user - no security checks here.
225 * @deprecated since 2.6
226 * @param int $userid
227 * @param stdClass $context
228 * @return void
230 function session_loginas($userid, $context) {
231 debugging('session_loginas() is deprecated, use \core\session\manager::loginas() instead', DEBUG_DEVELOPER);
232 \core\session\manager::loginas($userid, $context);
236 * Minify JavaScript files.
238 * @deprecated since 2.6
240 * @param array $files
241 * @return string
243 function js_minify($files) {
244 debugging('js_minify() is deprecated, use core_minify::js_files() or core_minify::js() instead.');
245 return core_minify::js_files($files);
249 * Minify CSS files.
251 * @deprecated since 2.6
253 * @param array $files
254 * @return string
256 function css_minify_css($files) {
257 debugging('css_minify_css() is deprecated, use core_minify::css_files() or core_minify::css() instead.');
258 return core_minify::css_files($files);
262 * Function to call all event handlers when triggering an event
264 * @deprecated since 2.6
266 * @param string $eventname name of the event
267 * @param mixed $eventdata event data object
268 * @return int number of failed events
270 function events_trigger($eventname, $eventdata) {
271 // TODO: uncomment after conversion of all events in standard distribution
272 // debugging('events_trigger() is deprecated, please use new events instead', DEBUG_DEVELOPER);
273 return events_trigger_legacy($eventname, $eventdata);
277 * List all core subsystems and their location
279 * This is a whitelist of components that are part of the core and their
280 * language strings are defined in /lang/en/<<subsystem>>.php. If a given
281 * plugin is not listed here and it does not have proper plugintype prefix,
282 * then it is considered as course activity module.
284 * The location is optionally dirroot relative path. NULL means there is no special
285 * directory for this subsystem. If the location is set, the subsystem's
286 * renderer.php is expected to be there.
288 * @deprecated since 2.6, use core_component::get_core_subsystems()
290 * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons
291 * @return array of (string)name => (string|null)location
293 function get_core_subsystems($fullpaths = false) {
294 global $CFG;
296 // NOTE: do not add any other debugging here, keep forever.
298 $subsystems = core_component::get_core_subsystems();
300 if ($fullpaths) {
301 return $subsystems;
304 debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
306 $dlength = strlen($CFG->dirroot);
308 foreach ($subsystems as $k => $v) {
309 if ($v === null) {
310 continue;
312 $subsystems[$k] = substr($v, $dlength+1);
315 return $subsystems;
319 * Lists all plugin types.
321 * @deprecated since 2.6, use core_component::get_plugin_types()
323 * @param bool $fullpaths false means relative paths from dirroot
324 * @return array Array of strings - name=>location
326 function get_plugin_types($fullpaths = true) {
327 global $CFG;
329 // NOTE: do not add any other debugging here, keep forever.
331 $types = core_component::get_plugin_types();
333 if ($fullpaths) {
334 return $types;
337 debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
339 $dlength = strlen($CFG->dirroot);
341 foreach ($types as $k => $v) {
342 if ($k === 'theme') {
343 $types[$k] = 'theme';
344 continue;
346 $types[$k] = substr($v, $dlength+1);
349 return $types;
353 * Use when listing real plugins of one type.
355 * @deprecated since 2.6, use core_component::get_plugin_list()
357 * @param string $plugintype type of plugin
358 * @return array name=>fulllocation pairs of plugins of given type
360 function get_plugin_list($plugintype) {
362 // NOTE: do not add any other debugging here, keep forever.
364 if ($plugintype === '') {
365 $plugintype = 'mod';
368 return core_component::get_plugin_list($plugintype);
372 * Get a list of all the plugins of a given type that define a certain class
373 * in a certain file. The plugin component names and class names are returned.
375 * @deprecated since 2.6, use core_component::get_plugin_list_with_class()
377 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
378 * @param string $class the part of the name of the class after the
379 * frankenstyle prefix. e.g 'thing' if you are looking for classes with
380 * names like report_courselist_thing. If you are looking for classes with
381 * the same name as the plugin name (e.g. qtype_multichoice) then pass ''.
382 * @param string $file the name of file within the plugin that defines the class.
383 * @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum')
384 * and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice').
386 function get_plugin_list_with_class($plugintype, $class, $file) {
388 // NOTE: do not add any other debugging here, keep forever.
390 return core_component::get_plugin_list_with_class($plugintype, $class, $file);
394 * Returns the exact absolute path to plugin directory.
396 * @deprecated since 2.6, use core_component::get_plugin_directory()
398 * @param string $plugintype type of plugin
399 * @param string $name name of the plugin
400 * @return string full path to plugin directory; NULL if not found
402 function get_plugin_directory($plugintype, $name) {
404 // NOTE: do not add any other debugging here, keep forever.
406 if ($plugintype === '') {
407 $plugintype = 'mod';
410 return core_component::get_plugin_directory($plugintype, $name);
414 * Normalize the component name using the "frankenstyle" names.
416 * @deprecated since 2.6, use core_component::normalize_component()
418 * @param string $component
419 * @return array as (string)$type => (string)$plugin
421 function normalize_component($component) {
423 // NOTE: do not add any other debugging here, keep forever.
425 return core_component::normalize_component($component);
429 * Return exact absolute path to a plugin directory.
431 * @deprecated since 2.6, use core_component::normalize_component()
433 * @param string $component name such as 'moodle', 'mod_forum'
434 * @return string full path to component directory; NULL if not found
436 function get_component_directory($component) {
438 // NOTE: do not add any other debugging here, keep forever.
440 return core_component::get_component_directory($component);
444 // === Deprecated before 2.6.0 ===
447 * Hack to find out the GD version by parsing phpinfo output
449 * @return int GD version (1, 2, or 0)
451 function check_gd_version() {
452 // TODO: delete function in Moodle 2.7
453 debugging('check_gd_version() is deprecated, GD extension is always available now');
455 $gdversion = 0;
457 if (function_exists('gd_info')){
458 $gd_info = gd_info();
459 if (substr_count($gd_info['GD Version'], '2.')) {
460 $gdversion = 2;
461 } else if (substr_count($gd_info['GD Version'], '1.')) {
462 $gdversion = 1;
465 } else {
466 ob_start();
467 phpinfo(INFO_MODULES);
468 $phpinfo = ob_get_contents();
469 ob_end_clean();
471 $phpinfo = explode("\n", $phpinfo);
474 foreach ($phpinfo as $text) {
475 $parts = explode('</td>', $text);
476 foreach ($parts as $key => $val) {
477 $parts[$key] = trim(strip_tags($val));
479 if ($parts[0] == 'GD Version') {
480 if (substr_count($parts[1], '2.0')) {
481 $parts[1] = '2.0';
483 $gdversion = intval($parts[1]);
488 return $gdversion; // 1, 2 or 0
492 * Not used any more, the account lockout handling is now
493 * part of authenticate_user_login().
494 * @deprecated
496 function update_login_count() {
497 // TODO: delete function in Moodle 2.6
498 debugging('update_login_count() is deprecated, all calls need to be removed');
502 * Not used any more, replaced by proper account lockout.
503 * @deprecated
505 function reset_login_count() {
506 // TODO: delete function in Moodle 2.6
507 debugging('reset_login_count() is deprecated, all calls need to be removed');
511 * Insert or update log display entry. Entry may already exist.
512 * $module, $action must be unique
513 * @deprecated
515 * @param string $module
516 * @param string $action
517 * @param string $mtable
518 * @param string $field
519 * @return void
522 function update_log_display_entry($module, $action, $mtable, $field) {
523 global $DB;
525 debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
529 * Given some text in HTML format, this function will pass it
530 * through any filters that have been configured for this context.
532 * @deprecated use the text formatting in a standard way instead (http://docs.moodle.org/dev/Output_functions)
533 * this was abused mostly for embedding of attachments
534 * @todo final deprecation of this function in MDL-40607
535 * @param string $text The text to be passed through format filters
536 * @param int $courseid The current course.
537 * @return string the filtered string.
539 function filter_text($text, $courseid = NULL) {
540 global $CFG, $COURSE;
542 debugging('filter_text() is deprecated, use format_text(), format_string() etc instead.', DEBUG_DEVELOPER);
544 if (!$courseid) {
545 $courseid = $COURSE->id;
548 if (!$context = context_course::instance($courseid, IGNORE_MISSING)) {
549 return $text;
552 return filter_manager::instance()->filter_text($text, $context);
556 * This function indicates that current page requires the https
557 * when $CFG->loginhttps enabled.
559 * By using this function properly, we can ensure 100% https-ized pages
560 * at our entire discretion (login, forgot_password, change_password)
561 * @deprecated use $PAGE->https_required() instead
562 * @todo final deprecation of this function in MDL-40607
564 function httpsrequired() {
565 global $PAGE;
566 debugging('httpsrequired() is deprecated use $PAGE->https_required() instead.', DEBUG_DEVELOPER);
567 $PAGE->https_required();
571 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
573 * @deprecated use moodle_url factory methods instead
575 * @param string $path Physical path to a file
576 * @param array $options associative array of GET variables to append to the URL
577 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
578 * @return string URL to file
580 function get_file_url($path, $options=null, $type='coursefile') {
581 global $CFG;
583 $path = str_replace('//', '/', $path);
584 $path = trim($path, '/'); // no leading and trailing slashes
586 // type of file
587 switch ($type) {
588 case 'questionfile':
589 $url = $CFG->wwwroot."/question/exportfile.php";
590 break;
591 case 'rssfile':
592 $url = $CFG->wwwroot."/rss/file.php";
593 break;
594 case 'httpscoursefile':
595 $url = $CFG->httpswwwroot."/file.php";
596 break;
597 case 'coursefile':
598 default:
599 $url = $CFG->wwwroot."/file.php";
602 if ($CFG->slasharguments) {
603 $parts = explode('/', $path);
604 foreach ($parts as $key => $part) {
605 /// anchor dash character should not be encoded
606 $subparts = explode('#', $part);
607 $subparts = array_map('rawurlencode', $subparts);
608 $parts[$key] = implode('#', $subparts);
610 $path = implode('/', $parts);
611 $ffurl = $url.'/'.$path;
612 $separator = '?';
613 } else {
614 $path = rawurlencode('/'.$path);
615 $ffurl = $url.'?file='.$path;
616 $separator = '&amp;';
619 if ($options) {
620 foreach ($options as $name=>$value) {
621 $ffurl = $ffurl.$separator.$name.'='.$value;
622 $separator = '&amp;';
626 return $ffurl;
630 * Return all course participant for a given course
632 * @deprecated use get_enrolled_users($context) instead.
633 * @todo final deprecation of this function in MDL-40607
634 * @param integer $courseid
635 * @return array of user
637 function get_course_participants($courseid) {
638 debugging('get_course_participants() is deprecated, use get_enrolled_users() instead.', DEBUG_DEVELOPER);
639 return get_enrolled_users(context_course::instance($courseid));
643 * Return true if the user is a participant for a given course
645 * @deprecated use is_enrolled($context, $userid) instead.
646 * @todo final deprecation of this function in MDL-40607
647 * @param integer $userid
648 * @param integer $courseid
649 * @return boolean
651 function is_course_participant($userid, $courseid) {
652 debugging('is_course_participant() is deprecated, use is_enrolled() instead.', DEBUG_DEVELOPER);
653 return is_enrolled(context_course::instance($courseid), $userid);
657 * Searches logs to find all enrolments since a certain date
659 * used to print recent activity
661 * @param int $courseid The course in question.
662 * @param int $timestart The date to check forward of
663 * @return object|false {@link $USER} records or false if error.
665 function get_recent_enrolments($courseid, $timestart) {
666 global $DB;
668 debugging('get_recent_enrolments() is deprecated as it returned inaccurate results.', DEBUG_DEVELOPER);
670 $context = context_course::instance($courseid);
671 $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
672 FROM {user} u, {role_assignments} ra, {log} l
673 WHERE l.time > ?
674 AND l.course = ?
675 AND l.module = 'course'
676 AND l.action = 'enrol'
677 AND ".$DB->sql_cast_char2int('l.info')." = u.id
678 AND u.id = ra.userid
679 AND ra.contextid ".get_related_contexts_string($context)."
680 GROUP BY u.id, u.firstname, u.lastname
681 ORDER BY MAX(l.time) ASC";
682 $params = array($timestart, $courseid);
683 return $DB->get_records_sql($sql, $params);
687 * @deprecated use clean_param($string, PARAM_FILE) instead.
688 * @todo final deprecation of this function in MDL-40607
690 * @param string $string ?
691 * @param int $allowdots ?
692 * @return bool
694 function detect_munged_arguments($string, $allowdots=1) {
695 debugging('detect_munged_arguments() is deprecated, please use clean_param(,PARAM_FILE) instead.', DEBUG_DEVELOPER);
696 if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
697 return true;
699 if (preg_match('/[\|\`]/', $string)) { // check for other bad characters
700 return true;
702 if (empty($string) or $string == '/') {
703 return true;
706 return false;
711 * Unzip one zip file to a destination dir
712 * Both parameters must be FULL paths
713 * If destination isn't specified, it will be the
714 * SAME directory where the zip file resides.
716 * @global object
717 * @param string $zipfile The zip file to unzip
718 * @param string $destination The location to unzip to
719 * @param bool $showstatus_ignored Unused
721 function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
722 global $CFG;
724 //Extract everything from zipfile
725 $path_parts = pathinfo(cleardoubleslashes($zipfile));
726 $zippath = $path_parts["dirname"]; //The path of the zip file
727 $zipfilename = $path_parts["basename"]; //The name of the zip file
728 $extension = $path_parts["extension"]; //The extension of the file
730 //If no file, error
731 if (empty($zipfilename)) {
732 return false;
735 //If no extension, error
736 if (empty($extension)) {
737 return false;
740 //Clear $zipfile
741 $zipfile = cleardoubleslashes($zipfile);
743 //Check zipfile exists
744 if (!file_exists($zipfile)) {
745 return false;
748 //If no destination, passed let's go with the same directory
749 if (empty($destination)) {
750 $destination = $zippath;
753 //Clear $destination
754 $destpath = rtrim(cleardoubleslashes($destination), "/");
756 //Check destination path exists
757 if (!is_dir($destpath)) {
758 return false;
761 $packer = get_file_packer('application/zip');
763 $result = $packer->extract_to_pathname($zipfile, $destpath);
765 if ($result === false) {
766 return false;
769 foreach ($result as $status) {
770 if ($status !== true) {
771 return false;
775 return true;
779 * Zip an array of files/dirs to a destination zip file
780 * Both parameters must be FULL paths to the files/dirs
782 * @global object
783 * @param array $originalfiles Files to zip
784 * @param string $destination The destination path
785 * @return bool Outcome
787 function zip_files ($originalfiles, $destination) {
788 global $CFG;
790 //Extract everything from destination
791 $path_parts = pathinfo(cleardoubleslashes($destination));
792 $destpath = $path_parts["dirname"]; //The path of the zip file
793 $destfilename = $path_parts["basename"]; //The name of the zip file
794 $extension = $path_parts["extension"]; //The extension of the file
796 //If no file, error
797 if (empty($destfilename)) {
798 return false;
801 //If no extension, add it
802 if (empty($extension)) {
803 $extension = 'zip';
804 $destfilename = $destfilename.'.'.$extension;
807 //Check destination path exists
808 if (!is_dir($destpath)) {
809 return false;
812 //Check destination path is writable. TODO!!
814 //Clean destination filename
815 $destfilename = clean_filename($destfilename);
817 //Now check and prepare every file
818 $files = array();
819 $origpath = NULL;
821 foreach ($originalfiles as $file) { //Iterate over each file
822 //Check for every file
823 $tempfile = cleardoubleslashes($file); // no doubleslashes!
824 //Calculate the base path for all files if it isn't set
825 if ($origpath === NULL) {
826 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
828 //See if the file is readable
829 if (!is_readable($tempfile)) { //Is readable
830 continue;
832 //See if the file/dir is in the same directory than the rest
833 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
834 continue;
836 //Add the file to the array
837 $files[] = $tempfile;
840 $zipfiles = array();
841 $start = strlen($origpath)+1;
842 foreach($files as $file) {
843 $zipfiles[substr($file, $start)] = $file;
846 $packer = get_file_packer('application/zip');
848 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
852 * Get the IDs for the user's groups in the given course.
854 * @global object
855 * @param int $courseid The course being examined - the 'course' table id field.
856 * @return array|bool An _array_ of groupids, or false
857 * (Was return $groupids[0] - consequences!)
858 * @deprecated use groups_get_all_groups() instead.
859 * @todo final deprecation of this function in MDL-40607
861 function mygroupid($courseid) {
862 global $USER;
864 debugging('mygroupid() is deprecated, please use groups_get_all_groups() instead.', DEBUG_DEVELOPER);
866 if ($groups = groups_get_all_groups($courseid, $USER->id)) {
867 return array_keys($groups);
868 } else {
869 return false;
875 * Returns the current group mode for a given course or activity module
877 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
879 * @param object $course Course Object
880 * @param object $cm Course Manager Object
881 * @return mixed $course->groupmode
883 function groupmode($course, $cm=null) {
885 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
886 return $cm->groupmode;
888 return $course->groupmode;
892 * Sets the current group in the session variable
893 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
894 * Sets currentgroup[$courseid] in the session variable appropriately.
895 * Does not do any permission checking.
897 * @global object
898 * @param int $courseid The course being examined - relates to id field in
899 * 'course' table.
900 * @param int $groupid The group being examined.
901 * @return int Current group id which was set by this function
903 function set_current_group($courseid, $groupid) {
904 global $SESSION;
905 return $SESSION->currentgroup[$courseid] = $groupid;
910 * Gets the current group - either from the session variable or from the database.
912 * @global object
913 * @param int $courseid The course being examined - relates to id field in
914 * 'course' table.
915 * @param bool $full If true, the return value is a full record object.
916 * If false, just the id of the record.
917 * @return int|bool
919 function get_current_group($courseid, $full = false) {
920 global $SESSION;
922 if (isset($SESSION->currentgroup[$courseid])) {
923 if ($full) {
924 return groups_get_group($SESSION->currentgroup[$courseid]);
925 } else {
926 return $SESSION->currentgroup[$courseid];
930 $mygroupid = mygroupid($courseid);
931 if (is_array($mygroupid)) {
932 $mygroupid = array_shift($mygroupid);
933 set_current_group($courseid, $mygroupid);
934 if ($full) {
935 return groups_get_group($mygroupid);
936 } else {
937 return $mygroupid;
941 if ($full) {
942 return false;
943 } else {
944 return 0;
950 * Inndicates fatal error. This function was originally printing the
951 * error message directly, since 2.0 it is throwing exception instead.
952 * The error printing is handled in default exception handler.
954 * Old method, don't call directly in new code - use print_error instead.
956 * @param string $message The message to display to the user about the error.
957 * @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.
958 * @return void, always throws moodle_exception
960 function error($message, $link='') {
961 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
966 * @deprecated use $PAGE->theme->name instead.
967 * @todo final deprecation of this function in MDL-40607
968 * @return string the name of the current theme.
970 function current_theme() {
971 global $PAGE;
973 debugging('current_theme() is deprecated, please use $PAGE->theme->name instead', DEBUG_DEVELOPER);
974 return $PAGE->theme->name;
978 * Prints some red text using echo
980 * @deprecated
981 * @param string $error The text to be displayed in red
983 function formerr($error) {
984 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
985 global $OUTPUT;
986 echo $OUTPUT->error_text($error);
990 * Return the markup for the destination of the 'Skip to main content' links.
991 * Accessibility improvement for keyboard-only users.
993 * Used in course formats, /index.php and /course/index.php
995 * @deprecated use $OUTPUT->skip_link_target() in instead.
996 * @todo final deprecation of this function in MDL-40607
997 * @return string HTML element.
999 function skip_main_destination() {
1000 global $OUTPUT;
1002 debugging('skip_main_destination() is deprecated, please use $OUTPUT->skip_link_target() instead.', DEBUG_DEVELOPER);
1003 return $OUTPUT->skip_link_target();
1007 * Print a message in a standard themed container.
1009 * @deprecated use $OUTPUT->container() instead.
1010 * @todo final deprecation of this function in MDL-40607
1011 * @param string $message, the content of the container
1012 * @param boolean $clearfix clear both sides
1013 * @param string $classes, space-separated class names.
1014 * @param string $idbase
1015 * @param boolean $return, return as string or just print it
1016 * @return string|void Depending on value of $return
1018 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
1019 global $OUTPUT;
1021 debugging('print_container() is deprecated. Please use $OUTPUT->container() instead.', DEBUG_DEVELOPER);
1022 if ($clearfix) {
1023 $classes .= ' clearfix';
1025 $output = $OUTPUT->container($message, $classes, $idbase);
1026 if ($return) {
1027 return $output;
1028 } else {
1029 echo $output;
1034 * Starts a container using divs
1036 * @deprecated use $OUTPUT->container_start() instead.
1037 * @todo final deprecation of this function in MDL-40607
1038 * @param boolean $clearfix clear both sides
1039 * @param string $classes, space-separated class names.
1040 * @param string $idbase
1041 * @param boolean $return, return as string or just print it
1042 * @return string|void Based on value of $return
1044 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
1045 global $OUTPUT;
1047 debugging('print_container_start() is deprecated. Please use $OUTPUT->container_start() instead.', DEBUG_DEVELOPER);
1049 if ($clearfix) {
1050 $classes .= ' clearfix';
1052 $output = $OUTPUT->container_start($classes, $idbase);
1053 if ($return) {
1054 return $output;
1055 } else {
1056 echo $output;
1061 * Simple function to end a container (see above)
1063 * @deprecated use $OUTPUT->container_end() instead.
1064 * @todo final deprecation of this function in MDL-40607
1065 * @param boolean $return, return as string or just print it
1066 * @return string|void Based on $return
1068 function print_container_end($return=false) {
1069 global $OUTPUT;
1070 debugging('print_container_end() is deprecated. Please use $OUTPUT->container_end() instead.', DEBUG_DEVELOPER);
1071 $output = $OUTPUT->container_end();
1072 if ($return) {
1073 return $output;
1074 } else {
1075 echo $output;
1080 * Print a bold message in an optional color.
1082 * @deprecated use $OUTPUT->notification instead.
1083 * @param string $message The message to print out
1084 * @param string $style Optional style to display message text in
1085 * @param string $align Alignment option
1086 * @param bool $return whether to return an output string or echo now
1087 * @return string|bool Depending on $result
1089 function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
1090 global $OUTPUT;
1092 if ($classes == 'green') {
1093 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
1094 $classes = 'notifysuccess'; // Backward compatible with old color system
1097 $output = $OUTPUT->notification($message, $classes);
1098 if ($return) {
1099 return $output;
1100 } else {
1101 echo $output;
1106 * Print a continue button that goes to a particular URL.
1108 * @deprecated use $OUTPUT->continue_button() instead.
1109 * @todo final deprecation of this function in MDL-40607
1111 * @param string $link The url to create a link to.
1112 * @param bool $return If set to true output is returned rather than echoed, default false
1113 * @return string|void HTML String if return=true nothing otherwise
1115 function print_continue($link, $return = false) {
1116 global $CFG, $OUTPUT;
1118 debugging('print_continue() is deprecated. Please use $OUTPUT->continue_button() instead.', DEBUG_DEVELOPER);
1120 if ($link == '') {
1121 if (!empty($_SERVER['HTTP_REFERER'])) {
1122 $link = $_SERVER['HTTP_REFERER'];
1123 $link = str_replace('&', '&amp;', $link); // make it valid XHTML
1124 } else {
1125 $link = $CFG->wwwroot .'/';
1129 $output = $OUTPUT->continue_button($link);
1130 if ($return) {
1131 return $output;
1132 } else {
1133 echo $output;
1138 * Print a standard header
1140 * @deprecated use $PAGE methods instead.
1141 * @todo final deprecation of this function in MDL-40607
1142 * @param string $title Appears at the top of the window
1143 * @param string $heading Appears at the top of the page
1144 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
1145 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1146 * @param string $meta Meta tags to be added to the header
1147 * @param boolean $cache Should this page be cacheable?
1148 * @param string $button HTML code for a button (usually for module editing)
1149 * @param string $menu HTML code for a popup menu
1150 * @param boolean $usexml use XML for this page
1151 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1152 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1153 * @return string|void If return=true then string else void
1155 function print_header($title='', $heading='', $navigation='', $focus='',
1156 $meta='', $cache=true, $button='&nbsp;', $menu=null,
1157 $usexml=false, $bodytags='', $return=false) {
1158 global $PAGE, $OUTPUT;
1160 debugging('print_header() is deprecated. Please use $PAGE methods instead.', DEBUG_DEVELOPER);
1162 $PAGE->set_title($title);
1163 $PAGE->set_heading($heading);
1164 $PAGE->set_cacheable($cache);
1165 if ($button == '') {
1166 $button = '&nbsp;';
1168 $PAGE->set_button($button);
1169 $PAGE->set_headingmenu($menu);
1171 // TODO $menu
1173 if ($meta) {
1174 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1175 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1177 if ($usexml) {
1178 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1180 if ($bodytags) {
1181 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1184 $output = $OUTPUT->header();
1186 if ($return) {
1187 return $output;
1188 } else {
1189 echo $output;
1194 * This version of print_header is simpler because the course name does not have to be
1195 * provided explicitly in the strings. It can be used on the site page as in courses
1196 * Eventually all print_header could be replaced by print_header_simple
1198 * @deprecated use $PAGE methods instead.
1199 * @todo final deprecation of this function in MDL-40607
1200 * @param string $title Appears at the top of the window
1201 * @param string $heading Appears at the top of the page
1202 * @param string $navigation Premade navigation string (for use as breadcrumbs links)
1203 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1204 * @param string $meta Meta tags to be added to the header
1205 * @param boolean $cache Should this page be cacheable?
1206 * @param string $button HTML code for a button (usually for module editing)
1207 * @param string $menu HTML code for a popup menu
1208 * @param boolean $usexml use XML for this page
1209 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1210 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1211 * @return string|void If $return=true the return string else nothing
1213 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
1214 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
1216 global $COURSE, $CFG, $PAGE, $OUTPUT;
1218 debugging('print_header_simple() is deprecated. Please use $PAGE methods instead.', DEBUG_DEVELOPER);
1220 if ($meta) {
1221 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1222 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1224 if ($usexml) {
1225 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1227 if ($bodytags) {
1228 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1231 $PAGE->set_title($title);
1232 $PAGE->set_heading($heading);
1233 $PAGE->set_cacheable(true);
1234 $PAGE->set_button($button);
1236 $output = $OUTPUT->header();
1238 if ($return) {
1239 return $output;
1240 } else {
1241 echo $output;
1246 * Prints a nice side block with an optional header. The content can either
1247 * be a block of HTML or a list of text with optional icons.
1249 * @static int $block_id Increments for each call to the function
1250 * @param string $heading HTML for the heading. Can include full HTML or just
1251 * plain text - plain text will automatically be enclosed in the appropriate
1252 * heading tags.
1253 * @param string $content HTML for the content
1254 * @param array $list an alternative to $content, it you want a list of things with optional icons.
1255 * @param array $icons optional icons for the things in $list.
1256 * @param string $footer Extra HTML content that gets output at the end, inside a &lt;div class="footer">
1257 * @param array $attributes an array of attribute => value pairs that are put on the
1258 * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
1259 * already a class, class='block' is used.
1260 * @param string $title Plain text title, as embedded in the $heading.
1261 * @deprecated use $OUTPUT->block() instead.
1262 * @todo final deprecation of this function in MDL-40607
1264 function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
1265 global $OUTPUT;
1267 debugging('print_side_block() is deprecated, please use $OUTPUT->block() instead.', DEBUG_DEVELOPER);
1268 // We don't use $heading, becuse it often contains HTML that we don't want.
1269 // However, sometimes $title is not set, but $heading is.
1270 if (empty($title)) {
1271 $title = strip_tags($heading);
1274 // Render list contents to HTML if required.
1275 if (empty($content) && $list) {
1276 $content = $OUTPUT->list_block_contents($icons, $list);
1279 $bc = new block_contents();
1280 $bc->content = $content;
1281 $bc->footer = $footer;
1282 $bc->title = $title;
1284 if (isset($attributes['id'])) {
1285 $bc->id = $attributes['id'];
1286 unset($attributes['id']);
1288 $bc->attributes = $attributes;
1290 echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
1294 * Prints a basic textarea field.
1296 * @deprecated since Moodle 2.0
1298 * When using this function, you should
1300 * @global object
1301 * @param bool $unused No longer used.
1302 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
1303 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
1304 * @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.
1305 * @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.
1306 * @param string $name Name to use for the textarea element.
1307 * @param string $value Initial content to display in the textarea.
1308 * @param int $obsolete deprecated
1309 * @param bool $return If false, will output string. If true, will return string value.
1310 * @param string $id CSS ID to add to the textarea element.
1311 * @return string|void depending on the value of $return
1313 function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
1314 /// $width and height are legacy fields and no longer used as pixels like they used to be.
1315 /// However, you can set them to zero to override the mincols and minrows values below.
1317 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
1318 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
1320 global $CFG;
1322 $mincols = 65;
1323 $minrows = 10;
1324 $str = '';
1326 if ($id === '') {
1327 $id = 'edit-'.$name;
1330 if ($height && ($rows < $minrows)) {
1331 $rows = $minrows;
1333 if ($width && ($cols < $mincols)) {
1334 $cols = $mincols;
1337 editors_head_setup();
1338 $editor = editors_get_preferred_editor(FORMAT_HTML);
1339 $editor->use_editor($id, array('legacy'=>true));
1341 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'" spellcheck="true">'."\n";
1342 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
1343 $str .= '</textarea>'."\n";
1345 if ($return) {
1346 return $str;
1348 echo $str;
1352 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
1353 * Should be used only with htmleditor or textarea.
1355 * @global object
1356 * @global object
1357 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
1358 * helpbutton.
1359 * @return string Link to help button
1361 function editorhelpbutton(){
1362 return '';
1364 /// TODO: MDL-21215
1368 * Print a help button.
1370 * Prints a special help button for html editors (htmlarea in this case)
1372 * @todo Write code into this function! detect current editor and print correct info
1373 * @global object
1374 * @return string Only returns an empty string at the moment
1376 function editorshortcutshelpbutton() {
1377 /// TODO: MDL-21215
1379 global $CFG;
1380 //TODO: detect current editor and print correct info
1381 return '';
1386 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
1387 * provide this function with the language strings for sortasc and sortdesc.
1389 * @deprecated use $OUTPUT->arrow() instead.
1390 * @todo final deprecation of this function in MDL-40607
1392 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
1394 * @global object
1395 * @param string $direction 'up' or 'down'
1396 * @param string $strsort The language string used for the alt attribute of this image
1397 * @param bool $return Whether to print directly or return the html string
1398 * @return string|void depending on $return
1401 function print_arrow($direction='up', $strsort=null, $return=false) {
1402 global $OUTPUT;
1404 debugging('print_arrow() is deprecated. Please use $OUTPUT->arrow() instead.', DEBUG_DEVELOPER);
1406 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
1407 return null;
1410 $return = null;
1412 switch ($direction) {
1413 case 'up':
1414 $sortdir = 'asc';
1415 break;
1416 case 'down':
1417 $sortdir = 'desc';
1418 break;
1419 case 'move':
1420 $sortdir = 'asc';
1421 break;
1422 default:
1423 $sortdir = null;
1424 break;
1427 // Prepare language string
1428 $strsort = '';
1429 if (empty($strsort) && !empty($sortdir)) {
1430 $strsort = get_string('sort' . $sortdir, 'grades');
1433 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
1435 if ($return) {
1436 return $return;
1437 } else {
1438 echo $return;
1443 * Given an array of values, output the HTML for a select element with those options.
1445 * @deprecated since Moodle 2.0
1447 * Normally, you only need to use the first few parameters.
1449 * @param array $options The options to offer. An array of the form
1450 * $options[{value}] = {text displayed for that option};
1451 * @param string $name the name of this form control, as in &lt;select name="..." ...
1452 * @param string $selected the option to select initially, default none.
1453 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
1454 * Set this to '' if you don't want a 'nothing is selected' option.
1455 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
1456 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
1457 * @param boolean $return if false (the default) the the output is printed directly, If true, the
1458 * generated HTML is returned as a string.
1459 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
1460 * @param int $tabindex if give, sets the tabindex attribute on the &lt;select> element. Default none.
1461 * @param string $id value to use for the id attribute of the &lt;select> element. If none is given,
1462 * then a suitable one is constructed.
1463 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
1464 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
1465 * $listbox is an integer, that number is used for size instead.
1466 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
1467 * when $listbox display is enabled
1468 * @param string $class value to use for the class attribute of the &lt;select> element. If none is given,
1469 * then a suitable one is constructed.
1470 * @return string|void If $return=true returns string, else echo's and returns void
1472 function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
1473 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
1474 $id='', $listbox=false, $multiple=false, $class='') {
1476 global $OUTPUT;
1477 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
1479 if ($script) {
1480 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
1482 $attributes = array();
1483 $attributes['disabled'] = $disabled ? 'disabled' : null;
1484 $attributes['tabindex'] = $tabindex ? $tabindex : null;
1485 $attributes['multiple'] = $multiple ? $multiple : null;
1486 $attributes['class'] = $class ? $class : null;
1487 $attributes['id'] = $id ? $id : null;
1489 $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
1491 if ($return) {
1492 return $output;
1493 } else {
1494 echo $output;
1499 * Prints a help button about a scale
1501 * @deprecated use $OUTPUT->help_icon_scale($courseid, $scale) instead.
1502 * @todo final deprecation of this function in MDL-40607
1504 * @global object
1505 * @param id $courseid
1506 * @param object $scale
1507 * @param boolean $return If set to true returns rather than echo's
1508 * @return string|bool Depending on value of $return
1510 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
1511 global $OUTPUT;
1513 debugging('print_scale_menu_helpbutton() is deprecated. Please use $OUTPUT->help_icon_scale($courseid, $scale) instead.', DEBUG_DEVELOPER);
1515 $output = $OUTPUT->help_icon_scale($courseid, $scale);
1517 if ($return) {
1518 return $output;
1519 } else {
1520 echo $output;
1525 * Display an standard html checkbox with an optional label
1527 * @deprecated use html_writer::checkbox() instead.
1528 * @todo final deprecation of this function in MDL-40607
1530 * @staticvar int $idcounter
1531 * @param string $name The name of the checkbox
1532 * @param string $value The valus that the checkbox will pass when checked
1533 * @param bool $checked The flag to tell the checkbox initial state
1534 * @param string $label The label to be showed near the checkbox
1535 * @param string $alt The info to be inserted in the alt tag
1536 * @param string $script If not '', then this is added to the checkbox element
1537 * as an onchange handler.
1538 * @param bool $return Whether this function should return a string or output
1539 * it (defaults to false)
1540 * @return string|void If $return=true returns string, else echo's and returns void
1542 function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
1543 global $OUTPUT;
1545 debugging('print_checkbox() is deprecated. Please use html_writer::checkbox() instead.', DEBUG_DEVELOPER);
1547 if (!empty($script)) {
1548 debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER);
1551 $output = html_writer::checkbox($name, $value, $checked, $label);
1553 if (empty($return)) {
1554 echo $output;
1555 } else {
1556 return $output;
1562 * Prints the 'update this xxx' button that appears on module pages.
1564 * @deprecated since Moodle 2.0
1566 * @param string $cmid the course_module id.
1567 * @param string $ignored not used any more. (Used to be courseid.)
1568 * @param string $string the module name - get_string('modulename', 'xxx')
1569 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
1571 function update_module_button($cmid, $ignored, $string) {
1572 global $CFG, $OUTPUT;
1574 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
1576 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
1578 if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) {
1579 $string = get_string('updatethis', '', $string);
1581 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
1582 return $OUTPUT->single_button($url, $string);
1583 } else {
1584 return '';
1589 * Prints breadcrumb trail of links, called in theme/-/header.html
1591 * This function has now been deprecated please use output's navbar method instead
1592 * as shown below
1594 * <code php>
1595 * echo $OUTPUT->navbar();
1596 * </code>
1598 * @deprecated use $OUTPUT->navbar() instead
1599 * @todo final deprecation of this function in MDL-40607
1600 * @param mixed $navigation deprecated
1601 * @param string $separator OBSOLETE, and now deprecated
1602 * @param boolean $return False to echo the breadcrumb string (default), true to return it.
1603 * @return string|void String or null, depending on $return.
1605 function print_navigation ($navigation, $separator=0, $return=false) {
1606 global $OUTPUT,$PAGE;
1608 debugging('print_navigation() is deprecated, please update use $OUTPUT->navbar() instead.', DEBUG_DEVELOPER);
1610 $output = $OUTPUT->navbar();
1612 if ($return) {
1613 return $output;
1614 } else {
1615 echo $output;
1620 * This function will build the navigation string to be used by print_header
1621 * and others.
1623 * It automatically generates the site and course level (if appropriate) links.
1625 * If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums')
1626 * and activityinstances (e.g. 'General Developer Forum') navigation levels.
1628 * If you want to add any further navigation links after the ones this function generates,
1629 * the pass an array of extra link arrays like this:
1630 * array(
1631 * array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1),
1632 * array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2)
1634 * The normal case is to just add one further link, for example 'Editing forum' after
1635 * 'General Developer Forum', with no link.
1636 * To do that, you need to pass
1637 * array(array('name' => $linktext, 'link' => '', 'type' => 'title'))
1638 * However, becuase this is a very common case, you can use a shortcut syntax, and just
1639 * pass the string 'Editing forum', instead of an array as $extranavlinks.
1641 * At the moment, the link types only have limited significance. Type 'activity' is
1642 * recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types
1643 * that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'.
1644 * This really needs to be documented better. In the mean time, try to be consistent, it will
1645 * enable people to customise the navigation more in future.
1647 * When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course.
1648 * If you get the $cm object using the function get_coursemodule_from_instance or
1649 * get_coursemodule_from_id (as recommended) then this will be done for you automatically.
1650 * If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using
1651 * the $cm->module and $cm->instance fields, but this takes extra database queries, so a
1652 * warning is printed in developer debug mode.
1654 * @deprecated Please use $PAGE->navabar methods instead.
1655 * @todo final deprecation of this function in MDL-40607
1656 * @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you
1657 * only want one extra item with no link, you can pass a string instead. If you don't want
1658 * any extra links, pass an empty string.
1659 * @param mixed $cm deprecated
1660 * @return array Navigation array
1662 function build_navigation($extranavlinks, $cm = null) {
1663 global $CFG, $COURSE, $DB, $SITE, $PAGE;
1665 debugging('build_navigation() is deprecated, please use $PAGE->navbar methods instead.', DEBUG_DEVELOPER);
1666 if (is_array($extranavlinks) && count($extranavlinks)>0) {
1667 foreach ($extranavlinks as $nav) {
1668 if (array_key_exists('name', $nav)) {
1669 if (array_key_exists('link', $nav) && !empty($nav['link'])) {
1670 $link = $nav['link'];
1671 } else {
1672 $link = null;
1674 $PAGE->navbar->add($nav['name'],$link);
1679 return(array('newnav' => true, 'navlinks' => array()));
1683 * @deprecated not relevant with global navigation in Moodle 2.x+
1684 * @todo remove completely in MDL-40607
1686 function navmenu($course, $cm=NULL, $targetwindow='self') {
1687 // This function has been deprecated with the creation of the global nav in
1688 // moodle 2.0
1689 debugging('navmenu() is deprecated, it is no longer relevant with global navigation.', DEBUG_DEVELOPER);
1691 return '';
1694 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
1698 * Call this function to add an event to the calendar table and to call any calendar plugins
1700 * @param object $event An object representing an event from the calendar table.
1701 * The event will be identified by the id field. The object event should include the following:
1702 * <ul>
1703 * <li><b>$event->name</b> - Name for the event
1704 * <li><b>$event->description</b> - Description of the event (defaults to '')
1705 * <li><b>$event->format</b> - Format for the description (using formatting types defined at the top of weblib.php)
1706 * <li><b>$event->courseid</b> - The id of the course this event belongs to (0 = all courses)
1707 * <li><b>$event->groupid</b> - The id of the group this event belongs to (0 = no group)
1708 * <li><b>$event->userid</b> - The id of the user this event belongs to (0 = no user)
1709 * <li><b>$event->modulename</b> - Name of the module that creates this event
1710 * <li><b>$event->instance</b> - Instance of the module that owns this event
1711 * <li><b>$event->eventtype</b> - The type info together with the module info could
1712 * be used by calendar plugins to decide how to display event
1713 * <li><b>$event->timestart</b>- Timestamp for start of event
1714 * <li><b>$event->timeduration</b> - Duration (defaults to zero)
1715 * <li><b>$event->visible</b> - 0 if the event should be hidden (e.g. because the activity that created it is hidden)
1716 * </ul>
1717 * @return int|false The id number of the resulting record or false if failed
1718 * @deprecated please use calendar_event::create() instead.
1719 * @todo final deprecation of this function in MDL-40607
1721 function add_event($event) {
1722 global $CFG;
1723 require_once($CFG->dirroot.'/calendar/lib.php');
1725 debugging('add_event() is deprecated, please use calendar_event::create() instead.', DEBUG_DEVELOPER);
1726 $event = calendar_event::create($event);
1727 if ($event !== false) {
1728 return $event->id;
1730 return false;
1734 * Call this function to update an event in the calendar table
1735 * the event will be identified by the id field of the $event object.
1737 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
1738 * @return bool Success
1739 * @deprecated please calendar_event->update() instead.
1741 function update_event($event) {
1742 global $CFG;
1743 require_once($CFG->dirroot.'/calendar/lib.php');
1745 debugging('update_event() is deprecated, please use calendar_event->update() instead.', DEBUG_DEVELOPER);
1746 $event = (object)$event;
1747 $calendarevent = calendar_event::load($event->id);
1748 return $calendarevent->update($event);
1752 * Call this function to delete the event with id $id from calendar table.
1754 * @param int $id The id of an event from the 'event' table.
1755 * @return bool
1756 * @deprecated please use calendar_event->delete() instead.
1757 * @todo final deprecation of this function in MDL-40607
1759 function delete_event($id) {
1760 global $CFG;
1761 require_once($CFG->dirroot.'/calendar/lib.php');
1763 debugging('delete_event() is deprecated, please use calendar_event->delete() instead.', DEBUG_DEVELOPER);
1765 $event = calendar_event::load($id);
1766 return $event->delete();
1770 * Call this function to hide an event in the calendar table
1771 * the event will be identified by the id field of the $event object.
1773 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
1774 * @return true
1775 * @deprecated please use calendar_event->toggle_visibility(false) instead.
1776 * @todo final deprecation of this function in MDL-40607
1778 function hide_event($event) {
1779 global $CFG;
1780 require_once($CFG->dirroot.'/calendar/lib.php');
1782 debugging('hide_event() is deprecated, please use calendar_event->toggle_visibility(false) instead.', DEBUG_DEVELOPER);
1784 $event = new calendar_event($event);
1785 return $event->toggle_visibility(false);
1789 * Call this function to unhide an event in the calendar table
1790 * the event will be identified by the id field of the $event object.
1792 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
1793 * @return true
1794 * @deprecated please use calendar_event->toggle_visibility(true) instead.
1795 * @todo final deprecation of this function in MDL-40607
1797 function show_event($event) {
1798 global $CFG;
1799 require_once($CFG->dirroot.'/calendar/lib.php');
1801 debugging('show_event() is deprecated, please use calendar_event->toggle_visibility(true) instead.', DEBUG_DEVELOPER);
1803 $event = new calendar_event($event);
1804 return $event->toggle_visibility(true);
1808 * Original singleton helper function, please use static methods instead,
1809 * ex: core_text::convert()
1811 * @deprecated since Moodle 2.2 use core_text::xxxx() instead
1812 * @see textlib
1813 * @return textlib instance
1815 function textlib_get_instance() {
1817 debugging('textlib_get_instance() is deprecated. Please use static calling core_text::functioname() instead.', DEBUG_DEVELOPER);
1819 return new textlib();
1823 * Gets the generic section name for a courses section
1825 * The global function is deprecated. Each course format can define their own generic section name
1827 * @deprecated since 2.4
1828 * @see get_section_name()
1829 * @see format_base::get_section_name()
1831 * @param string $format Course format ID e.g. 'weeks' $course->format
1832 * @param stdClass $section Section object from database
1833 * @return Display name that the course format prefers, e.g. "Week 2"
1835 function get_generic_section_name($format, stdClass $section) {
1836 debugging('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base', DEBUG_DEVELOPER);
1837 return get_string('sectionname', "format_$format") . ' ' . $section->section;
1841 * Returns an array of sections for the requested course id
1843 * It is usually not recommended to display the list of sections used
1844 * in course because the course format may have it's own way to do it.
1846 * If you need to just display the name of the section please call:
1847 * get_section_name($course, $section)
1848 * {@link get_section_name()}
1849 * from 2.4 $section may also be just the field course_sections.section
1851 * If you need the list of all sections it is more efficient to get this data by calling
1852 * $modinfo = get_fast_modinfo($courseorid);
1853 * $sections = $modinfo->get_section_info_all()
1854 * {@link get_fast_modinfo()}
1855 * {@link course_modinfo::get_section_info_all()}
1857 * Information about one section (instance of section_info):
1858 * get_fast_modinfo($courseorid)->get_sections_info($section)
1859 * {@link course_modinfo::get_section_info()}
1861 * @deprecated since 2.4
1863 * @param int $courseid
1864 * @return array Array of section_info objects
1866 function get_all_sections($courseid) {
1867 global $DB;
1868 debugging('get_all_sections() is deprecated. See phpdocs for this function', DEBUG_DEVELOPER);
1869 return get_fast_modinfo($courseid)->get_section_info_all();
1873 * Given a full mod object with section and course already defined, adds this module to that section.
1875 * This function is deprecated, please use {@link course_add_cm_to_section()}
1876 * Note that course_add_cm_to_section() also updates field course_modules.section and
1877 * calls rebuild_course_cache()
1879 * @deprecated since 2.4
1881 * @param object $mod
1882 * @param int $beforemod An existing ID which we will insert the new module before
1883 * @return int The course_sections ID where the mod is inserted
1885 function add_mod_to_section($mod, $beforemod = null) {
1886 debugging('Function add_mod_to_section() is deprecated, please use course_add_cm_to_section()', DEBUG_DEVELOPER);
1887 global $DB;
1888 return course_add_cm_to_section($mod->course, $mod->coursemodule, $mod->section, $beforemod);
1892 * Returns a number of useful structures for course displays
1894 * Function get_all_mods() is deprecated in 2.4
1895 * Instead of:
1896 * <code>
1897 * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
1898 * </code>
1899 * please use:
1900 * <code>
1901 * $mods = get_fast_modinfo($courseorid)->get_cms();
1902 * $modnames = get_module_types_names();
1903 * $modnamesplural = get_module_types_names(true);
1904 * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names();
1905 * </code>
1907 * @deprecated since 2.4
1909 * @param int $courseid id of the course to get info about
1910 * @param array $mods (return) list of course modules
1911 * @param array $modnames (return) list of names of all module types installed and available
1912 * @param array $modnamesplural (return) list of names of all module types installed and available in the plural form
1913 * @param array $modnamesused (return) list of names of all module types used in the course
1915 function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
1916 debugging('Function get_all_mods() is deprecated. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details', DEBUG_DEVELOPER);
1918 global $COURSE;
1919 $modnames = get_module_types_names();
1920 $modnamesplural= get_module_types_names(true);
1921 $modinfo = get_fast_modinfo($courseid);
1922 $mods = $modinfo->get_cms();
1923 $modnamesused = $modinfo->get_used_module_names();
1927 * Returns course section - creates new if does not exist yet
1929 * This function is deprecated. To create a course section call:
1930 * course_create_sections_if_missing($courseorid, $sections);
1931 * to get the section call:
1932 * get_fast_modinfo($courseorid)->get_section_info($sectionnum);
1934 * @see course_create_sections_if_missing()
1935 * @see get_fast_modinfo()
1936 * @deprecated since 2.4
1938 * @param int $section relative section number (field course_sections.section)
1939 * @param int $courseid
1940 * @return stdClass record from table {course_sections}
1942 function get_course_section($section, $courseid) {
1943 global $DB;
1944 debugging('Function get_course_section() is deprecated. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.', DEBUG_DEVELOPER);
1946 if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) {
1947 return $cw;
1949 $cw = new stdClass();
1950 $cw->course = $courseid;
1951 $cw->section = $section;
1952 $cw->summary = "";
1953 $cw->summaryformat = FORMAT_HTML;
1954 $cw->sequence = "";
1955 $id = $DB->insert_record("course_sections", $cw);
1956 rebuild_course_cache($courseid, true);
1957 return $DB->get_record("course_sections", array("id"=>$id));
1961 * Return the start and end date of the week in Weekly course format
1963 * It is not recommended to use this function outside of format_weeks plugin
1965 * @deprecated since 2.4
1966 * @see format_weeks::get_section_dates()
1968 * @param stdClass $section The course_section entry from the DB
1969 * @param stdClass $course The course entry from DB
1970 * @return stdClass property start for startdate, property end for enddate
1972 function format_weeks_get_section_dates($section, $course) {
1973 debugging('Function format_weeks_get_section_dates() is deprecated. It is not recommended to'.
1974 ' use it outside of format_weeks plugin', DEBUG_DEVELOPER);
1975 if (isset($course->format) && $course->format === 'weeks') {
1976 return course_get_format($course)->get_section_dates($section);
1978 return null;
1982 * Obtains shared data that is used in print_section when displaying a
1983 * course-module entry.
1985 * Deprecated. Instead of:
1986 * list($content, $name) = get_print_section_cm_text($cm, $course);
1987 * use:
1988 * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
1989 * $name = $cm->get_formatted_name();
1991 * @deprecated since 2.5
1992 * @see cm_info::get_formatted_content()
1993 * @see cm_info::get_formatted_name()
1995 * This data is also used in other areas of the code.
1996 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
1997 * @param object $course (argument not used)
1998 * @return array An array with the following values in this order:
1999 * $content (optional extra content for after link),
2000 * $instancename (text of link)
2002 function get_print_section_cm_text(cm_info $cm, $course) {
2003 debugging('Function get_print_section_cm_text() is deprecated. Please use '.
2004 'cm_info::get_formatted_content() and cm_info::get_formatted_name()',
2005 DEBUG_DEVELOPER);
2006 return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)),
2007 $cm->get_formatted_name());
2011 * Prints the menus to add activities and resources.
2013 * Deprecated. Please use:
2014 * $courserenderer = $PAGE->get_renderer('core', 'course');
2015 * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
2016 * array('inblock' => $vertical));
2017 * echo $output; // if $return argument in print_section_add_menus() set to false
2019 * @deprecated since 2.5
2020 * @see core_course_renderer::course_section_add_cm_control()
2022 * @param stdClass $course course object, must be the same as set on the page
2023 * @param int $section relative section number (field course_sections.section)
2024 * @param null|array $modnames (argument ignored) get_module_types_names() is used instead of argument
2025 * @param bool $vertical Vertical orientation
2026 * @param bool $return Return the menus or send them to output
2027 * @param int $sectionreturn The section to link back to
2028 * @return void|string depending on $return
2030 function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
2031 global $PAGE;
2032 debugging('Function print_section_add_menus() is deprecated. Please use course renderer '.
2033 'function course_section_add_cm_control()', DEBUG_DEVELOPER);
2034 $output = '';
2035 $courserenderer = $PAGE->get_renderer('core', 'course');
2036 $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
2037 array('inblock' => $vertical));
2038 if ($return) {
2039 return $output;
2040 } else {
2041 echo $output;
2042 return !empty($output);
2047 * Produces the editing buttons for a module
2049 * Deprecated. Please use:
2050 * $courserenderer = $PAGE->get_renderer('core', 'course');
2051 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
2052 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
2054 * @deprecated since 2.5
2055 * @see course_get_cm_edit_actions()
2056 * @see core_course_renderer->course_section_cm_edit_actions()
2058 * @param stdClass $mod The module to produce editing buttons for
2059 * @param bool $absolute_ignored (argument ignored) - all links are absolute
2060 * @param bool $moveselect (argument ignored)
2061 * @param int $indent The current indenting
2062 * @param int $section The section to link back to
2063 * @return string XHTML for the editing buttons
2065 function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
2066 global $PAGE;
2067 debugging('Function make_editing_buttons() is deprecated, please see PHPdocs in '.
2068 'lib/deprecatedlib.php on how to replace it', DEBUG_DEVELOPER);
2069 if (!($mod instanceof cm_info)) {
2070 $modinfo = get_fast_modinfo($mod->course);
2071 $mod = $modinfo->get_cm($mod->id);
2073 $actions = course_get_cm_edit_actions($mod, $indent, $section);
2075 $courserenderer = $PAGE->get_renderer('core', 'course');
2076 // The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap
2077 // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
2078 // the course page HTML will allow this to be removed.
2079 return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
2083 * Prints a section full of activity modules
2085 * Deprecated. Please use:
2086 * $courserenderer = $PAGE->get_renderer('core', 'course');
2087 * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn,
2088 * array('hidecompletion' => $hidecompletion));
2090 * @deprecated since 2.5
2091 * @see core_course_renderer::course_section_cm_list()
2093 * @param stdClass $course The course
2094 * @param stdClass|section_info $section The section object containing properties id and section
2095 * @param array $mods (argument not used)
2096 * @param array $modnamesused (argument not used)
2097 * @param bool $absolute (argument not used)
2098 * @param string $width (argument not used)
2099 * @param bool $hidecompletion Hide completion status
2100 * @param int $sectionreturn The section to return to
2101 * @return void
2103 function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
2104 global $PAGE;
2105 debugging('Function print_section() is deprecated. Please use course renderer function '.
2106 'course_section_cm_list() instead.', DEBUG_DEVELOPER);
2107 $displayoptions = array('hidecompletion' => $hidecompletion);
2108 $courserenderer = $PAGE->get_renderer('core', 'course');
2109 echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions);
2113 * Displays the list of courses with user notes
2115 * This function is not used in core. It was replaced by block course_overview
2117 * @deprecated since 2.5
2119 * @param array $courses
2120 * @param array $remote_courses
2122 function print_overview($courses, array $remote_courses=array()) {
2123 global $CFG, $USER, $DB, $OUTPUT;
2124 debugging('Function print_overview() is deprecated. Use block course_overview to display this information', DEBUG_DEVELOPER);
2126 $htmlarray = array();
2127 if ($modules = $DB->get_records('modules')) {
2128 foreach ($modules as $mod) {
2129 if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) {
2130 include_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php');
2131 $fname = $mod->name.'_print_overview';
2132 if (function_exists($fname)) {
2133 $fname($courses,$htmlarray);
2138 foreach ($courses as $course) {
2139 $fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
2140 echo $OUTPUT->box_start('coursebox');
2141 $attributes = array('title' => s($fullname));
2142 if (empty($course->visible)) {
2143 $attributes['class'] = 'dimmed';
2145 echo $OUTPUT->heading(html_writer::link(
2146 new moodle_url('/course/view.php', array('id' => $course->id)), $fullname, $attributes), 3);
2147 if (array_key_exists($course->id,$htmlarray)) {
2148 foreach ($htmlarray[$course->id] as $modname => $html) {
2149 echo $html;
2152 echo $OUTPUT->box_end();
2155 if (!empty($remote_courses)) {
2156 echo $OUTPUT->heading(get_string('remotecourses', 'mnet'));
2158 foreach ($remote_courses as $course) {
2159 echo $OUTPUT->box_start('coursebox');
2160 $attributes = array('title' => s($course->fullname));
2161 echo $OUTPUT->heading(html_writer::link(
2162 new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)),
2163 format_string($course->shortname),
2164 $attributes) . ' (' . format_string($course->hostname) . ')', 3);
2165 echo $OUTPUT->box_end();
2170 * This function trawls through the logs looking for
2171 * anything new since the user's last login
2173 * This function was only used to print the content of block recent_activity
2174 * All functionality is moved into class {@link block_recent_activity}
2175 * and renderer {@link block_recent_activity_renderer}
2177 * @deprecated since 2.5
2178 * @param stdClass $course
2180 function print_recent_activity($course) {
2181 // $course is an object
2182 global $CFG, $USER, $SESSION, $DB, $OUTPUT;
2183 debugging('Function print_recent_activity() is deprecated. It is not recommended to'.
2184 ' use it outside of block_recent_activity', DEBUG_DEVELOPER);
2186 $context = context_course::instance($course->id);
2188 $viewfullnames = has_capability('moodle/site:viewfullnames', $context);
2190 $timestart = round(time() - COURSE_MAX_RECENT_PERIOD, -2); // better db caching for guests - 100 seconds
2192 if (!isguestuser()) {
2193 if (!empty($USER->lastcourseaccess[$course->id])) {
2194 if ($USER->lastcourseaccess[$course->id] > $timestart) {
2195 $timestart = $USER->lastcourseaccess[$course->id];
2200 echo '<div class="activitydate">';
2201 echo get_string('activitysince', '', userdate($timestart));
2202 echo '</div>';
2203 echo '<div class="activityhead">';
2205 echo '<a href="'.$CFG->wwwroot.'/course/recent.php?id='.$course->id.'">'.get_string('recentactivityreport').'</a>';
2207 echo "</div>\n";
2209 $content = false;
2211 /// Firstly, have there been any new enrolments?
2213 $users = get_recent_enrolments($course->id, $timestart);
2215 //Accessibility: new users now appear in an <OL> list.
2216 if ($users) {
2217 echo '<div class="newusers">';
2218 echo $OUTPUT->heading(get_string("newusers").':', 3);
2219 $content = true;
2220 echo "<ol class=\"list\">\n";
2221 foreach ($users as $user) {
2222 $fullname = fullname($user, $viewfullnames);
2223 echo '<li class="name"><a href="'."$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a></li>\n";
2225 echo "</ol>\n</div>\n";
2228 /// Next, have there been any modifications to the course structure?
2230 $modinfo = get_fast_modinfo($course);
2232 $changelist = array();
2234 $logs = $DB->get_records_select('log', "time > ? AND course = ? AND
2235 module = 'course' AND
2236 (action = 'add mod' OR action = 'update mod' OR action = 'delete mod')",
2237 array($timestart, $course->id), "id ASC");
2239 if ($logs) {
2240 $actions = array('add mod', 'update mod', 'delete mod');
2241 $newgones = array(); // added and later deleted items
2242 foreach ($logs as $key => $log) {
2243 if (!in_array($log->action, $actions)) {
2244 continue;
2246 $info = explode(' ', $log->info);
2248 // note: in most cases I replaced hardcoding of label with use of
2249 // $cm->has_view() but it was not possible to do this here because
2250 // we don't necessarily have the $cm for it
2251 if ($info[0] == 'label') { // Labels are ignored in recent activity
2252 continue;
2255 if (count($info) != 2) {
2256 debugging("Incorrect log entry info: id = ".$log->id, DEBUG_DEVELOPER);
2257 continue;
2260 $modname = $info[0];
2261 $instanceid = $info[1];
2263 if ($log->action == 'delete mod') {
2264 // unfortunately we do not know if the mod was visible
2265 if (!array_key_exists($log->info, $newgones)) {
2266 $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $modname));
2267 $changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted);
2269 } else {
2270 if (!isset($modinfo->instances[$modname][$instanceid])) {
2271 if ($log->action == 'add mod') {
2272 // do not display added and later deleted activities
2273 $newgones[$log->info] = true;
2275 continue;
2277 $cm = $modinfo->instances[$modname][$instanceid];
2278 if (!$cm->uservisible) {
2279 continue;
2282 if ($log->action == 'add mod') {
2283 $stradded = get_string('added', 'moodle', get_string('modulename', $modname));
2284 $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>");
2286 } else if ($log->action == 'update mod' and empty($changelist[$log->info])) {
2287 $strupdated = get_string('updated', 'moodle', get_string('modulename', $modname));
2288 $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>");
2294 if (!empty($changelist)) {
2295 echo $OUTPUT->heading(get_string("courseupdates").':', 3);
2296 $content = true;
2297 foreach ($changelist as $changeinfo => $change) {
2298 echo '<p class="activity">'.$change['text'].'</p>';
2302 /// Now display new things from each module
2304 $usedmodules = array();
2305 foreach($modinfo->cms as $cm) {
2306 if (isset($usedmodules[$cm->modname])) {
2307 continue;
2309 if (!$cm->uservisible) {
2310 continue;
2312 $usedmodules[$cm->modname] = $cm->modname;
2315 foreach ($usedmodules as $modname) { // Each module gets it's own logs and prints them
2316 if (file_exists($CFG->dirroot.'/mod/'.$modname.'/lib.php')) {
2317 include_once($CFG->dirroot.'/mod/'.$modname.'/lib.php');
2318 $print_recent_activity = $modname.'_print_recent_activity';
2319 if (function_exists($print_recent_activity)) {
2320 // NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames!
2321 $content = $print_recent_activity($course, $viewfullnames, $timestart) || $content;
2323 } else {
2324 debugging("Missing lib.php in lib/{$modname} - please reinstall files or uninstall the module");
2328 if (! $content) {
2329 echo '<p class="message">'.get_string('nothingnew').'</p>';
2334 * Delete a course module and any associated data at the course level (events)
2335 * Until 1.5 this function simply marked a deleted flag ... now it
2336 * deletes it completely.
2338 * @deprecated since 2.5
2340 * @param int $id the course module id
2341 * @return boolean true on success, false on failure
2343 function delete_course_module($id) {
2344 debugging('Function delete_course_module() is deprecated. Please use course_delete_module() instead.', DEBUG_DEVELOPER);
2346 global $CFG, $DB;
2348 require_once($CFG->libdir.'/gradelib.php');
2349 require_once($CFG->dirroot.'/blog/lib.php');
2351 if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) {
2352 return true;
2354 $modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module));
2355 //delete events from calendar
2356 if ($events = $DB->get_records('event', array('instance'=>$cm->instance, 'modulename'=>$modulename))) {
2357 foreach($events as $event) {
2358 delete_event($event->id);
2361 //delete grade items, outcome items and grades attached to modules
2362 if ($grade_items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename,
2363 'iteminstance'=>$cm->instance, 'courseid'=>$cm->course))) {
2364 foreach ($grade_items as $grade_item) {
2365 $grade_item->delete('moddelete');
2368 // Delete completion and availability data; it is better to do this even if the
2369 // features are not turned on, in case they were turned on previously (these will be
2370 // very quick on an empty table)
2371 $DB->delete_records('course_modules_completion', array('coursemoduleid' => $cm->id));
2372 $DB->delete_records('course_modules_availability', array('coursemoduleid'=> $cm->id));
2373 $DB->delete_records('course_completion_criteria', array('moduleinstance' => $cm->id,
2374 'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY));
2376 delete_context(CONTEXT_MODULE, $cm->id);
2377 return $DB->delete_records('course_modules', array('id'=>$cm->id));
2381 * Prints the turn editing on/off button on course/index.php or course/category.php.
2383 * @deprecated since 2.5
2385 * @param integer $categoryid The id of the category we are showing, or 0 for system context.
2386 * @return string HTML of the editing button, or empty string, if this user is not allowed
2387 * to see it.
2389 function update_category_button($categoryid = 0) {
2390 global $CFG, $PAGE, $OUTPUT;
2391 debugging('Function update_category_button() is deprecated. Pages to view '.
2392 'and edit courses are now separate and no longer depend on editing mode.',
2393 DEBUG_DEVELOPER);
2395 // Check permissions.
2396 if (!can_edit_in_category($categoryid)) {
2397 return '';
2400 // Work out the appropriate action.
2401 if ($PAGE->user_is_editing()) {
2402 $label = get_string('turneditingoff');
2403 $edit = 'off';
2404 } else {
2405 $label = get_string('turneditingon');
2406 $edit = 'on';
2409 // Generate the button HTML.
2410 $options = array('categoryedit' => $edit, 'sesskey' => sesskey());
2411 if ($categoryid) {
2412 $options['id'] = $categoryid;
2413 $page = 'category.php';
2414 } else {
2415 $page = 'index.php';
2417 return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get');
2421 * This function recursively travels the categories, building up a nice list
2422 * for display. It also makes an array that list all the parents for each
2423 * category.
2425 * For example, if you have a tree of categories like:
2426 * Miscellaneous (id = 1)
2427 * Subcategory (id = 2)
2428 * Sub-subcategory (id = 4)
2429 * Other category (id = 3)
2430 * Then after calling this function you will have
2431 * $list = array(1 => 'Miscellaneous', 2 => 'Miscellaneous / Subcategory',
2432 * 4 => 'Miscellaneous / Subcategory / Sub-subcategory',
2433 * 3 => 'Other category');
2434 * $parents = array(2 => array(1), 4 => array(1, 2));
2436 * If you specify $requiredcapability, then only categories where the current
2437 * user has that capability will be added to $list, although all categories
2438 * will still be added to $parents, and if you only have $requiredcapability
2439 * in a child category, not the parent, then the child catgegory will still be
2440 * included.
2442 * If you specify the option $excluded, then that category, and all its children,
2443 * are omitted from the tree. This is useful when you are doing something like
2444 * moving categories, where you do not want to allow people to move a category
2445 * to be the child of itself.
2447 * This function is deprecated! For list of categories use
2448 * coursecat::make_all_categories($requiredcapability, $excludeid, $separator)
2449 * For parents of one particular category use
2450 * coursecat::get($id)->get_parents()
2452 * @deprecated since 2.5
2454 * @param array $list For output, accumulates an array categoryid => full category path name
2455 * @param array $parents For output, accumulates an array categoryid => list of parent category ids.
2456 * @param string/array $requiredcapability if given, only categories where the current
2457 * user has this capability will be added to $list. Can also be an array of capabilities,
2458 * in which case they are all required.
2459 * @param integer $excludeid Omit this category and its children from the lists built.
2460 * @param object $category Not used
2461 * @param string $path Not used
2463 function make_categories_list(&$list, &$parents, $requiredcapability = '',
2464 $excludeid = 0, $category = NULL, $path = "") {
2465 global $CFG, $DB;
2466 require_once($CFG->libdir.'/coursecatlib.php');
2468 debugging('Global function make_categories_list() is deprecated. Please use '.
2469 'coursecat::make_categories_list() and coursecat::get_parents()',
2470 DEBUG_DEVELOPER);
2472 // For categories list use just this one function:
2473 if (empty($list)) {
2474 $list = array();
2476 $list += coursecat::make_categories_list($requiredcapability, $excludeid);
2478 // Building the list of all parents of all categories in the system is highly undesirable and hardly ever needed.
2479 // Usually user needs only parents for one particular category, in which case should be used:
2480 // coursecat::get($categoryid)->get_parents()
2481 if (empty($parents)) {
2482 $parents = array();
2484 $all = $DB->get_records_sql('SELECT id, parent FROM {course_categories} ORDER BY sortorder');
2485 foreach ($all as $record) {
2486 if ($record->parent) {
2487 $parents[$record->id] = array_merge($parents[$record->parent], array($record->parent));
2488 } else {
2489 $parents[$record->id] = array();
2495 * Delete category, but move contents to another category.
2497 * This function is deprecated. Please use
2498 * coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2500 * @see coursecat::delete_move()
2501 * @deprecated since 2.5
2503 * @param object $category
2504 * @param int $newparentid category id
2505 * @return bool status
2507 function category_delete_move($category, $newparentid, $showfeedback=true) {
2508 global $CFG;
2509 require_once($CFG->libdir.'/coursecatlib.php');
2511 debugging('Function category_delete_move() is deprecated. Please use coursecat::delete_move() instead.');
2513 return coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2517 * Recursively delete category including all subcategories and courses.
2519 * This function is deprecated. Please use
2520 * coursecat::get($category->id)->delete_full($showfeedback);
2522 * @see coursecat::delete_full()
2523 * @deprecated since 2.5
2525 * @param stdClass $category
2526 * @param boolean $showfeedback display some notices
2527 * @return array return deleted courses
2529 function category_delete_full($category, $showfeedback=true) {
2530 global $CFG, $DB;
2531 require_once($CFG->libdir.'/coursecatlib.php');
2533 debugging('Function category_delete_full() is deprecated. Please use coursecat::delete_full() instead.');
2535 return coursecat::get($category->id)->delete_full($showfeedback);
2539 * Efficiently moves a category - NOTE that this can have
2540 * a huge impact access-control-wise...
2542 * This function is deprecated. Please use
2543 * $coursecat = coursecat::get($category->id);
2544 * if ($coursecat->can_change_parent($newparentcat->id)) {
2545 * $coursecat->change_parent($newparentcat->id);
2548 * Alternatively you can use
2549 * $coursecat->update(array('parent' => $newparentcat->id));
2551 * Function update() also updates field course_categories.timemodified
2553 * @see coursecat::change_parent()
2554 * @see coursecat::update()
2555 * @deprecated since 2.5
2557 * @param stdClass|coursecat $category
2558 * @param stdClass|coursecat $newparentcat
2560 function move_category($category, $newparentcat) {
2561 global $CFG;
2562 require_once($CFG->libdir.'/coursecatlib.php');
2564 debugging('Function move_category() is deprecated. Please use coursecat::change_parent() instead.');
2566 return coursecat::get($category->id)->change_parent($newparentcat->id);
2570 * Hide course category and child course and subcategories
2572 * This function is deprecated. Please use
2573 * coursecat::get($category->id)->hide();
2575 * @see coursecat::hide()
2576 * @deprecated since 2.5
2578 * @param stdClass $category
2579 * @return void
2581 function course_category_hide($category) {
2582 global $CFG;
2583 require_once($CFG->libdir.'/coursecatlib.php');
2585 debugging('Function course_category_hide() is deprecated. Please use coursecat::hide() instead.');
2587 coursecat::get($category->id)->hide();
2591 * Show course category and child course and subcategories
2593 * This function is deprecated. Please use
2594 * coursecat::get($category->id)->show();
2596 * @see coursecat::show()
2597 * @deprecated since 2.5
2599 * @param stdClass $category
2600 * @return void
2602 function course_category_show($category) {
2603 global $CFG;
2604 require_once($CFG->libdir.'/coursecatlib.php');
2606 debugging('Function course_category_show() is deprecated. Please use coursecat::show() instead.');
2608 coursecat::get($category->id)->show();
2612 * Return specified category, default if given does not exist
2614 * This function is deprecated.
2615 * To get the category with the specified it please use:
2616 * coursecat::get($catid, IGNORE_MISSING);
2617 * or
2618 * coursecat::get($catid, MUST_EXIST);
2620 * To get the first available category please use
2621 * coursecat::get_default();
2623 * class coursecat will also make sure that at least one category exists in DB
2625 * @deprecated since 2.5
2626 * @see coursecat::get()
2627 * @see coursecat::get_default()
2629 * @param int $catid course category id
2630 * @return object caregory
2632 function get_course_category($catid=0) {
2633 global $DB;
2635 debugging('Function get_course_category() is deprecated. Please use coursecat::get(), see phpdocs for more details');
2637 $category = false;
2639 if (!empty($catid)) {
2640 $category = $DB->get_record('course_categories', array('id'=>$catid));
2643 if (!$category) {
2644 // the first category is considered default for now
2645 if ($category = $DB->get_records('course_categories', null, 'sortorder', '*', 0, 1)) {
2646 $category = reset($category);
2648 } else {
2649 $cat = new stdClass();
2650 $cat->name = get_string('miscellaneous');
2651 $cat->depth = 1;
2652 $cat->sortorder = MAX_COURSES_IN_CATEGORY;
2653 $cat->timemodified = time();
2654 $catid = $DB->insert_record('course_categories', $cat);
2655 // make sure category context exists
2656 context_coursecat::instance($catid);
2657 mark_context_dirty('/'.SYSCONTEXTID);
2658 fix_course_sortorder(); // Required to build course_categories.depth and .path.
2659 $category = $DB->get_record('course_categories', array('id'=>$catid));
2663 return $category;
2667 * Create a new course category and marks the context as dirty
2669 * This function does not set the sortorder for the new category and
2670 * {@link fix_course_sortorder()} should be called after creating a new course
2671 * category
2673 * Please note that this function does not verify access control.
2675 * This function is deprecated. It is replaced with the method create() in class coursecat.
2676 * {@link coursecat::create()} also verifies the data, fixes sortorder and logs the action
2678 * @deprecated since 2.5
2680 * @param object $category All of the data required for an entry in the course_categories table
2681 * @return object new course category
2683 function create_course_category($category) {
2684 global $DB;
2686 debugging('Function create_course_category() is deprecated. Please use coursecat::create(), see phpdocs for more details', DEBUG_DEVELOPER);
2688 $category->timemodified = time();
2689 $category->id = $DB->insert_record('course_categories', $category);
2690 $category = $DB->get_record('course_categories', array('id' => $category->id));
2692 // We should mark the context as dirty
2693 $category->context = context_coursecat::instance($category->id);
2694 $category->context->mark_dirty();
2696 return $category;
2700 * Returns an array of category ids of all the subcategories for a given
2701 * category.
2703 * This function is deprecated.
2705 * To get visible children categories of the given category use:
2706 * coursecat::get($categoryid)->get_children();
2707 * This function will return the array or coursecat objects, on each of them
2708 * you can call get_children() again
2710 * @see coursecat::get()
2711 * @see coursecat::get_children()
2713 * @deprecated since 2.5
2715 * @global object
2716 * @param int $catid - The id of the category whose subcategories we want to find.
2717 * @return array of category ids.
2719 function get_all_subcategories($catid) {
2720 global $DB;
2722 debugging('Function get_all_subcategories() is deprecated. Please use appropriate methods() of coursecat class. See phpdocs for more details',
2723 DEBUG_DEVELOPER);
2725 $subcats = array();
2727 if ($categories = $DB->get_records('course_categories', array('parent' => $catid))) {
2728 foreach ($categories as $cat) {
2729 array_push($subcats, $cat->id);
2730 $subcats = array_merge($subcats, get_all_subcategories($cat->id));
2733 return $subcats;
2737 * Gets the child categories of a given courses category
2739 * This function is deprecated. Please use functions in class coursecat:
2740 * - coursecat::get($parentid)->has_children()
2741 * tells if the category has children (visible or not to the current user)
2743 * - coursecat::get($parentid)->get_children()
2744 * returns an array of coursecat objects, each of them represents a children category visible
2745 * to the current user (i.e. visible=1 or user has capability to view hidden categories)
2747 * - coursecat::get($parentid)->get_children_count()
2748 * returns number of children categories visible to the current user
2750 * - coursecat::count_all()
2751 * returns total count of all categories in the system (both visible and not)
2753 * - coursecat::get_default()
2754 * returns the first category (usually to be used if count_all() == 1)
2756 * @deprecated since 2.5
2758 * @param int $parentid the id of a course category.
2759 * @return array all the child course categories.
2761 function get_child_categories($parentid) {
2762 global $DB;
2763 debugging('Function get_child_categories() is deprecated. Use coursecat::get_children() or see phpdocs for more details.',
2764 DEBUG_DEVELOPER);
2766 $rv = array();
2767 $sql = context_helper::get_preload_record_columns_sql('ctx');
2768 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
2769 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
2770 array(CONTEXT_COURSECAT, $parentid));
2771 foreach ($records as $category) {
2772 context_helper::preload_from_record($category);
2773 if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) {
2774 continue;
2776 $rv[] = $category;
2778 return $rv;
2782 * Returns a sorted list of categories.
2784 * When asking for $parent='none' it will return all the categories, regardless
2785 * of depth. Wheen asking for a specific parent, the default is to return
2786 * a "shallow" resultset. Pass false to $shallow and it will return all
2787 * the child categories as well.
2789 * @deprecated since 2.5
2791 * This function is deprecated. Use appropriate functions from class coursecat.
2792 * Examples:
2794 * coursecat::get($categoryid)->get_children()
2795 * - returns all children of the specified category as instances of class
2796 * coursecat, which means on each of them method get_children() can be called again.
2797 * Only categories visible to the current user are returned.
2799 * coursecat::get(0)->get_children()
2800 * - returns all top-level categories visible to the current user.
2802 * Sort fields can be specified, see phpdocs to {@link coursecat::get_children()}
2804 * coursecat::make_categories_list()
2805 * - returns an array of all categories id/names in the system.
2806 * Also only returns categories visible to current user and can additionally be
2807 * filetered by capability, see phpdocs to {@link coursecat::make_categories_list()}
2809 * make_categories_options()
2810 * - Returns full course categories tree to be used in html_writer::select()
2812 * Also see functions {@link coursecat::get_children_count()}, {@link coursecat::count_all()},
2813 * {@link coursecat::get_default()}
2815 * The code of this deprecated function is left as it is because coursecat::get_children()
2816 * returns categories as instances of coursecat and not stdClass. Also there is no
2817 * substitute for retrieving the category with all it's subcategories. Plugin developers
2818 * may re-use the code/queries from this function in their plugins if really necessary.
2820 * @param string $parent The parent category if any
2821 * @param string $sort the sortorder
2822 * @param bool $shallow - set to false to get the children too
2823 * @return array of categories
2825 function get_categories($parent='none', $sort=NULL, $shallow=true) {
2826 global $DB;
2828 debugging('Function get_categories() is deprecated. Please use coursecat::get_children() or see phpdocs for other alternatives',
2829 DEBUG_DEVELOPER);
2831 if ($sort === NULL) {
2832 $sort = 'ORDER BY cc.sortorder ASC';
2833 } elseif ($sort ==='') {
2834 // leave it as empty
2835 } else {
2836 $sort = "ORDER BY $sort";
2839 list($ccselect, $ccjoin) = context_instance_preload_sql('cc.id', CONTEXT_COURSECAT, 'ctx');
2841 if ($parent === 'none') {
2842 $sql = "SELECT cc.* $ccselect
2843 FROM {course_categories} cc
2844 $ccjoin
2845 $sort";
2846 $params = array();
2848 } elseif ($shallow) {
2849 $sql = "SELECT cc.* $ccselect
2850 FROM {course_categories} cc
2851 $ccjoin
2852 WHERE cc.parent=?
2853 $sort";
2854 $params = array($parent);
2856 } else {
2857 $sql = "SELECT cc.* $ccselect
2858 FROM {course_categories} cc
2859 $ccjoin
2860 JOIN {course_categories} ccp
2861 ON ((cc.parent = ccp.id) OR (cc.path LIKE ".$DB->sql_concat('ccp.path',"'/%'")."))
2862 WHERE ccp.id=?
2863 $sort";
2864 $params = array($parent);
2866 $categories = array();
2868 $rs = $DB->get_recordset_sql($sql, $params);
2869 foreach($rs as $cat) {
2870 context_helper::preload_from_record($cat);
2871 $catcontext = context_coursecat::instance($cat->id);
2872 if ($cat->visible || has_capability('moodle/category:viewhiddencategories', $catcontext)) {
2873 $categories[$cat->id] = $cat;
2876 $rs->close();
2877 return $categories;
2881 * Displays a course search form
2883 * This function is deprecated, please use course renderer:
2884 * $renderer = $PAGE->get_renderer('core', 'course');
2885 * echo $renderer->course_search_form($value, $format);
2887 * @deprecated since 2.5
2889 * @param string $value default value to populate the search field
2890 * @param bool $return if true returns the value, if false - outputs
2891 * @param string $format display format - 'plain' (default), 'short' or 'navbar'
2892 * @return null|string
2894 function print_course_search($value="", $return=false, $format="plain") {
2895 global $PAGE;
2896 debugging('Function print_course_search() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2897 $renderer = $PAGE->get_renderer('core', 'course');
2898 if ($return) {
2899 return $renderer->course_search_form($value, $format);
2900 } else {
2901 echo $renderer->course_search_form($value, $format);
2906 * Prints custom user information on the home page
2908 * This function is deprecated, please use:
2909 * $renderer = $PAGE->get_renderer('core', 'course');
2910 * echo $renderer->frontpage_my_courses()
2912 * @deprecated since 2.5
2914 function print_my_moodle() {
2915 global $PAGE;
2916 debugging('Function print_my_moodle() is deprecated, please use course renderer function frontpage_my_courses()', DEBUG_DEVELOPER);
2918 $renderer = $PAGE->get_renderer('core', 'course');
2919 echo $renderer->frontpage_my_courses();
2923 * Prints information about one remote course
2925 * This function is deprecated, it is replaced with protected function
2926 * {@link core_course_renderer::frontpage_remote_course()}
2927 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
2929 * @deprecated since 2.5
2931 function print_remote_course($course, $width="100%") {
2932 global $CFG, $USER;
2933 debugging('Function print_remote_course() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2935 $linkcss = '';
2937 $url = "{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&amp;wantsurl=/course/view.php?id={$course->remoteid}";
2939 echo '<div class="coursebox remotecoursebox clearfix">';
2940 echo '<div class="info">';
2941 echo '<div class="name"><a title="'.get_string('entercourse').'"'.
2942 $linkcss.' href="'.$url.'">'
2943 . format_string($course->fullname) .'</a><br />'
2944 . format_string($course->hostname) . ' : '
2945 . format_string($course->cat_name) . ' : '
2946 . format_string($course->shortname). '</div>';
2947 echo '</div><div class="summary">';
2948 $options = new stdClass();
2949 $options->noclean = true;
2950 $options->para = false;
2951 $options->overflowdiv = true;
2952 echo format_text($course->summary, $course->summaryformat, $options);
2953 echo '</div>';
2954 echo '</div>';
2958 * Prints information about one remote host
2960 * This function is deprecated, it is replaced with protected function
2961 * {@link core_course_renderer::frontpage_remote_host()}
2962 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
2964 * @deprecated since 2.5
2966 function print_remote_host($host, $width="100%") {
2967 global $OUTPUT;
2968 debugging('Function print_remote_host() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2970 $linkcss = '';
2972 echo '<div class="coursebox clearfix">';
2973 echo '<div class="info">';
2974 echo '<div class="name">';
2975 echo '<img src="'.$OUTPUT->pix_url('i/mnethost') . '" class="icon" alt="'.get_string('course').'" />';
2976 echo '<a title="'.s($host['name']).'" href="'.s($host['url']).'">'
2977 . s($host['name']).'</a> - ';
2978 echo $host['count'] . ' ' . get_string('courses');
2979 echo '</div>';
2980 echo '</div>';
2981 echo '</div>';
2985 * Recursive function to print out all the categories in a nice format
2986 * with or without courses included
2988 * @deprecated since 2.5
2990 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
2992 function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) {
2993 global $PAGE;
2994 debugging('Function print_whole_category_list() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2996 $renderer = $PAGE->get_renderer('core', 'course');
2997 if ($showcourses && $category) {
2998 echo $renderer->course_category($category);
2999 } else if ($showcourses) {
3000 echo $renderer->frontpage_combo_list();
3001 } else {
3002 echo $renderer->frontpage_categories_list();
3007 * Prints the category information.
3009 * @deprecated since 2.5
3011 * This function was only used by {@link print_whole_category_list()} but now
3012 * all course category rendering is moved to core_course_renderer.
3014 * @param stdClass $category
3015 * @param int $depth The depth of the category.
3016 * @param bool $showcourses If set to true course information will also be printed.
3017 * @param array|null $courses An array of courses belonging to the category, or null if you don't have it yet.
3019 function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) {
3020 global $PAGE;
3021 debugging('Function print_category_info() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3023 $renderer = $PAGE->get_renderer('core', 'course');
3024 echo $renderer->course_category($category);
3028 * This function generates a structured array of courses and categories.
3030 * @deprecated since 2.5
3032 * This function is not used any more in moodle core and course renderer does not have render function for it.
3033 * Combo list on the front page is displayed as:
3034 * $renderer = $PAGE->get_renderer('core', 'course');
3035 * echo $renderer->frontpage_combo_list()
3037 * The new class {@link coursecat} stores the information about course category tree
3038 * To get children categories use:
3039 * coursecat::get($id)->get_children()
3040 * To get list of courses use:
3041 * coursecat::get($id)->get_courses()
3043 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3045 * @param int $id
3046 * @param int $depth
3048 function get_course_category_tree($id = 0, $depth = 0) {
3049 global $DB, $CFG;
3050 if (!$depth) {
3051 debugging('Function get_course_category_tree() is deprecated, please use course renderer or coursecat class, see function phpdocs for more info', DEBUG_DEVELOPER);
3054 $categories = array();
3055 $categoryids = array();
3056 $sql = context_helper::get_preload_record_columns_sql('ctx');
3057 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
3058 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
3059 array(CONTEXT_COURSECAT, $id));
3060 foreach ($records as $category) {
3061 context_helper::preload_from_record($category);
3062 if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) {
3063 continue;
3065 $categories[] = $category;
3066 $categoryids[$category->id] = $category;
3067 if (empty($CFG->maxcategorydepth) || $depth <= $CFG->maxcategorydepth) {
3068 list($category->categories, $subcategories) = get_course_category_tree($category->id, $depth+1);
3069 foreach ($subcategories as $subid=>$subcat) {
3070 $categoryids[$subid] = $subcat;
3072 $category->courses = array();
3076 if ($depth > 0) {
3077 // This is a recursive call so return the required array
3078 return array($categories, $categoryids);
3081 if (empty($categoryids)) {
3082 // No categories available (probably all hidden).
3083 return array();
3086 // The depth is 0 this function has just been called so we can finish it off
3088 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
3089 list($catsql, $catparams) = $DB->get_in_or_equal(array_keys($categoryids));
3090 $sql = "SELECT
3091 c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary,c.category
3092 $ccselect
3093 FROM {course} c
3094 $ccjoin
3095 WHERE c.category $catsql ORDER BY c.sortorder ASC";
3096 if ($courses = $DB->get_records_sql($sql, $catparams)) {
3097 // loop throught them
3098 foreach ($courses as $course) {
3099 if ($course->id == SITEID) {
3100 continue;
3102 context_helper::preload_from_record($course);
3103 if (!empty($course->visible) || has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
3104 $categoryids[$course->category]->courses[$course->id] = $course;
3108 return $categories;
3112 * Print courses in category. If category is 0 then all courses are printed.
3114 * @deprecated since 2.5
3116 * To print a generic list of courses use:
3117 * $renderer = $PAGE->get_renderer('core', 'course');
3118 * echo $renderer->courses_list($courses);
3120 * To print list of all courses:
3121 * $renderer = $PAGE->get_renderer('core', 'course');
3122 * echo $renderer->frontpage_available_courses();
3124 * To print list of courses inside category:
3125 * $renderer = $PAGE->get_renderer('core', 'course');
3126 * echo $renderer->course_category($category); // this will also print subcategories
3128 * @param int|stdClass $category category object or id.
3129 * @return bool true if courses found and printed, else false.
3131 function print_courses($category) {
3132 global $CFG, $OUTPUT, $PAGE;
3133 require_once($CFG->libdir. '/coursecatlib.php');
3134 debugging('Function print_courses() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3136 if (!is_object($category) && $category==0) {
3137 $courses = coursecat::get(0)->get_courses(array('recursive' => true, 'summary' => true, 'coursecontacts' => true));
3138 } else {
3139 $courses = coursecat::get($category->id)->get_courses(array('summary' => true, 'coursecontacts' => true));
3142 if ($courses) {
3143 $renderer = $PAGE->get_renderer('core', 'course');
3144 echo $renderer->courses_list($courses);
3145 } else {
3146 echo $OUTPUT->heading(get_string("nocoursesyet"));
3147 $context = context_system::instance();
3148 if (has_capability('moodle/course:create', $context)) {
3149 $options = array();
3150 if (!empty($category->id)) {
3151 $options['category'] = $category->id;
3152 } else {
3153 $options['category'] = $CFG->defaultrequestcategory;
3155 echo html_writer::start_tag('div', array('class'=>'addcoursebutton'));
3156 echo $OUTPUT->single_button(new moodle_url('/course/edit.php', $options), get_string("addnewcourse"));
3157 echo html_writer::end_tag('div');
3158 return false;
3161 return true;
3165 * Print a description of a course, suitable for browsing in a list.
3167 * @deprecated since 2.5
3169 * Please use course renderer to display a course information box.
3170 * $renderer = $PAGE->get_renderer('core', 'course');
3171 * echo $renderer->courses_list($courses); // will print list of courses
3172 * echo $renderer->course_info_box($course); // will print one course wrapped in div.generalbox
3174 * @param object $course the course object.
3175 * @param string $highlightterms Ignored in this deprecated function!
3177 function print_course($course, $highlightterms = '') {
3178 global $PAGE;
3180 debugging('Function print_course() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3181 $renderer = $PAGE->get_renderer('core', 'course');
3182 // Please note, correct would be to use $renderer->coursecat_coursebox() but this function is protected.
3183 // To print list of courses use $renderer->courses_list();
3184 echo $renderer->course_info_box($course);
3188 * Gets an array whose keys are category ids and whose values are arrays of courses in the corresponding category.
3190 * @deprecated since 2.5
3192 * This function is not used any more in moodle core and course renderer does not have render function for it.
3193 * Combo list on the front page is displayed as:
3194 * $renderer = $PAGE->get_renderer('core', 'course');
3195 * echo $renderer->frontpage_combo_list()
3197 * The new class {@link coursecat} stores the information about course category tree
3198 * To get children categories use:
3199 * coursecat::get($id)->get_children()
3200 * To get list of courses use:
3201 * coursecat::get($id)->get_courses()
3203 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3205 * @param int $categoryid
3206 * @return array
3208 function get_category_courses_array($categoryid = 0) {
3209 debugging('Function get_category_courses_array() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
3210 $tree = get_course_category_tree($categoryid);
3211 $flattened = array();
3212 foreach ($tree as $category) {
3213 get_category_courses_array_recursively($flattened, $category);
3215 return $flattened;
3219 * Recursive function to help flatten the course category tree.
3221 * @deprecated since 2.5
3223 * Was intended to be called from {@link get_category_courses_array()}
3225 * @param array &$flattened An array passed by reference in which to store courses for each category.
3226 * @param stdClass $category The category to get courses for.
3228 function get_category_courses_array_recursively(array &$flattened, $category) {
3229 debugging('Function get_category_courses_array_recursively() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
3230 $flattened[$category->id] = $category->courses;
3231 foreach ($category->categories as $childcategory) {
3232 get_category_courses_array_recursively($flattened, $childcategory);
3237 * Returns a URL based on the context of the current page.
3238 * This URL points to blog/index.php and includes filter parameters appropriate for the current page.
3240 * @param stdclass $context
3241 * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more.
3242 * @todo Remove this in 2.7
3243 * @return string
3245 function blog_get_context_url($context=null) {
3246 global $CFG;
3248 debugging('Function blog_get_context_url() is deprecated, getting params from context is not reliable for blogs.', DEBUG_DEVELOPER);
3249 $viewblogentriesurl = new moodle_url('/blog/index.php');
3251 if (empty($context)) {
3252 global $PAGE;
3253 $context = $PAGE->context;
3256 // Change contextlevel to SYSTEM if viewing the site course
3257 if ($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID) {
3258 $context = context_system::instance();
3261 $filterparam = '';
3262 $strlevel = '';
3264 switch ($context->contextlevel) {
3265 case CONTEXT_SYSTEM:
3266 case CONTEXT_BLOCK:
3267 case CONTEXT_COURSECAT:
3268 break;
3269 case CONTEXT_COURSE:
3270 $filterparam = 'courseid';
3271 $strlevel = get_string('course');
3272 break;
3273 case CONTEXT_MODULE:
3274 $filterparam = 'modid';
3275 $strlevel = $context->get_context_name();
3276 break;
3277 case CONTEXT_USER:
3278 $filterparam = 'userid';
3279 $strlevel = get_string('user');
3280 break;
3283 if (!empty($filterparam)) {
3284 $viewblogentriesurl->param($filterparam, $context->instanceid);
3287 return $viewblogentriesurl;
3291 * Retrieve course records with the course managers and other related records
3292 * that we need for print_course(). This allows print_courses() to do its job
3293 * in a constant number of DB queries, regardless of the number of courses,
3294 * role assignments, etc.
3296 * The returned array is indexed on c.id, and each course will have
3297 * - $course->managers - array containing RA objects that include a $user obj
3298 * with the minimal fields needed for fullname()
3300 * @deprecated since 2.5
3302 * To get list of all courses with course contacts ('managers') use
3303 * coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true));
3305 * To get list of courses inside particular category use
3306 * coursecat::get($id)->get_courses(array('coursecontacts' => true));
3308 * Additionally you can specify sort order, offset and maximum number of courses,
3309 * see {@link coursecat::get_courses()}
3311 * Please note that code of this function is not changed to use coursecat class because
3312 * coursecat::get_courses() returns result in slightly different format. Also note that
3313 * get_courses_wmanagers() DOES NOT check that users are enrolled in the course and
3314 * coursecat::get_courses() does.
3316 * @global object
3317 * @global object
3318 * @global object
3319 * @uses CONTEXT_COURSE
3320 * @uses CONTEXT_SYSTEM
3321 * @uses CONTEXT_COURSECAT
3322 * @uses SITEID
3323 * @param int|string $categoryid Either the categoryid for the courses or 'all'
3324 * @param string $sort A SQL sort field and direction
3325 * @param array $fields An array of additional fields to fetch
3326 * @return array
3328 function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) {
3330 * The plan is to
3332 * - Grab the courses JOINed w/context
3334 * - Grab the interesting course-manager RAs
3335 * JOINed with a base user obj and add them to each course
3337 * So as to do all the work in 2 DB queries. The RA+user JOIN
3338 * ends up being pretty expensive if it happens over _all_
3339 * courses on a large site. (Are we surprised!?)
3341 * So this should _never_ get called with 'all' on a large site.
3344 global $USER, $CFG, $DB;
3345 debugging('Function get_courses_wmanagers() is deprecated, please use coursecat::get_courses()', DEBUG_DEVELOPER);
3347 $params = array();
3348 $allcats = false; // bool flag
3349 if ($categoryid === 'all') {
3350 $categoryclause = '';
3351 $allcats = true;
3352 } elseif (is_numeric($categoryid)) {
3353 $categoryclause = "c.category = :catid";
3354 $params['catid'] = $categoryid;
3355 } else {
3356 debugging("Could not recognise categoryid = $categoryid");
3357 $categoryclause = '';
3360 $basefields = array('id', 'category', 'sortorder',
3361 'shortname', 'fullname', 'idnumber',
3362 'startdate', 'visible',
3363 'newsitems', 'groupmode', 'groupmodeforce');
3365 if (!is_null($fields) && is_string($fields)) {
3366 if (empty($fields)) {
3367 $fields = $basefields;
3368 } else {
3369 // turn the fields from a string to an array that
3370 // get_user_courses_bycap() will like...
3371 $fields = explode(',',$fields);
3372 $fields = array_map('trim', $fields);
3373 $fields = array_unique(array_merge($basefields, $fields));
3375 } elseif (is_array($fields)) {
3376 $fields = array_merge($basefields,$fields);
3378 $coursefields = 'c.' .join(',c.', $fields);
3380 if (empty($sort)) {
3381 $sortstatement = "";
3382 } else {
3383 $sortstatement = "ORDER BY $sort";
3386 $where = 'WHERE c.id != ' . SITEID;
3387 if ($categoryclause !== ''){
3388 $where = "$where AND $categoryclause";
3391 // pull out all courses matching the cat
3392 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
3393 $sql = "SELECT $coursefields $ccselect
3394 FROM {course} c
3395 $ccjoin
3396 $where
3397 $sortstatement";
3399 $catpaths = array();
3400 $catpath = NULL;
3401 if ($courses = $DB->get_records_sql($sql, $params)) {
3402 // loop on courses materialising
3403 // the context, and prepping data to fetch the
3404 // managers efficiently later...
3405 foreach ($courses as $k => $course) {
3406 context_helper::preload_from_record($course);
3407 $coursecontext = context_course::instance($course->id);
3408 $courses[$k] = $course;
3409 $courses[$k]->managers = array();
3410 if ($allcats === false) {
3411 // single cat, so take just the first one...
3412 if ($catpath === NULL) {
3413 $catpath = preg_replace(':/\d+$:', '', $coursecontext->path);
3415 } else {
3416 // chop off the contextid of the course itself
3417 // like dirname() does...
3418 $catpaths[] = preg_replace(':/\d+$:', '', $coursecontext->path);
3421 } else {
3422 return array(); // no courses!
3425 $CFG->coursecontact = trim($CFG->coursecontact);
3426 if (empty($CFG->coursecontact)) {
3427 return $courses;
3430 $managerroles = explode(',', $CFG->coursecontact);
3431 $catctxids = '';
3432 if (count($managerroles)) {
3433 if ($allcats === true) {
3434 $catpaths = array_unique($catpaths);
3435 $ctxids = array();
3436 foreach ($catpaths as $cpath) {
3437 $ctxids = array_merge($ctxids, explode('/',substr($cpath,1)));
3439 $ctxids = array_unique($ctxids);
3440 $catctxids = implode( ',' , $ctxids);
3441 unset($catpaths);
3442 unset($cpath);
3443 } else {
3444 // take the ctx path from the first course
3445 // as all categories will be the same...
3446 $catpath = substr($catpath,1);
3447 $catpath = preg_replace(':/\d+$:','',$catpath);
3448 $catctxids = str_replace('/',',',$catpath);
3450 if ($categoryclause !== '') {
3451 $categoryclause = "AND $categoryclause";
3454 * Note: Here we use a LEFT OUTER JOIN that can
3455 * "optionally" match to avoid passing a ton of context
3456 * ids in an IN() clause. Perhaps a subselect is faster.
3458 * In any case, this SQL is not-so-nice over large sets of
3459 * courses with no $categoryclause.
3462 $sql = "SELECT ctx.path, ctx.instanceid, ctx.contextlevel,
3463 r.id AS roleid, r.name AS rolename, r.shortname AS roleshortname,
3464 rn.name AS rolecoursealias, u.id AS userid, u.firstname, u.lastname
3465 FROM {role_assignments} ra
3466 JOIN {context} ctx ON ra.contextid = ctx.id
3467 JOIN {user} u ON ra.userid = u.id
3468 JOIN {role} r ON ra.roleid = r.id
3469 LEFT JOIN {role_names} rn ON (rn.contextid = ctx.id AND rn.roleid = r.id)
3470 LEFT OUTER JOIN {course} c
3471 ON (ctx.instanceid=c.id AND ctx.contextlevel=".CONTEXT_COURSE.")
3472 WHERE ( c.id IS NOT NULL";
3473 // under certain conditions, $catctxids is NULL
3474 if($catctxids == NULL){
3475 $sql .= ") ";
3476 }else{
3477 $sql .= " OR ra.contextid IN ($catctxids) )";
3480 $sql .= "AND ra.roleid IN ({$CFG->coursecontact})
3481 $categoryclause
3482 ORDER BY r.sortorder ASC, ctx.contextlevel ASC, ra.sortorder ASC";
3483 $rs = $DB->get_recordset_sql($sql, $params);
3485 // This loop is fairly stupid as it stands - might get better
3486 // results doing an initial pass clustering RAs by path.
3487 foreach($rs as $ra) {
3488 $user = new stdClass;
3489 $user->id = $ra->userid; unset($ra->userid);
3490 $user->firstname = $ra->firstname; unset($ra->firstname);
3491 $user->lastname = $ra->lastname; unset($ra->lastname);
3492 $ra->user = $user;
3493 if ($ra->contextlevel == CONTEXT_SYSTEM) {
3494 foreach ($courses as $k => $course) {
3495 $courses[$k]->managers[] = $ra;
3497 } else if ($ra->contextlevel == CONTEXT_COURSECAT) {
3498 if ($allcats === false) {
3499 // It always applies
3500 foreach ($courses as $k => $course) {
3501 $courses[$k]->managers[] = $ra;
3503 } else {
3504 foreach ($courses as $k => $course) {
3505 $coursecontext = context_course::instance($course->id);
3506 // Note that strpos() returns 0 as "matched at pos 0"
3507 if (strpos($coursecontext->path, $ra->path.'/') === 0) {
3508 // Only add it to subpaths
3509 $courses[$k]->managers[] = $ra;
3513 } else { // course-level
3514 if (!array_key_exists($ra->instanceid, $courses)) {
3515 //this course is not in a list, probably a frontpage course
3516 continue;
3518 $courses[$ra->instanceid]->managers[] = $ra;
3521 $rs->close();
3524 return $courses;
3528 * Converts a nested array tree into HTML ul:li [recursive]
3530 * @deprecated since 2.5
3532 * @param array $tree A tree array to convert
3533 * @param int $row Used in identifying the iteration level and in ul classes
3534 * @return string HTML structure
3536 function convert_tree_to_html($tree, $row=0) {
3537 debugging('Function convert_tree_to_html() is deprecated since Moodle 2.5. Consider using class tabtree and core_renderer::render_tabtree()', DEBUG_DEVELOPER);
3539 $str = "\n".'<ul class="tabrow'.$row.'">'."\n";
3541 $first = true;
3542 $count = count($tree);
3544 foreach ($tree as $tab) {
3545 $count--; // countdown to zero
3547 $liclass = '';
3549 if ($first && ($count == 0)) { // Just one in the row
3550 $liclass = 'first last';
3551 $first = false;
3552 } else if ($first) {
3553 $liclass = 'first';
3554 $first = false;
3555 } else if ($count == 0) {
3556 $liclass = 'last';
3559 if ((empty($tab->subtree)) && (!empty($tab->selected))) {
3560 $liclass .= (empty($liclass)) ? 'onerow' : ' onerow';
3563 if ($tab->inactive || $tab->active || $tab->selected) {
3564 if ($tab->selected) {
3565 $liclass .= (empty($liclass)) ? 'here selected' : ' here selected';
3566 } else if ($tab->active) {
3567 $liclass .= (empty($liclass)) ? 'here active' : ' here active';
3571 $str .= (!empty($liclass)) ? '<li class="'.$liclass.'">' : '<li>';
3573 if ($tab->inactive || $tab->active || ($tab->selected && !$tab->linkedwhenselected)) {
3574 // The a tag is used for styling
3575 $str .= '<a class="nolink"><span>'.$tab->text.'</span></a>';
3576 } else {
3577 $str .= '<a href="'.$tab->link.'" title="'.$tab->title.'"><span>'.$tab->text.'</span></a>';
3580 if (!empty($tab->subtree)) {
3581 $str .= convert_tree_to_html($tab->subtree, $row+1);
3582 } else if ($tab->selected) {
3583 $str .= '<div class="tabrow'.($row+1).' empty">&nbsp;</div>'."\n";
3586 $str .= ' </li>'."\n";
3588 $str .= '</ul>'."\n";
3590 return $str;
3594 * Convert nested tabrows to a nested array
3596 * @deprecated since 2.5
3598 * @param array $tabrows A [nested] array of tab row objects
3599 * @param string $selected The tabrow to select (by id)
3600 * @param array $inactive An array of tabrow id's to make inactive
3601 * @param array $activated An array of tabrow id's to make active
3602 * @return array The nested array
3604 function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) {
3606 debugging('Function convert_tabrows_to_tree() is deprecated since Moodle 2.5. Consider using class tabtree', DEBUG_DEVELOPER);
3608 // Work backwards through the rows (bottom to top) collecting the tree as we go.
3609 $tabrows = array_reverse($tabrows);
3611 $subtree = array();
3613 foreach ($tabrows as $row) {
3614 $tree = array();
3616 foreach ($row as $tab) {
3617 $tab->inactive = in_array((string)$tab->id, $inactive);
3618 $tab->active = in_array((string)$tab->id, $activated);
3619 $tab->selected = (string)$tab->id == $selected;
3621 if ($tab->active || $tab->selected) {
3622 if ($subtree) {
3623 $tab->subtree = $subtree;
3626 $tree[] = $tab;
3628 $subtree = $tree;
3631 return $subtree;
3635 * Can handle rotated text. Whether it is safe to use the trickery in textrotate.js.
3637 * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically
3638 * @return bool True for yes, false for no
3640 function can_use_rotated_text() {
3641 debugging('can_use_rotated_text() is deprecated since Moodle 2.5. JS feature detection is used automatically.', DEBUG_DEVELOPER);
3642 return true;
3646 * Get the context instance as an object. This function will create the
3647 * context instance if it does not exist yet.
3649 * @deprecated since 2.2, use context_course::instance() or other relevant class instead
3650 * @todo This will be deleted in Moodle 2.8, refer MDL-34472
3651 * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
3652 * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
3653 * for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
3654 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
3655 * MUST_EXIST means throw exception if no record or multiple records found
3656 * @return context The context object.
3658 function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
3660 debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER);
3662 $instances = (array)$instance;
3663 $contexts = array();
3665 $classname = context_helper::get_class_for_level($contextlevel);
3667 // we do not load multiple contexts any more, PAGE should be responsible for any preloading
3668 foreach ($instances as $inst) {
3669 $contexts[$inst] = $classname::instance($inst, $strictness);
3672 if (is_array($instance)) {
3673 return $contexts;
3674 } else {
3675 return $contexts[$instance];
3680 * Get a context instance as an object, from a given context id.
3682 * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more.
3683 * @todo MDL-34550 This will be deleted in Moodle 2.8
3684 * @see context::instance_by_id($id)
3685 * @param int $id context id
3686 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
3687 * MUST_EXIST means throw exception if no record or multiple records found
3688 * @return context|bool the context object or false if not found.
3690 function get_context_instance_by_id($id, $strictness = IGNORE_MISSING) {
3691 debugging('get_context_instance_by_id() is deprecated, please use context::instance_by_id($id) instead.', DEBUG_DEVELOPER);
3692 return context::instance_by_id($id, $strictness);
3696 * Returns system context or null if can not be created yet.
3698 * @see context_system::instance()
3699 * @deprecated since 2.2
3700 * @param bool $cache use caching
3701 * @return context system context (null if context table not created yet)
3703 function get_system_context($cache = true) {
3704 debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER);
3705 return context_system::instance(0, IGNORE_MISSING, $cache);
3709 * Recursive function which, given a context, find all parent context ids,
3710 * and return the array in reverse order, i.e. parent first, then grand
3711 * parent, etc.
3713 * @see context::get_parent_context_ids()
3714 * @deprecated since 2.2, use $context->get_parent_context_ids() instead
3715 * @param context $context
3716 * @param bool $includeself optional, defaults to false
3717 * @return array
3719 function get_parent_contexts(context $context, $includeself = false) {
3720 debugging('get_parent_contexts() is deprecated, please use $context->get_parent_context_ids() instead.', DEBUG_DEVELOPER);
3721 return $context->get_parent_context_ids($includeself);
3725 * Return the id of the parent of this context, or false if there is no parent (only happens if this
3726 * is the site context.)
3728 * @deprecated since Moodle 2.2
3729 * @see context::get_parent_context()
3730 * @param context $context
3731 * @return integer the id of the parent context.
3733 function get_parent_contextid(context $context) {
3734 debugging('get_parent_contextid() is deprecated, please use $context->get_parent_context() instead.', DEBUG_DEVELOPER);
3736 if ($parent = $context->get_parent_context()) {
3737 return $parent->id;
3738 } else {
3739 return false;
3744 * Recursive function which, given a context, find all its children contexts.
3746 * For course category contexts it will return immediate children only categories and courses.
3747 * It will NOT recurse into courses or child categories.
3748 * If you want to do that, call it on the returned courses/categories.
3750 * When called for a course context, it will return the modules and blocks
3751 * displayed in the course page.
3753 * If called on a user/course/module context it _will_ populate the cache with the appropriate
3754 * contexts ;-)
3756 * @see context::get_child_contexts()
3757 * @deprecated since 2.2
3758 * @param context $context
3759 * @return array Array of child records
3761 function get_child_contexts(context $context) {
3762 debugging('get_child_contexts() is deprecated, please use $context->get_child_contexts() instead.', DEBUG_DEVELOPER);
3763 return $context->get_child_contexts();
3767 * Precreates all contexts including all parents.
3769 * @see context_helper::create_instances()
3770 * @deprecated since 2.2
3771 * @param int $contextlevel empty means all
3772 * @param bool $buildpaths update paths and depths
3773 * @return void
3775 function create_contexts($contextlevel = null, $buildpaths = true) {
3776 debugging('create_contexts() is deprecated, please use context_helper::create_instances() instead.', DEBUG_DEVELOPER);
3777 context_helper::create_instances($contextlevel, $buildpaths);
3781 * Remove stale context records.
3783 * @see context_helper::cleanup_instances()
3784 * @deprecated since 2.2
3785 * @return bool
3787 function cleanup_contexts() {
3788 debugging('cleanup_contexts() is deprecated, please use context_helper::cleanup_instances() instead.', DEBUG_DEVELOPER);
3789 context_helper::cleanup_instances();
3790 return true;
3794 * Populate context.path and context.depth where missing.
3796 * @see context_helper::build_all_paths()
3797 * @deprecated since 2.2
3798 * @param bool $force force a complete rebuild of the path and depth fields, defaults to false
3799 * @return void
3801 function build_context_path($force = false) {
3802 debugging('build_context_path() is deprecated, please use context_helper::build_all_paths() instead.', DEBUG_DEVELOPER);
3803 context_helper::build_all_paths($force);
3807 * Rebuild all related context depth and path caches.
3809 * @see context::reset_paths()
3810 * @deprecated since 2.2
3811 * @param array $fixcontexts array of contexts, strongtyped
3812 * @return void
3814 function rebuild_contexts(array $fixcontexts) {
3815 debugging('rebuild_contexts() is deprecated, please use $context->reset_paths(true) instead.', DEBUG_DEVELOPER);
3816 foreach ($fixcontexts as $fixcontext) {
3817 $fixcontext->reset_paths(false);
3819 context_helper::build_all_paths(false);
3823 * Preloads all contexts relating to a course: course, modules. Block contexts
3824 * are no longer loaded here. The contexts for all the blocks on the current
3825 * page are now efficiently loaded by {@link block_manager::load_blocks()}.
3827 * @deprecated since Moodle 2.2
3828 * @see context_helper::preload_course()
3829 * @param int $courseid Course ID
3830 * @return void
3832 function preload_course_contexts($courseid) {
3833 debugging('preload_course_contexts() is deprecated, please use context_helper::preload_course() instead.', DEBUG_DEVELOPER);
3834 context_helper::preload_course($courseid);
3838 * Update the path field of the context and all dep. subcontexts that follow
3840 * Update the path field of the context and
3841 * all the dependent subcontexts that follow
3842 * the move.
3844 * The most important thing here is to be as
3845 * DB efficient as possible. This op can have a
3846 * massive impact in the DB.
3848 * @deprecated since Moodle 2.2
3849 * @see context::update_moved()
3850 * @param context $context context obj
3851 * @param context $newparent new parent obj
3852 * @return void
3854 function context_moved(context $context, context $newparent) {
3855 debugging('context_moved() is deprecated, please use context::update_moved() instead.', DEBUG_DEVELOPER);
3856 $context->update_moved($newparent);
3860 * Extracts the relevant capabilities given a contextid.
3861 * All case based, example an instance of forum context.
3862 * Will fetch all forum related capabilities, while course contexts
3863 * Will fetch all capabilities
3865 * capabilities
3866 * `name` varchar(150) NOT NULL,
3867 * `captype` varchar(50) NOT NULL,
3868 * `contextlevel` int(10) NOT NULL,
3869 * `component` varchar(100) NOT NULL,
3871 * @see context::get_capabilities()
3872 * @deprecated since 2.2
3873 * @param context $context
3874 * @return array
3876 function fetch_context_capabilities(context $context) {
3877 debugging('fetch_context_capabilities() is deprecated, please use $context->get_capabilities() instead.', DEBUG_DEVELOPER);
3878 return $context->get_capabilities();
3882 * Preloads context information from db record and strips the cached info.
3883 * The db request has to contain both the $join and $select from context_instance_preload_sql()
3885 * @deprecated since 2.2
3886 * @see context_helper::preload_from_record()
3887 * @param stdClass $rec
3888 * @return void (modifies $rec)
3890 function context_instance_preload(stdClass $rec) {
3891 debugging('context_instance_preload() is deprecated, please use context_helper::preload_from_record() instead.', DEBUG_DEVELOPER);
3892 context_helper::preload_from_record($rec);
3896 * Returns context level name
3898 * @deprecated since 2.2
3899 * @see context_helper::get_level_name()
3900 * @param integer $contextlevel $context->context level. One of the CONTEXT_... constants.
3901 * @return string the name for this type of context.
3903 function get_contextlevel_name($contextlevel) {
3904 debugging('get_contextlevel_name() is deprecated, please use context_helper::get_level_name() instead.', DEBUG_DEVELOPER);
3905 return context_helper::get_level_name($contextlevel);
3909 * Prints human readable context identifier.
3911 * @deprecated since 2.2
3912 * @see context::get_context_name()
3913 * @param context $context the context.
3914 * @param boolean $withprefix whether to prefix the name of the context with the
3915 * type of context, e.g. User, Course, Forum, etc.
3916 * @param boolean $short whether to user the short name of the thing. Only applies
3917 * to course contexts
3918 * @return string the human readable context name.
3920 function print_context_name(context $context, $withprefix = true, $short = false) {
3921 debugging('print_context_name() is deprecated, please use $context->get_context_name() instead.', DEBUG_DEVELOPER);
3922 return $context->get_context_name($withprefix, $short);
3926 * Mark a context as dirty (with timestamp) so as to force reloading of the context.
3928 * @deprecated since 2.2, use $context->mark_dirty() instead
3929 * @see context::mark_dirty()
3930 * @param string $path context path
3932 function mark_context_dirty($path) {
3933 global $CFG, $USER, $ACCESSLIB_PRIVATE;
3934 debugging('mark_context_dirty() is deprecated, please use $context->mark_dirty() instead.', DEBUG_DEVELOPER);
3936 if (during_initial_install()) {
3937 return;
3940 // only if it is a non-empty string
3941 if (is_string($path) && $path !== '') {
3942 set_cache_flag('accesslib/dirtycontexts', $path, 1, time()+$CFG->sessiontimeout);
3943 if (isset($ACCESSLIB_PRIVATE->dirtycontexts)) {
3944 $ACCESSLIB_PRIVATE->dirtycontexts[$path] = 1;
3945 } else {
3946 if (CLI_SCRIPT) {
3947 $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1);
3948 } else {
3949 if (isset($USER->access['time'])) {
3950 $ACCESSLIB_PRIVATE->dirtycontexts = get_cache_flags('accesslib/dirtycontexts', $USER->access['time']-2);
3951 } else {
3952 $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1);
3954 // flags not loaded yet, it will be done later in $context->reload_if_dirty()
3961 * Remove a context record and any dependent entries,
3962 * removes context from static context cache too
3964 * @deprecated since Moodle 2.2
3965 * @see context_helper::delete_instance() or context::delete_content()
3966 * @param int $contextlevel
3967 * @param int $instanceid
3968 * @param bool $deleterecord false means keep record for now
3969 * @return bool returns true or throws an exception
3971 function delete_context($contextlevel, $instanceid, $deleterecord = true) {
3972 if ($deleterecord) {
3973 debugging('delete_context() is deprecated, please use context_helper::delete_instance() instead.', DEBUG_DEVELOPER);
3974 context_helper::delete_instance($contextlevel, $instanceid);
3975 } else {
3976 debugging('delete_context() is deprecated, please use $context->delete_content() instead.', DEBUG_DEVELOPER);
3977 $classname = context_helper::get_class_for_level($contextlevel);
3978 if ($context = $classname::instance($instanceid, IGNORE_MISSING)) {
3979 $context->delete_content();
3983 return true;
3987 * Get a URL for a context, if there is a natural one. For example, for
3988 * CONTEXT_COURSE, this is the course page. For CONTEXT_USER it is the
3989 * user profile page.
3991 * @deprecated since 2.2
3992 * @see context::get_url()
3993 * @param context $context the context
3994 * @return moodle_url
3996 function get_context_url(context $context) {
3997 debugging('get_context_url() is deprecated, please use $context->get_url() instead.', DEBUG_DEVELOPER);
3998 return $context->get_url();
4002 * Is this context part of any course? if yes return course context,
4003 * if not return null or throw exception.
4005 * @deprecated since 2.2
4006 * @see context::get_course_context()
4007 * @param context $context
4008 * @return course_context context of the enclosing course, null if not found or exception
4010 function get_course_context(context $context) {
4011 debugging('get_course_context() is deprecated, please use $context->get_course_context(true) instead.', DEBUG_DEVELOPER);
4012 return $context->get_course_context(true);
4016 * Get an array of courses where cap requested is available
4017 * and user is enrolled, this can be relatively slow.
4019 * @deprecated since 2.2
4020 * @see enrol_get_users_courses()
4021 * @param int $userid A user id. By default (null) checks the permissions of the current user.
4022 * @param string $cap - name of the capability
4023 * @param array $accessdata_ignored
4024 * @param bool $doanything_ignored
4025 * @param string $sort - sorting fields - prefix each fieldname with "c."
4026 * @param array $fields - additional fields you are interested in...
4027 * @param int $limit_ignored
4028 * @return array $courses - ordered array of course objects - see notes above
4030 function get_user_courses_bycap($userid, $cap, $accessdata_ignored, $doanything_ignored, $sort = 'c.sortorder ASC', $fields = null, $limit_ignored = 0) {
4032 debugging('get_user_courses_bycap() is deprecated, please use enrol_get_users_courses() instead.', DEBUG_DEVELOPER);
4033 $courses = enrol_get_users_courses($userid, true, $fields, $sort);
4034 foreach ($courses as $id=>$course) {
4035 $context = context_course::instance($id);
4036 if (!has_capability($cap, $context, $userid)) {
4037 unset($courses[$id]);
4041 return $courses;
4045 * This is really slow!!! do not use above course context level
4047 * @deprecated since Moodle 2.2
4048 * @param int $roleid
4049 * @param context $context
4050 * @return array
4052 function get_role_context_caps($roleid, context $context) {
4053 global $DB;
4054 debugging('get_role_context_caps() is deprecated, it is really slow. Don\'t use it.', DEBUG_DEVELOPER);
4056 // This is really slow!!!! - do not use above course context level.
4057 $result = array();
4058 $result[$context->id] = array();
4060 // First emulate the parent context capabilities merging into context.
4061 $searchcontexts = array_reverse($context->get_parent_context_ids(true));
4062 foreach ($searchcontexts as $cid) {
4063 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
4064 foreach ($capabilities as $cap) {
4065 if (!array_key_exists($cap->capability, $result[$context->id])) {
4066 $result[$context->id][$cap->capability] = 0;
4068 $result[$context->id][$cap->capability] += $cap->permission;
4073 // Now go through the contexts below given context.
4074 $searchcontexts = array_keys($context->get_child_contexts());
4075 foreach ($searchcontexts as $cid) {
4076 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
4077 foreach ($capabilities as $cap) {
4078 if (!array_key_exists($cap->contextid, $result)) {
4079 $result[$cap->contextid] = array();
4081 $result[$cap->contextid][$cap->capability] = $cap->permission;
4086 return $result;
4090 * Returns current course id or false if outside of course based on context parameter.
4092 * @see context::get_course_context()
4093 * @deprecated since 2.2
4094 * @param context $context
4095 * @return int|bool related course id or false
4097 function get_courseid_from_context(context $context) {
4098 debugging('get_courseid_from_context() is deprecated, please use $context->get_course_context(false) instead.', DEBUG_DEVELOPER);
4099 if ($coursecontext = $context->get_course_context(false)) {
4100 return $coursecontext->instanceid;
4101 } else {
4102 return false;
4107 * Preloads context information together with instances.
4108 * Use context_instance_preload() to strip the context info from the record and cache the context instance.
4110 * If you are using this methid, you should have something like this:
4112 * list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
4114 * To prevent the use of this deprecated function, replace the line above with something similar to this:
4116 * $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
4118 * $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
4119 * ^ ^ ^ ^
4120 * $params = array('contextlevel' => CONTEXT_COURSE);
4122 * @see context_helper:;get_preload_record_columns_sql()
4123 * @deprecated since 2.2
4124 * @param string $joinon for example 'u.id'
4125 * @param string $contextlevel context level of instance in $joinon
4126 * @param string $tablealias context table alias
4127 * @return array with two values - select and join part
4129 function context_instance_preload_sql($joinon, $contextlevel, $tablealias) {
4130 debugging('context_instance_preload_sql() is deprecated, please use context_helper::get_preload_record_columns_sql() instead.', DEBUG_DEVELOPER);
4131 $select = ", " . context_helper::get_preload_record_columns_sql($tablealias);
4132 $join = "LEFT JOIN {context} $tablealias ON ($tablealias.instanceid = $joinon AND $tablealias.contextlevel = $contextlevel)";
4133 return array($select, $join);
4137 * Gets a string for sql calls, searching for stuff in this context or above.
4139 * @deprecated since 2.2
4140 * @see context::get_parent_context_ids()
4141 * @param context $context
4142 * @return string
4144 function get_related_contexts_string(context $context) {
4145 debugging('get_related_contexts_string() is deprecated, please use $context->get_parent_context_ids(true) instead.', DEBUG_DEVELOPER);
4146 if ($parents = $context->get_parent_context_ids()) {
4147 return (' IN ('.$context->id.','.implode(',', $parents).')');
4148 } else {
4149 return (' ='.$context->id);
4154 * Get a list of all the plugins of a given type that contain a particular file.
4156 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
4157 * @param string $file the name of file that must be present in the plugin.
4158 * (e.g. 'view.php', 'db/install.xml').
4159 * @param bool $include if true (default false), the file will be include_once-ed if found.
4160 * @return array with plugin name as keys (e.g. 'forum', 'courselist') and the path
4161 * to the file relative to dirroot as value (e.g. "$CFG->dirroot/mod/forum/view.php").
4162 * @deprecated since 2.6
4163 * @see core_component::get_plugin_list_with_file()
4165 function get_plugin_list_with_file($plugintype, $file, $include = false) {
4166 debugging('get_plugin_list_with_file() is deprecated, please use core_component::get_plugin_list_with_file() instead.',
4167 DEBUG_DEVELOPER);
4168 return core_component::get_plugin_list_with_file($plugintype, $file, $include);
4172 * Checks to see if is the browser operating system matches the specified brand.
4174 * Known brand: 'Windows','Linux','Macintosh','SGI','SunOS','HP-UX'
4176 * @deprecated since 2.6
4177 * @param string $brand The operating system identifier being tested
4178 * @return bool true if the given brand below to the detected operating system
4180 function check_browser_operating_system($brand) {
4181 debugging('check_browser_operating_system has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4182 return core_useragent::check_browser_operating_system($brand);
4186 * Checks to see if is a browser matches the specified
4187 * brand and is equal or better version.
4189 * @deprecated since 2.6
4190 * @param string $brand The browser identifier being tested
4191 * @param int $version The version of the browser, if not specified any version (except 5.5 for IE for BC reasons)
4192 * @return bool true if the given version is below that of the detected browser
4194 function check_browser_version($brand, $version = null) {
4195 debugging('check_browser_version has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4196 return core_useragent::check_browser_version($brand, $version);
4200 * Returns whether a device/browser combination is mobile, tablet, legacy, default or the result of
4201 * an optional admin specified regular expression. If enabledevicedetection is set to no or not set
4202 * it returns default
4204 * @deprecated since 2.6
4205 * @return string device type
4207 function get_device_type() {
4208 debugging('get_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4209 return core_useragent::get_device_type();
4213 * Returns a list of the device types supporting by Moodle
4215 * @deprecated since 2.6
4216 * @param boolean $incusertypes includes types specified using the devicedetectregex admin setting
4217 * @return array $types
4219 function get_device_type_list($incusertypes = true) {
4220 debugging('get_device_type_list has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4221 return core_useragent::get_device_type_list($incusertypes);
4225 * Returns the theme selected for a particular device or false if none selected.
4227 * @deprecated since 2.6
4228 * @param string $devicetype
4229 * @return string|false The name of the theme to use for the device or the false if not set
4231 function get_selected_theme_for_device_type($devicetype = null) {
4232 debugging('get_selected_theme_for_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4233 return core_useragent::get_device_type_theme($devicetype);
4237 * Returns the name of the device type theme var in $CFG because there is not a convention to allow backwards compatibility.
4239 * @deprecated since 2.6
4240 * @param string $devicetype
4241 * @return string The config variable to use to determine the theme
4243 function get_device_cfg_var_name($devicetype = null) {
4244 debugging('get_device_cfg_var_name has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4245 return core_useragent::get_device_type_cfg_var_name($devicetype);
4249 * Allows the user to switch the device they are seeing the theme for.
4250 * This allows mobile users to switch back to the default theme, or theme for any other device.
4252 * @deprecated since 2.6
4253 * @param string $newdevice The device the user is currently using.
4254 * @return string The device the user has switched to
4256 function set_user_device_type($newdevice) {
4257 debugging('set_user_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4258 return core_useragent::set_user_device_type($newdevice);
4262 * Returns the device the user is currently using, or if the user has chosen to switch devices
4263 * for the current device type the type they have switched to.
4265 * @deprecated since 2.6
4266 * @return string The device the user is currently using or wishes to use
4268 function get_user_device_type() {
4269 debugging('get_user_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4270 return core_useragent::get_user_device_type();
4274 * Returns one or several CSS class names that match the user's browser. These can be put
4275 * in the body tag of the page to apply browser-specific rules without relying on CSS hacks
4277 * @deprecated since 2.6
4278 * @return array An array of browser version classes
4280 function get_browser_version_classes() {
4281 debugging('get_browser_version_classes has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4282 return core_useragent::get_browser_version_classes();
4286 * Generate a fake user for emails based on support settings
4288 * @deprecated since Moodle 2.6
4289 * @see core_user::get_support_user()
4290 * @return stdClass user info
4292 function generate_email_supportuser() {
4293 debugging('generate_email_supportuser is deprecated, please use core_user::get_support_user');
4294 return core_user::get_support_user();
4298 * Get issued badge details for assertion URL
4300 * @deprecated since Moodle 2.6
4301 * @param string $hash Unique hash of a badge
4302 * @return array Information about issued badge.
4304 function badges_get_issued_badge_info($hash) {
4305 debugging('Function badges_get_issued_badge_info() is deprecated. Please use core_badges_assertion class and methods to generate badge assertion.', DEBUG_DEVELOPER);
4306 $assertion = new core_badges_assertion($hash);
4307 return $assertion->get_badge_assertion();
4311 * Does the user want and can edit using rich text html editor?
4312 * This function does not make sense anymore because a user can directly choose their preferred editor.
4314 * @deprecated since 2.6
4315 * @return bool
4317 function can_use_html_editor() {
4318 debugging('can_use_html_editor has been deprecated please update your code to assume it returns true.', DEBUG_DEVELOPER);
4319 return true;
4323 * Returns whether ajax is enabled/allowed or not.
4324 * This function is deprecated and always returns true.
4326 * @param array $unused - not used any more.
4327 * @return bool
4328 * @deprecated since 2.7 MDL-33099 - please do not use this function any more.
4329 * @todo MDL-44088 This will be removed in Moodle 2.9.
4331 function ajaxenabled(array $browsers = null) {
4332 debugging('ajaxenabled() is deprecated - please update your code to assume it returns true.', DEBUG_DEVELOPER);
4333 return true;