MDL-31936 workshop: Delete attachments on record removal
[moodle.git] / lib / deprecatedlib.php
blob506511449f8c13f24ef00f34db22b558ee6222c5
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * deprecatedlib.php - Old functions retained only for backward compatibility
21 * Old functions retained only for backward compatibility. New code should not
22 * use any of these functions.
24 * @package core
25 * @subpackage deprecated
26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 * @deprecated
31 defined('MOODLE_INTERNAL') || die();
33 /**
34 * Add an entry to the legacy log table.
36 * @deprecated since 2.7 use new events instead
38 * @param int $courseid The course id
39 * @param string $module The module name e.g. forum, journal, resource, course, user etc
40 * @param string $action 'view', 'update', 'add' or 'delete', possibly followed by another word to clarify.
41 * @param string $url The file and parameters used to see the results of the action
42 * @param string $info Additional description information
43 * @param int $cm The course_module->id if there is one
44 * @param int|stdClass $user If log regards $user other than $USER
45 * @return void
47 function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user=0) {
48 debugging('add_to_log() has been deprecated, please rewrite your code to the new events API', DEBUG_DEVELOPER);
50 // This is a nasty hack that allows us to put all the legacy stuff into legacy storage,
51 // this way we may move all the legacy settings there too.
52 $manager = get_log_manager();
53 if (method_exists($manager, 'legacy_add_to_log')) {
54 $manager->legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user);
58 /**
59 * Adds a file upload to the log table so that clam can resolve the filename to the user later if necessary
61 * @deprecated since 2.7 - use new file picker instead
63 * @param string $newfilepath
64 * @param stdClass $course
65 * @param bool $nourl
67 function clam_log_upload($newfilepath, $course=null, $nourl=false) {
68 debugging('clam_log_upload() is not supposed to be used any more, use new file picker instead', DEBUG_DEVELOPER);
71 /**
72 * This function logs to error_log and to the log table that an infected file has been found and what's happened to it.
74 * @deprecated since 2.7 - use new file picker instead
76 * @param string $oldfilepath
77 * @param string $newfilepath
78 * @param int $userid The user
80 function clam_log_infected($oldfilepath='', $newfilepath='', $userid=0) {
81 debugging('clam_log_infected() is not supposed to be used any more, use new file picker instead', DEBUG_DEVELOPER);
84 /**
85 * Some of the modules allow moving attachments (glossary), in which case we need to hunt down an original log and change the path.
87 * @deprecated since 2.7 - use new file picker instead
89 * @param string $oldpath
90 * @param string $newpath
91 * @param boolean $update
93 function clam_change_log($oldpath, $newpath, $update=true) {
94 debugging('clam_change_log() is not supposed to be used any more, use new file picker instead', DEBUG_DEVELOPER);
97 /**
98 * Replaces the given file with a string.
100 * @deprecated since 2.7 - infected files are now deleted in file picker
102 * @param string $file
103 * @return boolean
105 function clam_replace_infected_file($file) {
106 debugging('clam_change_log() is not supposed to be used any more', DEBUG_DEVELOPER);
107 return false;
111 * Checks whether the password compatibility library will work with the current
112 * version of PHP. This cannot be done using PHP version numbers since the fix
113 * has been backported to earlier versions in some distributions.
115 * See https://github.com/ircmaxell/password_compat/issues/10 for more details.
117 * @deprecated since 2.7 PHP 5.4.x should be always compatible.
119 * @return bool always returns false
121 function password_compat_not_supported() {
122 debugging('Do not use password_compat_not_supported() - bcrypt is now always available', DEBUG_DEVELOPER);
123 return false;
127 * Factory method that was returning moodle_session object.
129 * @deprecated since 2.6
130 * @return \core\session\manager
132 function session_get_instance() {
133 // Note: the new session manager includes all methods from the original session class.
134 static $deprecatedinstance = null;
136 debugging('session_get_instance() is deprecated, use \core\session\manager instead', DEBUG_DEVELOPER);
138 if (!$deprecatedinstance) {
139 $deprecatedinstance = new \core\session\manager();
142 return $deprecatedinstance;
146 * Returns true if legacy session used.
148 * @deprecated since 2.6
149 * @return bool
151 function session_is_legacy() {
152 debugging('session_is_legacy() is deprecated, do not use any more', DEBUG_DEVELOPER);
153 return false;
157 * Terminates all sessions, auth hooks are not executed.
158 * Useful in upgrade scripts.
160 * @deprecated since 2.6
162 function session_kill_all() {
163 debugging('session_kill_all() is deprecated, use \core\session\manager::kill_all_sessions() instead', DEBUG_DEVELOPER);
164 \core\session\manager::kill_all_sessions();
168 * Mark session as accessed, prevents timeouts.
170 * @deprecated since 2.6
171 * @param string $sid
173 function session_touch($sid) {
174 debugging('session_touch() is deprecated, use \core\session\manager::touch_session() instead', DEBUG_DEVELOPER);
175 \core\session\manager::touch_session($sid);
179 * Terminates one sessions, auth hooks are not executed.
181 * @deprecated since 2.6
182 * @param string $sid session id
184 function session_kill($sid) {
185 debugging('session_kill() is deprecated, use \core\session\manager::kill_session() instead', DEBUG_DEVELOPER);
186 \core\session\manager::kill_session($sid);
190 * Terminates all sessions of one user, auth hooks are not executed.
191 * NOTE: This can not work for file based sessions!
193 * @deprecated since 2.6
194 * @param int $userid user id
196 function session_kill_user($userid) {
197 debugging('session_kill_user() is deprecated, use \core\session\manager::kill_user_sessions() instead', DEBUG_DEVELOPER);
198 \core\session\manager::kill_user_sessions($userid);
202 * Setup $USER object - called during login, loginas, etc.
204 * Call sync_user_enrolments() manually after log-in, or log-in-as.
206 * @deprecated since 2.6
207 * @param stdClass $user full user record object
208 * @return void
210 function session_set_user($user) {
211 debugging('session_set_user() is deprecated, use \core\session\manager::set_user() instead', DEBUG_DEVELOPER);
212 \core\session\manager::set_user($user);
216 * Is current $USER logged-in-as somebody else?
217 * @deprecated since 2.6
218 * @return bool
220 function session_is_loggedinas() {
221 debugging('session_is_loggedinas() is deprecated, use \core\session\manager::is_loggedinas() instead', DEBUG_DEVELOPER);
222 return \core\session\manager::is_loggedinas();
226 * Returns the $USER object ignoring current login-as session
227 * @deprecated since 2.6
228 * @return stdClass user object
230 function session_get_realuser() {
231 debugging('session_get_realuser() is deprecated, use \core\session\manager::get_realuser() instead', DEBUG_DEVELOPER);
232 return \core\session\manager::get_realuser();
236 * Login as another user - no security checks here.
237 * @deprecated since 2.6
238 * @param int $userid
239 * @param stdClass $context
240 * @return void
242 function session_loginas($userid, $context) {
243 debugging('session_loginas() is deprecated, use \core\session\manager::loginas() instead', DEBUG_DEVELOPER);
244 \core\session\manager::loginas($userid, $context);
248 * Minify JavaScript files.
250 * @deprecated since 2.6
252 * @param array $files
253 * @return string
255 function js_minify($files) {
256 debugging('js_minify() is deprecated, use core_minify::js_files() or core_minify::js() instead.');
257 return core_minify::js_files($files);
261 * Minify CSS files.
263 * @deprecated since 2.6
265 * @param array $files
266 * @return string
268 function css_minify_css($files) {
269 debugging('css_minify_css() is deprecated, use core_minify::css_files() or core_minify::css() instead.');
270 return core_minify::css_files($files);
274 * Function to call all event handlers when triggering an event
276 * @deprecated since 2.6
278 * @param string $eventname name of the event
279 * @param mixed $eventdata event data object
280 * @return int number of failed events
282 function events_trigger($eventname, $eventdata) {
283 debugging('events_trigger() is deprecated, please use new events instead', DEBUG_DEVELOPER);
284 return events_trigger_legacy($eventname, $eventdata);
288 * List all core subsystems and their location
290 * This is a whitelist of components that are part of the core and their
291 * language strings are defined in /lang/en/<<subsystem>>.php. If a given
292 * plugin is not listed here and it does not have proper plugintype prefix,
293 * then it is considered as course activity module.
295 * The location is optionally dirroot relative path. NULL means there is no special
296 * directory for this subsystem. If the location is set, the subsystem's
297 * renderer.php is expected to be there.
299 * @deprecated since 2.6, use core_component::get_core_subsystems()
301 * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons
302 * @return array of (string)name => (string|null)location
304 function get_core_subsystems($fullpaths = false) {
305 global $CFG;
307 // NOTE: do not add any other debugging here, keep forever.
309 $subsystems = core_component::get_core_subsystems();
311 if ($fullpaths) {
312 return $subsystems;
315 debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
317 $dlength = strlen($CFG->dirroot);
319 foreach ($subsystems as $k => $v) {
320 if ($v === null) {
321 continue;
323 $subsystems[$k] = substr($v, $dlength+1);
326 return $subsystems;
330 * Lists all plugin types.
332 * @deprecated since 2.6, use core_component::get_plugin_types()
334 * @param bool $fullpaths false means relative paths from dirroot
335 * @return array Array of strings - name=>location
337 function get_plugin_types($fullpaths = true) {
338 global $CFG;
340 // NOTE: do not add any other debugging here, keep forever.
342 $types = core_component::get_plugin_types();
344 if ($fullpaths) {
345 return $types;
348 debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
350 $dlength = strlen($CFG->dirroot);
352 foreach ($types as $k => $v) {
353 if ($k === 'theme') {
354 $types[$k] = 'theme';
355 continue;
357 $types[$k] = substr($v, $dlength+1);
360 return $types;
364 * Use when listing real plugins of one type.
366 * @deprecated since 2.6, use core_component::get_plugin_list()
368 * @param string $plugintype type of plugin
369 * @return array name=>fulllocation pairs of plugins of given type
371 function get_plugin_list($plugintype) {
373 // NOTE: do not add any other debugging here, keep forever.
375 if ($plugintype === '') {
376 $plugintype = 'mod';
379 return core_component::get_plugin_list($plugintype);
383 * Get a list of all the plugins of a given type that define a certain class
384 * in a certain file. The plugin component names and class names are returned.
386 * @deprecated since 2.6, use core_component::get_plugin_list_with_class()
388 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
389 * @param string $class the part of the name of the class after the
390 * frankenstyle prefix. e.g 'thing' if you are looking for classes with
391 * names like report_courselist_thing. If you are looking for classes with
392 * the same name as the plugin name (e.g. qtype_multichoice) then pass ''.
393 * @param string $file the name of file within the plugin that defines the class.
394 * @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum')
395 * and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice').
397 function get_plugin_list_with_class($plugintype, $class, $file) {
399 // NOTE: do not add any other debugging here, keep forever.
401 return core_component::get_plugin_list_with_class($plugintype, $class, $file);
405 * Returns the exact absolute path to plugin directory.
407 * @deprecated since 2.6, use core_component::get_plugin_directory()
409 * @param string $plugintype type of plugin
410 * @param string $name name of the plugin
411 * @return string full path to plugin directory; NULL if not found
413 function get_plugin_directory($plugintype, $name) {
415 // NOTE: do not add any other debugging here, keep forever.
417 if ($plugintype === '') {
418 $plugintype = 'mod';
421 return core_component::get_plugin_directory($plugintype, $name);
425 * Normalize the component name using the "frankenstyle" names.
427 * @deprecated since 2.6, use core_component::normalize_component()
429 * @param string $component
430 * @return array as (string)$type => (string)$plugin
432 function normalize_component($component) {
434 // NOTE: do not add any other debugging here, keep forever.
436 return core_component::normalize_component($component);
440 * Return exact absolute path to a plugin directory.
442 * @deprecated since 2.6, use core_component::normalize_component()
444 * @param string $component name such as 'moodle', 'mod_forum'
445 * @return string full path to component directory; NULL if not found
447 function get_component_directory($component) {
449 // NOTE: do not add any other debugging here, keep forever.
451 return core_component::get_component_directory($component);
455 // === Deprecated before 2.6.0 ===
458 * Hack to find out the GD version by parsing phpinfo output
460 * @return int GD version (1, 2, or 0)
462 function check_gd_version() {
463 // TODO: delete function in Moodle 2.7
464 debugging('check_gd_version() is deprecated, GD extension is always available now');
466 $gdversion = 0;
468 if (function_exists('gd_info')){
469 $gd_info = gd_info();
470 if (substr_count($gd_info['GD Version'], '2.')) {
471 $gdversion = 2;
472 } else if (substr_count($gd_info['GD Version'], '1.')) {
473 $gdversion = 1;
476 } else {
477 ob_start();
478 phpinfo(INFO_MODULES);
479 $phpinfo = ob_get_contents();
480 ob_end_clean();
482 $phpinfo = explode("\n", $phpinfo);
485 foreach ($phpinfo as $text) {
486 $parts = explode('</td>', $text);
487 foreach ($parts as $key => $val) {
488 $parts[$key] = trim(strip_tags($val));
490 if ($parts[0] == 'GD Version') {
491 if (substr_count($parts[1], '2.0')) {
492 $parts[1] = '2.0';
494 $gdversion = intval($parts[1]);
499 return $gdversion; // 1, 2 or 0
503 * Not used any more, the account lockout handling is now
504 * part of authenticate_user_login().
505 * @deprecated
507 function update_login_count() {
508 // TODO: delete function in Moodle 2.6
509 debugging('update_login_count() is deprecated, all calls need to be removed');
513 * Not used any more, replaced by proper account lockout.
514 * @deprecated
516 function reset_login_count() {
517 // TODO: delete function in Moodle 2.6
518 debugging('reset_login_count() is deprecated, all calls need to be removed');
522 * Insert or update log display entry. Entry may already exist.
523 * $module, $action must be unique
524 * @deprecated
526 * @param string $module
527 * @param string $action
528 * @param string $mtable
529 * @param string $field
530 * @return void
533 function update_log_display_entry($module, $action, $mtable, $field) {
534 global $DB;
536 debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
540 * Given some text in HTML format, this function will pass it
541 * through any filters that have been configured for this context.
543 * @deprecated use the text formatting in a standard way instead (http://docs.moodle.org/dev/Output_functions)
544 * this was abused mostly for embedding of attachments
545 * @todo final deprecation of this function in MDL-40607
546 * @param string $text The text to be passed through format filters
547 * @param int $courseid The current course.
548 * @return string the filtered string.
550 function filter_text($text, $courseid = NULL) {
551 global $CFG, $COURSE;
553 debugging('filter_text() is deprecated, use format_text(), format_string() etc instead.', DEBUG_DEVELOPER);
555 if (!$courseid) {
556 $courseid = $COURSE->id;
559 if (!$context = context_course::instance($courseid, IGNORE_MISSING)) {
560 return $text;
563 return filter_manager::instance()->filter_text($text, $context);
567 * This function indicates that current page requires the https
568 * when $CFG->loginhttps enabled.
570 * By using this function properly, we can ensure 100% https-ized pages
571 * at our entire discretion (login, forgot_password, change_password)
572 * @deprecated use $PAGE->https_required() instead
573 * @todo final deprecation of this function in MDL-40607
575 function httpsrequired() {
576 global $PAGE;
577 debugging('httpsrequired() is deprecated use $PAGE->https_required() instead.', DEBUG_DEVELOPER);
578 $PAGE->https_required();
582 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
584 * @deprecated use moodle_url factory methods instead
586 * @param string $path Physical path to a file
587 * @param array $options associative array of GET variables to append to the URL
588 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
589 * @return string URL to file
591 function get_file_url($path, $options=null, $type='coursefile') {
592 global $CFG;
594 $path = str_replace('//', '/', $path);
595 $path = trim($path, '/'); // no leading and trailing slashes
597 // type of file
598 switch ($type) {
599 case 'questionfile':
600 $url = $CFG->wwwroot."/question/exportfile.php";
601 break;
602 case 'rssfile':
603 $url = $CFG->wwwroot."/rss/file.php";
604 break;
605 case 'httpscoursefile':
606 $url = $CFG->httpswwwroot."/file.php";
607 break;
608 case 'coursefile':
609 default:
610 $url = $CFG->wwwroot."/file.php";
613 if ($CFG->slasharguments) {
614 $parts = explode('/', $path);
615 foreach ($parts as $key => $part) {
616 /// anchor dash character should not be encoded
617 $subparts = explode('#', $part);
618 $subparts = array_map('rawurlencode', $subparts);
619 $parts[$key] = implode('#', $subparts);
621 $path = implode('/', $parts);
622 $ffurl = $url.'/'.$path;
623 $separator = '?';
624 } else {
625 $path = rawurlencode('/'.$path);
626 $ffurl = $url.'?file='.$path;
627 $separator = '&amp;';
630 if ($options) {
631 foreach ($options as $name=>$value) {
632 $ffurl = $ffurl.$separator.$name.'='.$value;
633 $separator = '&amp;';
637 return $ffurl;
641 * Return all course participant for a given course
643 * @deprecated use get_enrolled_users($context) instead.
644 * @todo final deprecation of this function in MDL-40607
645 * @param integer $courseid
646 * @return array of user
648 function get_course_participants($courseid) {
649 debugging('get_course_participants() is deprecated, use get_enrolled_users() instead.', DEBUG_DEVELOPER);
650 return get_enrolled_users(context_course::instance($courseid));
654 * Return true if the user is a participant for a given course
656 * @deprecated use is_enrolled($context, $userid) instead.
657 * @todo final deprecation of this function in MDL-40607
658 * @param integer $userid
659 * @param integer $courseid
660 * @return boolean
662 function is_course_participant($userid, $courseid) {
663 debugging('is_course_participant() is deprecated, use is_enrolled() instead.', DEBUG_DEVELOPER);
664 return is_enrolled(context_course::instance($courseid), $userid);
668 * Searches logs to find all enrolments since a certain date
670 * used to print recent activity
672 * @param int $courseid The course in question.
673 * @param int $timestart The date to check forward of
674 * @return object|false {@link $USER} records or false if error.
676 function get_recent_enrolments($courseid, $timestart) {
677 global $DB;
679 debugging('get_recent_enrolments() is deprecated as it returned inaccurate results.', DEBUG_DEVELOPER);
681 $context = context_course::instance($courseid);
682 $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
683 FROM {user} u, {role_assignments} ra, {log} l
684 WHERE l.time > ?
685 AND l.course = ?
686 AND l.module = 'course'
687 AND l.action = 'enrol'
688 AND ".$DB->sql_cast_char2int('l.info')." = u.id
689 AND u.id = ra.userid
690 AND ra.contextid ".get_related_contexts_string($context)."
691 GROUP BY u.id, u.firstname, u.lastname
692 ORDER BY MAX(l.time) ASC";
693 $params = array($timestart, $courseid);
694 return $DB->get_records_sql($sql, $params);
698 * @deprecated use clean_param($string, PARAM_FILE) instead.
699 * @todo final deprecation of this function in MDL-40607
701 * @param string $string ?
702 * @param int $allowdots ?
703 * @return bool
705 function detect_munged_arguments($string, $allowdots=1) {
706 debugging('detect_munged_arguments() is deprecated, please use clean_param(,PARAM_FILE) instead.', DEBUG_DEVELOPER);
707 if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
708 return true;
710 if (preg_match('/[\|\`]/', $string)) { // check for other bad characters
711 return true;
713 if (empty($string) or $string == '/') {
714 return true;
717 return false;
722 * Unzip one zip file to a destination dir
723 * Both parameters must be FULL paths
724 * If destination isn't specified, it will be the
725 * SAME directory where the zip file resides.
727 * @global object
728 * @param string $zipfile The zip file to unzip
729 * @param string $destination The location to unzip to
730 * @param bool $showstatus_ignored Unused
732 function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
733 global $CFG;
735 //Extract everything from zipfile
736 $path_parts = pathinfo(cleardoubleslashes($zipfile));
737 $zippath = $path_parts["dirname"]; //The path of the zip file
738 $zipfilename = $path_parts["basename"]; //The name of the zip file
739 $extension = $path_parts["extension"]; //The extension of the file
741 //If no file, error
742 if (empty($zipfilename)) {
743 return false;
746 //If no extension, error
747 if (empty($extension)) {
748 return false;
751 //Clear $zipfile
752 $zipfile = cleardoubleslashes($zipfile);
754 //Check zipfile exists
755 if (!file_exists($zipfile)) {
756 return false;
759 //If no destination, passed let's go with the same directory
760 if (empty($destination)) {
761 $destination = $zippath;
764 //Clear $destination
765 $destpath = rtrim(cleardoubleslashes($destination), "/");
767 //Check destination path exists
768 if (!is_dir($destpath)) {
769 return false;
772 $packer = get_file_packer('application/zip');
774 $result = $packer->extract_to_pathname($zipfile, $destpath);
776 if ($result === false) {
777 return false;
780 foreach ($result as $status) {
781 if ($status !== true) {
782 return false;
786 return true;
790 * Zip an array of files/dirs to a destination zip file
791 * Both parameters must be FULL paths to the files/dirs
793 * @global object
794 * @param array $originalfiles Files to zip
795 * @param string $destination The destination path
796 * @return bool Outcome
798 function zip_files ($originalfiles, $destination) {
799 global $CFG;
801 //Extract everything from destination
802 $path_parts = pathinfo(cleardoubleslashes($destination));
803 $destpath = $path_parts["dirname"]; //The path of the zip file
804 $destfilename = $path_parts["basename"]; //The name of the zip file
805 $extension = $path_parts["extension"]; //The extension of the file
807 //If no file, error
808 if (empty($destfilename)) {
809 return false;
812 //If no extension, add it
813 if (empty($extension)) {
814 $extension = 'zip';
815 $destfilename = $destfilename.'.'.$extension;
818 //Check destination path exists
819 if (!is_dir($destpath)) {
820 return false;
823 //Check destination path is writable. TODO!!
825 //Clean destination filename
826 $destfilename = clean_filename($destfilename);
828 //Now check and prepare every file
829 $files = array();
830 $origpath = NULL;
832 foreach ($originalfiles as $file) { //Iterate over each file
833 //Check for every file
834 $tempfile = cleardoubleslashes($file); // no doubleslashes!
835 //Calculate the base path for all files if it isn't set
836 if ($origpath === NULL) {
837 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
839 //See if the file is readable
840 if (!is_readable($tempfile)) { //Is readable
841 continue;
843 //See if the file/dir is in the same directory than the rest
844 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
845 continue;
847 //Add the file to the array
848 $files[] = $tempfile;
851 $zipfiles = array();
852 $start = strlen($origpath)+1;
853 foreach($files as $file) {
854 $zipfiles[substr($file, $start)] = $file;
857 $packer = get_file_packer('application/zip');
859 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
863 * Get the IDs for the user's groups in the given course.
865 * @global object
866 * @param int $courseid The course being examined - the 'course' table id field.
867 * @return array|bool An _array_ of groupids, or false
868 * (Was return $groupids[0] - consequences!)
869 * @deprecated use groups_get_all_groups() instead.
870 * @todo final deprecation of this function in MDL-40607
872 function mygroupid($courseid) {
873 global $USER;
875 debugging('mygroupid() is deprecated, please use groups_get_all_groups() instead.', DEBUG_DEVELOPER);
877 if ($groups = groups_get_all_groups($courseid, $USER->id)) {
878 return array_keys($groups);
879 } else {
880 return false;
886 * Returns the current group mode for a given course or activity module
888 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
890 * @param object $course Course Object
891 * @param object $cm Course Manager Object
892 * @return mixed $course->groupmode
894 function groupmode($course, $cm=null) {
896 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
897 return $cm->groupmode;
899 return $course->groupmode;
903 * Sets the current group in the session variable
904 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
905 * Sets currentgroup[$courseid] in the session variable appropriately.
906 * Does not do any permission checking.
908 * @global object
909 * @param int $courseid The course being examined - relates to id field in
910 * 'course' table.
911 * @param int $groupid The group being examined.
912 * @return int Current group id which was set by this function
914 function set_current_group($courseid, $groupid) {
915 global $SESSION;
916 return $SESSION->currentgroup[$courseid] = $groupid;
921 * Gets the current group - either from the session variable or from the database.
923 * @global object
924 * @param int $courseid The course being examined - relates to id field in
925 * 'course' table.
926 * @param bool $full If true, the return value is a full record object.
927 * If false, just the id of the record.
928 * @return int|bool
930 function get_current_group($courseid, $full = false) {
931 global $SESSION;
933 if (isset($SESSION->currentgroup[$courseid])) {
934 if ($full) {
935 return groups_get_group($SESSION->currentgroup[$courseid]);
936 } else {
937 return $SESSION->currentgroup[$courseid];
941 $mygroupid = mygroupid($courseid);
942 if (is_array($mygroupid)) {
943 $mygroupid = array_shift($mygroupid);
944 set_current_group($courseid, $mygroupid);
945 if ($full) {
946 return groups_get_group($mygroupid);
947 } else {
948 return $mygroupid;
952 if ($full) {
953 return false;
954 } else {
955 return 0;
960 * Filter a user list and return only the users that can see the course module based on
961 * groups/permissions etc. It is assumed that the users are pre-filtered to those who are enrolled in the course.
963 * @category group
964 * @param stdClass|cm_info $cm The course module
965 * @param array $users An array of users, indexed by userid
966 * @return array A filtered list of users that can see the module, indexed by userid.
967 * @deprecated Since Moodle 2.8
969 function groups_filter_users_by_course_module_visible($cm, $users) {
970 debugging('groups_filter_users_by_course_module_visible() is deprecated. ' .
971 'Replace with a call to \core_availability\info_module::filter_user_list(), ' .
972 'which does basically the same thing but includes other restrictions such ' .
973 'as profile restrictions.', DEBUG_DEVELOPER);
974 if (empty($users)) {
975 return $users;
977 // Since this function allows stdclass, let's play it safe and ensure we
978 // do have a cm_info.
979 if (!($cm instanceof cm_info)) {
980 $modinfo = get_fast_modinfo($cm->course);
981 $cm = $modinfo->get_cm($cm->id);
983 $info = new \core_availability\info_module($cm);
984 return $info->filter_user_list($users);
988 * Determine if a course module is currently visible to a user
990 * Deprecated (it was never very useful as it only took into account the
991 * groupmembersonly option and no other way of hiding activities). Always
992 * returns true.
994 * @category group
995 * @param stdClass|cm_info $cm The course module
996 * @param int $userid The user to check against the group.
997 * @return bool True
998 * @deprecated Since Moodle 2.8
1000 function groups_course_module_visible($cm, $userid=null) {
1001 debugging('groups_course_module_visible() is deprecated and always returns ' .
1002 'true; use $cm->uservisible to decide whether the current user can ' .
1003 'access an activity.', DEBUG_DEVELOPER);
1004 return true;
1008 * Inndicates fatal error. This function was originally printing the
1009 * error message directly, since 2.0 it is throwing exception instead.
1010 * The error printing is handled in default exception handler.
1012 * Old method, don't call directly in new code - use print_error instead.
1014 * @param string $message The message to display to the user about the error.
1015 * @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.
1016 * @return void, always throws moodle_exception
1018 function error($message, $link='') {
1019 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
1024 * @deprecated use $PAGE->theme->name instead.
1025 * @todo final deprecation of this function in MDL-40607
1026 * @return string the name of the current theme.
1028 function current_theme() {
1029 global $PAGE;
1031 debugging('current_theme() is deprecated, please use $PAGE->theme->name instead', DEBUG_DEVELOPER);
1032 return $PAGE->theme->name;
1036 * Prints some red text using echo
1038 * @deprecated
1039 * @param string $error The text to be displayed in red
1041 function formerr($error) {
1042 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
1043 global $OUTPUT;
1044 echo $OUTPUT->error_text($error);
1048 * Return the markup for the destination of the 'Skip to main content' links.
1049 * Accessibility improvement for keyboard-only users.
1051 * Used in course formats, /index.php and /course/index.php
1053 * @deprecated use $OUTPUT->skip_link_target() in instead.
1054 * @todo final deprecation of this function in MDL-40607
1055 * @return string HTML element.
1057 function skip_main_destination() {
1058 global $OUTPUT;
1060 debugging('skip_main_destination() is deprecated, please use $OUTPUT->skip_link_target() instead.', DEBUG_DEVELOPER);
1061 return $OUTPUT->skip_link_target();
1065 * Print a message in a standard themed container.
1067 * @deprecated use $OUTPUT->container() instead.
1068 * @todo final deprecation of this function in MDL-40607
1069 * @param string $message, the content of the container
1070 * @param boolean $clearfix clear both sides
1071 * @param string $classes, space-separated class names.
1072 * @param string $idbase
1073 * @param boolean $return, return as string or just print it
1074 * @return string|void Depending on value of $return
1076 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
1077 global $OUTPUT;
1079 debugging('print_container() is deprecated. Please use $OUTPUT->container() instead.', DEBUG_DEVELOPER);
1080 if ($clearfix) {
1081 $classes .= ' clearfix';
1083 $output = $OUTPUT->container($message, $classes, $idbase);
1084 if ($return) {
1085 return $output;
1086 } else {
1087 echo $output;
1092 * Starts a container using divs
1094 * @deprecated use $OUTPUT->container_start() instead.
1095 * @todo final deprecation of this function in MDL-40607
1096 * @param boolean $clearfix clear both sides
1097 * @param string $classes, space-separated class names.
1098 * @param string $idbase
1099 * @param boolean $return, return as string or just print it
1100 * @return string|void Based on value of $return
1102 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
1103 global $OUTPUT;
1105 debugging('print_container_start() is deprecated. Please use $OUTPUT->container_start() instead.', DEBUG_DEVELOPER);
1107 if ($clearfix) {
1108 $classes .= ' clearfix';
1110 $output = $OUTPUT->container_start($classes, $idbase);
1111 if ($return) {
1112 return $output;
1113 } else {
1114 echo $output;
1119 * Simple function to end a container (see above)
1121 * @deprecated use $OUTPUT->container_end() instead.
1122 * @todo final deprecation of this function in MDL-40607
1123 * @param boolean $return, return as string or just print it
1124 * @return string|void Based on $return
1126 function print_container_end($return=false) {
1127 global $OUTPUT;
1128 debugging('print_container_end() is deprecated. Please use $OUTPUT->container_end() instead.', DEBUG_DEVELOPER);
1129 $output = $OUTPUT->container_end();
1130 if ($return) {
1131 return $output;
1132 } else {
1133 echo $output;
1138 * Print a bold message in an optional color.
1140 * @deprecated use $OUTPUT->notification instead.
1141 * @param string $message The message to print out
1142 * @param string $style Optional style to display message text in
1143 * @param string $align Alignment option
1144 * @param bool $return whether to return an output string or echo now
1145 * @return string|bool Depending on $result
1147 function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
1148 global $OUTPUT;
1150 if ($classes == 'green') {
1151 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
1152 $classes = 'notifysuccess'; // Backward compatible with old color system
1155 $output = $OUTPUT->notification($message, $classes);
1156 if ($return) {
1157 return $output;
1158 } else {
1159 echo $output;
1164 * Print a continue button that goes to a particular URL.
1166 * @deprecated use $OUTPUT->continue_button() instead.
1167 * @todo final deprecation of this function in MDL-40607
1169 * @param string $link The url to create a link to.
1170 * @param bool $return If set to true output is returned rather than echoed, default false
1171 * @return string|void HTML String if return=true nothing otherwise
1173 function print_continue($link, $return = false) {
1174 global $CFG, $OUTPUT;
1176 debugging('print_continue() is deprecated. Please use $OUTPUT->continue_button() instead.', DEBUG_DEVELOPER);
1178 if ($link == '') {
1179 if (!empty($_SERVER['HTTP_REFERER'])) {
1180 $link = $_SERVER['HTTP_REFERER'];
1181 $link = str_replace('&', '&amp;', $link); // make it valid XHTML
1182 } else {
1183 $link = $CFG->wwwroot .'/';
1187 $output = $OUTPUT->continue_button($link);
1188 if ($return) {
1189 return $output;
1190 } else {
1191 echo $output;
1196 * Print a standard header
1198 * @deprecated use $PAGE methods instead.
1199 * @todo final deprecation of this function in MDL-40607
1200 * @param string $title Appears at the top of the window
1201 * @param string $heading Appears at the top of the page
1202 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
1203 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1204 * @param string $meta Meta tags to be added to the header
1205 * @param boolean $cache Should this page be cacheable?
1206 * @param string $button HTML code for a button (usually for module editing)
1207 * @param string $menu HTML code for a popup menu
1208 * @param boolean $usexml use XML for this page
1209 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1210 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1211 * @return string|void If return=true then string else void
1213 function print_header($title='', $heading='', $navigation='', $focus='',
1214 $meta='', $cache=true, $button='&nbsp;', $menu=null,
1215 $usexml=false, $bodytags='', $return=false) {
1216 global $PAGE, $OUTPUT;
1218 debugging('print_header() is deprecated. Please use $PAGE methods instead.', DEBUG_DEVELOPER);
1220 $PAGE->set_title($title);
1221 $PAGE->set_heading($heading);
1222 $PAGE->set_cacheable($cache);
1223 if ($button == '') {
1224 $button = '&nbsp;';
1226 $PAGE->set_button($button);
1227 $PAGE->set_headingmenu($menu);
1229 // TODO $menu
1231 if ($meta) {
1232 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1233 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1235 if ($usexml) {
1236 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1238 if ($bodytags) {
1239 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1242 $output = $OUTPUT->header();
1244 if ($return) {
1245 return $output;
1246 } else {
1247 echo $output;
1252 * This version of print_header is simpler because the course name does not have to be
1253 * provided explicitly in the strings. It can be used on the site page as in courses
1254 * Eventually all print_header could be replaced by print_header_simple
1256 * @deprecated use $PAGE methods instead.
1257 * @todo final deprecation of this function in MDL-40607
1258 * @param string $title Appears at the top of the window
1259 * @param string $heading Appears at the top of the page
1260 * @param string $navigation Premade navigation string (for use as breadcrumbs links)
1261 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1262 * @param string $meta Meta tags to be added to the header
1263 * @param boolean $cache Should this page be cacheable?
1264 * @param string $button HTML code for a button (usually for module editing)
1265 * @param string $menu HTML code for a popup menu
1266 * @param boolean $usexml use XML for this page
1267 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1268 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1269 * @return string|void If $return=true the return string else nothing
1271 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
1272 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
1274 global $COURSE, $CFG, $PAGE, $OUTPUT;
1276 debugging('print_header_simple() is deprecated. Please use $PAGE methods instead.', DEBUG_DEVELOPER);
1278 if ($meta) {
1279 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1280 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1282 if ($usexml) {
1283 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1285 if ($bodytags) {
1286 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1289 $PAGE->set_title($title);
1290 $PAGE->set_heading($heading);
1291 $PAGE->set_cacheable(true);
1292 $PAGE->set_button($button);
1294 $output = $OUTPUT->header();
1296 if ($return) {
1297 return $output;
1298 } else {
1299 echo $output;
1304 * Prints a nice side block with an optional header. The content can either
1305 * be a block of HTML or a list of text with optional icons.
1307 * @static int $block_id Increments for each call to the function
1308 * @param string $heading HTML for the heading. Can include full HTML or just
1309 * plain text - plain text will automatically be enclosed in the appropriate
1310 * heading tags.
1311 * @param string $content HTML for the content
1312 * @param array $list an alternative to $content, it you want a list of things with optional icons.
1313 * @param array $icons optional icons for the things in $list.
1314 * @param string $footer Extra HTML content that gets output at the end, inside a &lt;div class="footer">
1315 * @param array $attributes an array of attribute => value pairs that are put on the
1316 * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
1317 * already a class, class='block' is used.
1318 * @param string $title Plain text title, as embedded in the $heading.
1319 * @deprecated use $OUTPUT->block() instead.
1320 * @todo final deprecation of this function in MDL-40607
1322 function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
1323 global $OUTPUT;
1325 debugging('print_side_block() is deprecated, please use $OUTPUT->block() instead.', DEBUG_DEVELOPER);
1326 // We don't use $heading, becuse it often contains HTML that we don't want.
1327 // However, sometimes $title is not set, but $heading is.
1328 if (empty($title)) {
1329 $title = strip_tags($heading);
1332 // Render list contents to HTML if required.
1333 if (empty($content) && $list) {
1334 $content = $OUTPUT->list_block_contents($icons, $list);
1337 $bc = new block_contents();
1338 $bc->content = $content;
1339 $bc->footer = $footer;
1340 $bc->title = $title;
1342 if (isset($attributes['id'])) {
1343 $bc->id = $attributes['id'];
1344 unset($attributes['id']);
1346 $bc->attributes = $attributes;
1348 echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
1352 * Prints a basic textarea field.
1354 * @deprecated since Moodle 2.0
1356 * When using this function, you should
1358 * @global object
1359 * @param bool $unused No longer used.
1360 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
1361 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
1362 * @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.
1363 * @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.
1364 * @param string $name Name to use for the textarea element.
1365 * @param string $value Initial content to display in the textarea.
1366 * @param int $obsolete deprecated
1367 * @param bool $return If false, will output string. If true, will return string value.
1368 * @param string $id CSS ID to add to the textarea element.
1369 * @return string|void depending on the value of $return
1371 function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
1372 /// $width and height are legacy fields and no longer used as pixels like they used to be.
1373 /// However, you can set them to zero to override the mincols and minrows values below.
1375 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
1376 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
1378 global $CFG;
1380 $mincols = 65;
1381 $minrows = 10;
1382 $str = '';
1384 if ($id === '') {
1385 $id = 'edit-'.$name;
1388 if ($height && ($rows < $minrows)) {
1389 $rows = $minrows;
1391 if ($width && ($cols < $mincols)) {
1392 $cols = $mincols;
1395 editors_head_setup();
1396 $editor = editors_get_preferred_editor(FORMAT_HTML);
1397 $editor->use_editor($id, array('legacy'=>true));
1399 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'" spellcheck="true">'."\n";
1400 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
1401 $str .= '</textarea>'."\n";
1403 if ($return) {
1404 return $str;
1406 echo $str;
1410 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
1411 * Should be used only with htmleditor or textarea.
1413 * @global object
1414 * @global object
1415 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
1416 * helpbutton.
1417 * @return string Link to help button
1419 function editorhelpbutton(){
1420 return '';
1422 /// TODO: MDL-21215
1426 * Print a help button.
1428 * Prints a special help button for html editors (htmlarea in this case)
1430 * @todo Write code into this function! detect current editor and print correct info
1431 * @global object
1432 * @return string Only returns an empty string at the moment
1434 function editorshortcutshelpbutton() {
1435 /// TODO: MDL-21215
1437 global $CFG;
1438 //TODO: detect current editor and print correct info
1439 return '';
1444 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
1445 * provide this function with the language strings for sortasc and sortdesc.
1447 * @deprecated use $OUTPUT->arrow() instead.
1448 * @todo final deprecation of this function in MDL-40607
1450 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
1452 * @global object
1453 * @param string $direction 'up' or 'down'
1454 * @param string $strsort The language string used for the alt attribute of this image
1455 * @param bool $return Whether to print directly or return the html string
1456 * @return string|void depending on $return
1459 function print_arrow($direction='up', $strsort=null, $return=false) {
1460 global $OUTPUT;
1462 debugging('print_arrow() is deprecated. Please use $OUTPUT->arrow() instead.', DEBUG_DEVELOPER);
1464 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
1465 return null;
1468 $return = null;
1470 switch ($direction) {
1471 case 'up':
1472 $sortdir = 'asc';
1473 break;
1474 case 'down':
1475 $sortdir = 'desc';
1476 break;
1477 case 'move':
1478 $sortdir = 'asc';
1479 break;
1480 default:
1481 $sortdir = null;
1482 break;
1485 // Prepare language string
1486 $strsort = '';
1487 if (empty($strsort) && !empty($sortdir)) {
1488 $strsort = get_string('sort' . $sortdir, 'grades');
1491 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
1493 if ($return) {
1494 return $return;
1495 } else {
1496 echo $return;
1501 * Given an array of values, output the HTML for a select element with those options.
1503 * @deprecated since Moodle 2.0
1505 * Normally, you only need to use the first few parameters.
1507 * @param array $options The options to offer. An array of the form
1508 * $options[{value}] = {text displayed for that option};
1509 * @param string $name the name of this form control, as in &lt;select name="..." ...
1510 * @param string $selected the option to select initially, default none.
1511 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
1512 * Set this to '' if you don't want a 'nothing is selected' option.
1513 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
1514 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
1515 * @param boolean $return if false (the default) the the output is printed directly, If true, the
1516 * generated HTML is returned as a string.
1517 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
1518 * @param int $tabindex if give, sets the tabindex attribute on the &lt;select> element. Default none.
1519 * @param string $id value to use for the id attribute of the &lt;select> element. If none is given,
1520 * then a suitable one is constructed.
1521 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
1522 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
1523 * $listbox is an integer, that number is used for size instead.
1524 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
1525 * when $listbox display is enabled
1526 * @param string $class value to use for the class attribute of the &lt;select> element. If none is given,
1527 * then a suitable one is constructed.
1528 * @return string|void If $return=true returns string, else echo's and returns void
1530 function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
1531 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
1532 $id='', $listbox=false, $multiple=false, $class='') {
1534 global $OUTPUT;
1535 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
1537 if ($script) {
1538 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
1540 $attributes = array();
1541 $attributes['disabled'] = $disabled ? 'disabled' : null;
1542 $attributes['tabindex'] = $tabindex ? $tabindex : null;
1543 $attributes['multiple'] = $multiple ? $multiple : null;
1544 $attributes['class'] = $class ? $class : null;
1545 $attributes['id'] = $id ? $id : null;
1547 $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
1549 if ($return) {
1550 return $output;
1551 } else {
1552 echo $output;
1557 * Prints a help button about a scale
1559 * @deprecated use $OUTPUT->help_icon_scale($courseid, $scale) instead.
1560 * @todo final deprecation of this function in MDL-40607
1562 * @global object
1563 * @param id $courseid
1564 * @param object $scale
1565 * @param boolean $return If set to true returns rather than echo's
1566 * @return string|bool Depending on value of $return
1568 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
1569 global $OUTPUT;
1571 debugging('print_scale_menu_helpbutton() is deprecated. Please use $OUTPUT->help_icon_scale($courseid, $scale) instead.', DEBUG_DEVELOPER);
1573 $output = $OUTPUT->help_icon_scale($courseid, $scale);
1575 if ($return) {
1576 return $output;
1577 } else {
1578 echo $output;
1583 * Display an standard html checkbox with an optional label
1585 * @deprecated use html_writer::checkbox() instead.
1586 * @todo final deprecation of this function in MDL-40607
1588 * @staticvar int $idcounter
1589 * @param string $name The name of the checkbox
1590 * @param string $value The valus that the checkbox will pass when checked
1591 * @param bool $checked The flag to tell the checkbox initial state
1592 * @param string $label The label to be showed near the checkbox
1593 * @param string $alt The info to be inserted in the alt tag
1594 * @param string $script If not '', then this is added to the checkbox element
1595 * as an onchange handler.
1596 * @param bool $return Whether this function should return a string or output
1597 * it (defaults to false)
1598 * @return string|void If $return=true returns string, else echo's and returns void
1600 function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
1601 global $OUTPUT;
1603 debugging('print_checkbox() is deprecated. Please use html_writer::checkbox() instead.', DEBUG_DEVELOPER);
1605 if (!empty($script)) {
1606 debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER);
1609 $output = html_writer::checkbox($name, $value, $checked, $label);
1611 if (empty($return)) {
1612 echo $output;
1613 } else {
1614 return $output;
1620 * Prints the 'update this xxx' button that appears on module pages.
1622 * @deprecated since Moodle 2.0
1624 * @param string $cmid the course_module id.
1625 * @param string $ignored not used any more. (Used to be courseid.)
1626 * @param string $string the module name - get_string('modulename', 'xxx')
1627 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
1629 function update_module_button($cmid, $ignored, $string) {
1630 global $CFG, $OUTPUT;
1632 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
1634 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
1636 if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) {
1637 $string = get_string('updatethis', '', $string);
1639 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
1640 return $OUTPUT->single_button($url, $string);
1641 } else {
1642 return '';
1647 * Prints breadcrumb trail of links, called in theme/-/header.html
1649 * This function has now been deprecated please use output's navbar method instead
1650 * as shown below
1652 * <code php>
1653 * echo $OUTPUT->navbar();
1654 * </code>
1656 * @deprecated use $OUTPUT->navbar() instead
1657 * @todo final deprecation of this function in MDL-40607
1658 * @param mixed $navigation deprecated
1659 * @param string $separator OBSOLETE, and now deprecated
1660 * @param boolean $return False to echo the breadcrumb string (default), true to return it.
1661 * @return string|void String or null, depending on $return.
1663 function print_navigation ($navigation, $separator=0, $return=false) {
1664 global $OUTPUT,$PAGE;
1666 debugging('print_navigation() is deprecated, please update use $OUTPUT->navbar() instead.', DEBUG_DEVELOPER);
1668 $output = $OUTPUT->navbar();
1670 if ($return) {
1671 return $output;
1672 } else {
1673 echo $output;
1678 * This function will build the navigation string to be used by print_header
1679 * and others.
1681 * It automatically generates the site and course level (if appropriate) links.
1683 * If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums')
1684 * and activityinstances (e.g. 'General Developer Forum') navigation levels.
1686 * If you want to add any further navigation links after the ones this function generates,
1687 * the pass an array of extra link arrays like this:
1688 * array(
1689 * array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1),
1690 * array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2)
1692 * The normal case is to just add one further link, for example 'Editing forum' after
1693 * 'General Developer Forum', with no link.
1694 * To do that, you need to pass
1695 * array(array('name' => $linktext, 'link' => '', 'type' => 'title'))
1696 * However, becuase this is a very common case, you can use a shortcut syntax, and just
1697 * pass the string 'Editing forum', instead of an array as $extranavlinks.
1699 * At the moment, the link types only have limited significance. Type 'activity' is
1700 * recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types
1701 * that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'.
1702 * This really needs to be documented better. In the mean time, try to be consistent, it will
1703 * enable people to customise the navigation more in future.
1705 * When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course.
1706 * If you get the $cm object using the function get_coursemodule_from_instance or
1707 * get_coursemodule_from_id (as recommended) then this will be done for you automatically.
1708 * If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using
1709 * the $cm->module and $cm->instance fields, but this takes extra database queries, so a
1710 * warning is printed in developer debug mode.
1712 * @deprecated Please use $PAGE->navabar methods instead.
1713 * @todo final deprecation of this function in MDL-40607
1714 * @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you
1715 * only want one extra item with no link, you can pass a string instead. If you don't want
1716 * any extra links, pass an empty string.
1717 * @param mixed $cm deprecated
1718 * @return array Navigation array
1720 function build_navigation($extranavlinks, $cm = null) {
1721 global $CFG, $COURSE, $DB, $SITE, $PAGE;
1723 debugging('build_navigation() is deprecated, please use $PAGE->navbar methods instead.', DEBUG_DEVELOPER);
1724 if (is_array($extranavlinks) && count($extranavlinks)>0) {
1725 foreach ($extranavlinks as $nav) {
1726 if (array_key_exists('name', $nav)) {
1727 if (array_key_exists('link', $nav) && !empty($nav['link'])) {
1728 $link = $nav['link'];
1729 } else {
1730 $link = null;
1732 $PAGE->navbar->add($nav['name'],$link);
1737 return(array('newnav' => true, 'navlinks' => array()));
1741 * @deprecated not relevant with global navigation in Moodle 2.x+
1742 * @todo remove completely in MDL-40607
1744 function navmenu($course, $cm=NULL, $targetwindow='self') {
1745 // This function has been deprecated with the creation of the global nav in
1746 // moodle 2.0
1747 debugging('navmenu() is deprecated, it is no longer relevant with global navigation.', DEBUG_DEVELOPER);
1749 return '';
1752 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
1756 * Call this function to add an event to the calendar table and to call any calendar plugins
1758 * @param object $event An object representing an event from the calendar table.
1759 * The event will be identified by the id field. The object event should include the following:
1760 * <ul>
1761 * <li><b>$event->name</b> - Name for the event
1762 * <li><b>$event->description</b> - Description of the event (defaults to '')
1763 * <li><b>$event->format</b> - Format for the description (using formatting types defined at the top of weblib.php)
1764 * <li><b>$event->courseid</b> - The id of the course this event belongs to (0 = all courses)
1765 * <li><b>$event->groupid</b> - The id of the group this event belongs to (0 = no group)
1766 * <li><b>$event->userid</b> - The id of the user this event belongs to (0 = no user)
1767 * <li><b>$event->modulename</b> - Name of the module that creates this event
1768 * <li><b>$event->instance</b> - Instance of the module that owns this event
1769 * <li><b>$event->eventtype</b> - The type info together with the module info could
1770 * be used by calendar plugins to decide how to display event
1771 * <li><b>$event->timestart</b>- Timestamp for start of event
1772 * <li><b>$event->timeduration</b> - Duration (defaults to zero)
1773 * <li><b>$event->visible</b> - 0 if the event should be hidden (e.g. because the activity that created it is hidden)
1774 * </ul>
1775 * @return int|false The id number of the resulting record or false if failed
1776 * @deprecated please use calendar_event::create() instead.
1777 * @todo final deprecation of this function in MDL-40607
1779 function add_event($event) {
1780 global $CFG;
1781 require_once($CFG->dirroot.'/calendar/lib.php');
1783 debugging('add_event() is deprecated, please use calendar_event::create() instead.', DEBUG_DEVELOPER);
1784 $event = calendar_event::create($event);
1785 if ($event !== false) {
1786 return $event->id;
1788 return false;
1792 * Call this function to update an event in the calendar table
1793 * the event will be identified by the id field of the $event object.
1795 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
1796 * @return bool Success
1797 * @deprecated please calendar_event->update() instead.
1799 function update_event($event) {
1800 global $CFG;
1801 require_once($CFG->dirroot.'/calendar/lib.php');
1803 debugging('update_event() is deprecated, please use calendar_event->update() instead.', DEBUG_DEVELOPER);
1804 $event = (object)$event;
1805 $calendarevent = calendar_event::load($event->id);
1806 return $calendarevent->update($event);
1810 * Call this function to delete the event with id $id from calendar table.
1812 * @param int $id The id of an event from the 'event' table.
1813 * @return bool
1814 * @deprecated please use calendar_event->delete() instead.
1815 * @todo final deprecation of this function in MDL-40607
1817 function delete_event($id) {
1818 global $CFG;
1819 require_once($CFG->dirroot.'/calendar/lib.php');
1821 debugging('delete_event() is deprecated, please use calendar_event->delete() instead.', DEBUG_DEVELOPER);
1823 $event = calendar_event::load($id);
1824 return $event->delete();
1828 * Call this function to hide an event in the calendar table
1829 * the event will be identified by the id field of the $event object.
1831 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
1832 * @return true
1833 * @deprecated please use calendar_event->toggle_visibility(false) instead.
1834 * @todo final deprecation of this function in MDL-40607
1836 function hide_event($event) {
1837 global $CFG;
1838 require_once($CFG->dirroot.'/calendar/lib.php');
1840 debugging('hide_event() is deprecated, please use calendar_event->toggle_visibility(false) instead.', DEBUG_DEVELOPER);
1842 $event = new calendar_event($event);
1843 return $event->toggle_visibility(false);
1847 * Call this function to unhide an event in the calendar table
1848 * the event will be identified by the id field of the $event object.
1850 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
1851 * @return true
1852 * @deprecated please use calendar_event->toggle_visibility(true) instead.
1853 * @todo final deprecation of this function in MDL-40607
1855 function show_event($event) {
1856 global $CFG;
1857 require_once($CFG->dirroot.'/calendar/lib.php');
1859 debugging('show_event() is deprecated, please use calendar_event->toggle_visibility(true) instead.', DEBUG_DEVELOPER);
1861 $event = new calendar_event($event);
1862 return $event->toggle_visibility(true);
1866 * Original singleton helper function, please use static methods instead,
1867 * ex: core_text::convert()
1869 * @deprecated since Moodle 2.2 use core_text::xxxx() instead
1870 * @see textlib
1871 * @return textlib instance
1873 function textlib_get_instance() {
1875 debugging('textlib_get_instance() is deprecated. Please use static calling core_text::functioname() instead.', DEBUG_DEVELOPER);
1877 return new textlib();
1881 * Gets the generic section name for a courses section
1883 * The global function is deprecated. Each course format can define their own generic section name
1885 * @deprecated since 2.4
1886 * @see get_section_name()
1887 * @see format_base::get_section_name()
1889 * @param string $format Course format ID e.g. 'weeks' $course->format
1890 * @param stdClass $section Section object from database
1891 * @return Display name that the course format prefers, e.g. "Week 2"
1893 function get_generic_section_name($format, stdClass $section) {
1894 debugging('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base', DEBUG_DEVELOPER);
1895 return get_string('sectionname', "format_$format") . ' ' . $section->section;
1899 * Returns an array of sections for the requested course id
1901 * It is usually not recommended to display the list of sections used
1902 * in course because the course format may have it's own way to do it.
1904 * If you need to just display the name of the section please call:
1905 * get_section_name($course, $section)
1906 * {@link get_section_name()}
1907 * from 2.4 $section may also be just the field course_sections.section
1909 * If you need the list of all sections it is more efficient to get this data by calling
1910 * $modinfo = get_fast_modinfo($courseorid);
1911 * $sections = $modinfo->get_section_info_all()
1912 * {@link get_fast_modinfo()}
1913 * {@link course_modinfo::get_section_info_all()}
1915 * Information about one section (instance of section_info):
1916 * get_fast_modinfo($courseorid)->get_sections_info($section)
1917 * {@link course_modinfo::get_section_info()}
1919 * @deprecated since 2.4
1921 * @param int $courseid
1922 * @return array Array of section_info objects
1924 function get_all_sections($courseid) {
1925 global $DB;
1926 debugging('get_all_sections() is deprecated. See phpdocs for this function', DEBUG_DEVELOPER);
1927 return get_fast_modinfo($courseid)->get_section_info_all();
1931 * Given a full mod object with section and course already defined, adds this module to that section.
1933 * This function is deprecated, please use {@link course_add_cm_to_section()}
1934 * Note that course_add_cm_to_section() also updates field course_modules.section and
1935 * calls rebuild_course_cache()
1937 * @deprecated since 2.4
1939 * @param object $mod
1940 * @param int $beforemod An existing ID which we will insert the new module before
1941 * @return int The course_sections ID where the mod is inserted
1943 function add_mod_to_section($mod, $beforemod = null) {
1944 debugging('Function add_mod_to_section() is deprecated, please use course_add_cm_to_section()', DEBUG_DEVELOPER);
1945 global $DB;
1946 return course_add_cm_to_section($mod->course, $mod->coursemodule, $mod->section, $beforemod);
1950 * Returns a number of useful structures for course displays
1952 * Function get_all_mods() is deprecated in 2.4
1953 * Instead of:
1954 * <code>
1955 * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
1956 * </code>
1957 * please use:
1958 * <code>
1959 * $mods = get_fast_modinfo($courseorid)->get_cms();
1960 * $modnames = get_module_types_names();
1961 * $modnamesplural = get_module_types_names(true);
1962 * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names();
1963 * </code>
1965 * @deprecated since 2.4
1967 * @param int $courseid id of the course to get info about
1968 * @param array $mods (return) list of course modules
1969 * @param array $modnames (return) list of names of all module types installed and available
1970 * @param array $modnamesplural (return) list of names of all module types installed and available in the plural form
1971 * @param array $modnamesused (return) list of names of all module types used in the course
1973 function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
1974 debugging('Function get_all_mods() is deprecated. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details', DEBUG_DEVELOPER);
1976 global $COURSE;
1977 $modnames = get_module_types_names();
1978 $modnamesplural= get_module_types_names(true);
1979 $modinfo = get_fast_modinfo($courseid);
1980 $mods = $modinfo->get_cms();
1981 $modnamesused = $modinfo->get_used_module_names();
1985 * Returns course section - creates new if does not exist yet
1987 * This function is deprecated. To create a course section call:
1988 * course_create_sections_if_missing($courseorid, $sections);
1989 * to get the section call:
1990 * get_fast_modinfo($courseorid)->get_section_info($sectionnum);
1992 * @see course_create_sections_if_missing()
1993 * @see get_fast_modinfo()
1994 * @deprecated since 2.4
1996 * @param int $section relative section number (field course_sections.section)
1997 * @param int $courseid
1998 * @return stdClass record from table {course_sections}
2000 function get_course_section($section, $courseid) {
2001 global $DB;
2002 debugging('Function get_course_section() is deprecated. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.', DEBUG_DEVELOPER);
2004 if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) {
2005 return $cw;
2007 $cw = new stdClass();
2008 $cw->course = $courseid;
2009 $cw->section = $section;
2010 $cw->summary = "";
2011 $cw->summaryformat = FORMAT_HTML;
2012 $cw->sequence = "";
2013 $id = $DB->insert_record("course_sections", $cw);
2014 rebuild_course_cache($courseid, true);
2015 return $DB->get_record("course_sections", array("id"=>$id));
2019 * Return the start and end date of the week in Weekly course format
2021 * It is not recommended to use this function outside of format_weeks plugin
2023 * @deprecated since 2.4
2024 * @see format_weeks::get_section_dates()
2026 * @param stdClass $section The course_section entry from the DB
2027 * @param stdClass $course The course entry from DB
2028 * @return stdClass property start for startdate, property end for enddate
2030 function format_weeks_get_section_dates($section, $course) {
2031 debugging('Function format_weeks_get_section_dates() is deprecated. It is not recommended to'.
2032 ' use it outside of format_weeks plugin', DEBUG_DEVELOPER);
2033 if (isset($course->format) && $course->format === 'weeks') {
2034 return course_get_format($course)->get_section_dates($section);
2036 return null;
2040 * Obtains shared data that is used in print_section when displaying a
2041 * course-module entry.
2043 * Deprecated. Instead of:
2044 * list($content, $name) = get_print_section_cm_text($cm, $course);
2045 * use:
2046 * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
2047 * $name = $cm->get_formatted_name();
2049 * @deprecated since 2.5
2050 * @see cm_info::get_formatted_content()
2051 * @see cm_info::get_formatted_name()
2053 * This data is also used in other areas of the code.
2054 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
2055 * @param object $course (argument not used)
2056 * @return array An array with the following values in this order:
2057 * $content (optional extra content for after link),
2058 * $instancename (text of link)
2060 function get_print_section_cm_text(cm_info $cm, $course) {
2061 debugging('Function get_print_section_cm_text() is deprecated. Please use '.
2062 'cm_info::get_formatted_content() and cm_info::get_formatted_name()',
2063 DEBUG_DEVELOPER);
2064 return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)),
2065 $cm->get_formatted_name());
2069 * Prints the menus to add activities and resources.
2071 * Deprecated. Please use:
2072 * $courserenderer = $PAGE->get_renderer('core', 'course');
2073 * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
2074 * array('inblock' => $vertical));
2075 * echo $output; // if $return argument in print_section_add_menus() set to false
2077 * @deprecated since 2.5
2078 * @see core_course_renderer::course_section_add_cm_control()
2080 * @param stdClass $course course object, must be the same as set on the page
2081 * @param int $section relative section number (field course_sections.section)
2082 * @param null|array $modnames (argument ignored) get_module_types_names() is used instead of argument
2083 * @param bool $vertical Vertical orientation
2084 * @param bool $return Return the menus or send them to output
2085 * @param int $sectionreturn The section to link back to
2086 * @return void|string depending on $return
2088 function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
2089 global $PAGE;
2090 debugging('Function print_section_add_menus() is deprecated. Please use course renderer '.
2091 'function course_section_add_cm_control()', DEBUG_DEVELOPER);
2092 $output = '';
2093 $courserenderer = $PAGE->get_renderer('core', 'course');
2094 $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
2095 array('inblock' => $vertical));
2096 if ($return) {
2097 return $output;
2098 } else {
2099 echo $output;
2100 return !empty($output);
2105 * Produces the editing buttons for a module
2107 * Deprecated. Please use:
2108 * $courserenderer = $PAGE->get_renderer('core', 'course');
2109 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
2110 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
2112 * @deprecated since 2.5
2113 * @see course_get_cm_edit_actions()
2114 * @see core_course_renderer->course_section_cm_edit_actions()
2116 * @param stdClass $mod The module to produce editing buttons for
2117 * @param bool $absolute_ignored (argument ignored) - all links are absolute
2118 * @param bool $moveselect (argument ignored)
2119 * @param int $indent The current indenting
2120 * @param int $section The section to link back to
2121 * @return string XHTML for the editing buttons
2123 function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
2124 global $PAGE;
2125 debugging('Function make_editing_buttons() is deprecated, please see PHPdocs in '.
2126 'lib/deprecatedlib.php on how to replace it', DEBUG_DEVELOPER);
2127 if (!($mod instanceof cm_info)) {
2128 $modinfo = get_fast_modinfo($mod->course);
2129 $mod = $modinfo->get_cm($mod->id);
2131 $actions = course_get_cm_edit_actions($mod, $indent, $section);
2133 $courserenderer = $PAGE->get_renderer('core', 'course');
2134 // The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap
2135 // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
2136 // the course page HTML will allow this to be removed.
2137 return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
2141 * Prints a section full of activity modules
2143 * Deprecated. Please use:
2144 * $courserenderer = $PAGE->get_renderer('core', 'course');
2145 * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn,
2146 * array('hidecompletion' => $hidecompletion));
2148 * @deprecated since 2.5
2149 * @see core_course_renderer::course_section_cm_list()
2151 * @param stdClass $course The course
2152 * @param stdClass|section_info $section The section object containing properties id and section
2153 * @param array $mods (argument not used)
2154 * @param array $modnamesused (argument not used)
2155 * @param bool $absolute (argument not used)
2156 * @param string $width (argument not used)
2157 * @param bool $hidecompletion Hide completion status
2158 * @param int $sectionreturn The section to return to
2159 * @return void
2161 function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
2162 global $PAGE;
2163 debugging('Function print_section() is deprecated. Please use course renderer function '.
2164 'course_section_cm_list() instead.', DEBUG_DEVELOPER);
2165 $displayoptions = array('hidecompletion' => $hidecompletion);
2166 $courserenderer = $PAGE->get_renderer('core', 'course');
2167 echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions);
2171 * Displays the list of courses with user notes
2173 * This function is not used in core. It was replaced by block course_overview
2175 * @deprecated since 2.5
2177 * @param array $courses
2178 * @param array $remote_courses
2180 function print_overview($courses, array $remote_courses=array()) {
2181 global $CFG, $USER, $DB, $OUTPUT;
2182 debugging('Function print_overview() is deprecated. Use block course_overview to display this information', DEBUG_DEVELOPER);
2184 $htmlarray = array();
2185 if ($modules = $DB->get_records('modules')) {
2186 foreach ($modules as $mod) {
2187 if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) {
2188 include_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php');
2189 $fname = $mod->name.'_print_overview';
2190 if (function_exists($fname)) {
2191 $fname($courses,$htmlarray);
2196 foreach ($courses as $course) {
2197 $fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
2198 echo $OUTPUT->box_start('coursebox');
2199 $attributes = array('title' => s($fullname));
2200 if (empty($course->visible)) {
2201 $attributes['class'] = 'dimmed';
2203 echo $OUTPUT->heading(html_writer::link(
2204 new moodle_url('/course/view.php', array('id' => $course->id)), $fullname, $attributes), 3);
2205 if (array_key_exists($course->id,$htmlarray)) {
2206 foreach ($htmlarray[$course->id] as $modname => $html) {
2207 echo $html;
2210 echo $OUTPUT->box_end();
2213 if (!empty($remote_courses)) {
2214 echo $OUTPUT->heading(get_string('remotecourses', 'mnet'));
2216 foreach ($remote_courses as $course) {
2217 echo $OUTPUT->box_start('coursebox');
2218 $attributes = array('title' => s($course->fullname));
2219 echo $OUTPUT->heading(html_writer::link(
2220 new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)),
2221 format_string($course->shortname),
2222 $attributes) . ' (' . format_string($course->hostname) . ')', 3);
2223 echo $OUTPUT->box_end();
2228 * This function trawls through the logs looking for
2229 * anything new since the user's last login
2231 * This function was only used to print the content of block recent_activity
2232 * All functionality is moved into class {@link block_recent_activity}
2233 * and renderer {@link block_recent_activity_renderer}
2235 * @deprecated since 2.5
2236 * @param stdClass $course
2238 function print_recent_activity($course) {
2239 // $course is an object
2240 global $CFG, $USER, $SESSION, $DB, $OUTPUT;
2241 debugging('Function print_recent_activity() is deprecated. It is not recommended to'.
2242 ' use it outside of block_recent_activity', DEBUG_DEVELOPER);
2244 $context = context_course::instance($course->id);
2246 $viewfullnames = has_capability('moodle/site:viewfullnames', $context);
2248 $timestart = round(time() - COURSE_MAX_RECENT_PERIOD, -2); // better db caching for guests - 100 seconds
2250 if (!isguestuser()) {
2251 if (!empty($USER->lastcourseaccess[$course->id])) {
2252 if ($USER->lastcourseaccess[$course->id] > $timestart) {
2253 $timestart = $USER->lastcourseaccess[$course->id];
2258 echo '<div class="activitydate">';
2259 echo get_string('activitysince', '', userdate($timestart));
2260 echo '</div>';
2261 echo '<div class="activityhead">';
2263 echo '<a href="'.$CFG->wwwroot.'/course/recent.php?id='.$course->id.'">'.get_string('recentactivityreport').'</a>';
2265 echo "</div>\n";
2267 $content = false;
2269 /// Firstly, have there been any new enrolments?
2271 $users = get_recent_enrolments($course->id, $timestart);
2273 //Accessibility: new users now appear in an <OL> list.
2274 if ($users) {
2275 echo '<div class="newusers">';
2276 echo $OUTPUT->heading(get_string("newusers").':', 3);
2277 $content = true;
2278 echo "<ol class=\"list\">\n";
2279 foreach ($users as $user) {
2280 $fullname = fullname($user, $viewfullnames);
2281 echo '<li class="name"><a href="'."$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a></li>\n";
2283 echo "</ol>\n</div>\n";
2286 /// Next, have there been any modifications to the course structure?
2288 $modinfo = get_fast_modinfo($course);
2290 $changelist = array();
2292 $logs = $DB->get_records_select('log', "time > ? AND course = ? AND
2293 module = 'course' AND
2294 (action = 'add mod' OR action = 'update mod' OR action = 'delete mod')",
2295 array($timestart, $course->id), "id ASC");
2297 if ($logs) {
2298 $actions = array('add mod', 'update mod', 'delete mod');
2299 $newgones = array(); // added and later deleted items
2300 foreach ($logs as $key => $log) {
2301 if (!in_array($log->action, $actions)) {
2302 continue;
2304 $info = explode(' ', $log->info);
2306 // note: in most cases I replaced hardcoding of label with use of
2307 // $cm->has_view() but it was not possible to do this here because
2308 // we don't necessarily have the $cm for it
2309 if ($info[0] == 'label') { // Labels are ignored in recent activity
2310 continue;
2313 if (count($info) != 2) {
2314 debugging("Incorrect log entry info: id = ".$log->id, DEBUG_DEVELOPER);
2315 continue;
2318 $modname = $info[0];
2319 $instanceid = $info[1];
2321 if ($log->action == 'delete mod') {
2322 // unfortunately we do not know if the mod was visible
2323 if (!array_key_exists($log->info, $newgones)) {
2324 $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $modname));
2325 $changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted);
2327 } else {
2328 if (!isset($modinfo->instances[$modname][$instanceid])) {
2329 if ($log->action == 'add mod') {
2330 // do not display added and later deleted activities
2331 $newgones[$log->info] = true;
2333 continue;
2335 $cm = $modinfo->instances[$modname][$instanceid];
2336 if (!$cm->uservisible) {
2337 continue;
2340 if ($log->action == 'add mod') {
2341 $stradded = get_string('added', 'moodle', get_string('modulename', $modname));
2342 $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>");
2344 } else if ($log->action == 'update mod' and empty($changelist[$log->info])) {
2345 $strupdated = get_string('updated', 'moodle', get_string('modulename', $modname));
2346 $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>");
2352 if (!empty($changelist)) {
2353 echo $OUTPUT->heading(get_string("courseupdates").':', 3);
2354 $content = true;
2355 foreach ($changelist as $changeinfo => $change) {
2356 echo '<p class="activity">'.$change['text'].'</p>';
2360 /// Now display new things from each module
2362 $usedmodules = array();
2363 foreach($modinfo->cms as $cm) {
2364 if (isset($usedmodules[$cm->modname])) {
2365 continue;
2367 if (!$cm->uservisible) {
2368 continue;
2370 $usedmodules[$cm->modname] = $cm->modname;
2373 foreach ($usedmodules as $modname) { // Each module gets it's own logs and prints them
2374 if (file_exists($CFG->dirroot.'/mod/'.$modname.'/lib.php')) {
2375 include_once($CFG->dirroot.'/mod/'.$modname.'/lib.php');
2376 $print_recent_activity = $modname.'_print_recent_activity';
2377 if (function_exists($print_recent_activity)) {
2378 // NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames!
2379 $content = $print_recent_activity($course, $viewfullnames, $timestart) || $content;
2381 } else {
2382 debugging("Missing lib.php in lib/{$modname} - please reinstall files or uninstall the module");
2386 if (! $content) {
2387 echo '<p class="message">'.get_string('nothingnew').'</p>';
2392 * Delete a course module and any associated data at the course level (events)
2393 * Until 1.5 this function simply marked a deleted flag ... now it
2394 * deletes it completely.
2396 * @deprecated since 2.5
2398 * @param int $id the course module id
2399 * @return boolean true on success, false on failure
2401 function delete_course_module($id) {
2402 debugging('Function delete_course_module() is deprecated. Please use course_delete_module() instead.', DEBUG_DEVELOPER);
2404 global $CFG, $DB;
2406 require_once($CFG->libdir.'/gradelib.php');
2407 require_once($CFG->dirroot.'/blog/lib.php');
2409 if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) {
2410 return true;
2412 $modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module));
2413 //delete events from calendar
2414 if ($events = $DB->get_records('event', array('instance'=>$cm->instance, 'modulename'=>$modulename))) {
2415 foreach($events as $event) {
2416 delete_event($event->id);
2419 //delete grade items, outcome items and grades attached to modules
2420 if ($grade_items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename,
2421 'iteminstance'=>$cm->instance, 'courseid'=>$cm->course))) {
2422 foreach ($grade_items as $grade_item) {
2423 $grade_item->delete('moddelete');
2426 // Delete completion and availability data; it is better to do this even if the
2427 // features are not turned on, in case they were turned on previously (these will be
2428 // very quick on an empty table)
2429 $DB->delete_records('course_modules_completion', array('coursemoduleid' => $cm->id));
2430 $DB->delete_records('course_completion_criteria', array('moduleinstance' => $cm->id,
2431 'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY));
2433 delete_context(CONTEXT_MODULE, $cm->id);
2434 return $DB->delete_records('course_modules', array('id'=>$cm->id));
2438 * Prints the turn editing on/off button on course/index.php or course/category.php.
2440 * @deprecated since 2.5
2442 * @param integer $categoryid The id of the category we are showing, or 0 for system context.
2443 * @return string HTML of the editing button, or empty string, if this user is not allowed
2444 * to see it.
2446 function update_category_button($categoryid = 0) {
2447 global $CFG, $PAGE, $OUTPUT;
2448 debugging('Function update_category_button() is deprecated. Pages to view '.
2449 'and edit courses are now separate and no longer depend on editing mode.',
2450 DEBUG_DEVELOPER);
2452 // Check permissions.
2453 if (!can_edit_in_category($categoryid)) {
2454 return '';
2457 // Work out the appropriate action.
2458 if ($PAGE->user_is_editing()) {
2459 $label = get_string('turneditingoff');
2460 $edit = 'off';
2461 } else {
2462 $label = get_string('turneditingon');
2463 $edit = 'on';
2466 // Generate the button HTML.
2467 $options = array('categoryedit' => $edit, 'sesskey' => sesskey());
2468 if ($categoryid) {
2469 $options['id'] = $categoryid;
2470 $page = 'category.php';
2471 } else {
2472 $page = 'index.php';
2474 return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get');
2478 * This function recursively travels the categories, building up a nice list
2479 * for display. It also makes an array that list all the parents for each
2480 * category.
2482 * For example, if you have a tree of categories like:
2483 * Miscellaneous (id = 1)
2484 * Subcategory (id = 2)
2485 * Sub-subcategory (id = 4)
2486 * Other category (id = 3)
2487 * Then after calling this function you will have
2488 * $list = array(1 => 'Miscellaneous', 2 => 'Miscellaneous / Subcategory',
2489 * 4 => 'Miscellaneous / Subcategory / Sub-subcategory',
2490 * 3 => 'Other category');
2491 * $parents = array(2 => array(1), 4 => array(1, 2));
2493 * If you specify $requiredcapability, then only categories where the current
2494 * user has that capability will be added to $list, although all categories
2495 * will still be added to $parents, and if you only have $requiredcapability
2496 * in a child category, not the parent, then the child catgegory will still be
2497 * included.
2499 * If you specify the option $excluded, then that category, and all its children,
2500 * are omitted from the tree. This is useful when you are doing something like
2501 * moving categories, where you do not want to allow people to move a category
2502 * to be the child of itself.
2504 * This function is deprecated! For list of categories use
2505 * coursecat::make_all_categories($requiredcapability, $excludeid, $separator)
2506 * For parents of one particular category use
2507 * coursecat::get($id)->get_parents()
2509 * @deprecated since 2.5
2511 * @param array $list For output, accumulates an array categoryid => full category path name
2512 * @param array $parents For output, accumulates an array categoryid => list of parent category ids.
2513 * @param string/array $requiredcapability if given, only categories where the current
2514 * user has this capability will be added to $list. Can also be an array of capabilities,
2515 * in which case they are all required.
2516 * @param integer $excludeid Omit this category and its children from the lists built.
2517 * @param object $category Not used
2518 * @param string $path Not used
2520 function make_categories_list(&$list, &$parents, $requiredcapability = '',
2521 $excludeid = 0, $category = NULL, $path = "") {
2522 global $CFG, $DB;
2523 require_once($CFG->libdir.'/coursecatlib.php');
2525 debugging('Global function make_categories_list() is deprecated. Please use '.
2526 'coursecat::make_categories_list() and coursecat::get_parents()',
2527 DEBUG_DEVELOPER);
2529 // For categories list use just this one function:
2530 if (empty($list)) {
2531 $list = array();
2533 $list += coursecat::make_categories_list($requiredcapability, $excludeid);
2535 // Building the list of all parents of all categories in the system is highly undesirable and hardly ever needed.
2536 // Usually user needs only parents for one particular category, in which case should be used:
2537 // coursecat::get($categoryid)->get_parents()
2538 if (empty($parents)) {
2539 $parents = array();
2541 $all = $DB->get_records_sql('SELECT id, parent FROM {course_categories} ORDER BY sortorder');
2542 foreach ($all as $record) {
2543 if ($record->parent) {
2544 $parents[$record->id] = array_merge($parents[$record->parent], array($record->parent));
2545 } else {
2546 $parents[$record->id] = array();
2552 * Delete category, but move contents to another category.
2554 * This function is deprecated. Please use
2555 * coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2557 * @see coursecat::delete_move()
2558 * @deprecated since 2.5
2560 * @param object $category
2561 * @param int $newparentid category id
2562 * @return bool status
2564 function category_delete_move($category, $newparentid, $showfeedback=true) {
2565 global $CFG;
2566 require_once($CFG->libdir.'/coursecatlib.php');
2568 debugging('Function category_delete_move() is deprecated. Please use coursecat::delete_move() instead.');
2570 return coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2574 * Recursively delete category including all subcategories and courses.
2576 * This function is deprecated. Please use
2577 * coursecat::get($category->id)->delete_full($showfeedback);
2579 * @see coursecat::delete_full()
2580 * @deprecated since 2.5
2582 * @param stdClass $category
2583 * @param boolean $showfeedback display some notices
2584 * @return array return deleted courses
2586 function category_delete_full($category, $showfeedback=true) {
2587 global $CFG, $DB;
2588 require_once($CFG->libdir.'/coursecatlib.php');
2590 debugging('Function category_delete_full() is deprecated. Please use coursecat::delete_full() instead.');
2592 return coursecat::get($category->id)->delete_full($showfeedback);
2596 * Efficiently moves a category - NOTE that this can have
2597 * a huge impact access-control-wise...
2599 * This function is deprecated. Please use
2600 * $coursecat = coursecat::get($category->id);
2601 * if ($coursecat->can_change_parent($newparentcat->id)) {
2602 * $coursecat->change_parent($newparentcat->id);
2605 * Alternatively you can use
2606 * $coursecat->update(array('parent' => $newparentcat->id));
2608 * Function update() also updates field course_categories.timemodified
2610 * @see coursecat::change_parent()
2611 * @see coursecat::update()
2612 * @deprecated since 2.5
2614 * @param stdClass|coursecat $category
2615 * @param stdClass|coursecat $newparentcat
2617 function move_category($category, $newparentcat) {
2618 global $CFG;
2619 require_once($CFG->libdir.'/coursecatlib.php');
2621 debugging('Function move_category() is deprecated. Please use coursecat::change_parent() instead.');
2623 return coursecat::get($category->id)->change_parent($newparentcat->id);
2627 * Hide course category and child course and subcategories
2629 * This function is deprecated. Please use
2630 * coursecat::get($category->id)->hide();
2632 * @see coursecat::hide()
2633 * @deprecated since 2.5
2635 * @param stdClass $category
2636 * @return void
2638 function course_category_hide($category) {
2639 global $CFG;
2640 require_once($CFG->libdir.'/coursecatlib.php');
2642 debugging('Function course_category_hide() is deprecated. Please use coursecat::hide() instead.');
2644 coursecat::get($category->id)->hide();
2648 * Show course category and child course and subcategories
2650 * This function is deprecated. Please use
2651 * coursecat::get($category->id)->show();
2653 * @see coursecat::show()
2654 * @deprecated since 2.5
2656 * @param stdClass $category
2657 * @return void
2659 function course_category_show($category) {
2660 global $CFG;
2661 require_once($CFG->libdir.'/coursecatlib.php');
2663 debugging('Function course_category_show() is deprecated. Please use coursecat::show() instead.');
2665 coursecat::get($category->id)->show();
2669 * Return specified category, default if given does not exist
2671 * This function is deprecated.
2672 * To get the category with the specified it please use:
2673 * coursecat::get($catid, IGNORE_MISSING);
2674 * or
2675 * coursecat::get($catid, MUST_EXIST);
2677 * To get the first available category please use
2678 * coursecat::get_default();
2680 * class coursecat will also make sure that at least one category exists in DB
2682 * @deprecated since 2.5
2683 * @see coursecat::get()
2684 * @see coursecat::get_default()
2686 * @param int $catid course category id
2687 * @return object caregory
2689 function get_course_category($catid=0) {
2690 global $DB;
2692 debugging('Function get_course_category() is deprecated. Please use coursecat::get(), see phpdocs for more details');
2694 $category = false;
2696 if (!empty($catid)) {
2697 $category = $DB->get_record('course_categories', array('id'=>$catid));
2700 if (!$category) {
2701 // the first category is considered default for now
2702 if ($category = $DB->get_records('course_categories', null, 'sortorder', '*', 0, 1)) {
2703 $category = reset($category);
2705 } else {
2706 $cat = new stdClass();
2707 $cat->name = get_string('miscellaneous');
2708 $cat->depth = 1;
2709 $cat->sortorder = MAX_COURSES_IN_CATEGORY;
2710 $cat->timemodified = time();
2711 $catid = $DB->insert_record('course_categories', $cat);
2712 // make sure category context exists
2713 context_coursecat::instance($catid);
2714 mark_context_dirty('/'.SYSCONTEXTID);
2715 fix_course_sortorder(); // Required to build course_categories.depth and .path.
2716 $category = $DB->get_record('course_categories', array('id'=>$catid));
2720 return $category;
2724 * Create a new course category and marks the context as dirty
2726 * This function does not set the sortorder for the new category and
2727 * {@link fix_course_sortorder()} should be called after creating a new course
2728 * category
2730 * Please note that this function does not verify access control.
2732 * This function is deprecated. It is replaced with the method create() in class coursecat.
2733 * {@link coursecat::create()} also verifies the data, fixes sortorder and logs the action
2735 * @deprecated since 2.5
2737 * @param object $category All of the data required for an entry in the course_categories table
2738 * @return object new course category
2740 function create_course_category($category) {
2741 global $DB;
2743 debugging('Function create_course_category() is deprecated. Please use coursecat::create(), see phpdocs for more details', DEBUG_DEVELOPER);
2745 $category->timemodified = time();
2746 $category->id = $DB->insert_record('course_categories', $category);
2747 $category = $DB->get_record('course_categories', array('id' => $category->id));
2749 // We should mark the context as dirty
2750 $category->context = context_coursecat::instance($category->id);
2751 $category->context->mark_dirty();
2753 return $category;
2757 * Returns an array of category ids of all the subcategories for a given
2758 * category.
2760 * This function is deprecated.
2762 * To get visible children categories of the given category use:
2763 * coursecat::get($categoryid)->get_children();
2764 * This function will return the array or coursecat objects, on each of them
2765 * you can call get_children() again
2767 * @see coursecat::get()
2768 * @see coursecat::get_children()
2770 * @deprecated since 2.5
2772 * @global object
2773 * @param int $catid - The id of the category whose subcategories we want to find.
2774 * @return array of category ids.
2776 function get_all_subcategories($catid) {
2777 global $DB;
2779 debugging('Function get_all_subcategories() is deprecated. Please use appropriate methods() of coursecat class. See phpdocs for more details',
2780 DEBUG_DEVELOPER);
2782 $subcats = array();
2784 if ($categories = $DB->get_records('course_categories', array('parent' => $catid))) {
2785 foreach ($categories as $cat) {
2786 array_push($subcats, $cat->id);
2787 $subcats = array_merge($subcats, get_all_subcategories($cat->id));
2790 return $subcats;
2794 * Gets the child categories of a given courses category
2796 * This function is deprecated. Please use functions in class coursecat:
2797 * - coursecat::get($parentid)->has_children()
2798 * tells if the category has children (visible or not to the current user)
2800 * - coursecat::get($parentid)->get_children()
2801 * returns an array of coursecat objects, each of them represents a children category visible
2802 * to the current user (i.e. visible=1 or user has capability to view hidden categories)
2804 * - coursecat::get($parentid)->get_children_count()
2805 * returns number of children categories visible to the current user
2807 * - coursecat::count_all()
2808 * returns total count of all categories in the system (both visible and not)
2810 * - coursecat::get_default()
2811 * returns the first category (usually to be used if count_all() == 1)
2813 * @deprecated since 2.5
2815 * @param int $parentid the id of a course category.
2816 * @return array all the child course categories.
2818 function get_child_categories($parentid) {
2819 global $DB;
2820 debugging('Function get_child_categories() is deprecated. Use coursecat::get_children() or see phpdocs for more details.',
2821 DEBUG_DEVELOPER);
2823 $rv = array();
2824 $sql = context_helper::get_preload_record_columns_sql('ctx');
2825 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
2826 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
2827 array(CONTEXT_COURSECAT, $parentid));
2828 foreach ($records as $category) {
2829 context_helper::preload_from_record($category);
2830 if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) {
2831 continue;
2833 $rv[] = $category;
2835 return $rv;
2839 * Returns a sorted list of categories.
2841 * When asking for $parent='none' it will return all the categories, regardless
2842 * of depth. Wheen asking for a specific parent, the default is to return
2843 * a "shallow" resultset. Pass false to $shallow and it will return all
2844 * the child categories as well.
2846 * @deprecated since 2.5
2848 * This function is deprecated. Use appropriate functions from class coursecat.
2849 * Examples:
2851 * coursecat::get($categoryid)->get_children()
2852 * - returns all children of the specified category as instances of class
2853 * coursecat, which means on each of them method get_children() can be called again.
2854 * Only categories visible to the current user are returned.
2856 * coursecat::get(0)->get_children()
2857 * - returns all top-level categories visible to the current user.
2859 * Sort fields can be specified, see phpdocs to {@link coursecat::get_children()}
2861 * coursecat::make_categories_list()
2862 * - returns an array of all categories id/names in the system.
2863 * Also only returns categories visible to current user and can additionally be
2864 * filetered by capability, see phpdocs to {@link coursecat::make_categories_list()}
2866 * make_categories_options()
2867 * - Returns full course categories tree to be used in html_writer::select()
2869 * Also see functions {@link coursecat::get_children_count()}, {@link coursecat::count_all()},
2870 * {@link coursecat::get_default()}
2872 * The code of this deprecated function is left as it is because coursecat::get_children()
2873 * returns categories as instances of coursecat and not stdClass. Also there is no
2874 * substitute for retrieving the category with all it's subcategories. Plugin developers
2875 * may re-use the code/queries from this function in their plugins if really necessary.
2877 * @param string $parent The parent category if any
2878 * @param string $sort the sortorder
2879 * @param bool $shallow - set to false to get the children too
2880 * @return array of categories
2882 function get_categories($parent='none', $sort=NULL, $shallow=true) {
2883 global $DB;
2885 debugging('Function get_categories() is deprecated. Please use coursecat::get_children() or see phpdocs for other alternatives',
2886 DEBUG_DEVELOPER);
2888 if ($sort === NULL) {
2889 $sort = 'ORDER BY cc.sortorder ASC';
2890 } elseif ($sort ==='') {
2891 // leave it as empty
2892 } else {
2893 $sort = "ORDER BY $sort";
2896 list($ccselect, $ccjoin) = context_instance_preload_sql('cc.id', CONTEXT_COURSECAT, 'ctx');
2898 if ($parent === 'none') {
2899 $sql = "SELECT cc.* $ccselect
2900 FROM {course_categories} cc
2901 $ccjoin
2902 $sort";
2903 $params = array();
2905 } elseif ($shallow) {
2906 $sql = "SELECT cc.* $ccselect
2907 FROM {course_categories} cc
2908 $ccjoin
2909 WHERE cc.parent=?
2910 $sort";
2911 $params = array($parent);
2913 } else {
2914 $sql = "SELECT cc.* $ccselect
2915 FROM {course_categories} cc
2916 $ccjoin
2917 JOIN {course_categories} ccp
2918 ON ((cc.parent = ccp.id) OR (cc.path LIKE ".$DB->sql_concat('ccp.path',"'/%'")."))
2919 WHERE ccp.id=?
2920 $sort";
2921 $params = array($parent);
2923 $categories = array();
2925 $rs = $DB->get_recordset_sql($sql, $params);
2926 foreach($rs as $cat) {
2927 context_helper::preload_from_record($cat);
2928 $catcontext = context_coursecat::instance($cat->id);
2929 if ($cat->visible || has_capability('moodle/category:viewhiddencategories', $catcontext)) {
2930 $categories[$cat->id] = $cat;
2933 $rs->close();
2934 return $categories;
2938 * Displays a course search form
2940 * This function is deprecated, please use course renderer:
2941 * $renderer = $PAGE->get_renderer('core', 'course');
2942 * echo $renderer->course_search_form($value, $format);
2944 * @deprecated since 2.5
2946 * @param string $value default value to populate the search field
2947 * @param bool $return if true returns the value, if false - outputs
2948 * @param string $format display format - 'plain' (default), 'short' or 'navbar'
2949 * @return null|string
2951 function print_course_search($value="", $return=false, $format="plain") {
2952 global $PAGE;
2953 debugging('Function print_course_search() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2954 $renderer = $PAGE->get_renderer('core', 'course');
2955 if ($return) {
2956 return $renderer->course_search_form($value, $format);
2957 } else {
2958 echo $renderer->course_search_form($value, $format);
2963 * Prints custom user information on the home page
2965 * This function is deprecated, please use:
2966 * $renderer = $PAGE->get_renderer('core', 'course');
2967 * echo $renderer->frontpage_my_courses()
2969 * @deprecated since 2.5
2971 function print_my_moodle() {
2972 global $PAGE;
2973 debugging('Function print_my_moodle() is deprecated, please use course renderer function frontpage_my_courses()', DEBUG_DEVELOPER);
2975 $renderer = $PAGE->get_renderer('core', 'course');
2976 echo $renderer->frontpage_my_courses();
2980 * Prints information about one remote course
2982 * This function is deprecated, it is replaced with protected function
2983 * {@link core_course_renderer::frontpage_remote_course()}
2984 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
2986 * @deprecated since 2.5
2988 function print_remote_course($course, $width="100%") {
2989 global $CFG, $USER;
2990 debugging('Function print_remote_course() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2992 $linkcss = '';
2994 $url = "{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&amp;wantsurl=/course/view.php?id={$course->remoteid}";
2996 echo '<div class="coursebox remotecoursebox clearfix">';
2997 echo '<div class="info">';
2998 echo '<div class="name"><a title="'.get_string('entercourse').'"'.
2999 $linkcss.' href="'.$url.'">'
3000 . format_string($course->fullname) .'</a><br />'
3001 . format_string($course->hostname) . ' : '
3002 . format_string($course->cat_name) . ' : '
3003 . format_string($course->shortname). '</div>';
3004 echo '</div><div class="summary">';
3005 $options = new stdClass();
3006 $options->noclean = true;
3007 $options->para = false;
3008 $options->overflowdiv = true;
3009 echo format_text($course->summary, $course->summaryformat, $options);
3010 echo '</div>';
3011 echo '</div>';
3015 * Prints information about one remote host
3017 * This function is deprecated, it is replaced with protected function
3018 * {@link core_course_renderer::frontpage_remote_host()}
3019 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
3021 * @deprecated since 2.5
3023 function print_remote_host($host, $width="100%") {
3024 global $OUTPUT;
3025 debugging('Function print_remote_host() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3027 $linkcss = '';
3029 echo '<div class="coursebox clearfix">';
3030 echo '<div class="info">';
3031 echo '<div class="name">';
3032 echo '<img src="'.$OUTPUT->pix_url('i/mnethost') . '" class="icon" alt="'.get_string('course').'" />';
3033 echo '<a title="'.s($host['name']).'" href="'.s($host['url']).'">'
3034 . s($host['name']).'</a> - ';
3035 echo $host['count'] . ' ' . get_string('courses');
3036 echo '</div>';
3037 echo '</div>';
3038 echo '</div>';
3042 * Recursive function to print out all the categories in a nice format
3043 * with or without courses included
3045 * @deprecated since 2.5
3047 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3049 function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) {
3050 global $PAGE;
3051 debugging('Function print_whole_category_list() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3053 $renderer = $PAGE->get_renderer('core', 'course');
3054 if ($showcourses && $category) {
3055 echo $renderer->course_category($category);
3056 } else if ($showcourses) {
3057 echo $renderer->frontpage_combo_list();
3058 } else {
3059 echo $renderer->frontpage_categories_list();
3064 * Prints the category information.
3066 * @deprecated since 2.5
3068 * This function was only used by {@link print_whole_category_list()} but now
3069 * all course category rendering is moved to core_course_renderer.
3071 * @param stdClass $category
3072 * @param int $depth The depth of the category.
3073 * @param bool $showcourses If set to true course information will also be printed.
3074 * @param array|null $courses An array of courses belonging to the category, or null if you don't have it yet.
3076 function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) {
3077 global $PAGE;
3078 debugging('Function print_category_info() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3080 $renderer = $PAGE->get_renderer('core', 'course');
3081 echo $renderer->course_category($category);
3085 * This function generates a structured array of courses and categories.
3087 * @deprecated since 2.5
3089 * This function is not used any more in moodle core and course renderer does not have render function for it.
3090 * Combo list on the front page is displayed as:
3091 * $renderer = $PAGE->get_renderer('core', 'course');
3092 * echo $renderer->frontpage_combo_list()
3094 * The new class {@link coursecat} stores the information about course category tree
3095 * To get children categories use:
3096 * coursecat::get($id)->get_children()
3097 * To get list of courses use:
3098 * coursecat::get($id)->get_courses()
3100 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3102 * @param int $id
3103 * @param int $depth
3105 function get_course_category_tree($id = 0, $depth = 0) {
3106 global $DB, $CFG;
3107 if (!$depth) {
3108 debugging('Function get_course_category_tree() is deprecated, please use course renderer or coursecat class, see function phpdocs for more info', DEBUG_DEVELOPER);
3111 $categories = array();
3112 $categoryids = array();
3113 $sql = context_helper::get_preload_record_columns_sql('ctx');
3114 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
3115 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
3116 array(CONTEXT_COURSECAT, $id));
3117 foreach ($records as $category) {
3118 context_helper::preload_from_record($category);
3119 if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) {
3120 continue;
3122 $categories[] = $category;
3123 $categoryids[$category->id] = $category;
3124 if (empty($CFG->maxcategorydepth) || $depth <= $CFG->maxcategorydepth) {
3125 list($category->categories, $subcategories) = get_course_category_tree($category->id, $depth+1);
3126 foreach ($subcategories as $subid=>$subcat) {
3127 $categoryids[$subid] = $subcat;
3129 $category->courses = array();
3133 if ($depth > 0) {
3134 // This is a recursive call so return the required array
3135 return array($categories, $categoryids);
3138 if (empty($categoryids)) {
3139 // No categories available (probably all hidden).
3140 return array();
3143 // The depth is 0 this function has just been called so we can finish it off
3145 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
3146 list($catsql, $catparams) = $DB->get_in_or_equal(array_keys($categoryids));
3147 $sql = "SELECT
3148 c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary,c.category
3149 $ccselect
3150 FROM {course} c
3151 $ccjoin
3152 WHERE c.category $catsql ORDER BY c.sortorder ASC";
3153 if ($courses = $DB->get_records_sql($sql, $catparams)) {
3154 // loop throught them
3155 foreach ($courses as $course) {
3156 if ($course->id == SITEID) {
3157 continue;
3159 context_helper::preload_from_record($course);
3160 if (!empty($course->visible) || has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
3161 $categoryids[$course->category]->courses[$course->id] = $course;
3165 return $categories;
3169 * Print courses in category. If category is 0 then all courses are printed.
3171 * @deprecated since 2.5
3173 * To print a generic list of courses use:
3174 * $renderer = $PAGE->get_renderer('core', 'course');
3175 * echo $renderer->courses_list($courses);
3177 * To print list of all courses:
3178 * $renderer = $PAGE->get_renderer('core', 'course');
3179 * echo $renderer->frontpage_available_courses();
3181 * To print list of courses inside category:
3182 * $renderer = $PAGE->get_renderer('core', 'course');
3183 * echo $renderer->course_category($category); // this will also print subcategories
3185 * @param int|stdClass $category category object or id.
3186 * @return bool true if courses found and printed, else false.
3188 function print_courses($category) {
3189 global $CFG, $OUTPUT, $PAGE;
3190 require_once($CFG->libdir. '/coursecatlib.php');
3191 debugging('Function print_courses() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3193 if (!is_object($category) && $category==0) {
3194 $courses = coursecat::get(0)->get_courses(array('recursive' => true, 'summary' => true, 'coursecontacts' => true));
3195 } else {
3196 $courses = coursecat::get($category->id)->get_courses(array('summary' => true, 'coursecontacts' => true));
3199 if ($courses) {
3200 $renderer = $PAGE->get_renderer('core', 'course');
3201 echo $renderer->courses_list($courses);
3202 } else {
3203 echo $OUTPUT->heading(get_string("nocoursesyet"));
3204 $context = context_system::instance();
3205 if (has_capability('moodle/course:create', $context)) {
3206 $options = array();
3207 if (!empty($category->id)) {
3208 $options['category'] = $category->id;
3209 } else {
3210 $options['category'] = $CFG->defaultrequestcategory;
3212 echo html_writer::start_tag('div', array('class'=>'addcoursebutton'));
3213 echo $OUTPUT->single_button(new moodle_url('/course/edit.php', $options), get_string("addnewcourse"));
3214 echo html_writer::end_tag('div');
3215 return false;
3218 return true;
3222 * Print a description of a course, suitable for browsing in a list.
3224 * @deprecated since 2.5
3226 * Please use course renderer to display a course information box.
3227 * $renderer = $PAGE->get_renderer('core', 'course');
3228 * echo $renderer->courses_list($courses); // will print list of courses
3229 * echo $renderer->course_info_box($course); // will print one course wrapped in div.generalbox
3231 * @param object $course the course object.
3232 * @param string $highlightterms Ignored in this deprecated function!
3234 function print_course($course, $highlightterms = '') {
3235 global $PAGE;
3237 debugging('Function print_course() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3238 $renderer = $PAGE->get_renderer('core', 'course');
3239 // Please note, correct would be to use $renderer->coursecat_coursebox() but this function is protected.
3240 // To print list of courses use $renderer->courses_list();
3241 echo $renderer->course_info_box($course);
3245 * Gets an array whose keys are category ids and whose values are arrays of courses in the corresponding category.
3247 * @deprecated since 2.5
3249 * This function is not used any more in moodle core and course renderer does not have render function for it.
3250 * Combo list on the front page is displayed as:
3251 * $renderer = $PAGE->get_renderer('core', 'course');
3252 * echo $renderer->frontpage_combo_list()
3254 * The new class {@link coursecat} stores the information about course category tree
3255 * To get children categories use:
3256 * coursecat::get($id)->get_children()
3257 * To get list of courses use:
3258 * coursecat::get($id)->get_courses()
3260 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3262 * @param int $categoryid
3263 * @return array
3265 function get_category_courses_array($categoryid = 0) {
3266 debugging('Function get_category_courses_array() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
3267 $tree = get_course_category_tree($categoryid);
3268 $flattened = array();
3269 foreach ($tree as $category) {
3270 get_category_courses_array_recursively($flattened, $category);
3272 return $flattened;
3276 * Recursive function to help flatten the course category tree.
3278 * @deprecated since 2.5
3280 * Was intended to be called from {@link get_category_courses_array()}
3282 * @param array &$flattened An array passed by reference in which to store courses for each category.
3283 * @param stdClass $category The category to get courses for.
3285 function get_category_courses_array_recursively(array &$flattened, $category) {
3286 debugging('Function get_category_courses_array_recursively() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
3287 $flattened[$category->id] = $category->courses;
3288 foreach ($category->categories as $childcategory) {
3289 get_category_courses_array_recursively($flattened, $childcategory);
3294 * Returns a URL based on the context of the current page.
3295 * This URL points to blog/index.php and includes filter parameters appropriate for the current page.
3297 * @param stdclass $context
3298 * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more.
3299 * @todo Remove this in 2.7
3300 * @return string
3302 function blog_get_context_url($context=null) {
3303 global $CFG;
3305 debugging('Function blog_get_context_url() is deprecated, getting params from context is not reliable for blogs.', DEBUG_DEVELOPER);
3306 $viewblogentriesurl = new moodle_url('/blog/index.php');
3308 if (empty($context)) {
3309 global $PAGE;
3310 $context = $PAGE->context;
3313 // Change contextlevel to SYSTEM if viewing the site course
3314 if ($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID) {
3315 $context = context_system::instance();
3318 $filterparam = '';
3319 $strlevel = '';
3321 switch ($context->contextlevel) {
3322 case CONTEXT_SYSTEM:
3323 case CONTEXT_BLOCK:
3324 case CONTEXT_COURSECAT:
3325 break;
3326 case CONTEXT_COURSE:
3327 $filterparam = 'courseid';
3328 $strlevel = get_string('course');
3329 break;
3330 case CONTEXT_MODULE:
3331 $filterparam = 'modid';
3332 $strlevel = $context->get_context_name();
3333 break;
3334 case CONTEXT_USER:
3335 $filterparam = 'userid';
3336 $strlevel = get_string('user');
3337 break;
3340 if (!empty($filterparam)) {
3341 $viewblogentriesurl->param($filterparam, $context->instanceid);
3344 return $viewblogentriesurl;
3348 * Retrieve course records with the course managers and other related records
3349 * that we need for print_course(). This allows print_courses() to do its job
3350 * in a constant number of DB queries, regardless of the number of courses,
3351 * role assignments, etc.
3353 * The returned array is indexed on c.id, and each course will have
3354 * - $course->managers - array containing RA objects that include a $user obj
3355 * with the minimal fields needed for fullname()
3357 * @deprecated since 2.5
3359 * To get list of all courses with course contacts ('managers') use
3360 * coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true));
3362 * To get list of courses inside particular category use
3363 * coursecat::get($id)->get_courses(array('coursecontacts' => true));
3365 * Additionally you can specify sort order, offset and maximum number of courses,
3366 * see {@link coursecat::get_courses()}
3368 * Please note that code of this function is not changed to use coursecat class because
3369 * coursecat::get_courses() returns result in slightly different format. Also note that
3370 * get_courses_wmanagers() DOES NOT check that users are enrolled in the course and
3371 * coursecat::get_courses() does.
3373 * @global object
3374 * @global object
3375 * @global object
3376 * @uses CONTEXT_COURSE
3377 * @uses CONTEXT_SYSTEM
3378 * @uses CONTEXT_COURSECAT
3379 * @uses SITEID
3380 * @param int|string $categoryid Either the categoryid for the courses or 'all'
3381 * @param string $sort A SQL sort field and direction
3382 * @param array $fields An array of additional fields to fetch
3383 * @return array
3385 function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) {
3387 * The plan is to
3389 * - Grab the courses JOINed w/context
3391 * - Grab the interesting course-manager RAs
3392 * JOINed with a base user obj and add them to each course
3394 * So as to do all the work in 2 DB queries. The RA+user JOIN
3395 * ends up being pretty expensive if it happens over _all_
3396 * courses on a large site. (Are we surprised!?)
3398 * So this should _never_ get called with 'all' on a large site.
3401 global $USER, $CFG, $DB;
3402 debugging('Function get_courses_wmanagers() is deprecated, please use coursecat::get_courses()', DEBUG_DEVELOPER);
3404 $params = array();
3405 $allcats = false; // bool flag
3406 if ($categoryid === 'all') {
3407 $categoryclause = '';
3408 $allcats = true;
3409 } elseif (is_numeric($categoryid)) {
3410 $categoryclause = "c.category = :catid";
3411 $params['catid'] = $categoryid;
3412 } else {
3413 debugging("Could not recognise categoryid = $categoryid");
3414 $categoryclause = '';
3417 $basefields = array('id', 'category', 'sortorder',
3418 'shortname', 'fullname', 'idnumber',
3419 'startdate', 'visible',
3420 'newsitems', 'groupmode', 'groupmodeforce');
3422 if (!is_null($fields) && is_string($fields)) {
3423 if (empty($fields)) {
3424 $fields = $basefields;
3425 } else {
3426 // turn the fields from a string to an array that
3427 // get_user_courses_bycap() will like...
3428 $fields = explode(',',$fields);
3429 $fields = array_map('trim', $fields);
3430 $fields = array_unique(array_merge($basefields, $fields));
3432 } elseif (is_array($fields)) {
3433 $fields = array_merge($basefields,$fields);
3435 $coursefields = 'c.' .join(',c.', $fields);
3437 if (empty($sort)) {
3438 $sortstatement = "";
3439 } else {
3440 $sortstatement = "ORDER BY $sort";
3443 $where = 'WHERE c.id != ' . SITEID;
3444 if ($categoryclause !== ''){
3445 $where = "$where AND $categoryclause";
3448 // pull out all courses matching the cat
3449 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
3450 $sql = "SELECT $coursefields $ccselect
3451 FROM {course} c
3452 $ccjoin
3453 $where
3454 $sortstatement";
3456 $catpaths = array();
3457 $catpath = NULL;
3458 if ($courses = $DB->get_records_sql($sql, $params)) {
3459 // loop on courses materialising
3460 // the context, and prepping data to fetch the
3461 // managers efficiently later...
3462 foreach ($courses as $k => $course) {
3463 context_helper::preload_from_record($course);
3464 $coursecontext = context_course::instance($course->id);
3465 $courses[$k] = $course;
3466 $courses[$k]->managers = array();
3467 if ($allcats === false) {
3468 // single cat, so take just the first one...
3469 if ($catpath === NULL) {
3470 $catpath = preg_replace(':/\d+$:', '', $coursecontext->path);
3472 } else {
3473 // chop off the contextid of the course itself
3474 // like dirname() does...
3475 $catpaths[] = preg_replace(':/\d+$:', '', $coursecontext->path);
3478 } else {
3479 return array(); // no courses!
3482 $CFG->coursecontact = trim($CFG->coursecontact);
3483 if (empty($CFG->coursecontact)) {
3484 return $courses;
3487 $managerroles = explode(',', $CFG->coursecontact);
3488 $catctxids = '';
3489 if (count($managerroles)) {
3490 if ($allcats === true) {
3491 $catpaths = array_unique($catpaths);
3492 $ctxids = array();
3493 foreach ($catpaths as $cpath) {
3494 $ctxids = array_merge($ctxids, explode('/',substr($cpath,1)));
3496 $ctxids = array_unique($ctxids);
3497 $catctxids = implode( ',' , $ctxids);
3498 unset($catpaths);
3499 unset($cpath);
3500 } else {
3501 // take the ctx path from the first course
3502 // as all categories will be the same...
3503 $catpath = substr($catpath,1);
3504 $catpath = preg_replace(':/\d+$:','',$catpath);
3505 $catctxids = str_replace('/',',',$catpath);
3507 if ($categoryclause !== '') {
3508 $categoryclause = "AND $categoryclause";
3511 * Note: Here we use a LEFT OUTER JOIN that can
3512 * "optionally" match to avoid passing a ton of context
3513 * ids in an IN() clause. Perhaps a subselect is faster.
3515 * In any case, this SQL is not-so-nice over large sets of
3516 * courses with no $categoryclause.
3519 $sql = "SELECT ctx.path, ctx.instanceid, ctx.contextlevel,
3520 r.id AS roleid, r.name AS rolename, r.shortname AS roleshortname,
3521 rn.name AS rolecoursealias, u.id AS userid, u.firstname, u.lastname
3522 FROM {role_assignments} ra
3523 JOIN {context} ctx ON ra.contextid = ctx.id
3524 JOIN {user} u ON ra.userid = u.id
3525 JOIN {role} r ON ra.roleid = r.id
3526 LEFT JOIN {role_names} rn ON (rn.contextid = ctx.id AND rn.roleid = r.id)
3527 LEFT OUTER JOIN {course} c
3528 ON (ctx.instanceid=c.id AND ctx.contextlevel=".CONTEXT_COURSE.")
3529 WHERE ( c.id IS NOT NULL";
3530 // under certain conditions, $catctxids is NULL
3531 if($catctxids == NULL){
3532 $sql .= ") ";
3533 }else{
3534 $sql .= " OR ra.contextid IN ($catctxids) )";
3537 $sql .= "AND ra.roleid IN ({$CFG->coursecontact})
3538 $categoryclause
3539 ORDER BY r.sortorder ASC, ctx.contextlevel ASC, ra.sortorder ASC";
3540 $rs = $DB->get_recordset_sql($sql, $params);
3542 // This loop is fairly stupid as it stands - might get better
3543 // results doing an initial pass clustering RAs by path.
3544 foreach($rs as $ra) {
3545 $user = new stdClass;
3546 $user->id = $ra->userid; unset($ra->userid);
3547 $user->firstname = $ra->firstname; unset($ra->firstname);
3548 $user->lastname = $ra->lastname; unset($ra->lastname);
3549 $ra->user = $user;
3550 if ($ra->contextlevel == CONTEXT_SYSTEM) {
3551 foreach ($courses as $k => $course) {
3552 $courses[$k]->managers[] = $ra;
3554 } else if ($ra->contextlevel == CONTEXT_COURSECAT) {
3555 if ($allcats === false) {
3556 // It always applies
3557 foreach ($courses as $k => $course) {
3558 $courses[$k]->managers[] = $ra;
3560 } else {
3561 foreach ($courses as $k => $course) {
3562 $coursecontext = context_course::instance($course->id);
3563 // Note that strpos() returns 0 as "matched at pos 0"
3564 if (strpos($coursecontext->path, $ra->path.'/') === 0) {
3565 // Only add it to subpaths
3566 $courses[$k]->managers[] = $ra;
3570 } else { // course-level
3571 if (!array_key_exists($ra->instanceid, $courses)) {
3572 //this course is not in a list, probably a frontpage course
3573 continue;
3575 $courses[$ra->instanceid]->managers[] = $ra;
3578 $rs->close();
3581 return $courses;
3585 * Converts a nested array tree into HTML ul:li [recursive]
3587 * @deprecated since 2.5
3589 * @param array $tree A tree array to convert
3590 * @param int $row Used in identifying the iteration level and in ul classes
3591 * @return string HTML structure
3593 function convert_tree_to_html($tree, $row=0) {
3594 debugging('Function convert_tree_to_html() is deprecated since Moodle 2.5. Consider using class tabtree and core_renderer::render_tabtree()', DEBUG_DEVELOPER);
3596 $str = "\n".'<ul class="tabrow'.$row.'">'."\n";
3598 $first = true;
3599 $count = count($tree);
3601 foreach ($tree as $tab) {
3602 $count--; // countdown to zero
3604 $liclass = '';
3606 if ($first && ($count == 0)) { // Just one in the row
3607 $liclass = 'first last';
3608 $first = false;
3609 } else if ($first) {
3610 $liclass = 'first';
3611 $first = false;
3612 } else if ($count == 0) {
3613 $liclass = 'last';
3616 if ((empty($tab->subtree)) && (!empty($tab->selected))) {
3617 $liclass .= (empty($liclass)) ? 'onerow' : ' onerow';
3620 if ($tab->inactive || $tab->active || $tab->selected) {
3621 if ($tab->selected) {
3622 $liclass .= (empty($liclass)) ? 'here selected' : ' here selected';
3623 } else if ($tab->active) {
3624 $liclass .= (empty($liclass)) ? 'here active' : ' here active';
3628 $str .= (!empty($liclass)) ? '<li class="'.$liclass.'">' : '<li>';
3630 if ($tab->inactive || $tab->active || ($tab->selected && !$tab->linkedwhenselected)) {
3631 // The a tag is used for styling
3632 $str .= '<a class="nolink"><span>'.$tab->text.'</span></a>';
3633 } else {
3634 $str .= '<a href="'.$tab->link.'" title="'.$tab->title.'"><span>'.$tab->text.'</span></a>';
3637 if (!empty($tab->subtree)) {
3638 $str .= convert_tree_to_html($tab->subtree, $row+1);
3639 } else if ($tab->selected) {
3640 $str .= '<div class="tabrow'.($row+1).' empty">&nbsp;</div>'."\n";
3643 $str .= ' </li>'."\n";
3645 $str .= '</ul>'."\n";
3647 return $str;
3651 * Convert nested tabrows to a nested array
3653 * @deprecated since 2.5
3655 * @param array $tabrows A [nested] array of tab row objects
3656 * @param string $selected The tabrow to select (by id)
3657 * @param array $inactive An array of tabrow id's to make inactive
3658 * @param array $activated An array of tabrow id's to make active
3659 * @return array The nested array
3661 function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) {
3663 debugging('Function convert_tabrows_to_tree() is deprecated since Moodle 2.5. Consider using class tabtree', DEBUG_DEVELOPER);
3665 // Work backwards through the rows (bottom to top) collecting the tree as we go.
3666 $tabrows = array_reverse($tabrows);
3668 $subtree = array();
3670 foreach ($tabrows as $row) {
3671 $tree = array();
3673 foreach ($row as $tab) {
3674 $tab->inactive = in_array((string)$tab->id, $inactive);
3675 $tab->active = in_array((string)$tab->id, $activated);
3676 $tab->selected = (string)$tab->id == $selected;
3678 if ($tab->active || $tab->selected) {
3679 if ($subtree) {
3680 $tab->subtree = $subtree;
3683 $tree[] = $tab;
3685 $subtree = $tree;
3688 return $subtree;
3692 * Can handle rotated text. Whether it is safe to use the trickery in textrotate.js.
3694 * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically
3695 * @return bool True for yes, false for no
3697 function can_use_rotated_text() {
3698 debugging('can_use_rotated_text() is deprecated since Moodle 2.5. JS feature detection is used automatically.', DEBUG_DEVELOPER);
3699 return true;
3703 * Get the context instance as an object. This function will create the
3704 * context instance if it does not exist yet.
3706 * @deprecated since 2.2, use context_course::instance() or other relevant class instead
3707 * @todo This will be deleted in Moodle 2.8, refer MDL-34472
3708 * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
3709 * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
3710 * for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
3711 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
3712 * MUST_EXIST means throw exception if no record or multiple records found
3713 * @return context The context object.
3715 function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
3717 debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER);
3719 $instances = (array)$instance;
3720 $contexts = array();
3722 $classname = context_helper::get_class_for_level($contextlevel);
3724 // we do not load multiple contexts any more, PAGE should be responsible for any preloading
3725 foreach ($instances as $inst) {
3726 $contexts[$inst] = $classname::instance($inst, $strictness);
3729 if (is_array($instance)) {
3730 return $contexts;
3731 } else {
3732 return $contexts[$instance];
3737 * Get a context instance as an object, from a given context id.
3739 * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more.
3740 * @todo MDL-34550 This will be deleted in Moodle 2.8
3741 * @see context::instance_by_id($id)
3742 * @param int $id context id
3743 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
3744 * MUST_EXIST means throw exception if no record or multiple records found
3745 * @return context|bool the context object or false if not found.
3747 function get_context_instance_by_id($id, $strictness = IGNORE_MISSING) {
3748 debugging('get_context_instance_by_id() is deprecated, please use context::instance_by_id($id) instead.', DEBUG_DEVELOPER);
3749 return context::instance_by_id($id, $strictness);
3753 * Returns system context or null if can not be created yet.
3755 * @see context_system::instance()
3756 * @deprecated since 2.2
3757 * @param bool $cache use caching
3758 * @return context system context (null if context table not created yet)
3760 function get_system_context($cache = true) {
3761 debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER);
3762 return context_system::instance(0, IGNORE_MISSING, $cache);
3766 * Recursive function which, given a context, find all parent context ids,
3767 * and return the array in reverse order, i.e. parent first, then grand
3768 * parent, etc.
3770 * @see context::get_parent_context_ids()
3771 * @deprecated since 2.2, use $context->get_parent_context_ids() instead
3772 * @param context $context
3773 * @param bool $includeself optional, defaults to false
3774 * @return array
3776 function get_parent_contexts(context $context, $includeself = false) {
3777 debugging('get_parent_contexts() is deprecated, please use $context->get_parent_context_ids() instead.', DEBUG_DEVELOPER);
3778 return $context->get_parent_context_ids($includeself);
3782 * Return the id of the parent of this context, or false if there is no parent (only happens if this
3783 * is the site context.)
3785 * @deprecated since Moodle 2.2
3786 * @see context::get_parent_context()
3787 * @param context $context
3788 * @return integer the id of the parent context.
3790 function get_parent_contextid(context $context) {
3791 debugging('get_parent_contextid() is deprecated, please use $context->get_parent_context() instead.', DEBUG_DEVELOPER);
3793 if ($parent = $context->get_parent_context()) {
3794 return $parent->id;
3795 } else {
3796 return false;
3801 * Recursive function which, given a context, find all its children contexts.
3803 * For course category contexts it will return immediate children only categories and courses.
3804 * It will NOT recurse into courses or child categories.
3805 * If you want to do that, call it on the returned courses/categories.
3807 * When called for a course context, it will return the modules and blocks
3808 * displayed in the course page.
3810 * If called on a user/course/module context it _will_ populate the cache with the appropriate
3811 * contexts ;-)
3813 * @see context::get_child_contexts()
3814 * @deprecated since 2.2
3815 * @param context $context
3816 * @return array Array of child records
3818 function get_child_contexts(context $context) {
3819 debugging('get_child_contexts() is deprecated, please use $context->get_child_contexts() instead.', DEBUG_DEVELOPER);
3820 return $context->get_child_contexts();
3824 * Precreates all contexts including all parents.
3826 * @see context_helper::create_instances()
3827 * @deprecated since 2.2
3828 * @param int $contextlevel empty means all
3829 * @param bool $buildpaths update paths and depths
3830 * @return void
3832 function create_contexts($contextlevel = null, $buildpaths = true) {
3833 debugging('create_contexts() is deprecated, please use context_helper::create_instances() instead.', DEBUG_DEVELOPER);
3834 context_helper::create_instances($contextlevel, $buildpaths);
3838 * Remove stale context records.
3840 * @see context_helper::cleanup_instances()
3841 * @deprecated since 2.2
3842 * @return bool
3844 function cleanup_contexts() {
3845 debugging('cleanup_contexts() is deprecated, please use context_helper::cleanup_instances() instead.', DEBUG_DEVELOPER);
3846 context_helper::cleanup_instances();
3847 return true;
3851 * Populate context.path and context.depth where missing.
3853 * @see context_helper::build_all_paths()
3854 * @deprecated since 2.2
3855 * @param bool $force force a complete rebuild of the path and depth fields, defaults to false
3856 * @return void
3858 function build_context_path($force = false) {
3859 debugging('build_context_path() is deprecated, please use context_helper::build_all_paths() instead.', DEBUG_DEVELOPER);
3860 context_helper::build_all_paths($force);
3864 * Rebuild all related context depth and path caches.
3866 * @see context::reset_paths()
3867 * @deprecated since 2.2
3868 * @param array $fixcontexts array of contexts, strongtyped
3869 * @return void
3871 function rebuild_contexts(array $fixcontexts) {
3872 debugging('rebuild_contexts() is deprecated, please use $context->reset_paths(true) instead.', DEBUG_DEVELOPER);
3873 foreach ($fixcontexts as $fixcontext) {
3874 $fixcontext->reset_paths(false);
3876 context_helper::build_all_paths(false);
3880 * Preloads all contexts relating to a course: course, modules. Block contexts
3881 * are no longer loaded here. The contexts for all the blocks on the current
3882 * page are now efficiently loaded by {@link block_manager::load_blocks()}.
3884 * @deprecated since Moodle 2.2
3885 * @see context_helper::preload_course()
3886 * @param int $courseid Course ID
3887 * @return void
3889 function preload_course_contexts($courseid) {
3890 debugging('preload_course_contexts() is deprecated, please use context_helper::preload_course() instead.', DEBUG_DEVELOPER);
3891 context_helper::preload_course($courseid);
3895 * Update the path field of the context and all dep. subcontexts that follow
3897 * Update the path field of the context and
3898 * all the dependent subcontexts that follow
3899 * the move.
3901 * The most important thing here is to be as
3902 * DB efficient as possible. This op can have a
3903 * massive impact in the DB.
3905 * @deprecated since Moodle 2.2
3906 * @see context::update_moved()
3907 * @param context $context context obj
3908 * @param context $newparent new parent obj
3909 * @return void
3911 function context_moved(context $context, context $newparent) {
3912 debugging('context_moved() is deprecated, please use context::update_moved() instead.', DEBUG_DEVELOPER);
3913 $context->update_moved($newparent);
3917 * Extracts the relevant capabilities given a contextid.
3918 * All case based, example an instance of forum context.
3919 * Will fetch all forum related capabilities, while course contexts
3920 * Will fetch all capabilities
3922 * capabilities
3923 * `name` varchar(150) NOT NULL,
3924 * `captype` varchar(50) NOT NULL,
3925 * `contextlevel` int(10) NOT NULL,
3926 * `component` varchar(100) NOT NULL,
3928 * @see context::get_capabilities()
3929 * @deprecated since 2.2
3930 * @param context $context
3931 * @return array
3933 function fetch_context_capabilities(context $context) {
3934 debugging('fetch_context_capabilities() is deprecated, please use $context->get_capabilities() instead.', DEBUG_DEVELOPER);
3935 return $context->get_capabilities();
3939 * Preloads context information from db record and strips the cached info.
3940 * The db request has to contain both the $join and $select from context_instance_preload_sql()
3942 * @deprecated since 2.2
3943 * @see context_helper::preload_from_record()
3944 * @param stdClass $rec
3945 * @return void (modifies $rec)
3947 function context_instance_preload(stdClass $rec) {
3948 debugging('context_instance_preload() is deprecated, please use context_helper::preload_from_record() instead.', DEBUG_DEVELOPER);
3949 context_helper::preload_from_record($rec);
3953 * Returns context level name
3955 * @deprecated since 2.2
3956 * @see context_helper::get_level_name()
3957 * @param integer $contextlevel $context->context level. One of the CONTEXT_... constants.
3958 * @return string the name for this type of context.
3960 function get_contextlevel_name($contextlevel) {
3961 debugging('get_contextlevel_name() is deprecated, please use context_helper::get_level_name() instead.', DEBUG_DEVELOPER);
3962 return context_helper::get_level_name($contextlevel);
3966 * Prints human readable context identifier.
3968 * @deprecated since 2.2
3969 * @see context::get_context_name()
3970 * @param context $context the context.
3971 * @param boolean $withprefix whether to prefix the name of the context with the
3972 * type of context, e.g. User, Course, Forum, etc.
3973 * @param boolean $short whether to user the short name of the thing. Only applies
3974 * to course contexts
3975 * @return string the human readable context name.
3977 function print_context_name(context $context, $withprefix = true, $short = false) {
3978 debugging('print_context_name() is deprecated, please use $context->get_context_name() instead.', DEBUG_DEVELOPER);
3979 return $context->get_context_name($withprefix, $short);
3983 * Mark a context as dirty (with timestamp) so as to force reloading of the context.
3985 * @deprecated since 2.2, use $context->mark_dirty() instead
3986 * @see context::mark_dirty()
3987 * @param string $path context path
3989 function mark_context_dirty($path) {
3990 global $CFG, $USER, $ACCESSLIB_PRIVATE;
3991 debugging('mark_context_dirty() is deprecated, please use $context->mark_dirty() instead.', DEBUG_DEVELOPER);
3993 if (during_initial_install()) {
3994 return;
3997 // only if it is a non-empty string
3998 if (is_string($path) && $path !== '') {
3999 set_cache_flag('accesslib/dirtycontexts', $path, 1, time()+$CFG->sessiontimeout);
4000 if (isset($ACCESSLIB_PRIVATE->dirtycontexts)) {
4001 $ACCESSLIB_PRIVATE->dirtycontexts[$path] = 1;
4002 } else {
4003 if (CLI_SCRIPT) {
4004 $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1);
4005 } else {
4006 if (isset($USER->access['time'])) {
4007 $ACCESSLIB_PRIVATE->dirtycontexts = get_cache_flags('accesslib/dirtycontexts', $USER->access['time']-2);
4008 } else {
4009 $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1);
4011 // flags not loaded yet, it will be done later in $context->reload_if_dirty()
4018 * Remove a context record and any dependent entries,
4019 * removes context from static context cache too
4021 * @deprecated since Moodle 2.2
4022 * @see context_helper::delete_instance() or context::delete_content()
4023 * @param int $contextlevel
4024 * @param int $instanceid
4025 * @param bool $deleterecord false means keep record for now
4026 * @return bool returns true or throws an exception
4028 function delete_context($contextlevel, $instanceid, $deleterecord = true) {
4029 if ($deleterecord) {
4030 debugging('delete_context() is deprecated, please use context_helper::delete_instance() instead.', DEBUG_DEVELOPER);
4031 context_helper::delete_instance($contextlevel, $instanceid);
4032 } else {
4033 debugging('delete_context() is deprecated, please use $context->delete_content() instead.', DEBUG_DEVELOPER);
4034 $classname = context_helper::get_class_for_level($contextlevel);
4035 if ($context = $classname::instance($instanceid, IGNORE_MISSING)) {
4036 $context->delete_content();
4040 return true;
4044 * Get a URL for a context, if there is a natural one. For example, for
4045 * CONTEXT_COURSE, this is the course page. For CONTEXT_USER it is the
4046 * user profile page.
4048 * @deprecated since 2.2
4049 * @see context::get_url()
4050 * @param context $context the context
4051 * @return moodle_url
4053 function get_context_url(context $context) {
4054 debugging('get_context_url() is deprecated, please use $context->get_url() instead.', DEBUG_DEVELOPER);
4055 return $context->get_url();
4059 * Is this context part of any course? if yes return course context,
4060 * if not return null or throw exception.
4062 * @deprecated since 2.2
4063 * @see context::get_course_context()
4064 * @param context $context
4065 * @return context_course context of the enclosing course, null if not found or exception
4067 function get_course_context(context $context) {
4068 debugging('get_course_context() is deprecated, please use $context->get_course_context(true) instead.', DEBUG_DEVELOPER);
4069 return $context->get_course_context(true);
4073 * Get an array of courses where cap requested is available
4074 * and user is enrolled, this can be relatively slow.
4076 * @deprecated since 2.2
4077 * @see enrol_get_users_courses()
4078 * @param int $userid A user id. By default (null) checks the permissions of the current user.
4079 * @param string $cap - name of the capability
4080 * @param array $accessdata_ignored
4081 * @param bool $doanything_ignored
4082 * @param string $sort - sorting fields - prefix each fieldname with "c."
4083 * @param array $fields - additional fields you are interested in...
4084 * @param int $limit_ignored
4085 * @return array $courses - ordered array of course objects - see notes above
4087 function get_user_courses_bycap($userid, $cap, $accessdata_ignored, $doanything_ignored, $sort = 'c.sortorder ASC', $fields = null, $limit_ignored = 0) {
4089 debugging('get_user_courses_bycap() is deprecated, please use enrol_get_users_courses() instead.', DEBUG_DEVELOPER);
4090 $courses = enrol_get_users_courses($userid, true, $fields, $sort);
4091 foreach ($courses as $id=>$course) {
4092 $context = context_course::instance($id);
4093 if (!has_capability($cap, $context, $userid)) {
4094 unset($courses[$id]);
4098 return $courses;
4102 * This is really slow!!! do not use above course context level
4104 * @deprecated since Moodle 2.2
4105 * @param int $roleid
4106 * @param context $context
4107 * @return array
4109 function get_role_context_caps($roleid, context $context) {
4110 global $DB;
4111 debugging('get_role_context_caps() is deprecated, it is really slow. Don\'t use it.', DEBUG_DEVELOPER);
4113 // This is really slow!!!! - do not use above course context level.
4114 $result = array();
4115 $result[$context->id] = array();
4117 // First emulate the parent context capabilities merging into context.
4118 $searchcontexts = array_reverse($context->get_parent_context_ids(true));
4119 foreach ($searchcontexts as $cid) {
4120 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
4121 foreach ($capabilities as $cap) {
4122 if (!array_key_exists($cap->capability, $result[$context->id])) {
4123 $result[$context->id][$cap->capability] = 0;
4125 $result[$context->id][$cap->capability] += $cap->permission;
4130 // Now go through the contexts below given context.
4131 $searchcontexts = array_keys($context->get_child_contexts());
4132 foreach ($searchcontexts as $cid) {
4133 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
4134 foreach ($capabilities as $cap) {
4135 if (!array_key_exists($cap->contextid, $result)) {
4136 $result[$cap->contextid] = array();
4138 $result[$cap->contextid][$cap->capability] = $cap->permission;
4143 return $result;
4147 * Returns current course id or false if outside of course based on context parameter.
4149 * @see context::get_course_context()
4150 * @deprecated since 2.2
4151 * @param context $context
4152 * @return int|bool related course id or false
4154 function get_courseid_from_context(context $context) {
4155 debugging('get_courseid_from_context() is deprecated, please use $context->get_course_context(false) instead.', DEBUG_DEVELOPER);
4156 if ($coursecontext = $context->get_course_context(false)) {
4157 return $coursecontext->instanceid;
4158 } else {
4159 return false;
4164 * Preloads context information together with instances.
4165 * Use context_instance_preload() to strip the context info from the record and cache the context instance.
4167 * If you are using this methid, you should have something like this:
4169 * list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
4171 * To prevent the use of this deprecated function, replace the line above with something similar to this:
4173 * $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
4175 * $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
4176 * ^ ^ ^ ^
4177 * $params = array('contextlevel' => CONTEXT_COURSE);
4179 * @see context_helper:;get_preload_record_columns_sql()
4180 * @deprecated since 2.2
4181 * @param string $joinon for example 'u.id'
4182 * @param string $contextlevel context level of instance in $joinon
4183 * @param string $tablealias context table alias
4184 * @return array with two values - select and join part
4186 function context_instance_preload_sql($joinon, $contextlevel, $tablealias) {
4187 debugging('context_instance_preload_sql() is deprecated, please use context_helper::get_preload_record_columns_sql() instead.', DEBUG_DEVELOPER);
4188 $select = ", " . context_helper::get_preload_record_columns_sql($tablealias);
4189 $join = "LEFT JOIN {context} $tablealias ON ($tablealias.instanceid = $joinon AND $tablealias.contextlevel = $contextlevel)";
4190 return array($select, $join);
4194 * Gets a string for sql calls, searching for stuff in this context or above.
4196 * @deprecated since 2.2
4197 * @see context::get_parent_context_ids()
4198 * @param context $context
4199 * @return string
4201 function get_related_contexts_string(context $context) {
4202 debugging('get_related_contexts_string() is deprecated, please use $context->get_parent_context_ids(true) instead.', DEBUG_DEVELOPER);
4203 if ($parents = $context->get_parent_context_ids()) {
4204 return (' IN ('.$context->id.','.implode(',', $parents).')');
4205 } else {
4206 return (' ='.$context->id);
4211 * Get a list of all the plugins of a given type that contain a particular file.
4213 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
4214 * @param string $file the name of file that must be present in the plugin.
4215 * (e.g. 'view.php', 'db/install.xml').
4216 * @param bool $include if true (default false), the file will be include_once-ed if found.
4217 * @return array with plugin name as keys (e.g. 'forum', 'courselist') and the path
4218 * to the file relative to dirroot as value (e.g. "$CFG->dirroot/mod/forum/view.php").
4219 * @deprecated since 2.6
4220 * @see core_component::get_plugin_list_with_file()
4222 function get_plugin_list_with_file($plugintype, $file, $include = false) {
4223 debugging('get_plugin_list_with_file() is deprecated, please use core_component::get_plugin_list_with_file() instead.',
4224 DEBUG_DEVELOPER);
4225 return core_component::get_plugin_list_with_file($plugintype, $file, $include);
4229 * Checks to see if is the browser operating system matches the specified brand.
4231 * Known brand: 'Windows','Linux','Macintosh','SGI','SunOS','HP-UX'
4233 * @deprecated since 2.6
4234 * @param string $brand The operating system identifier being tested
4235 * @return bool true if the given brand below to the detected operating system
4237 function check_browser_operating_system($brand) {
4238 debugging('check_browser_operating_system has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4239 return core_useragent::check_browser_operating_system($brand);
4243 * Checks to see if is a browser matches the specified
4244 * brand and is equal or better version.
4246 * @deprecated since 2.6
4247 * @param string $brand The browser identifier being tested
4248 * @param int $version The version of the browser, if not specified any version (except 5.5 for IE for BC reasons)
4249 * @return bool true if the given version is below that of the detected browser
4251 function check_browser_version($brand, $version = null) {
4252 debugging('check_browser_version has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4253 return core_useragent::check_browser_version($brand, $version);
4257 * Returns whether a device/browser combination is mobile, tablet, legacy, default or the result of
4258 * an optional admin specified regular expression. If enabledevicedetection is set to no or not set
4259 * it returns default
4261 * @deprecated since 2.6
4262 * @return string device type
4264 function get_device_type() {
4265 debugging('get_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4266 return core_useragent::get_device_type();
4270 * Returns a list of the device types supporting by Moodle
4272 * @deprecated since 2.6
4273 * @param boolean $incusertypes includes types specified using the devicedetectregex admin setting
4274 * @return array $types
4276 function get_device_type_list($incusertypes = true) {
4277 debugging('get_device_type_list has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4278 return core_useragent::get_device_type_list($incusertypes);
4282 * Returns the theme selected for a particular device or false if none selected.
4284 * @deprecated since 2.6
4285 * @param string $devicetype
4286 * @return string|false The name of the theme to use for the device or the false if not set
4288 function get_selected_theme_for_device_type($devicetype = null) {
4289 debugging('get_selected_theme_for_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4290 return core_useragent::get_device_type_theme($devicetype);
4294 * Returns the name of the device type theme var in $CFG because there is not a convention to allow backwards compatibility.
4296 * @deprecated since 2.6
4297 * @param string $devicetype
4298 * @return string The config variable to use to determine the theme
4300 function get_device_cfg_var_name($devicetype = null) {
4301 debugging('get_device_cfg_var_name has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4302 return core_useragent::get_device_type_cfg_var_name($devicetype);
4306 * Allows the user to switch the device they are seeing the theme for.
4307 * This allows mobile users to switch back to the default theme, or theme for any other device.
4309 * @deprecated since 2.6
4310 * @param string $newdevice The device the user is currently using.
4311 * @return string The device the user has switched to
4313 function set_user_device_type($newdevice) {
4314 debugging('set_user_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4315 return core_useragent::set_user_device_type($newdevice);
4319 * Returns the device the user is currently using, or if the user has chosen to switch devices
4320 * for the current device type the type they have switched to.
4322 * @deprecated since 2.6
4323 * @return string The device the user is currently using or wishes to use
4325 function get_user_device_type() {
4326 debugging('get_user_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4327 return core_useragent::get_user_device_type();
4331 * Returns one or several CSS class names that match the user's browser. These can be put
4332 * in the body tag of the page to apply browser-specific rules without relying on CSS hacks
4334 * @deprecated since 2.6
4335 * @return array An array of browser version classes
4337 function get_browser_version_classes() {
4338 debugging('get_browser_version_classes has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4339 return core_useragent::get_browser_version_classes();
4343 * Generate a fake user for emails based on support settings
4345 * @deprecated since Moodle 2.6
4346 * @see core_user::get_support_user()
4347 * @return stdClass user info
4349 function generate_email_supportuser() {
4350 debugging('generate_email_supportuser is deprecated, please use core_user::get_support_user');
4351 return core_user::get_support_user();
4355 * Get issued badge details for assertion URL
4357 * @deprecated since Moodle 2.6
4358 * @param string $hash Unique hash of a badge
4359 * @return array Information about issued badge.
4361 function badges_get_issued_badge_info($hash) {
4362 debugging('Function badges_get_issued_badge_info() is deprecated. Please use core_badges_assertion class and methods to generate badge assertion.', DEBUG_DEVELOPER);
4363 $assertion = new core_badges_assertion($hash);
4364 return $assertion->get_badge_assertion();
4368 * Does the user want and can edit using rich text html editor?
4369 * This function does not make sense anymore because a user can directly choose their preferred editor.
4371 * @deprecated since 2.6
4372 * @return bool
4374 function can_use_html_editor() {
4375 debugging('can_use_html_editor has been deprecated please update your code to assume it returns true.', DEBUG_DEVELOPER);
4376 return true;
4381 * Returns an object with counts of failed login attempts
4383 * Returns information about failed login attempts. If the current user is
4384 * an admin, then two numbers are returned: the number of attempts and the
4385 * number of accounts. For non-admins, only the attempts on the given user
4386 * are shown.
4388 * @deprecate since Moodle 2.7, use {@link user_count_login_failures()} instead.
4389 * @global moodle_database $DB
4390 * @uses CONTEXT_SYSTEM
4391 * @param string $mode Either 'admin' or 'everybody'
4392 * @param string $username The username we are searching for
4393 * @param string $lastlogin The date from which we are searching
4394 * @return int
4396 function count_login_failures($mode, $username, $lastlogin) {
4397 global $DB;
4399 debugging('This method has been deprecated. Please use user_count_login_failures() instead.', DEBUG_DEVELOPER);
4401 $params = array('mode'=>$mode, 'username'=>$username, 'lastlogin'=>$lastlogin);
4402 $select = "module='login' AND action='error' AND time > :lastlogin";
4404 $count = new stdClass();
4406 if (is_siteadmin()) {
4407 if ($count->attempts = $DB->count_records_select('log', $select, $params)) {
4408 $count->accounts = $DB->count_records_select('log', $select, $params, 'COUNT(DISTINCT info)');
4409 return $count;
4411 } else if ($mode == 'everybody') {
4412 if ($count->attempts = $DB->count_records_select('log', "$select AND info = :username", $params)) {
4413 return $count;
4416 return NULL;
4420 * Returns whether ajax is enabled/allowed or not.
4421 * This function is deprecated and always returns true.
4423 * @param array $unused - not used any more.
4424 * @return bool
4425 * @deprecated since 2.7 MDL-33099 - please do not use this function any more.
4426 * @todo MDL-44088 This will be removed in Moodle 2.9.
4428 function ajaxenabled(array $browsers = null) {
4429 debugging('ajaxenabled() is deprecated - please update your code to assume it returns true.', DEBUG_DEVELOPER);
4430 return true;
4434 * Determine whether a course module is visible within a course,
4435 * this is different from instance_is_visible() - faster and visibility for user
4437 * @global object
4438 * @global object
4439 * @uses DEBUG_DEVELOPER
4440 * @uses CONTEXT_MODULE
4441 * @param object $cm object
4442 * @param int $userid empty means current user
4443 * @return bool Success
4444 * @deprecated Since Moodle 2.7
4446 function coursemodule_visible_for_user($cm, $userid=0) {
4447 debugging('coursemodule_visible_for_user() deprecated since Moodle 2.7. ' .
4448 'Replace with \core_availability\info_module::is_user_visible().');
4449 return \core_availability\info_module::is_user_visible($cm, $userid, false);