3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * deprecatedlib.php - Old functions retained only for backward compatibility
21 * Old functions retained only for backward compatibility. New code should not
22 * use any of these functions.
25 * @subpackage deprecated
26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31 defined('MOODLE_INTERNAL') ||
die();
34 * Factory method that was returning moodle_session object.
36 * @deprecated since 2.6
37 * @return \core\session\manager
39 function session_get_instance() {
40 // Note: the new session manager includes all methods from the original session class.
41 static $deprecatedinstance = null;
43 debugging('session_get_instance() is deprecated, use \core\session\manager instead', DEBUG_DEVELOPER
);
45 if (!$deprecatedinstance) {
46 $deprecatedinstance = new \core\session\
manager();
49 return $deprecatedinstance;
53 * Returns true if legacy session used.
55 * @deprecated since 2.6
58 function session_is_legacy() {
59 debugging('session_is_legacy() is deprecated, do not use any more', DEBUG_DEVELOPER
);
64 * Terminates all sessions, auth hooks are not executed.
65 * Useful in upgrade scripts.
67 * @deprecated since 2.6
69 function session_kill_all() {
70 debugging('session_kill_all() is deprecated, use \core\session\manager::kill_all_sessions() instead', DEBUG_DEVELOPER
);
71 \core\session\manager
::kill_all_sessions();
75 * Mark session as accessed, prevents timeouts.
77 * @deprecated since 2.6
80 function session_touch($sid) {
81 debugging('session_touch() is deprecated, use \core\session\manager::touch_session() instead', DEBUG_DEVELOPER
);
82 \core\session\manager
::touch_session($sid);
86 * Terminates one sessions, auth hooks are not executed.
88 * @deprecated since 2.6
89 * @param string $sid session id
91 function session_kill($sid) {
92 debugging('session_kill() is deprecated, use \core\session\manager::kill_session() instead', DEBUG_DEVELOPER
);
93 \core\session\manager
::kill_session($sid);
97 * Terminates all sessions of one user, auth hooks are not executed.
98 * NOTE: This can not work for file based sessions!
100 * @deprecated since 2.6
101 * @param int $userid user id
103 function session_kill_user($userid) {
104 debugging('session_kill_user() is deprecated, use \core\session\manager::kill_user_sessions() instead', DEBUG_DEVELOPER
);
105 \core\session\manager
::kill_user_sessions($userid);
108 // PHP 5.6 includes session_gc(), we cannot define it any more.
109 if (!function_exists('session_gc')) {
111 * Session garbage collection
112 * - verify timeout for all users
113 * - kill sessions of all deleted users
114 * - kill sessions of users with disabled plugins or 'nologin' plugin
116 * @deprecated since 2.6
118 function session_gc()
120 debugging('session_gc() is deprecated, use \core\session\manager::gc() instead', DEBUG_DEVELOPER
);
121 \core\session\manager
::gc();
126 * Setup $USER object - called during login, loginas, etc.
128 * Call sync_user_enrolments() manually after log-in, or log-in-as.
130 * @deprecated since 2.6
131 * @param stdClass $user full user record object
134 function session_set_user($user) {
135 debugging('session_set_user() is deprecated, use \core\session\manager::set_user() instead', DEBUG_DEVELOPER
);
136 \core\session\manager
::set_user($user);
140 * Is current $USER logged-in-as somebody else?
141 * @deprecated since 2.6
144 function session_is_loggedinas() {
145 debugging('session_is_loggedinas() is deprecated, use \core\session\manager::is_loggedinas() instead', DEBUG_DEVELOPER
);
146 return \core\session\manager
::is_loggedinas();
150 * Returns the $USER object ignoring current login-as session
151 * @deprecated since 2.6
152 * @return stdClass user object
154 function session_get_realuser() {
155 debugging('session_get_realuser() is deprecated, use \core\session\manager::get_realuser() instead', DEBUG_DEVELOPER
);
156 return \core\session\manager
::get_realuser();
160 * Login as another user - no security checks here.
161 * @deprecated since 2.6
163 * @param stdClass $context
166 function session_loginas($userid, $context) {
167 debugging('session_loginas() is deprecated, use \core\session\manager::loginas() instead', DEBUG_DEVELOPER
);
168 \core\session\manager
::loginas($userid, $context);
172 * Minify JavaScript files.
174 * @deprecated since 2.6
176 * @param array $files
179 function js_minify($files) {
180 debugging('js_minify() is deprecated, use core_minify::js_files() or core_minify::js() instead.');
181 return core_minify
::js_files($files);
187 * @deprecated since 2.6
189 * @param array $files
192 function css_minify_css($files) {
193 debugging('css_minify_css() is deprecated, use core_minify::css_files() or core_minify::css() instead.');
194 return core_minify
::css_files($files);
198 * Function to call all event handlers when triggering an event
200 * @deprecated since 2.6
202 * @param string $eventname name of the event
203 * @param mixed $eventdata event data object
204 * @return int number of failed events
206 function events_trigger($eventname, $eventdata) {
207 // TODO: uncomment after conversion of all events in standard distribution
208 // debugging('events_trigger() is deprecated, please use new events instead', DEBUG_DEVELOPER);
209 return events_trigger_legacy($eventname, $eventdata);
213 * List all core subsystems and their location
215 * This is a whitelist of components that are part of the core and their
216 * language strings are defined in /lang/en/<<subsystem>>.php. If a given
217 * plugin is not listed here and it does not have proper plugintype prefix,
218 * then it is considered as course activity module.
220 * The location is optionally dirroot relative path. NULL means there is no special
221 * directory for this subsystem. If the location is set, the subsystem's
222 * renderer.php is expected to be there.
224 * @deprecated since 2.6, use core_component::get_core_subsystems()
226 * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons
227 * @return array of (string)name => (string|null)location
229 function get_core_subsystems($fullpaths = false) {
232 // NOTE: do not add any other debugging here, keep forever.
234 $subsystems = core_component
::get_core_subsystems();
240 debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER
);
242 $dlength = strlen($CFG->dirroot
);
244 foreach ($subsystems as $k => $v) {
248 $subsystems[$k] = substr($v, $dlength+
1);
255 * Lists all plugin types.
257 * @deprecated since 2.6, use core_component::get_plugin_types()
259 * @param bool $fullpaths false means relative paths from dirroot
260 * @return array Array of strings - name=>location
262 function get_plugin_types($fullpaths = true) {
265 // NOTE: do not add any other debugging here, keep forever.
267 $types = core_component
::get_plugin_types();
273 debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER
);
275 $dlength = strlen($CFG->dirroot
);
277 foreach ($types as $k => $v) {
278 if ($k === 'theme') {
279 $types[$k] = 'theme';
282 $types[$k] = substr($v, $dlength+
1);
289 * Use when listing real plugins of one type.
291 * @deprecated since 2.6, use core_component::get_plugin_list()
293 * @param string $plugintype type of plugin
294 * @return array name=>fulllocation pairs of plugins of given type
296 function get_plugin_list($plugintype) {
298 // NOTE: do not add any other debugging here, keep forever.
300 if ($plugintype === '') {
304 return core_component
::get_plugin_list($plugintype);
308 * Get a list of all the plugins of a given type that define a certain class
309 * in a certain file. The plugin component names and class names are returned.
311 * @deprecated since 2.6, use core_component::get_plugin_list_with_class()
313 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
314 * @param string $class the part of the name of the class after the
315 * frankenstyle prefix. e.g 'thing' if you are looking for classes with
316 * names like report_courselist_thing. If you are looking for classes with
317 * the same name as the plugin name (e.g. qtype_multichoice) then pass ''.
318 * @param string $file the name of file within the plugin that defines the class.
319 * @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum')
320 * and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice').
322 function get_plugin_list_with_class($plugintype, $class, $file) {
324 // NOTE: do not add any other debugging here, keep forever.
326 return core_component
::get_plugin_list_with_class($plugintype, $class, $file);
330 * Returns the exact absolute path to plugin directory.
332 * @deprecated since 2.6, use core_component::get_plugin_directory()
334 * @param string $plugintype type of plugin
335 * @param string $name name of the plugin
336 * @return string full path to plugin directory; NULL if not found
338 function get_plugin_directory($plugintype, $name) {
340 // NOTE: do not add any other debugging here, keep forever.
342 if ($plugintype === '') {
346 return core_component
::get_plugin_directory($plugintype, $name);
350 * Normalize the component name using the "frankenstyle" names.
352 * @deprecated since 2.6, use core_component::normalize_component()
354 * @param string $component
355 * @return array as (string)$type => (string)$plugin
357 function normalize_component($component) {
359 // NOTE: do not add any other debugging here, keep forever.
361 return core_component
::normalize_component($component);
365 * Return exact absolute path to a plugin directory.
367 * @deprecated since 2.6, use core_component::normalize_component()
369 * @param string $component name such as 'moodle', 'mod_forum'
370 * @return string full path to component directory; NULL if not found
372 function get_component_directory($component) {
374 // NOTE: do not add any other debugging here, keep forever.
376 return core_component
::get_component_directory($component);
380 // === Deprecated before 2.6.0 ===
383 * Hack to find out the GD version by parsing phpinfo output
385 * @return int GD version (1, 2, or 0)
387 function check_gd_version() {
388 // TODO: delete function in Moodle 2.7
389 debugging('check_gd_version() is deprecated, GD extension is always available now');
393 if (function_exists('gd_info')){
394 $gd_info = gd_info();
395 if (substr_count($gd_info['GD Version'], '2.')) {
397 } else if (substr_count($gd_info['GD Version'], '1.')) {
403 phpinfo(INFO_MODULES
);
404 $phpinfo = ob_get_contents();
407 $phpinfo = explode("\n", $phpinfo);
410 foreach ($phpinfo as $text) {
411 $parts = explode('</td>', $text);
412 foreach ($parts as $key => $val) {
413 $parts[$key] = trim(strip_tags($val));
415 if ($parts[0] == 'GD Version') {
416 if (substr_count($parts[1], '2.0')) {
419 $gdversion = intval($parts[1]);
424 return $gdversion; // 1, 2 or 0
428 * Not used any more, the account lockout handling is now
429 * part of authenticate_user_login().
432 function update_login_count() {
433 // TODO: delete function in Moodle 2.6
434 debugging('update_login_count() is deprecated, all calls need to be removed');
438 * Not used any more, replaced by proper account lockout.
441 function reset_login_count() {
442 // TODO: delete function in Moodle 2.6
443 debugging('reset_login_count() is deprecated, all calls need to be removed');
447 * Insert or update log display entry. Entry may already exist.
448 * $module, $action must be unique
451 * @param string $module
452 * @param string $action
453 * @param string $mtable
454 * @param string $field
458 function update_log_display_entry($module, $action, $mtable, $field) {
461 debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
465 * Given some text in HTML format, this function will pass it
466 * through any filters that have been configured for this context.
468 * @deprecated use the text formatting in a standard way instead (http://docs.moodle.org/dev/Output_functions)
469 * this was abused mostly for embedding of attachments
470 * @todo final deprecation of this function in MDL-40607
471 * @param string $text The text to be passed through format filters
472 * @param int $courseid The current course.
473 * @return string the filtered string.
475 function filter_text($text, $courseid = NULL) {
476 global $CFG, $COURSE;
478 debugging('filter_text() is deprecated, use format_text(), format_string() etc instead.', DEBUG_DEVELOPER
);
481 $courseid = $COURSE->id
;
484 if (!$context = context_course
::instance($courseid, IGNORE_MISSING
)) {
488 return filter_manager
::instance()->filter_text($text, $context);
492 * This function indicates that current page requires the https
493 * when $CFG->loginhttps enabled.
495 * By using this function properly, we can ensure 100% https-ized pages
496 * at our entire discretion (login, forgot_password, change_password)
497 * @deprecated use $PAGE->https_required() instead
498 * @todo final deprecation of this function in MDL-40607
500 function httpsrequired() {
502 debugging('httpsrequired() is deprecated use $PAGE->https_required() instead.', DEBUG_DEVELOPER
);
503 $PAGE->https_required();
507 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
509 * @deprecated use moodle_url factory methods instead
511 * @param string $path Physical path to a file
512 * @param array $options associative array of GET variables to append to the URL
513 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
514 * @return string URL to file
516 function get_file_url($path, $options=null, $type='coursefile') {
519 $path = str_replace('//', '/', $path);
520 $path = trim($path, '/'); // no leading and trailing slashes
525 $url = $CFG->wwwroot
."/question/exportfile.php";
528 $url = $CFG->wwwroot
."/rss/file.php";
530 case 'httpscoursefile':
531 $url = $CFG->httpswwwroot
."/file.php";
535 $url = $CFG->wwwroot
."/file.php";
538 if ($CFG->slasharguments
) {
539 $parts = explode('/', $path);
540 foreach ($parts as $key => $part) {
541 /// anchor dash character should not be encoded
542 $subparts = explode('#', $part);
543 $subparts = array_map('rawurlencode', $subparts);
544 $parts[$key] = implode('#', $subparts);
546 $path = implode('/', $parts);
547 $ffurl = $url.'/'.$path;
550 $path = rawurlencode('/'.$path);
551 $ffurl = $url.'?file='.$path;
552 $separator = '&';
556 foreach ($options as $name=>$value) {
557 $ffurl = $ffurl.$separator.$name.'='.$value;
558 $separator = '&';
566 * @deprecated use get_string("pluginname", "auth_[PLUINNAME]") instead.
567 * @todo remove completely in MDL-40517
569 function auth_get_plugin_title($authtype) {
570 throw new coding_exception('Function auth_get_plugin_title() is deprecated, please use standard get_string("pluginname", "auth_'.$authtype.'")!');
574 * @deprecated use indivividual enrol plugin settings instead
575 * @todo remove completely in MDL-40517
577 function get_default_course_role($course) {
578 throw new coding_exception('get_default_course_role() can not be used any more, please use enrol plugin settings instead!');
582 * @deprecated use get_string_manager()->get_list_of_translations() instead.
583 * @todo remove completely in MDL-40517
585 function get_list_of_languages($refreshcache=false, $returnall=false) {
586 throw new coding_exception('get_list_of_languages() can not be used any more, please use get_string_manager()->get_list_of_translations() instead.');
590 * @deprecated use get_string_manager()->get_list_of_currencies() instead.
591 * @todo remove completely in MDL-40517
593 function get_list_of_currencies() {
594 throw new coding_exception('get_list_of_currencies() can not be used any more, please use get_string_manager()->get_list_of_currencies() instead.');
598 * @deprecated use get_string_manager()->get_list_of_countries() instead.
599 * @todo remove completely in MDL-40517
601 function get_list_of_countries() {
602 throw new coding_exception('get_list_of_countries() can not be used any more, please use get_string_manager()->get_list_of_countries() instead.');
606 * Return all course participant for a given course
608 * @deprecated use get_enrolled_users($context) instead.
609 * @todo final deprecation of this function in MDL-40607
610 * @param integer $courseid
611 * @return array of user
613 function get_course_participants($courseid) {
614 debugging('get_course_participants() is deprecated, use get_enrolled_users() instead.', DEBUG_DEVELOPER
);
615 return get_enrolled_users(context_course
::instance($courseid));
619 * Return true if the user is a participant for a given course
621 * @deprecated use is_enrolled($context, $userid) instead.
622 * @todo final deprecation of this function in MDL-40607
623 * @param integer $userid
624 * @param integer $courseid
627 function is_course_participant($userid, $courseid) {
628 debugging('is_course_participant() is deprecated, use is_enrolled() instead.', DEBUG_DEVELOPER
);
629 return is_enrolled(context_course
::instance($courseid), $userid);
633 * Searches logs to find all enrolments since a certain date
635 * used to print recent activity
637 * @param int $courseid The course in question.
638 * @param int $timestart The date to check forward of
639 * @return object|false {@link $USER} records or false if error.
641 function get_recent_enrolments($courseid, $timestart) {
644 debugging('get_recent_enrolments() is deprecated as it returned inaccurate results.', DEBUG_DEVELOPER
);
646 $context = context_course
::instance($courseid);
647 $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
648 FROM {user} u, {role_assignments} ra, {log} l
651 AND l.module = 'course'
652 AND l.action = 'enrol'
653 AND ".$DB->sql_cast_char2int('l.info')." = u.id
655 AND ra.contextid ".get_related_contexts_string($context)."
656 GROUP BY u.id, u.firstname, u.lastname
657 ORDER BY MAX(l.time) ASC";
658 $params = array($timestart, $courseid);
659 return $DB->get_records_sql($sql, $params);
662 ########### FROM weblib.php ##########################################################################
665 * @deprecated use $OUTPUT->box() instead.
666 * @todo remove completely in MDL-40517
668 function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
669 throw new coding_exception('print_simple_box can not be used any more. Please use $OUTPUT->box() instead');
673 * @deprecated use $OUTPUT->box_start instead.
674 * @todo remove completely in MDL-40517
676 function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
677 throw new coding_exception('print_simple_box_start can not be used any more. Please use $OUTPUT->box_start instead');
681 * @deprecated use $OUTPUT->box_end instead.
682 * @todo remove completely in MDL-40517
684 function print_simple_box_end($return=false) {
685 throw new coding_exception('print_simple_box_end can not be used any more. Please use $OUTPUT->box_end instead');
689 * @deprecated the urltolink filter now does this job.
690 * @todo remove completely in MDL-40517
692 function convert_urls_into_links($text) {
693 throw new coding_exception('convert_urls_into_links() can not be used any more and replaced by the urltolink filter');
697 * @deprecated use the emoticon_manager class instead.
698 * @todo remove completely in MDL-40517
700 function get_emoticons_list_for_help_file() {
701 throw new coding_exception('get_emoticons_list_for_help_file() can not be used any more, use the new emoticon_manager API instead');
705 * @deprecated use emoticon filter now does this job.
706 * @todo remove completely in MDL-40517
708 function replace_smilies(&$text) {
709 throw new coding_exception('replace_smilies() can not be used any more and replaced with the emoticon filter.');
713 * @deprecated use clean_param($string, PARAM_FILE) instead.
714 * @todo final deprecation of this function in MDL-40607
716 * @param string $string ?
717 * @param int $allowdots ?
720 function detect_munged_arguments($string, $allowdots=1) {
721 debugging('detect_munged_arguments() is deprecated, please use clean_param(,PARAM_FILE) instead.', DEBUG_DEVELOPER
);
722 if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
725 if (preg_match('/[\|\`]/', $string)) { // check for other bad characters
728 if (empty($string) or $string == '/') {
737 * Unzip one zip file to a destination dir
738 * Both parameters must be FULL paths
739 * If destination isn't specified, it will be the
740 * SAME directory where the zip file resides.
743 * @param string $zipfile The zip file to unzip
744 * @param string $destination The location to unzip to
745 * @param bool $showstatus_ignored Unused
747 function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
750 //Extract everything from zipfile
751 $path_parts = pathinfo(cleardoubleslashes($zipfile));
752 $zippath = $path_parts["dirname"]; //The path of the zip file
753 $zipfilename = $path_parts["basename"]; //The name of the zip file
754 $extension = $path_parts["extension"]; //The extension of the file
757 if (empty($zipfilename)) {
761 //If no extension, error
762 if (empty($extension)) {
767 $zipfile = cleardoubleslashes($zipfile);
769 //Check zipfile exists
770 if (!file_exists($zipfile)) {
774 //If no destination, passed let's go with the same directory
775 if (empty($destination)) {
776 $destination = $zippath;
780 $destpath = rtrim(cleardoubleslashes($destination), "/");
782 //Check destination path exists
783 if (!is_dir($destpath)) {
787 $packer = get_file_packer('application/zip');
789 $result = $packer->extract_to_pathname($zipfile, $destpath);
791 if ($result === false) {
795 foreach ($result as $status) {
796 if ($status !== true) {
805 * Zip an array of files/dirs to a destination zip file
806 * Both parameters must be FULL paths to the files/dirs
809 * @param array $originalfiles Files to zip
810 * @param string $destination The destination path
811 * @return bool Outcome
813 function zip_files ($originalfiles, $destination) {
816 //Extract everything from destination
817 $path_parts = pathinfo(cleardoubleslashes($destination));
818 $destpath = $path_parts["dirname"]; //The path of the zip file
819 $destfilename = $path_parts["basename"]; //The name of the zip file
820 $extension = $path_parts["extension"]; //The extension of the file
823 if (empty($destfilename)) {
827 //If no extension, add it
828 if (empty($extension)) {
830 $destfilename = $destfilename.'.'.$extension;
833 //Check destination path exists
834 if (!is_dir($destpath)) {
838 //Check destination path is writable. TODO!!
840 //Clean destination filename
841 $destfilename = clean_filename($destfilename);
843 //Now check and prepare every file
847 foreach ($originalfiles as $file) { //Iterate over each file
848 //Check for every file
849 $tempfile = cleardoubleslashes($file); // no doubleslashes!
850 //Calculate the base path for all files if it isn't set
851 if ($origpath === NULL) {
852 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
854 //See if the file is readable
855 if (!is_readable($tempfile)) { //Is readable
858 //See if the file/dir is in the same directory than the rest
859 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
862 //Add the file to the array
863 $files[] = $tempfile;
867 $start = strlen($origpath)+
1;
868 foreach($files as $file) {
869 $zipfiles[substr($file, $start)] = $file;
872 $packer = get_file_packer('application/zip');
874 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
878 * Get the IDs for the user's groups in the given course.
881 * @param int $courseid The course being examined - the 'course' table id field.
882 * @return array|bool An _array_ of groupids, or false
883 * (Was return $groupids[0] - consequences!)
884 * @deprecated use groups_get_all_groups() instead.
885 * @todo final deprecation of this function in MDL-40607
887 function mygroupid($courseid) {
890 debugging('mygroupid() is deprecated, please use groups_get_all_groups() instead.', DEBUG_DEVELOPER
);
892 if ($groups = groups_get_all_groups($courseid, $USER->id
)) {
893 return array_keys($groups);
901 * Returns the current group mode for a given course or activity module
903 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
905 * @param object $course Course Object
906 * @param object $cm Course Manager Object
907 * @return mixed $course->groupmode
909 function groupmode($course, $cm=null) {
911 if (isset($cm->groupmode
) && empty($course->groupmodeforce
)) {
912 return $cm->groupmode
;
914 return $course->groupmode
;
918 * Sets the current group in the session variable
919 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
920 * Sets currentgroup[$courseid] in the session variable appropriately.
921 * Does not do any permission checking.
924 * @param int $courseid The course being examined - relates to id field in
926 * @param int $groupid The group being examined.
927 * @return int Current group id which was set by this function
929 function set_current_group($courseid, $groupid) {
931 return $SESSION->currentgroup
[$courseid] = $groupid;
936 * Gets the current group - either from the session variable or from the database.
939 * @param int $courseid The course being examined - relates to id field in
941 * @param bool $full If true, the return value is a full record object.
942 * If false, just the id of the record.
945 function get_current_group($courseid, $full = false) {
948 if (isset($SESSION->currentgroup
[$courseid])) {
950 return groups_get_group($SESSION->currentgroup
[$courseid]);
952 return $SESSION->currentgroup
[$courseid];
956 $mygroupid = mygroupid($courseid);
957 if (is_array($mygroupid)) {
958 $mygroupid = array_shift($mygroupid);
959 set_current_group($courseid, $mygroupid);
961 return groups_get_group($mygroupid);
976 * Inndicates fatal error. This function was originally printing the
977 * error message directly, since 2.0 it is throwing exception instead.
978 * The error printing is handled in default exception handler.
980 * Old method, don't call directly in new code - use print_error instead.
982 * @param string $message The message to display to the user about the error.
983 * @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.
984 * @return void, always throws moodle_exception
986 function error($message, $link='') {
987 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
992 * @deprecated use $PAGE->requires->js_module() instead.
994 function require_js($lib) {
995 throw new coding_exception('require_js() was removed, use new JS api');
999 * @deprecated use $PAGE->theme->name instead.
1000 * @todo final deprecation of this function in MDL-40607
1001 * @return string the name of the current theme.
1003 function current_theme() {
1006 debugging('current_theme() is deprecated, please use $PAGE->theme->name instead', DEBUG_DEVELOPER
);
1007 return $PAGE->theme
->name
;
1011 * Prints some red text using echo
1014 * @param string $error The text to be displayed in red
1016 function formerr($error) {
1017 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
1019 echo $OUTPUT->error_text($error);
1023 * Return the markup for the destination of the 'Skip to main content' links.
1024 * Accessibility improvement for keyboard-only users.
1026 * Used in course formats, /index.php and /course/index.php
1028 * @deprecated use $OUTPUT->skip_link_target() in instead.
1029 * @todo final deprecation of this function in MDL-40607
1030 * @return string HTML element.
1032 function skip_main_destination() {
1035 debugging('skip_main_destination() is deprecated, please use $OUTPUT->skip_link_target() instead.', DEBUG_DEVELOPER
);
1036 return $OUTPUT->skip_link_target();
1040 * @deprecated use $OUTPUT->heading() instead.
1041 * @todo remove completely in MDL-40517
1043 function print_headline($text, $size=2, $return=false) {
1044 throw new coding_exception('print_headline() can not be used any more. Please use $OUTPUT->heading() instead.');
1048 * @deprecated use $OUTPUT->heading() instead.
1049 * @todo remove completely in MDL-40517
1051 function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
1052 throw new coding_exception('print_heading() can not be used any more. Please use $OUTPUT->heading() instead.');
1056 * @deprecated use $OUTPUT->heading() instead.
1057 * @todo remove completely in MDL-40517
1059 function print_heading_block($heading, $class='', $return=false) {
1060 throw new coding_exception('print_heading_with_block() can not be used any more. Please use $OUTPUT->heading() instead.');
1064 * @deprecated use $OUTPUT->box() instead.
1065 * @todo remove completely in MDL-40517
1067 function print_box($message, $classes='generalbox', $ids='', $return=false) {
1068 throw new coding_exception('print_box() can not be used any more. Please use $OUTPUT->box() instead.');
1072 * @deprecated use $OUTPUT->box_start() instead.
1073 * @todo remove completely in MDL-40517
1075 function print_box_start($classes='generalbox', $ids='', $return=false) {
1076 throw new coding_exception('print_box_start() can not be used any more. Please use $OUTPUT->box_start() instead.');
1080 * @deprecated use $OUTPUT->box_end() instead.
1081 * @todo remove completely in MDL-40517
1083 function print_box_end($return=false) {
1084 throw new coding_exception('print_box_end() can not be used any more. Please use $OUTPUT->box_end() instead.');
1088 * Print a message in a standard themed container.
1090 * @deprecated use $OUTPUT->container() instead.
1091 * @todo final deprecation of this function in MDL-40607
1092 * @param string $message, the content of the container
1093 * @param boolean $clearfix clear both sides
1094 * @param string $classes, space-separated class names.
1095 * @param string $idbase
1096 * @param boolean $return, return as string or just print it
1097 * @return string|void Depending on value of $return
1099 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
1102 debugging('print_container() is deprecated. Please use $OUTPUT->container() instead.', DEBUG_DEVELOPER
);
1104 $classes .= ' clearfix';
1106 $output = $OUTPUT->container($message, $classes, $idbase);
1115 * Starts a container using divs
1117 * @deprecated use $OUTPUT->container_start() instead.
1118 * @todo final deprecation of this function in MDL-40607
1119 * @param boolean $clearfix clear both sides
1120 * @param string $classes, space-separated class names.
1121 * @param string $idbase
1122 * @param boolean $return, return as string or just print it
1123 * @return string|void Based on value of $return
1125 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
1128 debugging('print_container_start() is deprecated. Please use $OUTPUT->container_start() instead.', DEBUG_DEVELOPER
);
1131 $classes .= ' clearfix';
1133 $output = $OUTPUT->container_start($classes, $idbase);
1142 * @deprecated do not use any more, is not automatic
1143 * @todo remove completely in MDL-40517
1145 function check_theme_arrows() {
1146 throw new coding_exception('check_theme_arrows() has been deprecated, do not use it anymore, it is now automatic.');
1150 * Simple function to end a container (see above)
1152 * @deprecated use $OUTPUT->container_end() instead.
1153 * @todo final deprecation of this function in MDL-40607
1154 * @param boolean $return, return as string or just print it
1155 * @return string|void Based on $return
1157 function print_container_end($return=false) {
1159 debugging('print_container_end() is deprecated. Please use $OUTPUT->container_end() instead.', DEBUG_DEVELOPER
);
1160 $output = $OUTPUT->container_end();
1169 * Print a bold message in an optional color.
1171 * @deprecated use $OUTPUT->notification instead.
1172 * @param string $message The message to print out
1173 * @param string $style Optional style to display message text in
1174 * @param string $align Alignment option
1175 * @param bool $return whether to return an output string or echo now
1176 * @return string|bool Depending on $result
1178 function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
1181 if ($classes == 'green') {
1182 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER
);
1183 $classes = 'notifysuccess'; // Backward compatible with old color system
1186 $output = $OUTPUT->notification($message, $classes);
1195 * Print a continue button that goes to a particular URL.
1197 * @deprecated use $OUTPUT->continue_button() instead.
1198 * @todo final deprecation of this function in MDL-40607
1200 * @param string $link The url to create a link to.
1201 * @param bool $return If set to true output is returned rather than echoed, default false
1202 * @return string|void HTML String if return=true nothing otherwise
1204 function print_continue($link, $return = false) {
1205 global $CFG, $OUTPUT;
1207 debugging('print_continue() is deprecated. Please use $OUTPUT->continue_button() instead.', DEBUG_DEVELOPER
);
1210 if (!empty($_SERVER['HTTP_REFERER'])) {
1211 $link = $_SERVER['HTTP_REFERER'];
1212 $link = str_replace('&', '&', $link); // make it valid XHTML
1214 $link = $CFG->wwwroot
.'/';
1218 $output = $OUTPUT->continue_button($link);
1227 * Print a standard header
1229 * @deprecated use $PAGE methods instead.
1230 * @todo final deprecation of this function in MDL-40607
1231 * @param string $title Appears at the top of the window
1232 * @param string $heading Appears at the top of the page
1233 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
1234 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1235 * @param string $meta Meta tags to be added to the header
1236 * @param boolean $cache Should this page be cacheable?
1237 * @param string $button HTML code for a button (usually for module editing)
1238 * @param string $menu HTML code for a popup menu
1239 * @param boolean $usexml use XML for this page
1240 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1241 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1242 * @return string|void If return=true then string else void
1244 function print_header($title='', $heading='', $navigation='', $focus='',
1245 $meta='', $cache=true, $button=' ', $menu=null,
1246 $usexml=false, $bodytags='', $return=false) {
1247 global $PAGE, $OUTPUT;
1249 debugging('print_header() is deprecated. Please use $PAGE methods instead.', DEBUG_DEVELOPER
);
1251 $PAGE->set_title($title);
1252 $PAGE->set_heading($heading);
1253 $PAGE->set_cacheable($cache);
1254 if ($button == '') {
1257 $PAGE->set_button($button);
1258 $PAGE->set_headingmenu($menu);
1263 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1264 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1267 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1270 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1273 $output = $OUTPUT->header();
1283 * This version of print_header is simpler because the course name does not have to be
1284 * provided explicitly in the strings. It can be used on the site page as in courses
1285 * Eventually all print_header could be replaced by print_header_simple
1287 * @deprecated use $PAGE methods instead.
1288 * @todo final deprecation of this function in MDL-40607
1289 * @param string $title Appears at the top of the window
1290 * @param string $heading Appears at the top of the page
1291 * @param string $navigation Premade navigation string (for use as breadcrumbs links)
1292 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1293 * @param string $meta Meta tags to be added to the header
1294 * @param boolean $cache Should this page be cacheable?
1295 * @param string $button HTML code for a button (usually for module editing)
1296 * @param string $menu HTML code for a popup menu
1297 * @param boolean $usexml use XML for this page
1298 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1299 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1300 * @return string|void If $return=true the return string else nothing
1302 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
1303 $cache=true, $button=' ', $menu='', $usexml=false, $bodytags='', $return=false) {
1305 global $COURSE, $CFG, $PAGE, $OUTPUT;
1307 debugging('print_header_simple() is deprecated. Please use $PAGE methods instead.', DEBUG_DEVELOPER
);
1310 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1311 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1314 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1317 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1320 $PAGE->set_title($title);
1321 $PAGE->set_heading($heading);
1322 $PAGE->set_cacheable(true);
1323 $PAGE->set_button($button);
1325 $output = $OUTPUT->header();
1335 * @deprecated use $OUTPUT->footer() instead.
1336 * @todo remove completely in MDL-40517
1338 function print_footer($course = NULL, $usercourse = NULL, $return = false) {
1339 throw new coding_exception('print_footer() cant be used anymore. Please use $OUTPUT->footer() instead.');
1343 * @deprecated use theme layouts instead.
1344 * @todo remove completely in MDL-40517
1346 function user_login_string($course='ignored', $user='ignored') {
1347 throw new coding_exception('user_login_info() cant be used anymore. User login info is now handled via themes layouts.');
1351 * Prints a nice side block with an optional header. The content can either
1352 * be a block of HTML or a list of text with optional icons.
1354 * @static int $block_id Increments for each call to the function
1355 * @param string $heading HTML for the heading. Can include full HTML or just
1356 * plain text - plain text will automatically be enclosed in the appropriate
1358 * @param string $content HTML for the content
1359 * @param array $list an alternative to $content, it you want a list of things with optional icons.
1360 * @param array $icons optional icons for the things in $list.
1361 * @param string $footer Extra HTML content that gets output at the end, inside a <div class="footer">
1362 * @param array $attributes an array of attribute => value pairs that are put on the
1363 * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
1364 * already a class, class='block' is used.
1365 * @param string $title Plain text title, as embedded in the $heading.
1366 * @deprecated use $OUTPUT->block() instead.
1367 * @todo final deprecation of this function in MDL-40607
1369 function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
1372 debugging('print_side_block() is deprecated, please use $OUTPUT->block() instead.', DEBUG_DEVELOPER
);
1373 // We don't use $heading, becuse it often contains HTML that we don't want.
1374 // However, sometimes $title is not set, but $heading is.
1375 if (empty($title)) {
1376 $title = strip_tags($heading);
1379 // Render list contents to HTML if required.
1380 if (empty($content) && $list) {
1381 $content = $OUTPUT->list_block_contents($icons, $list);
1384 $bc = new block_contents();
1385 $bc->content
= $content;
1386 $bc->footer
= $footer;
1387 $bc->title
= $title;
1389 if (isset($attributes['id'])) {
1390 $bc->id
= $attributes['id'];
1391 unset($attributes['id']);
1393 $bc->attributes
= $attributes;
1395 echo $OUTPUT->block($bc, BLOCK_POS_LEFT
); // POS LEFT may be wrong, but no way to get a better guess here.
1399 * @deprecated blocks are now printed by theme.
1400 * @todo remove completely in MDL-40517
1402 function blocks_have_content(&$blockmanager, $region) {
1403 throw new coding_exception('blocks_have_content() can no longer be used. Blocks are now printed by the theme.');
1407 * @deprecated blocks are now printed by the theme.
1408 * @todo remove completely in MDL-40517
1410 function blocks_print_group($page, $blockmanager, $region) {
1411 throw new coding_exception('function blocks_print_group() can no longer be used. Blocks are now printed by the theme.');
1415 * @deprecated blocks are now printed by the theme.
1416 * @todo remove completely in MDL-40517
1418 function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE
) {
1419 throw new coding_exception('blocks_print_group() can no longer be used. Blocks are now printed by the theme.');
1423 * @deprecated Layout is now controlled by the theme.
1424 * @todo remove completely in MDL-40517
1426 function blocks_preferred_width($instances) {
1427 throw new coding_exception('blocks_print_group() can no longer be used. Blocks are now printed by the theme.');
1431 * @deprecated use html_writer::table() instead.
1432 * @todo remove completely in MDL-40517
1434 function print_table($table, $return=false) {
1435 throw new coding_exception('print_table() can no longer be used. Use html_writer::table() instead.');
1439 * @deprecated use $OUTPUT->action_link() instead (note: popups are discouraged for accesibility reasons)
1440 * @todo remove completely in MDL-40517
1442 function link_to_popup_window ($url, $name=null, $linkname=null, $height=400, $width=500, $title=null, $options=null, $return=false) {
1443 throw new coding_exception('link_to_popup_window() can no longer be used. Please to use $OUTPUT->action_link() instead.');
1447 * @deprecated use $OUTPUT->single_button() instead.
1448 * @todo remove completely in MDL-40517
1450 function button_to_popup_window ($url, $name=null, $linkname=null,
1451 $height=400, $width=500, $title=null, $options=null, $return=false,
1452 $id=null, $class=null) {
1453 throw new coding_exception('button_to_popup_window() can no longer be used. Please use $OUTPUT->single_button() instead.');
1457 * @deprecated use $OUTPUT->single_button() instead.
1458 * @todo remove completely in MDL-40517
1460 function print_single_button($link, $options, $label='OK', $method='get', $notusedanymore='',
1461 $return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
1463 throw new coding_exception('print_single_button() can no longer be used. Please use $OUTPUT->single_button() instead.');
1467 * @deprecated use $OUTPUT->spacer() instead.
1468 * @todo remove completely in MDL-40517
1470 function print_spacer($height=1, $width=1, $br=true, $return=false) {
1471 throw new coding_exception('print_spacer() can no longer be used. Please use $OUTPUT->spacer() instead.');
1475 * @deprecated use $OUTPUT->user_picture() instead.
1476 * @todo remove completely in MDL-40517
1478 function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
1479 throw new coding_exception('print_user_picture() can no longer be used. Please use $OUTPUT->user_picture($user, array(\'courseid\'=>$courseid) instead.');
1483 * Prints a basic textarea field.
1485 * @deprecated since Moodle 2.0
1487 * When using this function, you should
1490 * @param bool $unused No longer used.
1491 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
1492 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
1493 * @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.
1494 * @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.
1495 * @param string $name Name to use for the textarea element.
1496 * @param string $value Initial content to display in the textarea.
1497 * @param int $obsolete deprecated
1498 * @param bool $return If false, will output string. If true, will return string value.
1499 * @param string $id CSS ID to add to the textarea element.
1500 * @return string|void depending on the value of $return
1502 function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
1503 /// $width and height are legacy fields and no longer used as pixels like they used to be.
1504 /// However, you can set them to zero to override the mincols and minrows values below.
1506 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
1507 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
1516 $id = 'edit-'.$name;
1519 if ($height && ($rows < $minrows)) {
1522 if ($width && ($cols < $mincols)) {
1526 editors_head_setup();
1527 $editor = editors_get_preferred_editor(FORMAT_HTML
);
1528 $editor->use_editor($id, array('legacy'=>true));
1530 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'" spellcheck="true">'."\n";
1531 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
1532 $str .= '</textarea>'."\n";
1542 * Print a help button.
1544 * @deprecated since Moodle 2.0
1546 function helpbutton($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false, $imagetext='') {
1547 throw new coding_exception('helpbutton() can not be used any more, please see $OUTPUT->help_icon().');
1551 * @deprecated this is now handled by text editors
1552 * @todo remove completely in MDL-40517
1554 function emoticonhelpbutton($form, $field, $return = false) {
1555 throw new coding_exception('emoticonhelpbutton() was removed, new text editors will implement this feature');
1559 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
1560 * Should be used only with htmleditor or textarea.
1564 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
1566 * @return string Link to help button
1568 function editorhelpbutton(){
1575 * Print a help button.
1577 * Prints a special help button for html editors (htmlarea in this case)
1579 * @todo Write code into this function! detect current editor and print correct info
1581 * @return string Only returns an empty string at the moment
1583 function editorshortcutshelpbutton() {
1587 //TODO: detect current editor and print correct info
1593 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
1594 * provide this function with the language strings for sortasc and sortdesc.
1596 * @deprecated use $OUTPUT->arrow() instead.
1597 * @todo final deprecation of this function in MDL-40607
1599 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
1602 * @param string $direction 'up' or 'down'
1603 * @param string $strsort The language string used for the alt attribute of this image
1604 * @param bool $return Whether to print directly or return the html string
1605 * @return string|void depending on $return
1608 function print_arrow($direction='up', $strsort=null, $return=false) {
1611 debugging('print_arrow() is deprecated. Please use $OUTPUT->arrow() instead.', DEBUG_DEVELOPER
);
1613 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
1619 switch ($direction) {
1634 // Prepare language string
1636 if (empty($strsort) && !empty($sortdir)) {
1637 $strsort = get_string('sort' . $sortdir, 'grades');
1640 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
1650 * Returns a string containing a link to the user documentation.
1651 * Also contains an icon by default. Shown to teachers and admin only.
1653 * @deprecated since Moodle 2.0
1655 function doc_link($path='', $text='', $iconpath='ignored') {
1656 throw new coding_exception('doc_link() can not be used any more, please see $OUTPUT->doc_link().');
1660 * @deprecated use $OUTPUT->render($pagingbar) instead.
1661 * @todo remove completely in MDL-40517
1663 function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) {
1664 throw new coding_exception('print_paging_bar() can not be used any more. Please use $OUTPUT->render($pagingbar) instead.');
1668 * @deprecated use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel) instead.
1669 * @todo remove completely in MDL-40517
1671 function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
1672 throw new coding_exception('notice_yesno() can not be used any more. Please use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel) instead.');
1676 * Given an array of values, output the HTML for a select element with those options.
1678 * @deprecated since Moodle 2.0
1680 * Normally, you only need to use the first few parameters.
1682 * @param array $options The options to offer. An array of the form
1683 * $options[{value}] = {text displayed for that option};
1684 * @param string $name the name of this form control, as in <select name="..." ...
1685 * @param string $selected the option to select initially, default none.
1686 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
1687 * Set this to '' if you don't want a 'nothing is selected' option.
1688 * @param string $script if not '', then this is added to the <select> element as an onchange handler.
1689 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
1690 * @param boolean $return if false (the default) the the output is printed directly, If true, the
1691 * generated HTML is returned as a string.
1692 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
1693 * @param int $tabindex if give, sets the tabindex attribute on the <select> element. Default none.
1694 * @param string $id value to use for the id attribute of the <select> element. If none is given,
1695 * then a suitable one is constructed.
1696 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
1697 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
1698 * $listbox is an integer, that number is used for size instead.
1699 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
1700 * when $listbox display is enabled
1701 * @param string $class value to use for the class attribute of the <select> element. If none is given,
1702 * then a suitable one is constructed.
1703 * @return string|void If $return=true returns string, else echo's and returns void
1705 function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
1706 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
1707 $id='', $listbox=false, $multiple=false, $class='') {
1710 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
1713 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER
);
1715 $attributes = array();
1716 $attributes['disabled'] = $disabled ?
'disabled' : null;
1717 $attributes['tabindex'] = $tabindex ?
$tabindex : null;
1718 $attributes['multiple'] = $multiple ?
$multiple : null;
1719 $attributes['class'] = $class ?
$class : null;
1720 $attributes['id'] = $id ?
$id : null;
1722 $output = html_writer
::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
1732 * @deprecated use html_writer::select_yes_no() instead.
1733 * @todo remove completely in MDL-40517
1735 function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) {
1736 throw new coding_exception('choose_from_menu_yesno() can not be used anymore. Please use html_writerselect_yes_no() instead.');
1740 * @deprecated use html_writer::select() instead.
1741 * @todo remove completely in MDL-40517
1743 function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '',
1744 $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) {
1746 throw new coding_exception('choose_from_menu_nested() can not be used any more. Please use html_writer::select() instead.');
1750 * Prints a help button about a scale
1752 * @deprecated use $OUTPUT->help_icon_scale($courseid, $scale) instead.
1753 * @todo final deprecation of this function in MDL-40607
1756 * @param id $courseid
1757 * @param object $scale
1758 * @param boolean $return If set to true returns rather than echo's
1759 * @return string|bool Depending on value of $return
1761 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
1764 debugging('print_scale_menu_helpbutton() is deprecated. Please use $OUTPUT->help_icon_scale($courseid, $scale) instead.', DEBUG_DEVELOPER
);
1766 $output = $OUTPUT->help_icon_scale($courseid, $scale);
1776 * @deprecated use html_writer::select_time() instead
1777 * @todo remove completely in MDL-40517
1779 function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
1780 throw new moodle_exception('print_time_selector() can not be used any more . Please use html_writer::select_time() instead.');
1784 * @deprecated please use html_writer::select_time instead
1785 * @todo remove completely in MDL-40517
1787 function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
1788 throw new coding_exception('print_date_selector() can not be used any more. Please use html_writer::select_time() instead.');
1792 * Implements a complete little form with a dropdown menu.
1794 * @deprecated since Moodle 2.0
1796 function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false,
1797 $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) {
1798 throw new coding_exception('popup_form() can not be used any more, please see $OUTPUT->single_select or $OUTPUT->url_select().');
1802 * @deprecated use $OUTPUT->close_window_button() instead.
1803 * @todo remove completely in MDL-40517
1805 function close_window_button($name='closewindow', $return=false, $reloadopener = false) {
1806 throw new coding_exception('close_window_button() can not be used any more. Use $OUTPUT->close_window_button() instead.');
1810 * @deprecated use html_writer instead.
1811 * @todo remove completely in MDL-40517
1813 function choose_from_radio ($options, $name, $checked='', $return=false) {
1814 throw new coding_exception('choose_from_radio() can not be used any more. Please use html_writer instead.');
1818 * Display an standard html checkbox with an optional label
1820 * @deprecated use html_writer::checkbox() instead.
1821 * @todo final deprecation of this function in MDL-40607
1823 * @staticvar int $idcounter
1824 * @param string $name The name of the checkbox
1825 * @param string $value The valus that the checkbox will pass when checked
1826 * @param bool $checked The flag to tell the checkbox initial state
1827 * @param string $label The label to be showed near the checkbox
1828 * @param string $alt The info to be inserted in the alt tag
1829 * @param string $script If not '', then this is added to the checkbox element
1830 * as an onchange handler.
1831 * @param bool $return Whether this function should return a string or output
1832 * it (defaults to false)
1833 * @return string|void If $return=true returns string, else echo's and returns void
1835 function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
1838 debugging('print_checkbox() is deprecated. Please use html_writer::checkbox() instead.', DEBUG_DEVELOPER
);
1840 if (!empty($script)) {
1841 debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER
);
1844 $output = html_writer
::checkbox($name, $value, $checked, $label);
1846 if (empty($return)) {
1855 * @deprecated use mforms or html_writer instead.
1856 * @todo remove completely in MDL-40517
1858 function print_textfield($name, $value, $alt = '', $size=50, $maxlength=0, $return=false) {
1859 throw new coding_exception('print_textfield() can not be used anymore. Please use mforms or html_writer instead.');
1864 * @deprecated use $OUTPUT->heading_with_help() instead
1865 * @todo remove completely in MDL-40517
1867 function print_heading_with_help($text, $helppage, $module='moodle', $icon=false, $return=false) {
1868 throw new coding_exception('print_heading_with_help() can not be used anymore. Please use $OUTPUT->heading_with_help() instead.');
1872 * @deprecated use $OUTPUT->edit_button() instead.
1873 * @todo remove completely in MDL-40517
1875 function update_tag_button($tagid) {
1876 throw new coding_exception('update_tag_button() can not be used any more. Please $OUTPUT->edit_button(moodle_url) instead.');
1881 * Prints the 'update this xxx' button that appears on module pages.
1883 * @deprecated since Moodle 2.0
1885 * @param string $cmid the course_module id.
1886 * @param string $ignored not used any more. (Used to be courseid.)
1887 * @param string $string the module name - get_string('modulename', 'xxx')
1888 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
1890 function update_module_button($cmid, $ignored, $string) {
1891 global $CFG, $OUTPUT;
1893 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
1895 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
1897 if (has_capability('moodle/course:manageactivities', context_module
::instance($cmid))) {
1898 $string = get_string('updatethis', '', $string);
1900 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
1901 return $OUTPUT->single_button($url, $string);
1908 * @deprecated use $OUTPUT->edit_button() instead.
1909 * @todo remove completely in MDL-40517
1911 function update_course_icon($courseid) {
1912 throw new coding_exception('update_course_button() can not be used anymore. Please use $OUTPUT->edit_button(moodle_url) instead.');
1916 * Prints breadcrumb trail of links, called in theme/-/header.html
1918 * This function has now been deprecated please use output's navbar method instead
1922 * echo $OUTPUT->navbar();
1925 * @deprecated use $OUTPUT->navbar() instead
1926 * @todo final deprecation of this function in MDL-40607
1927 * @param mixed $navigation deprecated
1928 * @param string $separator OBSOLETE, and now deprecated
1929 * @param boolean $return False to echo the breadcrumb string (default), true to return it.
1930 * @return string|void String or null, depending on $return.
1932 function print_navigation ($navigation, $separator=0, $return=false) {
1933 global $OUTPUT,$PAGE;
1935 debugging('print_navigation() is deprecated, please update use $OUTPUT->navbar() instead.', DEBUG_DEVELOPER
);
1937 $output = $OUTPUT->navbar();
1947 * This function will build the navigation string to be used by print_header
1950 * It automatically generates the site and course level (if appropriate) links.
1952 * If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums')
1953 * and activityinstances (e.g. 'General Developer Forum') navigation levels.
1955 * If you want to add any further navigation links after the ones this function generates,
1956 * the pass an array of extra link arrays like this:
1958 * array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1),
1959 * array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2)
1961 * The normal case is to just add one further link, for example 'Editing forum' after
1962 * 'General Developer Forum', with no link.
1963 * To do that, you need to pass
1964 * array(array('name' => $linktext, 'link' => '', 'type' => 'title'))
1965 * However, becuase this is a very common case, you can use a shortcut syntax, and just
1966 * pass the string 'Editing forum', instead of an array as $extranavlinks.
1968 * At the moment, the link types only have limited significance. Type 'activity' is
1969 * recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types
1970 * that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'.
1971 * This really needs to be documented better. In the mean time, try to be consistent, it will
1972 * enable people to customise the navigation more in future.
1974 * When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course.
1975 * If you get the $cm object using the function get_coursemodule_from_instance or
1976 * get_coursemodule_from_id (as recommended) then this will be done for you automatically.
1977 * If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using
1978 * the $cm->module and $cm->instance fields, but this takes extra database queries, so a
1979 * warning is printed in developer debug mode.
1981 * @deprecated Please use $PAGE->navabar methods instead.
1982 * @todo final deprecation of this function in MDL-40607
1983 * @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you
1984 * only want one extra item with no link, you can pass a string instead. If you don't want
1985 * any extra links, pass an empty string.
1986 * @param mixed $cm deprecated
1987 * @return array Navigation array
1989 function build_navigation($extranavlinks, $cm = null) {
1990 global $CFG, $COURSE, $DB, $SITE, $PAGE;
1992 debugging('build_navigation() is deprecated, please use $PAGE->navbar methods instead.', DEBUG_DEVELOPER
);
1993 if (is_array($extranavlinks) && count($extranavlinks)>0) {
1994 foreach ($extranavlinks as $nav) {
1995 if (array_key_exists('name', $nav)) {
1996 if (array_key_exists('link', $nav) && !empty($nav['link'])) {
1997 $link = $nav['link'];
2001 $PAGE->navbar
->add($nav['name'],$link);
2006 return(array('newnav' => true, 'navlinks' => array()));
2010 * @deprecated not relevant with global navigation in Moodle 2.x+
2011 * @todo remove completely in MDL-40517
2013 function navmenu($course, $cm=NULL, $targetwindow='self') {
2014 // This function has been deprecated with the creation of the global nav in
2016 debugging('navmenu() is deprecated, it is no longer relevant with global navigation.', DEBUG_DEVELOPER
);
2022 * @deprecated use the settings block instead.
2023 * @todo remove completely in MDL-40517
2025 function switchroles_form($courseid) {
2026 throw new coding_exception('switchroles_form() can not be used any more. The global settings block does this job.');
2030 * @deprecated Please use normal $OUTPUT->header() instead
2031 * @todo remove completely in MDL-40517
2033 function admin_externalpage_print_header($focus='') {
2034 throw new coding_exception('admin_externalpage_print_header can not be used any more. Please $OUTPUT->header() instead.');
2038 * @deprecated Please use normal $OUTPUT->footer() instead
2039 * @todo remove completely in MDL-40517
2041 function admin_externalpage_print_footer() {
2042 throw new coding_exception('admin_externalpage_print_footer can not be used anymore Please $OUTPUT->footer() instead.');
2045 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
2049 * Call this function to add an event to the calendar table and to call any calendar plugins
2051 * @param object $event An object representing an event from the calendar table.
2052 * The event will be identified by the id field. The object event should include the following:
2054 * <li><b>$event->name</b> - Name for the event
2055 * <li><b>$event->description</b> - Description of the event (defaults to '')
2056 * <li><b>$event->format</b> - Format for the description (using formatting types defined at the top of weblib.php)
2057 * <li><b>$event->courseid</b> - The id of the course this event belongs to (0 = all courses)
2058 * <li><b>$event->groupid</b> - The id of the group this event belongs to (0 = no group)
2059 * <li><b>$event->userid</b> - The id of the user this event belongs to (0 = no user)
2060 * <li><b>$event->modulename</b> - Name of the module that creates this event
2061 * <li><b>$event->instance</b> - Instance of the module that owns this event
2062 * <li><b>$event->eventtype</b> - The type info together with the module info could
2063 * be used by calendar plugins to decide how to display event
2064 * <li><b>$event->timestart</b>- Timestamp for start of event
2065 * <li><b>$event->timeduration</b> - Duration (defaults to zero)
2066 * <li><b>$event->visible</b> - 0 if the event should be hidden (e.g. because the activity that created it is hidden)
2068 * @return int|false The id number of the resulting record or false if failed
2069 * @deprecated please use calendar_event::create() instead.
2070 * @todo final deprecation of this function in MDL-40607
2072 function add_event($event) {
2074 require_once($CFG->dirroot
.'/calendar/lib.php');
2076 debugging('add_event() is deprecated, please use calendar_event::create() instead.', DEBUG_DEVELOPER
);
2077 $event = calendar_event
::create($event);
2078 if ($event !== false) {
2085 * Call this function to update an event in the calendar table
2086 * the event will be identified by the id field of the $event object.
2088 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2089 * @return bool Success
2090 * @deprecated please calendar_event->update() instead.
2092 function update_event($event) {
2094 require_once($CFG->dirroot
.'/calendar/lib.php');
2096 debugging('update_event() is deprecated, please use calendar_event->update() instead.', DEBUG_DEVELOPER
);
2097 $event = (object)$event;
2098 $calendarevent = calendar_event
::load($event->id
);
2099 return $calendarevent->update($event);
2103 * Call this function to delete the event with id $id from calendar table.
2105 * @param int $id The id of an event from the 'event' table.
2107 * @deprecated please use calendar_event->delete() instead.
2108 * @todo final deprecation of this function in MDL-40607
2110 function delete_event($id) {
2112 require_once($CFG->dirroot
.'/calendar/lib.php');
2114 debugging('delete_event() is deprecated, please use calendar_event->delete() instead.', DEBUG_DEVELOPER
);
2116 $event = calendar_event
::load($id);
2117 return $event->delete();
2121 * Call this function to hide an event in the calendar table
2122 * the event will be identified by the id field of the $event object.
2124 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2126 * @deprecated please use calendar_event->toggle_visibility(false) instead.
2127 * @todo final deprecation of this function in MDL-40607
2129 function hide_event($event) {
2131 require_once($CFG->dirroot
.'/calendar/lib.php');
2133 debugging('hide_event() is deprecated, please use calendar_event->toggle_visibility(false) instead.', DEBUG_DEVELOPER
);
2135 $event = new calendar_event($event);
2136 return $event->toggle_visibility(false);
2140 * Call this function to unhide an event in the calendar table
2141 * the event will be identified by the id field of the $event object.
2143 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2145 * @deprecated please use calendar_event->toggle_visibility(true) instead.
2146 * @todo final deprecation of this function in MDL-40607
2148 function show_event($event) {
2150 require_once($CFG->dirroot
.'/calendar/lib.php');
2152 debugging('show_event() is deprecated, please use calendar_event->toggle_visibility(true) instead.', DEBUG_DEVELOPER
);
2154 $event = new calendar_event($event);
2155 return $event->toggle_visibility(true);
2159 * @deprecated Use core_text::strtolower($text) instead.
2161 function moodle_strtolower($string, $encoding='') {
2162 throw new coding_exception('moodle_strtolower() cannot be used any more. Please use core_text::strtolower() instead.');
2166 * Original singleton helper function, please use static methods instead,
2167 * ex: core_text::convert()
2169 * @deprecated since Moodle 2.2 use core_text::xxxx() instead
2171 * @return textlib instance
2173 function textlib_get_instance() {
2175 debugging('textlib_get_instance() is deprecated. Please use static calling core_text::functioname() instead.', DEBUG_DEVELOPER
);
2177 return new textlib();
2181 * Gets the generic section name for a courses section
2183 * The global function is deprecated. Each course format can define their own generic section name
2185 * @deprecated since 2.4
2186 * @see get_section_name()
2187 * @see format_base::get_section_name()
2189 * @param string $format Course format ID e.g. 'weeks' $course->format
2190 * @param stdClass $section Section object from database
2191 * @return Display name that the course format prefers, e.g. "Week 2"
2193 function get_generic_section_name($format, stdClass
$section) {
2194 debugging('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base', DEBUG_DEVELOPER
);
2195 return get_string('sectionname', "format_$format") . ' ' . $section->section
;
2199 * Returns an array of sections for the requested course id
2201 * It is usually not recommended to display the list of sections used
2202 * in course because the course format may have it's own way to do it.
2204 * If you need to just display the name of the section please call:
2205 * get_section_name($course, $section)
2206 * {@link get_section_name()}
2207 * from 2.4 $section may also be just the field course_sections.section
2209 * If you need the list of all sections it is more efficient to get this data by calling
2210 * $modinfo = get_fast_modinfo($courseorid);
2211 * $sections = $modinfo->get_section_info_all()
2212 * {@link get_fast_modinfo()}
2213 * {@link course_modinfo::get_section_info_all()}
2215 * Information about one section (instance of section_info):
2216 * get_fast_modinfo($courseorid)->get_sections_info($section)
2217 * {@link course_modinfo::get_section_info()}
2219 * @deprecated since 2.4
2221 * @param int $courseid
2222 * @return array Array of section_info objects
2224 function get_all_sections($courseid) {
2226 debugging('get_all_sections() is deprecated. See phpdocs for this function', DEBUG_DEVELOPER
);
2227 return get_fast_modinfo($courseid)->get_section_info_all();
2231 * Given a full mod object with section and course already defined, adds this module to that section.
2233 * This function is deprecated, please use {@link course_add_cm_to_section()}
2234 * Note that course_add_cm_to_section() also updates field course_modules.section and
2235 * calls rebuild_course_cache()
2237 * @deprecated since 2.4
2239 * @param object $mod
2240 * @param int $beforemod An existing ID which we will insert the new module before
2241 * @return int The course_sections ID where the mod is inserted
2243 function add_mod_to_section($mod, $beforemod = null) {
2244 debugging('Function add_mod_to_section() is deprecated, please use course_add_cm_to_section()', DEBUG_DEVELOPER
);
2246 return course_add_cm_to_section($mod->course
, $mod->coursemodule
, $mod->section
, $beforemod);
2250 * Returns a number of useful structures for course displays
2252 * Function get_all_mods() is deprecated in 2.4
2255 * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
2259 * $mods = get_fast_modinfo($courseorid)->get_cms();
2260 * $modnames = get_module_types_names();
2261 * $modnamesplural = get_module_types_names(true);
2262 * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names();
2265 * @deprecated since 2.4
2267 * @param int $courseid id of the course to get info about
2268 * @param array $mods (return) list of course modules
2269 * @param array $modnames (return) list of names of all module types installed and available
2270 * @param array $modnamesplural (return) list of names of all module types installed and available in the plural form
2271 * @param array $modnamesused (return) list of names of all module types used in the course
2273 function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
2274 debugging('Function get_all_mods() is deprecated. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details', DEBUG_DEVELOPER
);
2277 $modnames = get_module_types_names();
2278 $modnamesplural= get_module_types_names(true);
2279 $modinfo = get_fast_modinfo($courseid);
2280 $mods = $modinfo->get_cms();
2281 $modnamesused = $modinfo->get_used_module_names();
2285 * Returns course section - creates new if does not exist yet
2287 * This function is deprecated. To create a course section call:
2288 * course_create_sections_if_missing($courseorid, $sections);
2289 * to get the section call:
2290 * get_fast_modinfo($courseorid)->get_section_info($sectionnum);
2292 * @see course_create_sections_if_missing()
2293 * @see get_fast_modinfo()
2294 * @deprecated since 2.4
2296 * @param int $section relative section number (field course_sections.section)
2297 * @param int $courseid
2298 * @return stdClass record from table {course_sections}
2300 function get_course_section($section, $courseid) {
2302 debugging('Function get_course_section() is deprecated. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.', DEBUG_DEVELOPER
);
2304 if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) {
2307 $cw = new stdClass();
2308 $cw->course
= $courseid;
2309 $cw->section
= $section;
2311 $cw->summaryformat
= FORMAT_HTML
;
2313 $id = $DB->insert_record("course_sections", $cw);
2314 rebuild_course_cache($courseid, true);
2315 return $DB->get_record("course_sections", array("id"=>$id));
2319 * Return the start and end date of the week in Weekly course format
2321 * It is not recommended to use this function outside of format_weeks plugin
2323 * @deprecated since 2.4
2324 * @see format_weeks::get_section_dates()
2326 * @param stdClass $section The course_section entry from the DB
2327 * @param stdClass $course The course entry from DB
2328 * @return stdClass property start for startdate, property end for enddate
2330 function format_weeks_get_section_dates($section, $course) {
2331 debugging('Function format_weeks_get_section_dates() is deprecated. It is not recommended to'.
2332 ' use it outside of format_weeks plugin', DEBUG_DEVELOPER
);
2333 if (isset($course->format
) && $course->format
=== 'weeks') {
2334 return course_get_format($course)->get_section_dates($section);
2340 * Obtains shared data that is used in print_section when displaying a
2341 * course-module entry.
2343 * Deprecated. Instead of:
2344 * list($content, $name) = get_print_section_cm_text($cm, $course);
2346 * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
2347 * $name = $cm->get_formatted_name();
2349 * @deprecated since 2.5
2350 * @see cm_info::get_formatted_content()
2351 * @see cm_info::get_formatted_name()
2353 * This data is also used in other areas of the code.
2354 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
2355 * @param object $course (argument not used)
2356 * @return array An array with the following values in this order:
2357 * $content (optional extra content for after link),
2358 * $instancename (text of link)
2360 function get_print_section_cm_text(cm_info
$cm, $course) {
2361 debugging('Function get_print_section_cm_text() is deprecated. Please use '.
2362 'cm_info::get_formatted_content() and cm_info::get_formatted_name()',
2364 return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)),
2365 $cm->get_formatted_name());
2369 * Prints the menus to add activities and resources.
2371 * Deprecated. Please use:
2372 * $courserenderer = $PAGE->get_renderer('core', 'course');
2373 * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
2374 * array('inblock' => $vertical));
2375 * echo $output; // if $return argument in print_section_add_menus() set to false
2377 * @deprecated since 2.5
2378 * @see core_course_renderer::course_section_add_cm_control()
2380 * @param stdClass $course course object, must be the same as set on the page
2381 * @param int $section relative section number (field course_sections.section)
2382 * @param null|array $modnames (argument ignored) get_module_types_names() is used instead of argument
2383 * @param bool $vertical Vertical orientation
2384 * @param bool $return Return the menus or send them to output
2385 * @param int $sectionreturn The section to link back to
2386 * @return void|string depending on $return
2388 function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
2390 debugging('Function print_section_add_menus() is deprecated. Please use course renderer '.
2391 'function course_section_add_cm_control()', DEBUG_DEVELOPER
);
2393 $courserenderer = $PAGE->get_renderer('core', 'course');
2394 $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
2395 array('inblock' => $vertical));
2400 return !empty($output);
2405 * Produces the editing buttons for a module
2407 * Deprecated. Please use:
2408 * $courserenderer = $PAGE->get_renderer('core', 'course');
2409 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
2410 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
2412 * @deprecated since 2.5
2413 * @see course_get_cm_edit_actions()
2414 * @see core_course_renderer->course_section_cm_edit_actions()
2416 * @param stdClass $mod The module to produce editing buttons for
2417 * @param bool $absolute_ignored (argument ignored) - all links are absolute
2418 * @param bool $moveselect (argument ignored)
2419 * @param int $indent The current indenting
2420 * @param int $section The section to link back to
2421 * @return string XHTML for the editing buttons
2423 function make_editing_buttons(stdClass
$mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
2425 debugging('Function make_editing_buttons() is deprecated, please see PHPdocs in '.
2426 'lib/deprecatedlib.php on how to replace it', DEBUG_DEVELOPER
);
2427 if (!($mod instanceof cm_info
)) {
2428 $modinfo = get_fast_modinfo($mod->course
);
2429 $mod = $modinfo->get_cm($mod->id
);
2431 $actions = course_get_cm_edit_actions($mod, $indent, $section);
2433 $courserenderer = $PAGE->get_renderer('core', 'course');
2434 // The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap
2435 // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
2436 // the course page HTML will allow this to be removed.
2437 return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
2441 * Prints a section full of activity modules
2443 * Deprecated. Please use:
2444 * $courserenderer = $PAGE->get_renderer('core', 'course');
2445 * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn,
2446 * array('hidecompletion' => $hidecompletion));
2448 * @deprecated since 2.5
2449 * @see core_course_renderer::course_section_cm_list()
2451 * @param stdClass $course The course
2452 * @param stdClass|section_info $section The section object containing properties id and section
2453 * @param array $mods (argument not used)
2454 * @param array $modnamesused (argument not used)
2455 * @param bool $absolute (argument not used)
2456 * @param string $width (argument not used)
2457 * @param bool $hidecompletion Hide completion status
2458 * @param int $sectionreturn The section to return to
2461 function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
2463 debugging('Function print_section() is deprecated. Please use course renderer function '.
2464 'course_section_cm_list() instead.', DEBUG_DEVELOPER
);
2465 $displayoptions = array('hidecompletion' => $hidecompletion);
2466 $courserenderer = $PAGE->get_renderer('core', 'course');
2467 echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions);
2471 * Displays the list of courses with user notes
2473 * This function is not used in core. It was replaced by block course_overview
2475 * @deprecated since 2.5
2477 * @param array $courses
2478 * @param array $remote_courses
2480 function print_overview($courses, array $remote_courses=array()) {
2481 global $CFG, $USER, $DB, $OUTPUT;
2482 debugging('Function print_overview() is deprecated. Use block course_overview to display this information', DEBUG_DEVELOPER
);
2484 $htmlarray = array();
2485 if ($modules = $DB->get_records('modules')) {
2486 foreach ($modules as $mod) {
2487 if (file_exists(dirname(dirname(__FILE__
)).'/mod/'.$mod->name
.'/lib.php')) {
2488 include_once(dirname(dirname(__FILE__
)).'/mod/'.$mod->name
.'/lib.php');
2489 $fname = $mod->name
.'_print_overview';
2490 if (function_exists($fname)) {
2491 $fname($courses,$htmlarray);
2496 foreach ($courses as $course) {
2497 $fullname = format_string($course->fullname
, true, array('context' => context_course
::instance($course->id
)));
2498 echo $OUTPUT->box_start('coursebox');
2499 $attributes = array('title' => s($fullname));
2500 if (empty($course->visible
)) {
2501 $attributes['class'] = 'dimmed';
2503 echo $OUTPUT->heading(html_writer
::link(
2504 new moodle_url('/course/view.php', array('id' => $course->id
)), $fullname, $attributes), 3);
2505 if (array_key_exists($course->id
,$htmlarray)) {
2506 foreach ($htmlarray[$course->id
] as $modname => $html) {
2510 echo $OUTPUT->box_end();
2513 if (!empty($remote_courses)) {
2514 echo $OUTPUT->heading(get_string('remotecourses', 'mnet'));
2516 foreach ($remote_courses as $course) {
2517 echo $OUTPUT->box_start('coursebox');
2518 $attributes = array('title' => s($course->fullname
));
2519 echo $OUTPUT->heading(html_writer
::link(
2520 new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid
, 'wantsurl' => '/course/view.php?id='.$course->remoteid
)),
2521 format_string($course->shortname
),
2522 $attributes) . ' (' . format_string($course->hostname
) . ')', 3);
2523 echo $OUTPUT->box_end();
2528 * This function trawls through the logs looking for
2529 * anything new since the user's last login
2531 * This function was only used to print the content of block recent_activity
2532 * All functionality is moved into class {@link block_recent_activity}
2533 * and renderer {@link block_recent_activity_renderer}
2535 * @deprecated since 2.5
2536 * @param stdClass $course
2538 function print_recent_activity($course) {
2539 // $course is an object
2540 global $CFG, $USER, $SESSION, $DB, $OUTPUT;
2541 debugging('Function print_recent_activity() is deprecated. It is not recommended to'.
2542 ' use it outside of block_recent_activity', DEBUG_DEVELOPER
);
2544 $context = context_course
::instance($course->id
);
2546 $viewfullnames = has_capability('moodle/site:viewfullnames', $context);
2548 $timestart = round(time() - COURSE_MAX_RECENT_PERIOD
, -2); // better db caching for guests - 100 seconds
2550 if (!isguestuser()) {
2551 if (!empty($USER->lastcourseaccess
[$course->id
])) {
2552 if ($USER->lastcourseaccess
[$course->id
] > $timestart) {
2553 $timestart = $USER->lastcourseaccess
[$course->id
];
2558 echo '<div class="activitydate">';
2559 echo get_string('activitysince', '', userdate($timestart));
2561 echo '<div class="activityhead">';
2563 echo '<a href="'.$CFG->wwwroot
.'/course/recent.php?id='.$course->id
.'">'.get_string('recentactivityreport').'</a>';
2569 /// Firstly, have there been any new enrolments?
2571 $users = get_recent_enrolments($course->id
, $timestart);
2573 //Accessibility: new users now appear in an <OL> list.
2575 echo '<div class="newusers">';
2576 echo $OUTPUT->heading(get_string("newusers").':', 3);
2578 echo "<ol class=\"list\">\n";
2579 foreach ($users as $user) {
2580 $fullname = fullname($user, $viewfullnames);
2581 echo '<li class="name"><a href="'."$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id\">$fullname</a></li>\n";
2583 echo "</ol>\n</div>\n";
2586 /// Next, have there been any modifications to the course structure?
2588 $modinfo = get_fast_modinfo($course);
2590 $changelist = array();
2592 $logs = $DB->get_records_select('log', "time > ? AND course = ? AND
2593 module = 'course' AND
2594 (action = 'add mod' OR action = 'update mod' OR action = 'delete mod')",
2595 array($timestart, $course->id
), "id ASC");
2598 $actions = array('add mod', 'update mod', 'delete mod');
2599 $newgones = array(); // added and later deleted items
2600 foreach ($logs as $key => $log) {
2601 if (!in_array($log->action
, $actions)) {
2604 $info = explode(' ', $log->info
);
2606 // note: in most cases I replaced hardcoding of label with use of
2607 // $cm->has_view() but it was not possible to do this here because
2608 // we don't necessarily have the $cm for it
2609 if ($info[0] == 'label') { // Labels are ignored in recent activity
2613 if (count($info) != 2) {
2614 debugging("Incorrect log entry info: id = ".$log->id
, DEBUG_DEVELOPER
);
2618 $modname = $info[0];
2619 $instanceid = $info[1];
2621 if ($log->action
== 'delete mod') {
2622 // unfortunately we do not know if the mod was visible
2623 if (!array_key_exists($log->info
, $newgones)) {
2624 $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $modname));
2625 $changelist[$log->info
] = array ('operation' => 'delete', 'text' => $strdeleted);
2628 if (!isset($modinfo->instances
[$modname][$instanceid])) {
2629 if ($log->action
== 'add mod') {
2630 // do not display added and later deleted activities
2631 $newgones[$log->info
] = true;
2635 $cm = $modinfo->instances
[$modname][$instanceid];
2636 if (!$cm->uservisible
) {
2640 if ($log->action
== 'add mod') {
2641 $stradded = get_string('added', 'moodle', get_string('modulename', $modname));
2642 $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>");
2644 } else if ($log->action
== 'update mod' and empty($changelist[$log->info
])) {
2645 $strupdated = get_string('updated', 'moodle', get_string('modulename', $modname));
2646 $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>");
2652 if (!empty($changelist)) {
2653 echo $OUTPUT->heading(get_string("courseupdates").':', 3);
2655 foreach ($changelist as $changeinfo => $change) {
2656 echo '<p class="activity">'.$change['text'].'</p>';
2660 /// Now display new things from each module
2662 $usedmodules = array();
2663 foreach($modinfo->cms
as $cm) {
2664 if (isset($usedmodules[$cm->modname
])) {
2667 if (!$cm->uservisible
) {
2670 $usedmodules[$cm->modname
] = $cm->modname
;
2673 foreach ($usedmodules as $modname) { // Each module gets it's own logs and prints them
2674 if (file_exists($CFG->dirroot
.'/mod/'.$modname.'/lib.php')) {
2675 include_once($CFG->dirroot
.'/mod/'.$modname.'/lib.php');
2676 $print_recent_activity = $modname.'_print_recent_activity';
2677 if (function_exists($print_recent_activity)) {
2678 // NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames!
2679 $content = $print_recent_activity($course, $viewfullnames, $timestart) ||
$content;
2682 debugging("Missing lib.php in lib/{$modname} - please reinstall files or uninstall the module");
2687 echo '<p class="message">'.get_string('nothingnew').'</p>';
2692 * Delete a course module and any associated data at the course level (events)
2693 * Until 1.5 this function simply marked a deleted flag ... now it
2694 * deletes it completely.
2696 * @deprecated since 2.5
2698 * @param int $id the course module id
2699 * @return boolean true on success, false on failure
2701 function delete_course_module($id) {
2702 debugging('Function delete_course_module() is deprecated. Please use course_delete_module() instead.', DEBUG_DEVELOPER
);
2706 require_once($CFG->libdir
.'/gradelib.php');
2707 require_once($CFG->dirroot
.'/blog/lib.php');
2709 if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) {
2712 $modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module
));
2713 //delete events from calendar
2714 if ($events = $DB->get_records('event', array('instance'=>$cm->instance
, 'modulename'=>$modulename))) {
2715 foreach($events as $event) {
2716 delete_event($event->id
);
2719 //delete grade items, outcome items and grades attached to modules
2720 if ($grade_items = grade_item
::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename,
2721 'iteminstance'=>$cm->instance
, 'courseid'=>$cm->course
))) {
2722 foreach ($grade_items as $grade_item) {
2723 $grade_item->delete('moddelete');
2726 // Delete completion and availability data; it is better to do this even if the
2727 // features are not turned on, in case they were turned on previously (these will be
2728 // very quick on an empty table)
2729 $DB->delete_records('course_modules_completion', array('coursemoduleid' => $cm->id
));
2730 $DB->delete_records('course_modules_availability', array('coursemoduleid'=> $cm->id
));
2731 $DB->delete_records('course_completion_criteria', array('moduleinstance' => $cm->id
,
2732 'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY
));
2734 delete_context(CONTEXT_MODULE
, $cm->id
);
2735 return $DB->delete_records('course_modules', array('id'=>$cm->id
));
2739 * Prints the turn editing on/off button on course/index.php or course/category.php.
2741 * @deprecated since 2.5
2743 * @param integer $categoryid The id of the category we are showing, or 0 for system context.
2744 * @return string HTML of the editing button, or empty string, if this user is not allowed
2747 function update_category_button($categoryid = 0) {
2748 global $CFG, $PAGE, $OUTPUT;
2749 debugging('Function update_category_button() is deprecated. Pages to view '.
2750 'and edit courses are now separate and no longer depend on editing mode.',
2753 // Check permissions.
2754 if (!can_edit_in_category($categoryid)) {
2758 // Work out the appropriate action.
2759 if ($PAGE->user_is_editing()) {
2760 $label = get_string('turneditingoff');
2763 $label = get_string('turneditingon');
2767 // Generate the button HTML.
2768 $options = array('categoryedit' => $edit, 'sesskey' => sesskey());
2770 $options['id'] = $categoryid;
2771 $page = 'category.php';
2773 $page = 'index.php';
2775 return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get');
2779 * This function recursively travels the categories, building up a nice list
2780 * for display. It also makes an array that list all the parents for each
2783 * For example, if you have a tree of categories like:
2784 * Miscellaneous (id = 1)
2785 * Subcategory (id = 2)
2786 * Sub-subcategory (id = 4)
2787 * Other category (id = 3)
2788 * Then after calling this function you will have
2789 * $list = array(1 => 'Miscellaneous', 2 => 'Miscellaneous / Subcategory',
2790 * 4 => 'Miscellaneous / Subcategory / Sub-subcategory',
2791 * 3 => 'Other category');
2792 * $parents = array(2 => array(1), 4 => array(1, 2));
2794 * If you specify $requiredcapability, then only categories where the current
2795 * user has that capability will be added to $list, although all categories
2796 * will still be added to $parents, and if you only have $requiredcapability
2797 * in a child category, not the parent, then the child catgegory will still be
2800 * If you specify the option $excluded, then that category, and all its children,
2801 * are omitted from the tree. This is useful when you are doing something like
2802 * moving categories, where you do not want to allow people to move a category
2803 * to be the child of itself.
2805 * This function is deprecated! For list of categories use
2806 * coursecat::make_all_categories($requiredcapability, $excludeid, $separator)
2807 * For parents of one particular category use
2808 * coursecat::get($id)->get_parents()
2810 * @deprecated since 2.5
2812 * @param array $list For output, accumulates an array categoryid => full category path name
2813 * @param array $parents For output, accumulates an array categoryid => list of parent category ids.
2814 * @param string/array $requiredcapability if given, only categories where the current
2815 * user has this capability will be added to $list. Can also be an array of capabilities,
2816 * in which case they are all required.
2817 * @param integer $excludeid Omit this category and its children from the lists built.
2818 * @param object $category Not used
2819 * @param string $path Not used
2821 function make_categories_list(&$list, &$parents, $requiredcapability = '',
2822 $excludeid = 0, $category = NULL, $path = "") {
2824 require_once($CFG->libdir
.'/coursecatlib.php');
2826 debugging('Global function make_categories_list() is deprecated. Please use '.
2827 'coursecat::make_categories_list() and coursecat::get_parents()',
2830 // For categories list use just this one function:
2834 $list +
= coursecat
::make_categories_list($requiredcapability, $excludeid);
2836 // Building the list of all parents of all categories in the system is highly undesirable and hardly ever needed.
2837 // Usually user needs only parents for one particular category, in which case should be used:
2838 // coursecat::get($categoryid)->get_parents()
2839 if (empty($parents)) {
2842 $all = $DB->get_records_sql('SELECT id, parent FROM {course_categories} ORDER BY sortorder');
2843 foreach ($all as $record) {
2844 if ($record->parent
) {
2845 $parents[$record->id
] = array_merge($parents[$record->parent
], array($record->parent
));
2847 $parents[$record->id
] = array();
2853 * Delete category, but move contents to another category.
2855 * This function is deprecated. Please use
2856 * coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2858 * @see coursecat::delete_move()
2859 * @deprecated since 2.5
2861 * @param object $category
2862 * @param int $newparentid category id
2863 * @return bool status
2865 function category_delete_move($category, $newparentid, $showfeedback=true) {
2867 require_once($CFG->libdir
.'/coursecatlib.php');
2869 debugging('Function category_delete_move() is deprecated. Please use coursecat::delete_move() instead.');
2871 return coursecat
::get($category->id
)->delete_move($newparentid, $showfeedback);
2875 * Recursively delete category including all subcategories and courses.
2877 * This function is deprecated. Please use
2878 * coursecat::get($category->id)->delete_full($showfeedback);
2880 * @see coursecat::delete_full()
2881 * @deprecated since 2.5
2883 * @param stdClass $category
2884 * @param boolean $showfeedback display some notices
2885 * @return array return deleted courses
2887 function category_delete_full($category, $showfeedback=true) {
2889 require_once($CFG->libdir
.'/coursecatlib.php');
2891 debugging('Function category_delete_full() is deprecated. Please use coursecat::delete_full() instead.');
2893 return coursecat
::get($category->id
)->delete_full($showfeedback);
2897 * Efficiently moves a category - NOTE that this can have
2898 * a huge impact access-control-wise...
2900 * This function is deprecated. Please use
2901 * $coursecat = coursecat::get($category->id);
2902 * if ($coursecat->can_change_parent($newparentcat->id)) {
2903 * $coursecat->change_parent($newparentcat->id);
2906 * Alternatively you can use
2907 * $coursecat->update(array('parent' => $newparentcat->id));
2909 * Function update() also updates field course_categories.timemodified
2911 * @see coursecat::change_parent()
2912 * @see coursecat::update()
2913 * @deprecated since 2.5
2915 * @param stdClass|coursecat $category
2916 * @param stdClass|coursecat $newparentcat
2918 function move_category($category, $newparentcat) {
2920 require_once($CFG->libdir
.'/coursecatlib.php');
2922 debugging('Function move_category() is deprecated. Please use coursecat::change_parent() instead.');
2924 return coursecat
::get($category->id
)->change_parent($newparentcat->id
);
2928 * Hide course category and child course and subcategories
2930 * This function is deprecated. Please use
2931 * coursecat::get($category->id)->hide();
2933 * @see coursecat::hide()
2934 * @deprecated since 2.5
2936 * @param stdClass $category
2939 function course_category_hide($category) {
2941 require_once($CFG->libdir
.'/coursecatlib.php');
2943 debugging('Function course_category_hide() is deprecated. Please use coursecat::hide() instead.');
2945 coursecat
::get($category->id
)->hide();
2949 * Show course category and child course and subcategories
2951 * This function is deprecated. Please use
2952 * coursecat::get($category->id)->show();
2954 * @see coursecat::show()
2955 * @deprecated since 2.5
2957 * @param stdClass $category
2960 function course_category_show($category) {
2962 require_once($CFG->libdir
.'/coursecatlib.php');
2964 debugging('Function course_category_show() is deprecated. Please use coursecat::show() instead.');
2966 coursecat
::get($category->id
)->show();
2970 * Return specified category, default if given does not exist
2972 * This function is deprecated.
2973 * To get the category with the specified it please use:
2974 * coursecat::get($catid, IGNORE_MISSING);
2976 * coursecat::get($catid, MUST_EXIST);
2978 * To get the first available category please use
2979 * coursecat::get_default();
2981 * class coursecat will also make sure that at least one category exists in DB
2983 * @deprecated since 2.5
2984 * @see coursecat::get()
2985 * @see coursecat::get_default()
2987 * @param int $catid course category id
2988 * @return object caregory
2990 function get_course_category($catid=0) {
2993 debugging('Function get_course_category() is deprecated. Please use coursecat::get(), see phpdocs for more details');
2997 if (!empty($catid)) {
2998 $category = $DB->get_record('course_categories', array('id'=>$catid));
3002 // the first category is considered default for now
3003 if ($category = $DB->get_records('course_categories', null, 'sortorder', '*', 0, 1)) {
3004 $category = reset($category);
3007 $cat = new stdClass();
3008 $cat->name
= get_string('miscellaneous');
3010 $cat->sortorder
= MAX_COURSES_IN_CATEGORY
;
3011 $cat->timemodified
= time();
3012 $catid = $DB->insert_record('course_categories', $cat);
3013 // make sure category context exists
3014 context_coursecat
::instance($catid);
3015 mark_context_dirty('/'.SYSCONTEXTID
);
3016 fix_course_sortorder(); // Required to build course_categories.depth and .path.
3017 $category = $DB->get_record('course_categories', array('id'=>$catid));
3025 * Create a new course category and marks the context as dirty
3027 * This function does not set the sortorder for the new category and
3028 * {@link fix_course_sortorder()} should be called after creating a new course
3031 * Please note that this function does not verify access control.
3033 * This function is deprecated. It is replaced with the method create() in class coursecat.
3034 * {@link coursecat::create()} also verifies the data, fixes sortorder and logs the action
3036 * @deprecated since 2.5
3038 * @param object $category All of the data required for an entry in the course_categories table
3039 * @return object new course category
3041 function create_course_category($category) {
3044 debugging('Function create_course_category() is deprecated. Please use coursecat::create(), see phpdocs for more details', DEBUG_DEVELOPER
);
3046 $category->timemodified
= time();
3047 $category->id
= $DB->insert_record('course_categories', $category);
3048 $category = $DB->get_record('course_categories', array('id' => $category->id
));
3050 // We should mark the context as dirty
3051 $category->context
= context_coursecat
::instance($category->id
);
3052 $category->context
->mark_dirty();
3058 * Returns an array of category ids of all the subcategories for a given
3061 * This function is deprecated.
3063 * To get visible children categories of the given category use:
3064 * coursecat::get($categoryid)->get_children();
3065 * This function will return the array or coursecat objects, on each of them
3066 * you can call get_children() again
3068 * @see coursecat::get()
3069 * @see coursecat::get_children()
3071 * @deprecated since 2.5
3074 * @param int $catid - The id of the category whose subcategories we want to find.
3075 * @return array of category ids.
3077 function get_all_subcategories($catid) {
3080 debugging('Function get_all_subcategories() is deprecated. Please use appropriate methods() of coursecat class. See phpdocs for more details',
3085 if ($categories = $DB->get_records('course_categories', array('parent' => $catid))) {
3086 foreach ($categories as $cat) {
3087 array_push($subcats, $cat->id
);
3088 $subcats = array_merge($subcats, get_all_subcategories($cat->id
));
3095 * Gets the child categories of a given courses category
3097 * This function is deprecated. Please use functions in class coursecat:
3098 * - coursecat::get($parentid)->has_children()
3099 * tells if the category has children (visible or not to the current user)
3101 * - coursecat::get($parentid)->get_children()
3102 * returns an array of coursecat objects, each of them represents a children category visible
3103 * to the current user (i.e. visible=1 or user has capability to view hidden categories)
3105 * - coursecat::get($parentid)->get_children_count()
3106 * returns number of children categories visible to the current user
3108 * - coursecat::count_all()
3109 * returns total count of all categories in the system (both visible and not)
3111 * - coursecat::get_default()
3112 * returns the first category (usually to be used if count_all() == 1)
3114 * @deprecated since 2.5
3116 * @param int $parentid the id of a course category.
3117 * @return array all the child course categories.
3119 function get_child_categories($parentid) {
3121 debugging('Function get_child_categories() is deprecated. Use coursecat::get_children() or see phpdocs for more details.',
3125 $sql = context_helper
::get_preload_record_columns_sql('ctx');
3126 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
3127 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
3128 array(CONTEXT_COURSECAT
, $parentid));
3129 foreach ($records as $category) {
3130 context_helper
::preload_from_record($category);
3131 if (!$category->visible
&& !has_capability('moodle/category:viewhiddencategories', context_coursecat
::instance($category->id
))) {
3140 * Returns a sorted list of categories.
3142 * When asking for $parent='none' it will return all the categories, regardless
3143 * of depth. Wheen asking for a specific parent, the default is to return
3144 * a "shallow" resultset. Pass false to $shallow and it will return all
3145 * the child categories as well.
3147 * @deprecated since 2.5
3149 * This function is deprecated. Use appropriate functions from class coursecat.
3152 * coursecat::get($categoryid)->get_children()
3153 * - returns all children of the specified category as instances of class
3154 * coursecat, which means on each of them method get_children() can be called again.
3155 * Only categories visible to the current user are returned.
3157 * coursecat::get(0)->get_children()
3158 * - returns all top-level categories visible to the current user.
3160 * Sort fields can be specified, see phpdocs to {@link coursecat::get_children()}
3162 * coursecat::make_categories_list()
3163 * - returns an array of all categories id/names in the system.
3164 * Also only returns categories visible to current user and can additionally be
3165 * filetered by capability, see phpdocs to {@link coursecat::make_categories_list()}
3167 * make_categories_options()
3168 * - Returns full course categories tree to be used in html_writer::select()
3170 * Also see functions {@link coursecat::get_children_count()}, {@link coursecat::count_all()},
3171 * {@link coursecat::get_default()}
3173 * The code of this deprecated function is left as it is because coursecat::get_children()
3174 * returns categories as instances of coursecat and not stdClass. Also there is no
3175 * substitute for retrieving the category with all it's subcategories. Plugin developers
3176 * may re-use the code/queries from this function in their plugins if really necessary.
3178 * @param string $parent The parent category if any
3179 * @param string $sort the sortorder
3180 * @param bool $shallow - set to false to get the children too
3181 * @return array of categories
3183 function get_categories($parent='none', $sort=NULL, $shallow=true) {
3186 debugging('Function get_categories() is deprecated. Please use coursecat::get_children() or see phpdocs for other alternatives',
3189 if ($sort === NULL) {
3190 $sort = 'ORDER BY cc.sortorder ASC';
3191 } elseif ($sort ==='') {
3192 // leave it as empty
3194 $sort = "ORDER BY $sort";
3197 list($ccselect, $ccjoin) = context_instance_preload_sql('cc.id', CONTEXT_COURSECAT
, 'ctx');
3199 if ($parent === 'none') {
3200 $sql = "SELECT cc.* $ccselect
3201 FROM {course_categories} cc
3206 } elseif ($shallow) {
3207 $sql = "SELECT cc.* $ccselect
3208 FROM {course_categories} cc
3212 $params = array($parent);
3215 $sql = "SELECT cc.* $ccselect
3216 FROM {course_categories} cc
3218 JOIN {course_categories} ccp
3219 ON ((cc.parent = ccp.id) OR (cc.path LIKE ".$DB->sql_concat('ccp.path',"'/%'")."))
3222 $params = array($parent);
3224 $categories = array();
3226 $rs = $DB->get_recordset_sql($sql, $params);
3227 foreach($rs as $cat) {
3228 context_helper
::preload_from_record($cat);
3229 $catcontext = context_coursecat
::instance($cat->id
);
3230 if ($cat->visible ||
has_capability('moodle/category:viewhiddencategories', $catcontext)) {
3231 $categories[$cat->id
] = $cat;
3239 * Displays a course search form
3241 * This function is deprecated, please use course renderer:
3242 * $renderer = $PAGE->get_renderer('core', 'course');
3243 * echo $renderer->course_search_form($value, $format);
3245 * @deprecated since 2.5
3247 * @param string $value default value to populate the search field
3248 * @param bool $return if true returns the value, if false - outputs
3249 * @param string $format display format - 'plain' (default), 'short' or 'navbar'
3250 * @return null|string
3252 function print_course_search($value="", $return=false, $format="plain") {
3254 debugging('Function print_course_search() is deprecated, please use course renderer', DEBUG_DEVELOPER
);
3255 $renderer = $PAGE->get_renderer('core', 'course');
3257 return $renderer->course_search_form($value, $format);
3259 echo $renderer->course_search_form($value, $format);
3264 * Prints custom user information on the home page
3266 * This function is deprecated, please use:
3267 * $renderer = $PAGE->get_renderer('core', 'course');
3268 * echo $renderer->frontpage_my_courses()
3270 * @deprecated since 2.5
3272 function print_my_moodle() {
3274 debugging('Function print_my_moodle() is deprecated, please use course renderer function frontpage_my_courses()', DEBUG_DEVELOPER
);
3276 $renderer = $PAGE->get_renderer('core', 'course');
3277 echo $renderer->frontpage_my_courses();
3281 * Prints information about one remote course
3283 * This function is deprecated, it is replaced with protected function
3284 * {@link core_course_renderer::frontpage_remote_course()}
3285 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
3287 * @deprecated since 2.5
3289 function print_remote_course($course, $width="100%") {
3291 debugging('Function print_remote_course() is deprecated, please use course renderer', DEBUG_DEVELOPER
);
3295 $url = "{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&wantsurl=/course/view.php?id={$course->remoteid}";
3297 echo '<div class="coursebox remotecoursebox clearfix">';
3298 echo '<div class="info">';
3299 echo '<div class="name"><a title="'.get_string('entercourse').'"'.
3300 $linkcss.' href="'.$url.'">'
3301 . format_string($course->fullname
) .'</a><br />'
3302 . format_string($course->hostname
) . ' : '
3303 . format_string($course->cat_name
) . ' : '
3304 . format_string($course->shortname
). '</div>';
3305 echo '</div><div class="summary">';
3306 $options = new stdClass();
3307 $options->noclean
= true;
3308 $options->para
= false;
3309 $options->overflowdiv
= true;
3310 echo format_text($course->summary
, $course->summaryformat
, $options);
3316 * Prints information about one remote host
3318 * This function is deprecated, it is replaced with protected function
3319 * {@link core_course_renderer::frontpage_remote_host()}
3320 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
3322 * @deprecated since 2.5
3324 function print_remote_host($host, $width="100%") {
3326 debugging('Function print_remote_host() is deprecated, please use course renderer', DEBUG_DEVELOPER
);
3330 echo '<div class="coursebox clearfix">';
3331 echo '<div class="info">';
3332 echo '<div class="name">';
3333 echo '<img src="'.$OUTPUT->pix_url('i/mnethost') . '" class="icon" alt="'.get_string('course').'" />';
3334 echo '<a title="'.s($host['name']).'" href="'.s($host['url']).'">'
3335 . s($host['name']).'</a> - ';
3336 echo $host['count'] . ' ' . get_string('courses');
3343 * Recursive function to print out all the categories in a nice format
3344 * with or without courses included
3346 * @deprecated since 2.5
3348 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3350 function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) {
3352 debugging('Function print_whole_category_list() is deprecated, please use course renderer', DEBUG_DEVELOPER
);
3354 $renderer = $PAGE->get_renderer('core', 'course');
3355 if ($showcourses && $category) {
3356 echo $renderer->course_category($category);
3357 } else if ($showcourses) {
3358 echo $renderer->frontpage_combo_list();
3360 echo $renderer->frontpage_categories_list();
3365 * Prints the category information.
3367 * @deprecated since 2.5
3369 * This function was only used by {@link print_whole_category_list()} but now
3370 * all course category rendering is moved to core_course_renderer.
3372 * @param stdClass $category
3373 * @param int $depth The depth of the category.
3374 * @param bool $showcourses If set to true course information will also be printed.
3375 * @param array|null $courses An array of courses belonging to the category, or null if you don't have it yet.
3377 function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) {
3379 debugging('Function print_category_info() is deprecated, please use course renderer', DEBUG_DEVELOPER
);
3381 $renderer = $PAGE->get_renderer('core', 'course');
3382 echo $renderer->course_category($category);
3386 * This function generates a structured array of courses and categories.
3388 * @deprecated since 2.5
3390 * This function is not used any more in moodle core and course renderer does not have render function for it.
3391 * Combo list on the front page is displayed as:
3392 * $renderer = $PAGE->get_renderer('core', 'course');
3393 * echo $renderer->frontpage_combo_list()
3395 * The new class {@link coursecat} stores the information about course category tree
3396 * To get children categories use:
3397 * coursecat::get($id)->get_children()
3398 * To get list of courses use:
3399 * coursecat::get($id)->get_courses()
3401 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3406 function get_course_category_tree($id = 0, $depth = 0) {
3409 debugging('Function get_course_category_tree() is deprecated, please use course renderer or coursecat class, see function phpdocs for more info', DEBUG_DEVELOPER
);
3412 $categories = array();
3413 $categoryids = array();
3414 $sql = context_helper
::get_preload_record_columns_sql('ctx');
3415 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
3416 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
3417 array(CONTEXT_COURSECAT
, $id));
3418 foreach ($records as $category) {
3419 context_helper
::preload_from_record($category);
3420 if (!$category->visible
&& !has_capability('moodle/category:viewhiddencategories', context_coursecat
::instance($category->id
))) {
3423 $categories[] = $category;
3424 $categoryids[$category->id
] = $category;
3425 if (empty($CFG->maxcategorydepth
) ||
$depth <= $CFG->maxcategorydepth
) {
3426 list($category->categories
, $subcategories) = get_course_category_tree($category->id
, $depth+
1);
3427 foreach ($subcategories as $subid=>$subcat) {
3428 $categoryids[$subid] = $subcat;
3430 $category->courses
= array();
3435 // This is a recursive call so return the required array
3436 return array($categories, $categoryids);
3439 if (empty($categoryids)) {
3440 // No categories available (probably all hidden).
3444 // The depth is 0 this function has just been called so we can finish it off
3446 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE
, 'ctx');
3447 list($catsql, $catparams) = $DB->get_in_or_equal(array_keys($categoryids));
3449 c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary,c.category
3453 WHERE c.category $catsql ORDER BY c.sortorder ASC";
3454 if ($courses = $DB->get_records_sql($sql, $catparams)) {
3455 // loop throught them
3456 foreach ($courses as $course) {
3457 if ($course->id
== SITEID
) {
3460 context_helper
::preload_from_record($course);
3461 if (!empty($course->visible
) ||
has_capability('moodle/course:viewhiddencourses', context_course
::instance($course->id
))) {
3462 $categoryids[$course->category
]->courses
[$course->id
] = $course;
3470 * Print courses in category. If category is 0 then all courses are printed.
3472 * @deprecated since 2.5
3474 * To print a generic list of courses use:
3475 * $renderer = $PAGE->get_renderer('core', 'course');
3476 * echo $renderer->courses_list($courses);
3478 * To print list of all courses:
3479 * $renderer = $PAGE->get_renderer('core', 'course');
3480 * echo $renderer->frontpage_available_courses();
3482 * To print list of courses inside category:
3483 * $renderer = $PAGE->get_renderer('core', 'course');
3484 * echo $renderer->course_category($category); // this will also print subcategories
3486 * @param int|stdClass $category category object or id.
3487 * @return bool true if courses found and printed, else false.
3489 function print_courses($category) {
3490 global $CFG, $OUTPUT, $PAGE;
3491 require_once($CFG->libdir
. '/coursecatlib.php');
3492 debugging('Function print_courses() is deprecated, please use course renderer', DEBUG_DEVELOPER
);
3494 if (!is_object($category) && $category==0) {
3495 $courses = coursecat
::get(0)->get_courses(array('recursive' => true, 'summary' => true, 'coursecontacts' => true));
3497 $courses = coursecat
::get($category->id
)->get_courses(array('summary' => true, 'coursecontacts' => true));
3501 $renderer = $PAGE->get_renderer('core', 'course');
3502 echo $renderer->courses_list($courses);
3504 echo $OUTPUT->heading(get_string("nocoursesyet"));
3505 $context = context_system
::instance();
3506 if (has_capability('moodle/course:create', $context)) {
3508 if (!empty($category->id
)) {
3509 $options['category'] = $category->id
;
3511 $options['category'] = $CFG->defaultrequestcategory
;
3513 echo html_writer
::start_tag('div', array('class'=>'addcoursebutton'));
3514 echo $OUTPUT->single_button(new moodle_url('/course/edit.php', $options), get_string("addnewcourse"));
3515 echo html_writer
::end_tag('div');
3523 * Print a description of a course, suitable for browsing in a list.
3525 * @deprecated since 2.5
3527 * Please use course renderer to display a course information box.
3528 * $renderer = $PAGE->get_renderer('core', 'course');
3529 * echo $renderer->courses_list($courses); // will print list of courses
3530 * echo $renderer->course_info_box($course); // will print one course wrapped in div.generalbox
3532 * @param object $course the course object.
3533 * @param string $highlightterms Ignored in this deprecated function!
3535 function print_course($course, $highlightterms = '') {
3538 debugging('Function print_course() is deprecated, please use course renderer', DEBUG_DEVELOPER
);
3539 $renderer = $PAGE->get_renderer('core', 'course');
3540 // Please note, correct would be to use $renderer->coursecat_coursebox() but this function is protected.
3541 // To print list of courses use $renderer->courses_list();
3542 echo $renderer->course_info_box($course);
3546 * Gets an array whose keys are category ids and whose values are arrays of courses in the corresponding category.
3548 * @deprecated since 2.5
3550 * This function is not used any more in moodle core and course renderer does not have render function for it.
3551 * Combo list on the front page is displayed as:
3552 * $renderer = $PAGE->get_renderer('core', 'course');
3553 * echo $renderer->frontpage_combo_list()
3555 * The new class {@link coursecat} stores the information about course category tree
3556 * To get children categories use:
3557 * coursecat::get($id)->get_children()
3558 * To get list of courses use:
3559 * coursecat::get($id)->get_courses()
3561 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3563 * @param int $categoryid
3566 function get_category_courses_array($categoryid = 0) {
3567 debugging('Function get_category_courses_array() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER
);
3568 $tree = get_course_category_tree($categoryid);
3569 $flattened = array();
3570 foreach ($tree as $category) {
3571 get_category_courses_array_recursively($flattened, $category);
3577 * Recursive function to help flatten the course category tree.
3579 * @deprecated since 2.5
3581 * Was intended to be called from {@link get_category_courses_array()}
3583 * @param array &$flattened An array passed by reference in which to store courses for each category.
3584 * @param stdClass $category The category to get courses for.
3586 function get_category_courses_array_recursively(array &$flattened, $category) {
3587 debugging('Function get_category_courses_array_recursively() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER
);
3588 $flattened[$category->id
] = $category->courses
;
3589 foreach ($category->categories
as $childcategory) {
3590 get_category_courses_array_recursively($flattened, $childcategory);
3595 * Returns a URL based on the context of the current page.
3596 * This URL points to blog/index.php and includes filter parameters appropriate for the current page.
3598 * @param stdclass $context
3599 * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more.
3600 * @todo Remove this in 2.7
3603 function blog_get_context_url($context=null) {
3606 debugging('Function blog_get_context_url() is deprecated, getting params from context is not reliable for blogs.', DEBUG_DEVELOPER
);
3607 $viewblogentriesurl = new moodle_url('/blog/index.php');
3609 if (empty($context)) {
3611 $context = $PAGE->context
;
3614 // Change contextlevel to SYSTEM if viewing the site course
3615 if ($context->contextlevel
== CONTEXT_COURSE
&& $context->instanceid
== SITEID
) {
3616 $context = context_system
::instance();
3622 switch ($context->contextlevel
) {
3623 case CONTEXT_SYSTEM
:
3625 case CONTEXT_COURSECAT
:
3627 case CONTEXT_COURSE
:
3628 $filterparam = 'courseid';
3629 $strlevel = get_string('course');
3631 case CONTEXT_MODULE
:
3632 $filterparam = 'modid';
3633 $strlevel = $context->get_context_name();
3636 $filterparam = 'userid';
3637 $strlevel = get_string('user');
3641 if (!empty($filterparam)) {
3642 $viewblogentriesurl->param($filterparam, $context->instanceid
);
3645 return $viewblogentriesurl;
3649 * Retrieve course records with the course managers and other related records
3650 * that we need for print_course(). This allows print_courses() to do its job
3651 * in a constant number of DB queries, regardless of the number of courses,
3652 * role assignments, etc.
3654 * The returned array is indexed on c.id, and each course will have
3655 * - $course->managers - array containing RA objects that include a $user obj
3656 * with the minimal fields needed for fullname()
3658 * @deprecated since 2.5
3660 * To get list of all courses with course contacts ('managers') use
3661 * coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true));
3663 * To get list of courses inside particular category use
3664 * coursecat::get($id)->get_courses(array('coursecontacts' => true));
3666 * Additionally you can specify sort order, offset and maximum number of courses,
3667 * see {@link coursecat::get_courses()}
3669 * Please note that code of this function is not changed to use coursecat class because
3670 * coursecat::get_courses() returns result in slightly different format. Also note that
3671 * get_courses_wmanagers() DOES NOT check that users are enrolled in the course and
3672 * coursecat::get_courses() does.
3677 * @uses CONTEXT_COURSE
3678 * @uses CONTEXT_SYSTEM
3679 * @uses CONTEXT_COURSECAT
3681 * @param int|string $categoryid Either the categoryid for the courses or 'all'
3682 * @param string $sort A SQL sort field and direction
3683 * @param array $fields An array of additional fields to fetch
3686 function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) {
3690 * - Grab the courses JOINed w/context
3692 * - Grab the interesting course-manager RAs
3693 * JOINed with a base user obj and add them to each course
3695 * So as to do all the work in 2 DB queries. The RA+user JOIN
3696 * ends up being pretty expensive if it happens over _all_
3697 * courses on a large site. (Are we surprised!?)
3699 * So this should _never_ get called with 'all' on a large site.
3702 global $USER, $CFG, $DB;
3703 debugging('Function get_courses_wmanagers() is deprecated, please use coursecat::get_courses()', DEBUG_DEVELOPER
);
3706 $allcats = false; // bool flag
3707 if ($categoryid === 'all') {
3708 $categoryclause = '';
3710 } elseif (is_numeric($categoryid)) {
3711 $categoryclause = "c.category = :catid";
3712 $params['catid'] = $categoryid;
3714 debugging("Could not recognise categoryid = $categoryid");
3715 $categoryclause = '';
3718 $basefields = array('id', 'category', 'sortorder',
3719 'shortname', 'fullname', 'idnumber',
3720 'startdate', 'visible',
3721 'newsitems', 'groupmode', 'groupmodeforce');
3723 if (!is_null($fields) && is_string($fields)) {
3724 if (empty($fields)) {
3725 $fields = $basefields;
3727 // turn the fields from a string to an array that
3728 // get_user_courses_bycap() will like...
3729 $fields = explode(',',$fields);
3730 $fields = array_map('trim', $fields);
3731 $fields = array_unique(array_merge($basefields, $fields));
3733 } elseif (is_array($fields)) {
3734 $fields = array_merge($basefields,$fields);
3736 $coursefields = 'c.' .join(',c.', $fields);
3739 $sortstatement = "";
3741 $sortstatement = "ORDER BY $sort";
3744 $where = 'WHERE c.id != ' . SITEID
;
3745 if ($categoryclause !== ''){
3746 $where = "$where AND $categoryclause";
3749 // pull out all courses matching the cat
3750 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE
, 'ctx');
3751 $sql = "SELECT $coursefields $ccselect
3757 $catpaths = array();
3759 if ($courses = $DB->get_records_sql($sql, $params)) {
3760 // loop on courses materialising
3761 // the context, and prepping data to fetch the
3762 // managers efficiently later...
3763 foreach ($courses as $k => $course) {
3764 context_helper
::preload_from_record($course);
3765 $coursecontext = context_course
::instance($course->id
);
3766 $courses[$k] = $course;
3767 $courses[$k]->managers
= array();
3768 if ($allcats === false) {
3769 // single cat, so take just the first one...
3770 if ($catpath === NULL) {
3771 $catpath = preg_replace(':/\d+$:', '', $coursecontext->path
);
3774 // chop off the contextid of the course itself
3775 // like dirname() does...
3776 $catpaths[] = preg_replace(':/\d+$:', '', $coursecontext->path
);
3780 return array(); // no courses!
3783 $CFG->coursecontact
= trim($CFG->coursecontact
);
3784 if (empty($CFG->coursecontact
)) {
3788 $managerroles = explode(',', $CFG->coursecontact
);
3790 if (count($managerroles)) {
3791 if ($allcats === true) {
3792 $catpaths = array_unique($catpaths);
3794 foreach ($catpaths as $cpath) {
3795 $ctxids = array_merge($ctxids, explode('/',substr($cpath,1)));
3797 $ctxids = array_unique($ctxids);
3798 $catctxids = implode( ',' , $ctxids);
3802 // take the ctx path from the first course
3803 // as all categories will be the same...
3804 $catpath = substr($catpath,1);
3805 $catpath = preg_replace(':/\d+$:','',$catpath);
3806 $catctxids = str_replace('/',',',$catpath);
3808 if ($categoryclause !== '') {
3809 $categoryclause = "AND $categoryclause";
3812 * Note: Here we use a LEFT OUTER JOIN that can
3813 * "optionally" match to avoid passing a ton of context
3814 * ids in an IN() clause. Perhaps a subselect is faster.
3816 * In any case, this SQL is not-so-nice over large sets of
3817 * courses with no $categoryclause.
3820 $sql = "SELECT ctx.path, ctx.instanceid, ctx.contextlevel,
3821 r.id AS roleid, r.name AS rolename, r.shortname AS roleshortname,
3822 rn.name AS rolecoursealias, u.id AS userid, u.firstname, u.lastname
3823 FROM {role_assignments} ra
3824 JOIN {context} ctx ON ra.contextid = ctx.id
3825 JOIN {user} u ON ra.userid = u.id
3826 JOIN {role} r ON ra.roleid = r.id
3827 LEFT JOIN {role_names} rn ON (rn.contextid = ctx.id AND rn.roleid = r.id)
3828 LEFT OUTER JOIN {course} c
3829 ON (ctx.instanceid=c.id AND ctx.contextlevel=".CONTEXT_COURSE
.")
3830 WHERE ( c.id IS NOT NULL";
3831 // under certain conditions, $catctxids is NULL
3832 if($catctxids == NULL){
3835 $sql .= " OR ra.contextid IN ($catctxids) )";
3838 $sql .= "AND ra.roleid IN ({$CFG->coursecontact})
3840 ORDER BY r.sortorder ASC, ctx.contextlevel ASC, ra.sortorder ASC";
3841 $rs = $DB->get_recordset_sql($sql, $params);
3843 // This loop is fairly stupid as it stands - might get better
3844 // results doing an initial pass clustering RAs by path.
3845 foreach($rs as $ra) {
3846 $user = new stdClass
;
3847 $user->id
= $ra->userid
; unset($ra->userid
);
3848 $user->firstname
= $ra->firstname
; unset($ra->firstname
);
3849 $user->lastname
= $ra->lastname
; unset($ra->lastname
);
3851 if ($ra->contextlevel
== CONTEXT_SYSTEM
) {
3852 foreach ($courses as $k => $course) {
3853 $courses[$k]->managers
[] = $ra;
3855 } else if ($ra->contextlevel
== CONTEXT_COURSECAT
) {
3856 if ($allcats === false) {
3857 // It always applies
3858 foreach ($courses as $k => $course) {
3859 $courses[$k]->managers
[] = $ra;
3862 foreach ($courses as $k => $course) {
3863 $coursecontext = context_course
::instance($course->id
);
3864 // Note that strpos() returns 0 as "matched at pos 0"
3865 if (strpos($coursecontext->path
, $ra->path
.'/') === 0) {
3866 // Only add it to subpaths
3867 $courses[$k]->managers
[] = $ra;
3871 } else { // course-level
3872 if (!array_key_exists($ra->instanceid
, $courses)) {
3873 //this course is not in a list, probably a frontpage course
3876 $courses[$ra->instanceid
]->managers
[] = $ra;
3886 * Converts a nested array tree into HTML ul:li [recursive]
3888 * @deprecated since 2.5
3890 * @param array $tree A tree array to convert
3891 * @param int $row Used in identifying the iteration level and in ul classes
3892 * @return string HTML structure
3894 function convert_tree_to_html($tree, $row=0) {
3895 debugging('Function convert_tree_to_html() is deprecated since Moodle 2.5. Consider using class tabtree and core_renderer::render_tabtree()', DEBUG_DEVELOPER
);
3897 $str = "\n".'<ul class="tabrow'.$row.'">'."\n";
3900 $count = count($tree);
3902 foreach ($tree as $tab) {
3903 $count--; // countdown to zero
3907 if ($first && ($count == 0)) { // Just one in the row
3908 $liclass = 'first last';
3910 } else if ($first) {
3913 } else if ($count == 0) {
3917 if ((empty($tab->subtree
)) && (!empty($tab->selected
))) {
3918 $liclass .= (empty($liclass)) ?
'onerow' : ' onerow';
3921 if ($tab->inactive ||
$tab->active ||
$tab->selected
) {
3922 if ($tab->selected
) {
3923 $liclass .= (empty($liclass)) ?
'here selected' : ' here selected';
3924 } else if ($tab->active
) {
3925 $liclass .= (empty($liclass)) ?
'here active' : ' here active';
3929 $str .= (!empty($liclass)) ?
'<li class="'.$liclass.'">' : '<li>';
3931 if ($tab->inactive ||
$tab->active ||
($tab->selected
&& !$tab->linkedwhenselected
)) {
3932 // The a tag is used for styling
3933 $str .= '<a class="nolink"><span>'.$tab->text
.'</span></a>';
3935 $str .= '<a href="'.$tab->link
.'" title="'.$tab->title
.'"><span>'.$tab->text
.'</span></a>';
3938 if (!empty($tab->subtree
)) {
3939 $str .= convert_tree_to_html($tab->subtree
, $row+
1);
3940 } else if ($tab->selected
) {
3941 $str .= '<div class="tabrow'.($row+
1).' empty"> </div>'."\n";
3944 $str .= ' </li>'."\n";
3946 $str .= '</ul>'."\n";
3952 * Convert nested tabrows to a nested array
3954 * @deprecated since 2.5
3956 * @param array $tabrows A [nested] array of tab row objects
3957 * @param string $selected The tabrow to select (by id)
3958 * @param array $inactive An array of tabrow id's to make inactive
3959 * @param array $activated An array of tabrow id's to make active
3960 * @return array The nested array
3962 function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) {
3964 debugging('Function convert_tabrows_to_tree() is deprecated since Moodle 2.5. Consider using class tabtree', DEBUG_DEVELOPER
);
3966 // Work backwards through the rows (bottom to top) collecting the tree as we go.
3967 $tabrows = array_reverse($tabrows);
3971 foreach ($tabrows as $row) {
3974 foreach ($row as $tab) {
3975 $tab->inactive
= in_array((string)$tab->id
, $inactive);
3976 $tab->active
= in_array((string)$tab->id
, $activated);
3977 $tab->selected
= (string)$tab->id
== $selected;
3979 if ($tab->active ||
$tab->selected
) {
3981 $tab->subtree
= $subtree;
3993 * @deprecated since Moodle 2.3
3995 function move_section($course, $section, $move) {
3996 throw new coding_exception('move_section() can not be used any more, please see move_section_to().');
3999 * Can handle rotated text. Whether it is safe to use the trickery in textrotate.js.
4001 * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically
4002 * @return bool True for yes, false for no
4004 function can_use_rotated_text() {
4005 debugging('can_use_rotated_text() is deprecated since Moodle 2.5. JS feature detection is used automatically.', DEBUG_DEVELOPER
);
4010 * Get the context instance as an object. This function will create the
4011 * context instance if it does not exist yet.
4013 * @deprecated since 2.2, use context_course::instance() or other relevant class instead
4014 * @todo This will be deleted in Moodle 2.8, refer MDL-34472
4015 * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
4016 * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
4017 * for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
4018 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
4019 * MUST_EXIST means throw exception if no record or multiple records found
4020 * @return context The context object.
4022 function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING
) {
4024 debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER
);
4026 $instances = (array)$instance;
4027 $contexts = array();
4029 $classname = context_helper
::get_class_for_level($contextlevel);
4031 // we do not load multiple contexts any more, PAGE should be responsible for any preloading
4032 foreach ($instances as $inst) {
4033 $contexts[$inst] = $classname::instance($inst, $strictness);
4036 if (is_array($instance)) {
4039 return $contexts[$instance];
4044 * Get a context instance as an object, from a given context id.
4046 * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more.
4047 * @todo MDL-34550 This will be deleted in Moodle 2.8
4048 * @see context::instance_by_id($id)
4049 * @param int $id context id
4050 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
4051 * MUST_EXIST means throw exception if no record or multiple records found
4052 * @return context|bool the context object or false if not found.
4054 function get_context_instance_by_id($id, $strictness = IGNORE_MISSING
) {
4055 debugging('get_context_instance_by_id() is deprecated, please use context::instance_by_id($id) instead.', DEBUG_DEVELOPER
);
4056 return context
::instance_by_id($id, $strictness);
4060 * @deprecated since Moodle 2.2
4061 * @see load_temp_course_role()
4063 function load_temp_role($context, $roleid, array $accessdata) {
4064 throw new coding_exception('load_temp_role() can not be used any more, please use load_temp_course_role()');
4068 * @deprecated since Moodle 2.2
4069 * @see remove_temp_course_roles()
4071 function remove_temp_roles($context, array $accessdata) {
4072 throw new coding_exception('remove_temp_roles() can not be used any more, please use remove_temp_course_roles()');
4076 * Returns system context or null if can not be created yet.
4078 * @see context_system::instance()
4079 * @deprecated since 2.2
4080 * @param bool $cache use caching
4081 * @return context system context (null if context table not created yet)
4083 function get_system_context($cache = true) {
4084 debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER
);
4085 return context_system
::instance(0, IGNORE_MISSING
, $cache);
4089 * Recursive function which, given a context, find all parent context ids,
4090 * and return the array in reverse order, i.e. parent first, then grand
4093 * @see context::get_parent_context_ids()
4094 * @deprecated since 2.2, use $context->get_parent_context_ids() instead
4095 * @param context $context
4096 * @param bool $includeself optional, defaults to false
4099 function get_parent_contexts(context
$context, $includeself = false) {
4100 debugging('get_parent_contexts() is deprecated, please use $context->get_parent_context_ids() instead.', DEBUG_DEVELOPER
);
4101 return $context->get_parent_context_ids($includeself);
4105 * Return the id of the parent of this context, or false if there is no parent (only happens if this
4106 * is the site context.)
4108 * @deprecated since Moodle 2.2
4109 * @see context::get_parent_context()
4110 * @param context $context
4111 * @return integer the id of the parent context.
4113 function get_parent_contextid(context
$context) {
4114 debugging('get_parent_contextid() is deprecated, please use $context->get_parent_context() instead.', DEBUG_DEVELOPER
);
4116 if ($parent = $context->get_parent_context()) {
4124 * Recursive function which, given a context, find all its children contexts.
4126 * For course category contexts it will return immediate children only categories and courses.
4127 * It will NOT recurse into courses or child categories.
4128 * If you want to do that, call it on the returned courses/categories.
4130 * When called for a course context, it will return the modules and blocks
4131 * displayed in the course page.
4133 * If called on a user/course/module context it _will_ populate the cache with the appropriate
4136 * @see context::get_child_contexts()
4137 * @deprecated since 2.2
4138 * @param context $context
4139 * @return array Array of child records
4141 function get_child_contexts(context
$context) {
4142 debugging('get_child_contexts() is deprecated, please use $context->get_child_contexts() instead.', DEBUG_DEVELOPER
);
4143 return $context->get_child_contexts();
4147 * Precreates all contexts including all parents.
4149 * @see context_helper::create_instances()
4150 * @deprecated since 2.2
4151 * @param int $contextlevel empty means all
4152 * @param bool $buildpaths update paths and depths
4155 function create_contexts($contextlevel = null, $buildpaths = true) {
4156 debugging('create_contexts() is deprecated, please use context_helper::create_instances() instead.', DEBUG_DEVELOPER
);
4157 context_helper
::create_instances($contextlevel, $buildpaths);
4161 * Remove stale context records.
4163 * @see context_helper::cleanup_instances()
4164 * @deprecated since 2.2
4167 function cleanup_contexts() {
4168 debugging('cleanup_contexts() is deprecated, please use context_helper::cleanup_instances() instead.', DEBUG_DEVELOPER
);
4169 context_helper
::cleanup_instances();
4174 * Populate context.path and context.depth where missing.
4176 * @see context_helper::build_all_paths()
4177 * @deprecated since 2.2
4178 * @param bool $force force a complete rebuild of the path and depth fields, defaults to false
4181 function build_context_path($force = false) {
4182 debugging('build_context_path() is deprecated, please use context_helper::build_all_paths() instead.', DEBUG_DEVELOPER
);
4183 context_helper
::build_all_paths($force);
4187 * Rebuild all related context depth and path caches.
4189 * @see context::reset_paths()
4190 * @deprecated since 2.2
4191 * @param array $fixcontexts array of contexts, strongtyped
4194 function rebuild_contexts(array $fixcontexts) {
4195 debugging('rebuild_contexts() is deprecated, please use $context->reset_paths(true) instead.', DEBUG_DEVELOPER
);
4196 foreach ($fixcontexts as $fixcontext) {
4197 $fixcontext->reset_paths(false);
4199 context_helper
::build_all_paths(false);
4203 * Preloads all contexts relating to a course: course, modules. Block contexts
4204 * are no longer loaded here. The contexts for all the blocks on the current
4205 * page are now efficiently loaded by {@link block_manager::load_blocks()}.
4207 * @deprecated since Moodle 2.2
4208 * @see context_helper::preload_course()
4209 * @param int $courseid Course ID
4212 function preload_course_contexts($courseid) {
4213 debugging('preload_course_contexts() is deprecated, please use context_helper::preload_course() instead.', DEBUG_DEVELOPER
);
4214 context_helper
::preload_course($courseid);
4218 * Update the path field of the context and all dep. subcontexts that follow
4220 * Update the path field of the context and
4221 * all the dependent subcontexts that follow
4224 * The most important thing here is to be as
4225 * DB efficient as possible. This op can have a
4226 * massive impact in the DB.
4228 * @deprecated since Moodle 2.2
4229 * @see context::update_moved()
4230 * @param context $context context obj
4231 * @param context $newparent new parent obj
4234 function context_moved(context
$context, context
$newparent) {
4235 debugging('context_moved() is deprecated, please use context::update_moved() instead.', DEBUG_DEVELOPER
);
4236 $context->update_moved($newparent);
4240 * Extracts the relevant capabilities given a contextid.
4241 * All case based, example an instance of forum context.
4242 * Will fetch all forum related capabilities, while course contexts
4243 * Will fetch all capabilities
4246 * `name` varchar(150) NOT NULL,
4247 * `captype` varchar(50) NOT NULL,
4248 * `contextlevel` int(10) NOT NULL,
4249 * `component` varchar(100) NOT NULL,
4251 * @see context::get_capabilities()
4252 * @deprecated since 2.2
4253 * @param context $context
4256 function fetch_context_capabilities(context
$context) {
4257 debugging('fetch_context_capabilities() is deprecated, please use $context->get_capabilities() instead.', DEBUG_DEVELOPER
);
4258 return $context->get_capabilities();
4262 * Preloads context information from db record and strips the cached info.
4263 * The db request has to contain both the $join and $select from context_instance_preload_sql()
4265 * @deprecated since 2.2
4266 * @see context_helper::preload_from_record()
4267 * @param stdClass $rec
4268 * @return void (modifies $rec)
4270 function context_instance_preload(stdClass
$rec) {
4271 debugging('context_instance_preload() is deprecated, please use context_helper::preload_from_record() instead.', DEBUG_DEVELOPER
);
4272 context_helper
::preload_from_record($rec);
4276 * Returns context level name
4278 * @deprecated since 2.2
4279 * @see context_helper::get_level_name()
4280 * @param integer $contextlevel $context->context level. One of the CONTEXT_... constants.
4281 * @return string the name for this type of context.
4283 function get_contextlevel_name($contextlevel) {
4284 debugging('get_contextlevel_name() is deprecated, please use context_helper::get_level_name() instead.', DEBUG_DEVELOPER
);
4285 return context_helper
::get_level_name($contextlevel);
4289 * Prints human readable context identifier.
4291 * @deprecated since 2.2
4292 * @see context::get_context_name()
4293 * @param context $context the context.
4294 * @param boolean $withprefix whether to prefix the name of the context with the
4295 * type of context, e.g. User, Course, Forum, etc.
4296 * @param boolean $short whether to user the short name of the thing. Only applies
4297 * to course contexts
4298 * @return string the human readable context name.
4300 function print_context_name(context
$context, $withprefix = true, $short = false) {
4301 debugging('print_context_name() is deprecated, please use $context->get_context_name() instead.', DEBUG_DEVELOPER
);
4302 return $context->get_context_name($withprefix, $short);
4306 * Mark a context as dirty (with timestamp) so as to force reloading of the context.
4308 * @deprecated since 2.2, use $context->mark_dirty() instead
4309 * @see context::mark_dirty()
4310 * @param string $path context path
4312 function mark_context_dirty($path) {
4313 global $CFG, $USER, $ACCESSLIB_PRIVATE;
4314 debugging('mark_context_dirty() is deprecated, please use $context->mark_dirty() instead.', DEBUG_DEVELOPER
);
4316 if (during_initial_install()) {
4320 // only if it is a non-empty string
4321 if (is_string($path) && $path !== '') {
4322 set_cache_flag('accesslib/dirtycontexts', $path, 1, time()+
$CFG->sessiontimeout
);
4323 if (isset($ACCESSLIB_PRIVATE->dirtycontexts
)) {
4324 $ACCESSLIB_PRIVATE->dirtycontexts
[$path] = 1;
4327 $ACCESSLIB_PRIVATE->dirtycontexts
= array($path => 1);
4329 if (isset($USER->access
['time'])) {
4330 $ACCESSLIB_PRIVATE->dirtycontexts
= get_cache_flags('accesslib/dirtycontexts', $USER->access
['time']-2);
4332 $ACCESSLIB_PRIVATE->dirtycontexts
= array($path => 1);
4334 // flags not loaded yet, it will be done later in $context->reload_if_dirty()
4341 * Remove a context record and any dependent entries,
4342 * removes context from static context cache too
4344 * @deprecated since Moodle 2.2
4345 * @see context_helper::delete_instance() or context::delete_content()
4346 * @param int $contextlevel
4347 * @param int $instanceid
4348 * @param bool $deleterecord false means keep record for now
4349 * @return bool returns true or throws an exception
4351 function delete_context($contextlevel, $instanceid, $deleterecord = true) {
4352 if ($deleterecord) {
4353 debugging('delete_context() is deprecated, please use context_helper::delete_instance() instead.', DEBUG_DEVELOPER
);
4354 context_helper
::delete_instance($contextlevel, $instanceid);
4356 debugging('delete_context() is deprecated, please use $context->delete_content() instead.', DEBUG_DEVELOPER
);
4357 $classname = context_helper
::get_class_for_level($contextlevel);
4358 if ($context = $classname::instance($instanceid, IGNORE_MISSING
)) {
4359 $context->delete_content();
4367 * Get a URL for a context, if there is a natural one. For example, for
4368 * CONTEXT_COURSE, this is the course page. For CONTEXT_USER it is the
4369 * user profile page.
4371 * @deprecated since 2.2
4372 * @see context::get_url()
4373 * @param context $context the context
4374 * @return moodle_url
4376 function get_context_url(context
$context) {
4377 debugging('get_context_url() is deprecated, please use $context->get_url() instead.', DEBUG_DEVELOPER
);
4378 return $context->get_url();
4382 * Is this context part of any course? if yes return course context,
4383 * if not return null or throw exception.
4385 * @deprecated since 2.2
4386 * @see context::get_course_context()
4387 * @param context $context
4388 * @return context_course context of the enclosing course, null if not found or exception
4390 function get_course_context(context
$context) {
4391 debugging('get_course_context() is deprecated, please use $context->get_course_context(true) instead.', DEBUG_DEVELOPER
);
4392 return $context->get_course_context(true);
4396 * Get an array of courses where cap requested is available
4397 * and user is enrolled, this can be relatively slow.
4399 * @deprecated since 2.2
4400 * @see enrol_get_users_courses()
4401 * @param int $userid A user id. By default (null) checks the permissions of the current user.
4402 * @param string $cap - name of the capability
4403 * @param array $accessdata_ignored
4404 * @param bool $doanything_ignored
4405 * @param string $sort - sorting fields - prefix each fieldname with "c."
4406 * @param array $fields - additional fields you are interested in...
4407 * @param int $limit_ignored
4408 * @return array $courses - ordered array of course objects - see notes above
4410 function get_user_courses_bycap($userid, $cap, $accessdata_ignored, $doanything_ignored, $sort = 'c.sortorder ASC', $fields = null, $limit_ignored = 0) {
4412 debugging('get_user_courses_bycap() is deprecated, please use enrol_get_users_courses() instead.', DEBUG_DEVELOPER
);
4413 $courses = enrol_get_users_courses($userid, true, $fields, $sort);
4414 foreach ($courses as $id=>$course) {
4415 $context = context_course
::instance($id);
4416 if (!has_capability($cap, $context, $userid)) {
4417 unset($courses[$id]);
4425 * This is really slow!!! do not use above course context level
4427 * @deprecated since Moodle 2.2
4428 * @param int $roleid
4429 * @param context $context
4432 function get_role_context_caps($roleid, context
$context) {
4434 debugging('get_role_context_caps() is deprecated, it is really slow. Don\'t use it.', DEBUG_DEVELOPER
);
4436 // This is really slow!!!! - do not use above course context level.
4438 $result[$context->id
] = array();
4440 // First emulate the parent context capabilities merging into context.
4441 $searchcontexts = array_reverse($context->get_parent_context_ids(true));
4442 foreach ($searchcontexts as $cid) {
4443 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
4444 foreach ($capabilities as $cap) {
4445 if (!array_key_exists($cap->capability
, $result[$context->id
])) {
4446 $result[$context->id
][$cap->capability
] = 0;
4448 $result[$context->id
][$cap->capability
] +
= $cap->permission
;
4453 // Now go through the contexts below given context.
4454 $searchcontexts = array_keys($context->get_child_contexts());
4455 foreach ($searchcontexts as $cid) {
4456 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
4457 foreach ($capabilities as $cap) {
4458 if (!array_key_exists($cap->contextid
, $result)) {
4459 $result[$cap->contextid
] = array();
4461 $result[$cap->contextid
][$cap->capability
] = $cap->permission
;
4470 * Returns current course id or false if outside of course based on context parameter.
4472 * @see context::get_course_context()
4473 * @deprecated since 2.2
4474 * @param context $context
4475 * @return int|bool related course id or false
4477 function get_courseid_from_context(context
$context) {
4478 debugging('get_courseid_from_context() is deprecated, please use $context->get_course_context(false) instead.', DEBUG_DEVELOPER
);
4479 if ($coursecontext = $context->get_course_context(false)) {
4480 return $coursecontext->instanceid
;
4487 * Preloads context information together with instances.
4488 * Use context_instance_preload() to strip the context info from the record and cache the context instance.
4490 * If you are using this methid, you should have something like this:
4492 * list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
4494 * To prevent the use of this deprecated function, replace the line above with something similar to this:
4496 * $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
4498 * $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
4500 * $params = array('contextlevel' => CONTEXT_COURSE);
4502 * @see context_helper:;get_preload_record_columns_sql()
4503 * @deprecated since 2.2
4504 * @param string $joinon for example 'u.id'
4505 * @param string $contextlevel context level of instance in $joinon
4506 * @param string $tablealias context table alias
4507 * @return array with two values - select and join part
4509 function context_instance_preload_sql($joinon, $contextlevel, $tablealias) {
4510 debugging('context_instance_preload_sql() is deprecated, please use context_helper::get_preload_record_columns_sql() instead.', DEBUG_DEVELOPER
);
4511 $select = ", " . context_helper
::get_preload_record_columns_sql($tablealias);
4512 $join = "LEFT JOIN {context} $tablealias ON ($tablealias.instanceid = $joinon AND $tablealias.contextlevel = $contextlevel)";
4513 return array($select, $join);
4517 * Gets a string for sql calls, searching for stuff in this context or above.
4519 * @deprecated since 2.2
4520 * @see context::get_parent_context_ids()
4521 * @param context $context
4524 function get_related_contexts_string(context
$context) {
4525 debugging('get_related_contexts_string() is deprecated, please use $context->get_parent_context_ids(true) instead.', DEBUG_DEVELOPER
);
4526 if ($parents = $context->get_parent_context_ids()) {
4527 return (' IN ('.$context->id
.','.implode(',', $parents).')');
4529 return (' ='.$context->id
);
4534 * @deprecated since Moodle 2.0 - use $PAGE->user_is_editing() instead.
4535 * @see moodle_page->user_is_editing()
4537 function isediting() {
4538 throw new coding_exception('isediting() can not be used any more, please use $PAGE->user_is_editing() instead.');
4542 * Get a list of all the plugins of a given type that contain a particular file.
4544 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
4545 * @param string $file the name of file that must be present in the plugin.
4546 * (e.g. 'view.php', 'db/install.xml').
4547 * @param bool $include if true (default false), the file will be include_once-ed if found.
4548 * @return array with plugin name as keys (e.g. 'forum', 'courselist') and the path
4549 * to the file relative to dirroot as value (e.g. "$CFG->dirroot/mod/forum/view.php").
4550 * @deprecated since 2.6
4551 * @see core_component::get_plugin_list_with_file()
4553 function get_plugin_list_with_file($plugintype, $file, $include = false) {
4554 debugging('get_plugin_list_with_file() is deprecated, please use core_component::get_plugin_list_with_file() instead.',
4556 return core_component
::get_plugin_list_with_file($plugintype, $file, $include);
4560 * Checks to see if is the browser operating system matches the specified brand.
4562 * Known brand: 'Windows','Linux','Macintosh','SGI','SunOS','HP-UX'
4564 * @deprecated since 2.6
4565 * @param string $brand The operating system identifier being tested
4566 * @return bool true if the given brand below to the detected operating system
4568 function check_browser_operating_system($brand) {
4569 debugging('check_browser_operating_system has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER
);
4570 return core_useragent
::check_browser_operating_system($brand);
4574 * Checks to see if is a browser matches the specified
4575 * brand and is equal or better version.
4577 * @deprecated since 2.6
4578 * @param string $brand The browser identifier being tested
4579 * @param int $version The version of the browser, if not specified any version (except 5.5 for IE for BC reasons)
4580 * @return bool true if the given version is below that of the detected browser
4582 function check_browser_version($brand, $version = null) {
4583 debugging('check_browser_version has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER
);
4584 return core_useragent
::check_browser_version($brand, $version);
4588 * Returns whether a device/browser combination is mobile, tablet, legacy, default or the result of
4589 * an optional admin specified regular expression. If enabledevicedetection is set to no or not set
4590 * it returns default
4592 * @deprecated since 2.6
4593 * @return string device type
4595 function get_device_type() {
4596 debugging('get_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER
);
4597 return core_useragent
::get_device_type();
4601 * Returns a list of the device types supporting by Moodle
4603 * @deprecated since 2.6
4604 * @param boolean $incusertypes includes types specified using the devicedetectregex admin setting
4605 * @return array $types
4607 function get_device_type_list($incusertypes = true) {
4608 debugging('get_device_type_list has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER
);
4609 return core_useragent
::get_device_type_list($incusertypes);
4613 * Returns the theme selected for a particular device or false if none selected.
4615 * @deprecated since 2.6
4616 * @param string $devicetype
4617 * @return string|false The name of the theme to use for the device or the false if not set
4619 function get_selected_theme_for_device_type($devicetype = null) {
4620 debugging('get_selected_theme_for_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER
);
4621 return core_useragent
::get_device_type_theme($devicetype);
4625 * Returns the name of the device type theme var in $CFG because there is not a convention to allow backwards compatibility.
4627 * @deprecated since 2.6
4628 * @param string $devicetype
4629 * @return string The config variable to use to determine the theme
4631 function get_device_cfg_var_name($devicetype = null) {
4632 debugging('get_device_cfg_var_name has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER
);
4633 return core_useragent
::get_device_type_cfg_var_name($devicetype);
4637 * Allows the user to switch the device they are seeing the theme for.
4638 * This allows mobile users to switch back to the default theme, or theme for any other device.
4640 * @deprecated since 2.6
4641 * @param string $newdevice The device the user is currently using.
4642 * @return string The device the user has switched to
4644 function set_user_device_type($newdevice) {
4645 debugging('set_user_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER
);
4646 return core_useragent
::set_user_device_type($newdevice);
4650 * Returns the device the user is currently using, or if the user has chosen to switch devices
4651 * for the current device type the type they have switched to.
4653 * @deprecated since 2.6
4654 * @return string The device the user is currently using or wishes to use
4656 function get_user_device_type() {
4657 debugging('get_user_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER
);
4658 return core_useragent
::get_user_device_type();
4662 * Returns one or several CSS class names that match the user's browser. These can be put
4663 * in the body tag of the page to apply browser-specific rules without relying on CSS hacks
4665 * @deprecated since 2.6
4666 * @return array An array of browser version classes
4668 function get_browser_version_classes() {
4669 debugging('get_browser_version_classes has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER
);
4670 return core_useragent
::get_browser_version_classes();
4674 * Generate a fake user for emails based on support settings
4676 * @deprecated since Moodle 2.6
4677 * @see core_user::get_support_user()
4678 * @return stdClass user info
4680 function generate_email_supportuser() {
4681 debugging('generate_email_supportuser is deprecated, please use core_user::get_support_user');
4682 return core_user
::get_support_user();
4686 * Get issued badge details for assertion URL
4688 * @deprecated since Moodle 2.6
4689 * @param string $hash Unique hash of a badge
4690 * @return array Information about issued badge.
4692 function badges_get_issued_badge_info($hash) {
4693 debugging('Function badges_get_issued_badge_info() is deprecated. Please use core_badges_assertion class and methods to generate badge assertion.', DEBUG_DEVELOPER
);
4694 $assertion = new core_badges_assertion($hash);
4695 return $assertion->get_badge_assertion();
4699 * Does the user want and can edit using rich text html editor?
4700 * This function does not make sense anymore because a user can directly choose their preferred editor.
4702 * @deprecated since 2.6
4705 function can_use_html_editor() {
4706 debugging('can_use_html_editor has been deprecated please update your code to assume it returns true.', DEBUG_DEVELOPER
);