MDL-50576 mod_forum: Correct use of movedicussions cap when posting This is a partial...
[moodle.git] / lib / deprecatedlib.php
blob4e57a7d8c239db143984799ea1b013fc8b499b9b
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;
961 * Inndicates fatal error. This function was originally printing the
962 * error message directly, since 2.0 it is throwing exception instead.
963 * The error printing is handled in default exception handler.
965 * Old method, don't call directly in new code - use print_error instead.
967 * @param string $message The message to display to the user about the error.
968 * @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.
969 * @return void, always throws moodle_exception
971 function error($message, $link='') {
972 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
977 * @deprecated use $PAGE->theme->name instead.
978 * @todo final deprecation of this function in MDL-40607
979 * @return string the name of the current theme.
981 function current_theme() {
982 global $PAGE;
984 debugging('current_theme() is deprecated, please use $PAGE->theme->name instead', DEBUG_DEVELOPER);
985 return $PAGE->theme->name;
989 * Prints some red text using echo
991 * @deprecated
992 * @param string $error The text to be displayed in red
994 function formerr($error) {
995 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
996 global $OUTPUT;
997 echo $OUTPUT->error_text($error);
1001 * Return the markup for the destination of the 'Skip to main content' links.
1002 * Accessibility improvement for keyboard-only users.
1004 * Used in course formats, /index.php and /course/index.php
1006 * @deprecated use $OUTPUT->skip_link_target() in instead.
1007 * @todo final deprecation of this function in MDL-40607
1008 * @return string HTML element.
1010 function skip_main_destination() {
1011 global $OUTPUT;
1013 debugging('skip_main_destination() is deprecated, please use $OUTPUT->skip_link_target() instead.', DEBUG_DEVELOPER);
1014 return $OUTPUT->skip_link_target();
1018 * Print a message in a standard themed container.
1020 * @deprecated use $OUTPUT->container() instead.
1021 * @todo final deprecation of this function in MDL-40607
1022 * @param string $message, the content of the container
1023 * @param boolean $clearfix clear both sides
1024 * @param string $classes, space-separated class names.
1025 * @param string $idbase
1026 * @param boolean $return, return as string or just print it
1027 * @return string|void Depending on value of $return
1029 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
1030 global $OUTPUT;
1032 debugging('print_container() is deprecated. Please use $OUTPUT->container() instead.', DEBUG_DEVELOPER);
1033 if ($clearfix) {
1034 $classes .= ' clearfix';
1036 $output = $OUTPUT->container($message, $classes, $idbase);
1037 if ($return) {
1038 return $output;
1039 } else {
1040 echo $output;
1045 * Starts a container using divs
1047 * @deprecated use $OUTPUT->container_start() instead.
1048 * @todo final deprecation of this function in MDL-40607
1049 * @param boolean $clearfix clear both sides
1050 * @param string $classes, space-separated class names.
1051 * @param string $idbase
1052 * @param boolean $return, return as string or just print it
1053 * @return string|void Based on value of $return
1055 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
1056 global $OUTPUT;
1058 debugging('print_container_start() is deprecated. Please use $OUTPUT->container_start() instead.', DEBUG_DEVELOPER);
1060 if ($clearfix) {
1061 $classes .= ' clearfix';
1063 $output = $OUTPUT->container_start($classes, $idbase);
1064 if ($return) {
1065 return $output;
1066 } else {
1067 echo $output;
1072 * Simple function to end a container (see above)
1074 * @deprecated use $OUTPUT->container_end() instead.
1075 * @todo final deprecation of this function in MDL-40607
1076 * @param boolean $return, return as string or just print it
1077 * @return string|void Based on $return
1079 function print_container_end($return=false) {
1080 global $OUTPUT;
1081 debugging('print_container_end() is deprecated. Please use $OUTPUT->container_end() instead.', DEBUG_DEVELOPER);
1082 $output = $OUTPUT->container_end();
1083 if ($return) {
1084 return $output;
1085 } else {
1086 echo $output;
1091 * Print a bold message in an optional color.
1093 * @deprecated use $OUTPUT->notification instead.
1094 * @param string $message The message to print out
1095 * @param string $style Optional style to display message text in
1096 * @param string $align Alignment option
1097 * @param bool $return whether to return an output string or echo now
1098 * @return string|bool Depending on $result
1100 function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
1101 global $OUTPUT;
1103 if ($classes == 'green') {
1104 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
1105 $classes = 'notifysuccess'; // Backward compatible with old color system
1108 $output = $OUTPUT->notification($message, $classes);
1109 if ($return) {
1110 return $output;
1111 } else {
1112 echo $output;
1117 * Print a continue button that goes to a particular URL.
1119 * @deprecated use $OUTPUT->continue_button() instead.
1120 * @todo final deprecation of this function in MDL-40607
1122 * @param string $link The url to create a link to.
1123 * @param bool $return If set to true output is returned rather than echoed, default false
1124 * @return string|void HTML String if return=true nothing otherwise
1126 function print_continue($link, $return = false) {
1127 global $CFG, $OUTPUT;
1129 debugging('print_continue() is deprecated. Please use $OUTPUT->continue_button() instead.', DEBUG_DEVELOPER);
1131 if ($link == '') {
1132 if (!empty($_SERVER['HTTP_REFERER'])) {
1133 $link = $_SERVER['HTTP_REFERER'];
1134 $link = str_replace('&', '&amp;', $link); // make it valid XHTML
1135 } else {
1136 $link = $CFG->wwwroot .'/';
1140 $output = $OUTPUT->continue_button($link);
1141 if ($return) {
1142 return $output;
1143 } else {
1144 echo $output;
1149 * Print a standard header
1151 * @deprecated use $PAGE methods instead.
1152 * @todo final deprecation of this function in MDL-40607
1153 * @param string $title Appears at the top of the window
1154 * @param string $heading Appears at the top of the page
1155 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
1156 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1157 * @param string $meta Meta tags to be added to the header
1158 * @param boolean $cache Should this page be cacheable?
1159 * @param string $button HTML code for a button (usually for module editing)
1160 * @param string $menu HTML code for a popup menu
1161 * @param boolean $usexml use XML for this page
1162 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1163 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1164 * @return string|void If return=true then string else void
1166 function print_header($title='', $heading='', $navigation='', $focus='',
1167 $meta='', $cache=true, $button='&nbsp;', $menu=null,
1168 $usexml=false, $bodytags='', $return=false) {
1169 global $PAGE, $OUTPUT;
1171 debugging('print_header() is deprecated. Please use $PAGE methods instead.', DEBUG_DEVELOPER);
1173 $PAGE->set_title($title);
1174 $PAGE->set_heading($heading);
1175 $PAGE->set_cacheable($cache);
1176 if ($button == '') {
1177 $button = '&nbsp;';
1179 $PAGE->set_button($button);
1180 $PAGE->set_headingmenu($menu);
1182 // TODO $menu
1184 if ($meta) {
1185 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1186 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1188 if ($usexml) {
1189 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1191 if ($bodytags) {
1192 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1195 $output = $OUTPUT->header();
1197 if ($return) {
1198 return $output;
1199 } else {
1200 echo $output;
1205 * This version of print_header is simpler because the course name does not have to be
1206 * provided explicitly in the strings. It can be used on the site page as in courses
1207 * Eventually all print_header could be replaced by print_header_simple
1209 * @deprecated use $PAGE methods instead.
1210 * @todo final deprecation of this function in MDL-40607
1211 * @param string $title Appears at the top of the window
1212 * @param string $heading Appears at the top of the page
1213 * @param string $navigation Premade navigation string (for use as breadcrumbs links)
1214 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1215 * @param string $meta Meta tags to be added to the header
1216 * @param boolean $cache Should this page be cacheable?
1217 * @param string $button HTML code for a button (usually for module editing)
1218 * @param string $menu HTML code for a popup menu
1219 * @param boolean $usexml use XML for this page
1220 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1221 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1222 * @return string|void If $return=true the return string else nothing
1224 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
1225 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
1227 global $COURSE, $CFG, $PAGE, $OUTPUT;
1229 debugging('print_header_simple() is deprecated. Please use $PAGE methods instead.', DEBUG_DEVELOPER);
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 $PAGE->set_title($title);
1243 $PAGE->set_heading($heading);
1244 $PAGE->set_cacheable(true);
1245 $PAGE->set_button($button);
1247 $output = $OUTPUT->header();
1249 if ($return) {
1250 return $output;
1251 } else {
1252 echo $output;
1257 * Prints a nice side block with an optional header. The content can either
1258 * be a block of HTML or a list of text with optional icons.
1260 * @static int $block_id Increments for each call to the function
1261 * @param string $heading HTML for the heading. Can include full HTML or just
1262 * plain text - plain text will automatically be enclosed in the appropriate
1263 * heading tags.
1264 * @param string $content HTML for the content
1265 * @param array $list an alternative to $content, it you want a list of things with optional icons.
1266 * @param array $icons optional icons for the things in $list.
1267 * @param string $footer Extra HTML content that gets output at the end, inside a &lt;div class="footer">
1268 * @param array $attributes an array of attribute => value pairs that are put on the
1269 * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
1270 * already a class, class='block' is used.
1271 * @param string $title Plain text title, as embedded in the $heading.
1272 * @deprecated use $OUTPUT->block() instead.
1273 * @todo final deprecation of this function in MDL-40607
1275 function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
1276 global $OUTPUT;
1278 debugging('print_side_block() is deprecated, please use $OUTPUT->block() instead.', DEBUG_DEVELOPER);
1279 // We don't use $heading, becuse it often contains HTML that we don't want.
1280 // However, sometimes $title is not set, but $heading is.
1281 if (empty($title)) {
1282 $title = strip_tags($heading);
1285 // Render list contents to HTML if required.
1286 if (empty($content) && $list) {
1287 $content = $OUTPUT->list_block_contents($icons, $list);
1290 $bc = new block_contents();
1291 $bc->content = $content;
1292 $bc->footer = $footer;
1293 $bc->title = $title;
1295 if (isset($attributes['id'])) {
1296 $bc->id = $attributes['id'];
1297 unset($attributes['id']);
1299 $bc->attributes = $attributes;
1301 echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
1305 * Prints a basic textarea field.
1307 * @deprecated since Moodle 2.0
1309 * When using this function, you should
1311 * @global object
1312 * @param bool $unused No longer used.
1313 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
1314 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
1315 * @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.
1316 * @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.
1317 * @param string $name Name to use for the textarea element.
1318 * @param string $value Initial content to display in the textarea.
1319 * @param int $obsolete deprecated
1320 * @param bool $return If false, will output string. If true, will return string value.
1321 * @param string $id CSS ID to add to the textarea element.
1322 * @return string|void depending on the value of $return
1324 function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
1325 /// $width and height are legacy fields and no longer used as pixels like they used to be.
1326 /// However, you can set them to zero to override the mincols and minrows values below.
1328 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
1329 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
1331 global $CFG;
1333 $mincols = 65;
1334 $minrows = 10;
1335 $str = '';
1337 if ($id === '') {
1338 $id = 'edit-'.$name;
1341 if ($height && ($rows < $minrows)) {
1342 $rows = $minrows;
1344 if ($width && ($cols < $mincols)) {
1345 $cols = $mincols;
1348 editors_head_setup();
1349 $editor = editors_get_preferred_editor(FORMAT_HTML);
1350 $editor->use_editor($id, array('legacy'=>true));
1352 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'" spellcheck="true">'."\n";
1353 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
1354 $str .= '</textarea>'."\n";
1356 if ($return) {
1357 return $str;
1359 echo $str;
1363 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
1364 * Should be used only with htmleditor or textarea.
1366 * @global object
1367 * @global object
1368 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
1369 * helpbutton.
1370 * @return string Link to help button
1372 function editorhelpbutton(){
1373 return '';
1375 /// TODO: MDL-21215
1379 * Print a help button.
1381 * Prints a special help button for html editors (htmlarea in this case)
1383 * @todo Write code into this function! detect current editor and print correct info
1384 * @global object
1385 * @return string Only returns an empty string at the moment
1387 function editorshortcutshelpbutton() {
1388 /// TODO: MDL-21215
1390 global $CFG;
1391 //TODO: detect current editor and print correct info
1392 return '';
1397 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
1398 * provide this function with the language strings for sortasc and sortdesc.
1400 * @deprecated use $OUTPUT->arrow() instead.
1401 * @todo final deprecation of this function in MDL-40607
1403 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
1405 * @global object
1406 * @param string $direction 'up' or 'down'
1407 * @param string $strsort The language string used for the alt attribute of this image
1408 * @param bool $return Whether to print directly or return the html string
1409 * @return string|void depending on $return
1412 function print_arrow($direction='up', $strsort=null, $return=false) {
1413 global $OUTPUT;
1415 debugging('print_arrow() is deprecated. Please use $OUTPUT->arrow() instead.', DEBUG_DEVELOPER);
1417 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
1418 return null;
1421 $return = null;
1423 switch ($direction) {
1424 case 'up':
1425 $sortdir = 'asc';
1426 break;
1427 case 'down':
1428 $sortdir = 'desc';
1429 break;
1430 case 'move':
1431 $sortdir = 'asc';
1432 break;
1433 default:
1434 $sortdir = null;
1435 break;
1438 // Prepare language string
1439 $strsort = '';
1440 if (empty($strsort) && !empty($sortdir)) {
1441 $strsort = get_string('sort' . $sortdir, 'grades');
1444 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
1446 if ($return) {
1447 return $return;
1448 } else {
1449 echo $return;
1454 * Given an array of values, output the HTML for a select element with those options.
1456 * @deprecated since Moodle 2.0
1458 * Normally, you only need to use the first few parameters.
1460 * @param array $options The options to offer. An array of the form
1461 * $options[{value}] = {text displayed for that option};
1462 * @param string $name the name of this form control, as in &lt;select name="..." ...
1463 * @param string $selected the option to select initially, default none.
1464 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
1465 * Set this to '' if you don't want a 'nothing is selected' option.
1466 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
1467 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
1468 * @param boolean $return if false (the default) the the output is printed directly, If true, the
1469 * generated HTML is returned as a string.
1470 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
1471 * @param int $tabindex if give, sets the tabindex attribute on the &lt;select> element. Default none.
1472 * @param string $id value to use for the id attribute of the &lt;select> element. If none is given,
1473 * then a suitable one is constructed.
1474 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
1475 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
1476 * $listbox is an integer, that number is used for size instead.
1477 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
1478 * when $listbox display is enabled
1479 * @param string $class value to use for the class attribute of the &lt;select> element. If none is given,
1480 * then a suitable one is constructed.
1481 * @return string|void If $return=true returns string, else echo's and returns void
1483 function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
1484 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
1485 $id='', $listbox=false, $multiple=false, $class='') {
1487 global $OUTPUT;
1488 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
1490 if ($script) {
1491 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
1493 $attributes = array();
1494 $attributes['disabled'] = $disabled ? 'disabled' : null;
1495 $attributes['tabindex'] = $tabindex ? $tabindex : null;
1496 $attributes['multiple'] = $multiple ? $multiple : null;
1497 $attributes['class'] = $class ? $class : null;
1498 $attributes['id'] = $id ? $id : null;
1500 $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
1502 if ($return) {
1503 return $output;
1504 } else {
1505 echo $output;
1510 * Prints a help button about a scale
1512 * @deprecated use $OUTPUT->help_icon_scale($courseid, $scale) instead.
1513 * @todo final deprecation of this function in MDL-40607
1515 * @global object
1516 * @param id $courseid
1517 * @param object $scale
1518 * @param boolean $return If set to true returns rather than echo's
1519 * @return string|bool Depending on value of $return
1521 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
1522 global $OUTPUT;
1524 debugging('print_scale_menu_helpbutton() is deprecated. Please use $OUTPUT->help_icon_scale($courseid, $scale) instead.', DEBUG_DEVELOPER);
1526 $output = $OUTPUT->help_icon_scale($courseid, $scale);
1528 if ($return) {
1529 return $output;
1530 } else {
1531 echo $output;
1536 * Display an standard html checkbox with an optional label
1538 * @deprecated use html_writer::checkbox() instead.
1539 * @todo final deprecation of this function in MDL-40607
1541 * @staticvar int $idcounter
1542 * @param string $name The name of the checkbox
1543 * @param string $value The valus that the checkbox will pass when checked
1544 * @param bool $checked The flag to tell the checkbox initial state
1545 * @param string $label The label to be showed near the checkbox
1546 * @param string $alt The info to be inserted in the alt tag
1547 * @param string $script If not '', then this is added to the checkbox element
1548 * as an onchange handler.
1549 * @param bool $return Whether this function should return a string or output
1550 * it (defaults to false)
1551 * @return string|void If $return=true returns string, else echo's and returns void
1553 function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
1554 global $OUTPUT;
1556 debugging('print_checkbox() is deprecated. Please use html_writer::checkbox() instead.', DEBUG_DEVELOPER);
1558 if (!empty($script)) {
1559 debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER);
1562 $output = html_writer::checkbox($name, $value, $checked, $label);
1564 if (empty($return)) {
1565 echo $output;
1566 } else {
1567 return $output;
1573 * Prints the 'update this xxx' button that appears on module pages.
1575 * @deprecated since Moodle 2.0
1577 * @param string $cmid the course_module id.
1578 * @param string $ignored not used any more. (Used to be courseid.)
1579 * @param string $string the module name - get_string('modulename', 'xxx')
1580 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
1582 function update_module_button($cmid, $ignored, $string) {
1583 global $CFG, $OUTPUT;
1585 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
1587 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
1589 if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) {
1590 $string = get_string('updatethis', '', $string);
1592 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
1593 return $OUTPUT->single_button($url, $string);
1594 } else {
1595 return '';
1600 * Prints breadcrumb trail of links, called in theme/-/header.html
1602 * This function has now been deprecated please use output's navbar method instead
1603 * as shown below
1605 * <code php>
1606 * echo $OUTPUT->navbar();
1607 * </code>
1609 * @deprecated use $OUTPUT->navbar() instead
1610 * @todo final deprecation of this function in MDL-40607
1611 * @param mixed $navigation deprecated
1612 * @param string $separator OBSOLETE, and now deprecated
1613 * @param boolean $return False to echo the breadcrumb string (default), true to return it.
1614 * @return string|void String or null, depending on $return.
1616 function print_navigation ($navigation, $separator=0, $return=false) {
1617 global $OUTPUT,$PAGE;
1619 debugging('print_navigation() is deprecated, please update use $OUTPUT->navbar() instead.', DEBUG_DEVELOPER);
1621 $output = $OUTPUT->navbar();
1623 if ($return) {
1624 return $output;
1625 } else {
1626 echo $output;
1631 * This function will build the navigation string to be used by print_header
1632 * and others.
1634 * It automatically generates the site and course level (if appropriate) links.
1636 * If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums')
1637 * and activityinstances (e.g. 'General Developer Forum') navigation levels.
1639 * If you want to add any further navigation links after the ones this function generates,
1640 * the pass an array of extra link arrays like this:
1641 * array(
1642 * array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1),
1643 * array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2)
1645 * The normal case is to just add one further link, for example 'Editing forum' after
1646 * 'General Developer Forum', with no link.
1647 * To do that, you need to pass
1648 * array(array('name' => $linktext, 'link' => '', 'type' => 'title'))
1649 * However, becuase this is a very common case, you can use a shortcut syntax, and just
1650 * pass the string 'Editing forum', instead of an array as $extranavlinks.
1652 * At the moment, the link types only have limited significance. Type 'activity' is
1653 * recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types
1654 * that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'.
1655 * This really needs to be documented better. In the mean time, try to be consistent, it will
1656 * enable people to customise the navigation more in future.
1658 * When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course.
1659 * If you get the $cm object using the function get_coursemodule_from_instance or
1660 * get_coursemodule_from_id (as recommended) then this will be done for you automatically.
1661 * If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using
1662 * the $cm->module and $cm->instance fields, but this takes extra database queries, so a
1663 * warning is printed in developer debug mode.
1665 * @deprecated Please use $PAGE->navabar methods instead.
1666 * @todo final deprecation of this function in MDL-40607
1667 * @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you
1668 * only want one extra item with no link, you can pass a string instead. If you don't want
1669 * any extra links, pass an empty string.
1670 * @param mixed $cm deprecated
1671 * @return array Navigation array
1673 function build_navigation($extranavlinks, $cm = null) {
1674 global $CFG, $COURSE, $DB, $SITE, $PAGE;
1676 debugging('build_navigation() is deprecated, please use $PAGE->navbar methods instead.', DEBUG_DEVELOPER);
1677 if (is_array($extranavlinks) && count($extranavlinks)>0) {
1678 foreach ($extranavlinks as $nav) {
1679 if (array_key_exists('name', $nav)) {
1680 if (array_key_exists('link', $nav) && !empty($nav['link'])) {
1681 $link = $nav['link'];
1682 } else {
1683 $link = null;
1685 $PAGE->navbar->add($nav['name'],$link);
1690 return(array('newnav' => true, 'navlinks' => array()));
1694 * @deprecated not relevant with global navigation in Moodle 2.x+
1695 * @todo remove completely in MDL-40607
1697 function navmenu($course, $cm=NULL, $targetwindow='self') {
1698 // This function has been deprecated with the creation of the global nav in
1699 // moodle 2.0
1700 debugging('navmenu() is deprecated, it is no longer relevant with global navigation.', DEBUG_DEVELOPER);
1702 return '';
1705 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
1709 * Call this function to add an event to the calendar table and to call any calendar plugins
1711 * @param object $event An object representing an event from the calendar table.
1712 * The event will be identified by the id field. The object event should include the following:
1713 * <ul>
1714 * <li><b>$event->name</b> - Name for the event
1715 * <li><b>$event->description</b> - Description of the event (defaults to '')
1716 * <li><b>$event->format</b> - Format for the description (using formatting types defined at the top of weblib.php)
1717 * <li><b>$event->courseid</b> - The id of the course this event belongs to (0 = all courses)
1718 * <li><b>$event->groupid</b> - The id of the group this event belongs to (0 = no group)
1719 * <li><b>$event->userid</b> - The id of the user this event belongs to (0 = no user)
1720 * <li><b>$event->modulename</b> - Name of the module that creates this event
1721 * <li><b>$event->instance</b> - Instance of the module that owns this event
1722 * <li><b>$event->eventtype</b> - The type info together with the module info could
1723 * be used by calendar plugins to decide how to display event
1724 * <li><b>$event->timestart</b>- Timestamp for start of event
1725 * <li><b>$event->timeduration</b> - Duration (defaults to zero)
1726 * <li><b>$event->visible</b> - 0 if the event should be hidden (e.g. because the activity that created it is hidden)
1727 * </ul>
1728 * @return int|false The id number of the resulting record or false if failed
1729 * @deprecated please use calendar_event::create() instead.
1730 * @todo final deprecation of this function in MDL-40607
1732 function add_event($event) {
1733 global $CFG;
1734 require_once($CFG->dirroot.'/calendar/lib.php');
1736 debugging('add_event() is deprecated, please use calendar_event::create() instead.', DEBUG_DEVELOPER);
1737 $event = calendar_event::create($event);
1738 if ($event !== false) {
1739 return $event->id;
1741 return false;
1745 * Call this function to update an event in the calendar table
1746 * the event will be identified by the id field of the $event object.
1748 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
1749 * @return bool Success
1750 * @deprecated please calendar_event->update() instead.
1752 function update_event($event) {
1753 global $CFG;
1754 require_once($CFG->dirroot.'/calendar/lib.php');
1756 debugging('update_event() is deprecated, please use calendar_event->update() instead.', DEBUG_DEVELOPER);
1757 $event = (object)$event;
1758 $calendarevent = calendar_event::load($event->id);
1759 return $calendarevent->update($event);
1763 * Call this function to delete the event with id $id from calendar table.
1765 * @param int $id The id of an event from the 'event' table.
1766 * @return bool
1767 * @deprecated please use calendar_event->delete() instead.
1768 * @todo final deprecation of this function in MDL-40607
1770 function delete_event($id) {
1771 global $CFG;
1772 require_once($CFG->dirroot.'/calendar/lib.php');
1774 debugging('delete_event() is deprecated, please use calendar_event->delete() instead.', DEBUG_DEVELOPER);
1776 $event = calendar_event::load($id);
1777 return $event->delete();
1781 * Call this function to hide an event in the calendar table
1782 * the event will be identified by the id field of the $event object.
1784 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
1785 * @return true
1786 * @deprecated please use calendar_event->toggle_visibility(false) instead.
1787 * @todo final deprecation of this function in MDL-40607
1789 function hide_event($event) {
1790 global $CFG;
1791 require_once($CFG->dirroot.'/calendar/lib.php');
1793 debugging('hide_event() is deprecated, please use calendar_event->toggle_visibility(false) instead.', DEBUG_DEVELOPER);
1795 $event = new calendar_event($event);
1796 return $event->toggle_visibility(false);
1800 * Call this function to unhide an event in the calendar table
1801 * the event will be identified by the id field of the $event object.
1803 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
1804 * @return true
1805 * @deprecated please use calendar_event->toggle_visibility(true) instead.
1806 * @todo final deprecation of this function in MDL-40607
1808 function show_event($event) {
1809 global $CFG;
1810 require_once($CFG->dirroot.'/calendar/lib.php');
1812 debugging('show_event() is deprecated, please use calendar_event->toggle_visibility(true) instead.', DEBUG_DEVELOPER);
1814 $event = new calendar_event($event);
1815 return $event->toggle_visibility(true);
1819 * Original singleton helper function, please use static methods instead,
1820 * ex: core_text::convert()
1822 * @deprecated since Moodle 2.2 use core_text::xxxx() instead
1823 * @see textlib
1824 * @return textlib instance
1826 function textlib_get_instance() {
1828 debugging('textlib_get_instance() is deprecated. Please use static calling core_text::functioname() instead.', DEBUG_DEVELOPER);
1830 return new textlib();
1834 * Gets the generic section name for a courses section
1836 * The global function is deprecated. Each course format can define their own generic section name
1838 * @deprecated since 2.4
1839 * @see get_section_name()
1840 * @see format_base::get_section_name()
1842 * @param string $format Course format ID e.g. 'weeks' $course->format
1843 * @param stdClass $section Section object from database
1844 * @return Display name that the course format prefers, e.g. "Week 2"
1846 function get_generic_section_name($format, stdClass $section) {
1847 debugging('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base', DEBUG_DEVELOPER);
1848 return get_string('sectionname', "format_$format") . ' ' . $section->section;
1852 * Returns an array of sections for the requested course id
1854 * It is usually not recommended to display the list of sections used
1855 * in course because the course format may have it's own way to do it.
1857 * If you need to just display the name of the section please call:
1858 * get_section_name($course, $section)
1859 * {@link get_section_name()}
1860 * from 2.4 $section may also be just the field course_sections.section
1862 * If you need the list of all sections it is more efficient to get this data by calling
1863 * $modinfo = get_fast_modinfo($courseorid);
1864 * $sections = $modinfo->get_section_info_all()
1865 * {@link get_fast_modinfo()}
1866 * {@link course_modinfo::get_section_info_all()}
1868 * Information about one section (instance of section_info):
1869 * get_fast_modinfo($courseorid)->get_sections_info($section)
1870 * {@link course_modinfo::get_section_info()}
1872 * @deprecated since 2.4
1874 * @param int $courseid
1875 * @return array Array of section_info objects
1877 function get_all_sections($courseid) {
1878 global $DB;
1879 debugging('get_all_sections() is deprecated. See phpdocs for this function', DEBUG_DEVELOPER);
1880 return get_fast_modinfo($courseid)->get_section_info_all();
1884 * Given a full mod object with section and course already defined, adds this module to that section.
1886 * This function is deprecated, please use {@link course_add_cm_to_section()}
1887 * Note that course_add_cm_to_section() also updates field course_modules.section and
1888 * calls rebuild_course_cache()
1890 * @deprecated since 2.4
1892 * @param object $mod
1893 * @param int $beforemod An existing ID which we will insert the new module before
1894 * @return int The course_sections ID where the mod is inserted
1896 function add_mod_to_section($mod, $beforemod = null) {
1897 debugging('Function add_mod_to_section() is deprecated, please use course_add_cm_to_section()', DEBUG_DEVELOPER);
1898 global $DB;
1899 return course_add_cm_to_section($mod->course, $mod->coursemodule, $mod->section, $beforemod);
1903 * Returns a number of useful structures for course displays
1905 * Function get_all_mods() is deprecated in 2.4
1906 * Instead of:
1907 * <code>
1908 * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
1909 * </code>
1910 * please use:
1911 * <code>
1912 * $mods = get_fast_modinfo($courseorid)->get_cms();
1913 * $modnames = get_module_types_names();
1914 * $modnamesplural = get_module_types_names(true);
1915 * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names();
1916 * </code>
1918 * @deprecated since 2.4
1920 * @param int $courseid id of the course to get info about
1921 * @param array $mods (return) list of course modules
1922 * @param array $modnames (return) list of names of all module types installed and available
1923 * @param array $modnamesplural (return) list of names of all module types installed and available in the plural form
1924 * @param array $modnamesused (return) list of names of all module types used in the course
1926 function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
1927 debugging('Function get_all_mods() is deprecated. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details', DEBUG_DEVELOPER);
1929 global $COURSE;
1930 $modnames = get_module_types_names();
1931 $modnamesplural= get_module_types_names(true);
1932 $modinfo = get_fast_modinfo($courseid);
1933 $mods = $modinfo->get_cms();
1934 $modnamesused = $modinfo->get_used_module_names();
1938 * Returns course section - creates new if does not exist yet
1940 * This function is deprecated. To create a course section call:
1941 * course_create_sections_if_missing($courseorid, $sections);
1942 * to get the section call:
1943 * get_fast_modinfo($courseorid)->get_section_info($sectionnum);
1945 * @see course_create_sections_if_missing()
1946 * @see get_fast_modinfo()
1947 * @deprecated since 2.4
1949 * @param int $section relative section number (field course_sections.section)
1950 * @param int $courseid
1951 * @return stdClass record from table {course_sections}
1953 function get_course_section($section, $courseid) {
1954 global $DB;
1955 debugging('Function get_course_section() is deprecated. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.', DEBUG_DEVELOPER);
1957 if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) {
1958 return $cw;
1960 $cw = new stdClass();
1961 $cw->course = $courseid;
1962 $cw->section = $section;
1963 $cw->summary = "";
1964 $cw->summaryformat = FORMAT_HTML;
1965 $cw->sequence = "";
1966 $id = $DB->insert_record("course_sections", $cw);
1967 rebuild_course_cache($courseid, true);
1968 return $DB->get_record("course_sections", array("id"=>$id));
1972 * Return the start and end date of the week in Weekly course format
1974 * It is not recommended to use this function outside of format_weeks plugin
1976 * @deprecated since 2.4
1977 * @see format_weeks::get_section_dates()
1979 * @param stdClass $section The course_section entry from the DB
1980 * @param stdClass $course The course entry from DB
1981 * @return stdClass property start for startdate, property end for enddate
1983 function format_weeks_get_section_dates($section, $course) {
1984 debugging('Function format_weeks_get_section_dates() is deprecated. It is not recommended to'.
1985 ' use it outside of format_weeks plugin', DEBUG_DEVELOPER);
1986 if (isset($course->format) && $course->format === 'weeks') {
1987 return course_get_format($course)->get_section_dates($section);
1989 return null;
1993 * Obtains shared data that is used in print_section when displaying a
1994 * course-module entry.
1996 * Deprecated. Instead of:
1997 * list($content, $name) = get_print_section_cm_text($cm, $course);
1998 * use:
1999 * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
2000 * $name = $cm->get_formatted_name();
2002 * @deprecated since 2.5
2003 * @see cm_info::get_formatted_content()
2004 * @see cm_info::get_formatted_name()
2006 * This data is also used in other areas of the code.
2007 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
2008 * @param object $course (argument not used)
2009 * @return array An array with the following values in this order:
2010 * $content (optional extra content for after link),
2011 * $instancename (text of link)
2013 function get_print_section_cm_text(cm_info $cm, $course) {
2014 debugging('Function get_print_section_cm_text() is deprecated. Please use '.
2015 'cm_info::get_formatted_content() and cm_info::get_formatted_name()',
2016 DEBUG_DEVELOPER);
2017 return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)),
2018 $cm->get_formatted_name());
2022 * Prints the menus to add activities and resources.
2024 * Deprecated. Please use:
2025 * $courserenderer = $PAGE->get_renderer('core', 'course');
2026 * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
2027 * array('inblock' => $vertical));
2028 * echo $output; // if $return argument in print_section_add_menus() set to false
2030 * @deprecated since 2.5
2031 * @see core_course_renderer::course_section_add_cm_control()
2033 * @param stdClass $course course object, must be the same as set on the page
2034 * @param int $section relative section number (field course_sections.section)
2035 * @param null|array $modnames (argument ignored) get_module_types_names() is used instead of argument
2036 * @param bool $vertical Vertical orientation
2037 * @param bool $return Return the menus or send them to output
2038 * @param int $sectionreturn The section to link back to
2039 * @return void|string depending on $return
2041 function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
2042 global $PAGE;
2043 debugging('Function print_section_add_menus() is deprecated. Please use course renderer '.
2044 'function course_section_add_cm_control()', DEBUG_DEVELOPER);
2045 $output = '';
2046 $courserenderer = $PAGE->get_renderer('core', 'course');
2047 $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
2048 array('inblock' => $vertical));
2049 if ($return) {
2050 return $output;
2051 } else {
2052 echo $output;
2053 return !empty($output);
2058 * Produces the editing buttons for a module
2060 * Deprecated. Please use:
2061 * $courserenderer = $PAGE->get_renderer('core', 'course');
2062 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
2063 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
2065 * @deprecated since 2.5
2066 * @see course_get_cm_edit_actions()
2067 * @see core_course_renderer->course_section_cm_edit_actions()
2069 * @param stdClass $mod The module to produce editing buttons for
2070 * @param bool $absolute_ignored (argument ignored) - all links are absolute
2071 * @param bool $moveselect (argument ignored)
2072 * @param int $indent The current indenting
2073 * @param int $section The section to link back to
2074 * @return string XHTML for the editing buttons
2076 function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
2077 global $PAGE;
2078 debugging('Function make_editing_buttons() is deprecated, please see PHPdocs in '.
2079 'lib/deprecatedlib.php on how to replace it', DEBUG_DEVELOPER);
2080 if (!($mod instanceof cm_info)) {
2081 $modinfo = get_fast_modinfo($mod->course);
2082 $mod = $modinfo->get_cm($mod->id);
2084 $actions = course_get_cm_edit_actions($mod, $indent, $section);
2086 $courserenderer = $PAGE->get_renderer('core', 'course');
2087 // The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap
2088 // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
2089 // the course page HTML will allow this to be removed.
2090 return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
2094 * Prints a section full of activity modules
2096 * Deprecated. Please use:
2097 * $courserenderer = $PAGE->get_renderer('core', 'course');
2098 * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn,
2099 * array('hidecompletion' => $hidecompletion));
2101 * @deprecated since 2.5
2102 * @see core_course_renderer::course_section_cm_list()
2104 * @param stdClass $course The course
2105 * @param stdClass|section_info $section The section object containing properties id and section
2106 * @param array $mods (argument not used)
2107 * @param array $modnamesused (argument not used)
2108 * @param bool $absolute (argument not used)
2109 * @param string $width (argument not used)
2110 * @param bool $hidecompletion Hide completion status
2111 * @param int $sectionreturn The section to return to
2112 * @return void
2114 function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
2115 global $PAGE;
2116 debugging('Function print_section() is deprecated. Please use course renderer function '.
2117 'course_section_cm_list() instead.', DEBUG_DEVELOPER);
2118 $displayoptions = array('hidecompletion' => $hidecompletion);
2119 $courserenderer = $PAGE->get_renderer('core', 'course');
2120 echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions);
2124 * Displays the list of courses with user notes
2126 * This function is not used in core. It was replaced by block course_overview
2128 * @deprecated since 2.5
2130 * @param array $courses
2131 * @param array $remote_courses
2133 function print_overview($courses, array $remote_courses=array()) {
2134 global $CFG, $USER, $DB, $OUTPUT;
2135 debugging('Function print_overview() is deprecated. Use block course_overview to display this information', DEBUG_DEVELOPER);
2137 $htmlarray = array();
2138 if ($modules = $DB->get_records('modules')) {
2139 foreach ($modules as $mod) {
2140 if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) {
2141 include_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php');
2142 $fname = $mod->name.'_print_overview';
2143 if (function_exists($fname)) {
2144 $fname($courses,$htmlarray);
2149 foreach ($courses as $course) {
2150 $fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
2151 echo $OUTPUT->box_start('coursebox');
2152 $attributes = array('title' => s($fullname));
2153 if (empty($course->visible)) {
2154 $attributes['class'] = 'dimmed';
2156 echo $OUTPUT->heading(html_writer::link(
2157 new moodle_url('/course/view.php', array('id' => $course->id)), $fullname, $attributes), 3);
2158 if (array_key_exists($course->id,$htmlarray)) {
2159 foreach ($htmlarray[$course->id] as $modname => $html) {
2160 echo $html;
2163 echo $OUTPUT->box_end();
2166 if (!empty($remote_courses)) {
2167 echo $OUTPUT->heading(get_string('remotecourses', 'mnet'));
2169 foreach ($remote_courses as $course) {
2170 echo $OUTPUT->box_start('coursebox');
2171 $attributes = array('title' => s($course->fullname));
2172 echo $OUTPUT->heading(html_writer::link(
2173 new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)),
2174 format_string($course->shortname),
2175 $attributes) . ' (' . format_string($course->hostname) . ')', 3);
2176 echo $OUTPUT->box_end();
2181 * This function trawls through the logs looking for
2182 * anything new since the user's last login
2184 * This function was only used to print the content of block recent_activity
2185 * All functionality is moved into class {@link block_recent_activity}
2186 * and renderer {@link block_recent_activity_renderer}
2188 * @deprecated since 2.5
2189 * @param stdClass $course
2191 function print_recent_activity($course) {
2192 // $course is an object
2193 global $CFG, $USER, $SESSION, $DB, $OUTPUT;
2194 debugging('Function print_recent_activity() is deprecated. It is not recommended to'.
2195 ' use it outside of block_recent_activity', DEBUG_DEVELOPER);
2197 $context = context_course::instance($course->id);
2199 $viewfullnames = has_capability('moodle/site:viewfullnames', $context);
2201 $timestart = round(time() - COURSE_MAX_RECENT_PERIOD, -2); // better db caching for guests - 100 seconds
2203 if (!isguestuser()) {
2204 if (!empty($USER->lastcourseaccess[$course->id])) {
2205 if ($USER->lastcourseaccess[$course->id] > $timestart) {
2206 $timestart = $USER->lastcourseaccess[$course->id];
2211 echo '<div class="activitydate">';
2212 echo get_string('activitysince', '', userdate($timestart));
2213 echo '</div>';
2214 echo '<div class="activityhead">';
2216 echo '<a href="'.$CFG->wwwroot.'/course/recent.php?id='.$course->id.'">'.get_string('recentactivityreport').'</a>';
2218 echo "</div>\n";
2220 $content = false;
2222 /// Firstly, have there been any new enrolments?
2224 $users = get_recent_enrolments($course->id, $timestart);
2226 //Accessibility: new users now appear in an <OL> list.
2227 if ($users) {
2228 echo '<div class="newusers">';
2229 echo $OUTPUT->heading(get_string("newusers").':', 3);
2230 $content = true;
2231 echo "<ol class=\"list\">\n";
2232 foreach ($users as $user) {
2233 $fullname = fullname($user, $viewfullnames);
2234 echo '<li class="name"><a href="'."$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a></li>\n";
2236 echo "</ol>\n</div>\n";
2239 /// Next, have there been any modifications to the course structure?
2241 $modinfo = get_fast_modinfo($course);
2243 $changelist = array();
2245 $logs = $DB->get_records_select('log', "time > ? AND course = ? AND
2246 module = 'course' AND
2247 (action = 'add mod' OR action = 'update mod' OR action = 'delete mod')",
2248 array($timestart, $course->id), "id ASC");
2250 if ($logs) {
2251 $actions = array('add mod', 'update mod', 'delete mod');
2252 $newgones = array(); // added and later deleted items
2253 foreach ($logs as $key => $log) {
2254 if (!in_array($log->action, $actions)) {
2255 continue;
2257 $info = explode(' ', $log->info);
2259 // note: in most cases I replaced hardcoding of label with use of
2260 // $cm->has_view() but it was not possible to do this here because
2261 // we don't necessarily have the $cm for it
2262 if ($info[0] == 'label') { // Labels are ignored in recent activity
2263 continue;
2266 if (count($info) != 2) {
2267 debugging("Incorrect log entry info: id = ".$log->id, DEBUG_DEVELOPER);
2268 continue;
2271 $modname = $info[0];
2272 $instanceid = $info[1];
2274 if ($log->action == 'delete mod') {
2275 // unfortunately we do not know if the mod was visible
2276 if (!array_key_exists($log->info, $newgones)) {
2277 $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $modname));
2278 $changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted);
2280 } else {
2281 if (!isset($modinfo->instances[$modname][$instanceid])) {
2282 if ($log->action == 'add mod') {
2283 // do not display added and later deleted activities
2284 $newgones[$log->info] = true;
2286 continue;
2288 $cm = $modinfo->instances[$modname][$instanceid];
2289 if (!$cm->uservisible) {
2290 continue;
2293 if ($log->action == 'add mod') {
2294 $stradded = get_string('added', 'moodle', get_string('modulename', $modname));
2295 $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>");
2297 } else if ($log->action == 'update mod' and empty($changelist[$log->info])) {
2298 $strupdated = get_string('updated', 'moodle', get_string('modulename', $modname));
2299 $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>");
2305 if (!empty($changelist)) {
2306 echo $OUTPUT->heading(get_string("courseupdates").':', 3);
2307 $content = true;
2308 foreach ($changelist as $changeinfo => $change) {
2309 echo '<p class="activity">'.$change['text'].'</p>';
2313 /// Now display new things from each module
2315 $usedmodules = array();
2316 foreach($modinfo->cms as $cm) {
2317 if (isset($usedmodules[$cm->modname])) {
2318 continue;
2320 if (!$cm->uservisible) {
2321 continue;
2323 $usedmodules[$cm->modname] = $cm->modname;
2326 foreach ($usedmodules as $modname) { // Each module gets it's own logs and prints them
2327 if (file_exists($CFG->dirroot.'/mod/'.$modname.'/lib.php')) {
2328 include_once($CFG->dirroot.'/mod/'.$modname.'/lib.php');
2329 $print_recent_activity = $modname.'_print_recent_activity';
2330 if (function_exists($print_recent_activity)) {
2331 // NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames!
2332 $content = $print_recent_activity($course, $viewfullnames, $timestart) || $content;
2334 } else {
2335 debugging("Missing lib.php in lib/{$modname} - please reinstall files or uninstall the module");
2339 if (! $content) {
2340 echo '<p class="message">'.get_string('nothingnew').'</p>';
2345 * Delete a course module and any associated data at the course level (events)
2346 * Until 1.5 this function simply marked a deleted flag ... now it
2347 * deletes it completely.
2349 * @deprecated since 2.5
2351 * @param int $id the course module id
2352 * @return boolean true on success, false on failure
2354 function delete_course_module($id) {
2355 debugging('Function delete_course_module() is deprecated. Please use course_delete_module() instead.', DEBUG_DEVELOPER);
2357 global $CFG, $DB;
2359 require_once($CFG->libdir.'/gradelib.php');
2360 require_once($CFG->dirroot.'/blog/lib.php');
2362 if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) {
2363 return true;
2365 $modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module));
2366 //delete events from calendar
2367 if ($events = $DB->get_records('event', array('instance'=>$cm->instance, 'modulename'=>$modulename))) {
2368 foreach($events as $event) {
2369 delete_event($event->id);
2372 //delete grade items, outcome items and grades attached to modules
2373 if ($grade_items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename,
2374 'iteminstance'=>$cm->instance, 'courseid'=>$cm->course))) {
2375 foreach ($grade_items as $grade_item) {
2376 $grade_item->delete('moddelete');
2379 // Delete completion and availability data; it is better to do this even if the
2380 // features are not turned on, in case they were turned on previously (these will be
2381 // very quick on an empty table)
2382 $DB->delete_records('course_modules_completion', array('coursemoduleid' => $cm->id));
2383 $DB->delete_records('course_completion_criteria', array('moduleinstance' => $cm->id,
2384 'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY));
2386 delete_context(CONTEXT_MODULE, $cm->id);
2387 return $DB->delete_records('course_modules', array('id'=>$cm->id));
2391 * Prints the turn editing on/off button on course/index.php or course/category.php.
2393 * @deprecated since 2.5
2395 * @param integer $categoryid The id of the category we are showing, or 0 for system context.
2396 * @return string HTML of the editing button, or empty string, if this user is not allowed
2397 * to see it.
2399 function update_category_button($categoryid = 0) {
2400 global $CFG, $PAGE, $OUTPUT;
2401 debugging('Function update_category_button() is deprecated. Pages to view '.
2402 'and edit courses are now separate and no longer depend on editing mode.',
2403 DEBUG_DEVELOPER);
2405 // Check permissions.
2406 if (!can_edit_in_category($categoryid)) {
2407 return '';
2410 // Work out the appropriate action.
2411 if ($PAGE->user_is_editing()) {
2412 $label = get_string('turneditingoff');
2413 $edit = 'off';
2414 } else {
2415 $label = get_string('turneditingon');
2416 $edit = 'on';
2419 // Generate the button HTML.
2420 $options = array('categoryedit' => $edit, 'sesskey' => sesskey());
2421 if ($categoryid) {
2422 $options['id'] = $categoryid;
2423 $page = 'category.php';
2424 } else {
2425 $page = 'index.php';
2427 return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get');
2431 * This function recursively travels the categories, building up a nice list
2432 * for display. It also makes an array that list all the parents for each
2433 * category.
2435 * For example, if you have a tree of categories like:
2436 * Miscellaneous (id = 1)
2437 * Subcategory (id = 2)
2438 * Sub-subcategory (id = 4)
2439 * Other category (id = 3)
2440 * Then after calling this function you will have
2441 * $list = array(1 => 'Miscellaneous', 2 => 'Miscellaneous / Subcategory',
2442 * 4 => 'Miscellaneous / Subcategory / Sub-subcategory',
2443 * 3 => 'Other category');
2444 * $parents = array(2 => array(1), 4 => array(1, 2));
2446 * If you specify $requiredcapability, then only categories where the current
2447 * user has that capability will be added to $list, although all categories
2448 * will still be added to $parents, and if you only have $requiredcapability
2449 * in a child category, not the parent, then the child catgegory will still be
2450 * included.
2452 * If you specify the option $excluded, then that category, and all its children,
2453 * are omitted from the tree. This is useful when you are doing something like
2454 * moving categories, where you do not want to allow people to move a category
2455 * to be the child of itself.
2457 * This function is deprecated! For list of categories use
2458 * coursecat::make_all_categories($requiredcapability, $excludeid, $separator)
2459 * For parents of one particular category use
2460 * coursecat::get($id)->get_parents()
2462 * @deprecated since 2.5
2464 * @param array $list For output, accumulates an array categoryid => full category path name
2465 * @param array $parents For output, accumulates an array categoryid => list of parent category ids.
2466 * @param string/array $requiredcapability if given, only categories where the current
2467 * user has this capability will be added to $list. Can also be an array of capabilities,
2468 * in which case they are all required.
2469 * @param integer $excludeid Omit this category and its children from the lists built.
2470 * @param object $category Not used
2471 * @param string $path Not used
2473 function make_categories_list(&$list, &$parents, $requiredcapability = '',
2474 $excludeid = 0, $category = NULL, $path = "") {
2475 global $CFG, $DB;
2476 require_once($CFG->libdir.'/coursecatlib.php');
2478 debugging('Global function make_categories_list() is deprecated. Please use '.
2479 'coursecat::make_categories_list() and coursecat::get_parents()',
2480 DEBUG_DEVELOPER);
2482 // For categories list use just this one function:
2483 if (empty($list)) {
2484 $list = array();
2486 $list += coursecat::make_categories_list($requiredcapability, $excludeid);
2488 // Building the list of all parents of all categories in the system is highly undesirable and hardly ever needed.
2489 // Usually user needs only parents for one particular category, in which case should be used:
2490 // coursecat::get($categoryid)->get_parents()
2491 if (empty($parents)) {
2492 $parents = array();
2494 $all = $DB->get_records_sql('SELECT id, parent FROM {course_categories} ORDER BY sortorder');
2495 foreach ($all as $record) {
2496 if ($record->parent) {
2497 $parents[$record->id] = array_merge($parents[$record->parent], array($record->parent));
2498 } else {
2499 $parents[$record->id] = array();
2505 * Delete category, but move contents to another category.
2507 * This function is deprecated. Please use
2508 * coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2510 * @see coursecat::delete_move()
2511 * @deprecated since 2.5
2513 * @param object $category
2514 * @param int $newparentid category id
2515 * @return bool status
2517 function category_delete_move($category, $newparentid, $showfeedback=true) {
2518 global $CFG;
2519 require_once($CFG->libdir.'/coursecatlib.php');
2521 debugging('Function category_delete_move() is deprecated. Please use coursecat::delete_move() instead.');
2523 return coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2527 * Recursively delete category including all subcategories and courses.
2529 * This function is deprecated. Please use
2530 * coursecat::get($category->id)->delete_full($showfeedback);
2532 * @see coursecat::delete_full()
2533 * @deprecated since 2.5
2535 * @param stdClass $category
2536 * @param boolean $showfeedback display some notices
2537 * @return array return deleted courses
2539 function category_delete_full($category, $showfeedback=true) {
2540 global $CFG, $DB;
2541 require_once($CFG->libdir.'/coursecatlib.php');
2543 debugging('Function category_delete_full() is deprecated. Please use coursecat::delete_full() instead.');
2545 return coursecat::get($category->id)->delete_full($showfeedback);
2549 * Efficiently moves a category - NOTE that this can have
2550 * a huge impact access-control-wise...
2552 * This function is deprecated. Please use
2553 * $coursecat = coursecat::get($category->id);
2554 * if ($coursecat->can_change_parent($newparentcat->id)) {
2555 * $coursecat->change_parent($newparentcat->id);
2558 * Alternatively you can use
2559 * $coursecat->update(array('parent' => $newparentcat->id));
2561 * Function update() also updates field course_categories.timemodified
2563 * @see coursecat::change_parent()
2564 * @see coursecat::update()
2565 * @deprecated since 2.5
2567 * @param stdClass|coursecat $category
2568 * @param stdClass|coursecat $newparentcat
2570 function move_category($category, $newparentcat) {
2571 global $CFG;
2572 require_once($CFG->libdir.'/coursecatlib.php');
2574 debugging('Function move_category() is deprecated. Please use coursecat::change_parent() instead.');
2576 return coursecat::get($category->id)->change_parent($newparentcat->id);
2580 * Hide course category and child course and subcategories
2582 * This function is deprecated. Please use
2583 * coursecat::get($category->id)->hide();
2585 * @see coursecat::hide()
2586 * @deprecated since 2.5
2588 * @param stdClass $category
2589 * @return void
2591 function course_category_hide($category) {
2592 global $CFG;
2593 require_once($CFG->libdir.'/coursecatlib.php');
2595 debugging('Function course_category_hide() is deprecated. Please use coursecat::hide() instead.');
2597 coursecat::get($category->id)->hide();
2601 * Show course category and child course and subcategories
2603 * This function is deprecated. Please use
2604 * coursecat::get($category->id)->show();
2606 * @see coursecat::show()
2607 * @deprecated since 2.5
2609 * @param stdClass $category
2610 * @return void
2612 function course_category_show($category) {
2613 global $CFG;
2614 require_once($CFG->libdir.'/coursecatlib.php');
2616 debugging('Function course_category_show() is deprecated. Please use coursecat::show() instead.');
2618 coursecat::get($category->id)->show();
2622 * Return specified category, default if given does not exist
2624 * This function is deprecated.
2625 * To get the category with the specified it please use:
2626 * coursecat::get($catid, IGNORE_MISSING);
2627 * or
2628 * coursecat::get($catid, MUST_EXIST);
2630 * To get the first available category please use
2631 * coursecat::get_default();
2633 * class coursecat will also make sure that at least one category exists in DB
2635 * @deprecated since 2.5
2636 * @see coursecat::get()
2637 * @see coursecat::get_default()
2639 * @param int $catid course category id
2640 * @return object caregory
2642 function get_course_category($catid=0) {
2643 global $DB;
2645 debugging('Function get_course_category() is deprecated. Please use coursecat::get(), see phpdocs for more details');
2647 $category = false;
2649 if (!empty($catid)) {
2650 $category = $DB->get_record('course_categories', array('id'=>$catid));
2653 if (!$category) {
2654 // the first category is considered default for now
2655 if ($category = $DB->get_records('course_categories', null, 'sortorder', '*', 0, 1)) {
2656 $category = reset($category);
2658 } else {
2659 $cat = new stdClass();
2660 $cat->name = get_string('miscellaneous');
2661 $cat->depth = 1;
2662 $cat->sortorder = MAX_COURSES_IN_CATEGORY;
2663 $cat->timemodified = time();
2664 $catid = $DB->insert_record('course_categories', $cat);
2665 // make sure category context exists
2666 context_coursecat::instance($catid);
2667 mark_context_dirty('/'.SYSCONTEXTID);
2668 fix_course_sortorder(); // Required to build course_categories.depth and .path.
2669 $category = $DB->get_record('course_categories', array('id'=>$catid));
2673 return $category;
2677 * Create a new course category and marks the context as dirty
2679 * This function does not set the sortorder for the new category and
2680 * {@link fix_course_sortorder()} should be called after creating a new course
2681 * category
2683 * Please note that this function does not verify access control.
2685 * This function is deprecated. It is replaced with the method create() in class coursecat.
2686 * {@link coursecat::create()} also verifies the data, fixes sortorder and logs the action
2688 * @deprecated since 2.5
2690 * @param object $category All of the data required for an entry in the course_categories table
2691 * @return object new course category
2693 function create_course_category($category) {
2694 global $DB;
2696 debugging('Function create_course_category() is deprecated. Please use coursecat::create(), see phpdocs for more details', DEBUG_DEVELOPER);
2698 $category->timemodified = time();
2699 $category->id = $DB->insert_record('course_categories', $category);
2700 $category = $DB->get_record('course_categories', array('id' => $category->id));
2702 // We should mark the context as dirty
2703 $category->context = context_coursecat::instance($category->id);
2704 $category->context->mark_dirty();
2706 return $category;
2710 * Returns an array of category ids of all the subcategories for a given
2711 * category.
2713 * This function is deprecated.
2715 * To get visible children categories of the given category use:
2716 * coursecat::get($categoryid)->get_children();
2717 * This function will return the array or coursecat objects, on each of them
2718 * you can call get_children() again
2720 * @see coursecat::get()
2721 * @see coursecat::get_children()
2723 * @deprecated since 2.5
2725 * @global object
2726 * @param int $catid - The id of the category whose subcategories we want to find.
2727 * @return array of category ids.
2729 function get_all_subcategories($catid) {
2730 global $DB;
2732 debugging('Function get_all_subcategories() is deprecated. Please use appropriate methods() of coursecat class. See phpdocs for more details',
2733 DEBUG_DEVELOPER);
2735 $subcats = array();
2737 if ($categories = $DB->get_records('course_categories', array('parent' => $catid))) {
2738 foreach ($categories as $cat) {
2739 array_push($subcats, $cat->id);
2740 $subcats = array_merge($subcats, get_all_subcategories($cat->id));
2743 return $subcats;
2747 * Gets the child categories of a given courses category
2749 * This function is deprecated. Please use functions in class coursecat:
2750 * - coursecat::get($parentid)->has_children()
2751 * tells if the category has children (visible or not to the current user)
2753 * - coursecat::get($parentid)->get_children()
2754 * returns an array of coursecat objects, each of them represents a children category visible
2755 * to the current user (i.e. visible=1 or user has capability to view hidden categories)
2757 * - coursecat::get($parentid)->get_children_count()
2758 * returns number of children categories visible to the current user
2760 * - coursecat::count_all()
2761 * returns total count of all categories in the system (both visible and not)
2763 * - coursecat::get_default()
2764 * returns the first category (usually to be used if count_all() == 1)
2766 * @deprecated since 2.5
2768 * @param int $parentid the id of a course category.
2769 * @return array all the child course categories.
2771 function get_child_categories($parentid) {
2772 global $DB;
2773 debugging('Function get_child_categories() is deprecated. Use coursecat::get_children() or see phpdocs for more details.',
2774 DEBUG_DEVELOPER);
2776 $rv = array();
2777 $sql = context_helper::get_preload_record_columns_sql('ctx');
2778 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
2779 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
2780 array(CONTEXT_COURSECAT, $parentid));
2781 foreach ($records as $category) {
2782 context_helper::preload_from_record($category);
2783 if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) {
2784 continue;
2786 $rv[] = $category;
2788 return $rv;
2792 * Returns a sorted list of categories.
2794 * When asking for $parent='none' it will return all the categories, regardless
2795 * of depth. Wheen asking for a specific parent, the default is to return
2796 * a "shallow" resultset. Pass false to $shallow and it will return all
2797 * the child categories as well.
2799 * @deprecated since 2.5
2801 * This function is deprecated. Use appropriate functions from class coursecat.
2802 * Examples:
2804 * coursecat::get($categoryid)->get_children()
2805 * - returns all children of the specified category as instances of class
2806 * coursecat, which means on each of them method get_children() can be called again.
2807 * Only categories visible to the current user are returned.
2809 * coursecat::get(0)->get_children()
2810 * - returns all top-level categories visible to the current user.
2812 * Sort fields can be specified, see phpdocs to {@link coursecat::get_children()}
2814 * coursecat::make_categories_list()
2815 * - returns an array of all categories id/names in the system.
2816 * Also only returns categories visible to current user and can additionally be
2817 * filetered by capability, see phpdocs to {@link coursecat::make_categories_list()}
2819 * make_categories_options()
2820 * - Returns full course categories tree to be used in html_writer::select()
2822 * Also see functions {@link coursecat::get_children_count()}, {@link coursecat::count_all()},
2823 * {@link coursecat::get_default()}
2825 * The code of this deprecated function is left as it is because coursecat::get_children()
2826 * returns categories as instances of coursecat and not stdClass. Also there is no
2827 * substitute for retrieving the category with all it's subcategories. Plugin developers
2828 * may re-use the code/queries from this function in their plugins if really necessary.
2830 * @param string $parent The parent category if any
2831 * @param string $sort the sortorder
2832 * @param bool $shallow - set to false to get the children too
2833 * @return array of categories
2835 function get_categories($parent='none', $sort=NULL, $shallow=true) {
2836 global $DB;
2838 debugging('Function get_categories() is deprecated. Please use coursecat::get_children() or see phpdocs for other alternatives',
2839 DEBUG_DEVELOPER);
2841 if ($sort === NULL) {
2842 $sort = 'ORDER BY cc.sortorder ASC';
2843 } elseif ($sort ==='') {
2844 // leave it as empty
2845 } else {
2846 $sort = "ORDER BY $sort";
2849 list($ccselect, $ccjoin) = context_instance_preload_sql('cc.id', CONTEXT_COURSECAT, 'ctx');
2851 if ($parent === 'none') {
2852 $sql = "SELECT cc.* $ccselect
2853 FROM {course_categories} cc
2854 $ccjoin
2855 $sort";
2856 $params = array();
2858 } elseif ($shallow) {
2859 $sql = "SELECT cc.* $ccselect
2860 FROM {course_categories} cc
2861 $ccjoin
2862 WHERE cc.parent=?
2863 $sort";
2864 $params = array($parent);
2866 } else {
2867 $sql = "SELECT cc.* $ccselect
2868 FROM {course_categories} cc
2869 $ccjoin
2870 JOIN {course_categories} ccp
2871 ON ((cc.parent = ccp.id) OR (cc.path LIKE ".$DB->sql_concat('ccp.path',"'/%'")."))
2872 WHERE ccp.id=?
2873 $sort";
2874 $params = array($parent);
2876 $categories = array();
2878 $rs = $DB->get_recordset_sql($sql, $params);
2879 foreach($rs as $cat) {
2880 context_helper::preload_from_record($cat);
2881 $catcontext = context_coursecat::instance($cat->id);
2882 if ($cat->visible || has_capability('moodle/category:viewhiddencategories', $catcontext)) {
2883 $categories[$cat->id] = $cat;
2886 $rs->close();
2887 return $categories;
2891 * Displays a course search form
2893 * This function is deprecated, please use course renderer:
2894 * $renderer = $PAGE->get_renderer('core', 'course');
2895 * echo $renderer->course_search_form($value, $format);
2897 * @deprecated since 2.5
2899 * @param string $value default value to populate the search field
2900 * @param bool $return if true returns the value, if false - outputs
2901 * @param string $format display format - 'plain' (default), 'short' or 'navbar'
2902 * @return null|string
2904 function print_course_search($value="", $return=false, $format="plain") {
2905 global $PAGE;
2906 debugging('Function print_course_search() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2907 $renderer = $PAGE->get_renderer('core', 'course');
2908 if ($return) {
2909 return $renderer->course_search_form($value, $format);
2910 } else {
2911 echo $renderer->course_search_form($value, $format);
2916 * Prints custom user information on the home page
2918 * This function is deprecated, please use:
2919 * $renderer = $PAGE->get_renderer('core', 'course');
2920 * echo $renderer->frontpage_my_courses()
2922 * @deprecated since 2.5
2924 function print_my_moodle() {
2925 global $PAGE;
2926 debugging('Function print_my_moodle() is deprecated, please use course renderer function frontpage_my_courses()', DEBUG_DEVELOPER);
2928 $renderer = $PAGE->get_renderer('core', 'course');
2929 echo $renderer->frontpage_my_courses();
2933 * Prints information about one remote course
2935 * This function is deprecated, it is replaced with protected function
2936 * {@link core_course_renderer::frontpage_remote_course()}
2937 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
2939 * @deprecated since 2.5
2941 function print_remote_course($course, $width="100%") {
2942 global $CFG, $USER;
2943 debugging('Function print_remote_course() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2945 $linkcss = '';
2947 $url = "{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&amp;wantsurl=/course/view.php?id={$course->remoteid}";
2949 echo '<div class="coursebox remotecoursebox clearfix">';
2950 echo '<div class="info">';
2951 echo '<div class="name"><a title="'.get_string('entercourse').'"'.
2952 $linkcss.' href="'.$url.'">'
2953 . format_string($course->fullname) .'</a><br />'
2954 . format_string($course->hostname) . ' : '
2955 . format_string($course->cat_name) . ' : '
2956 . format_string($course->shortname). '</div>';
2957 echo '</div><div class="summary">';
2958 $options = new stdClass();
2959 $options->noclean = true;
2960 $options->para = false;
2961 $options->overflowdiv = true;
2962 echo format_text($course->summary, $course->summaryformat, $options);
2963 echo '</div>';
2964 echo '</div>';
2968 * Prints information about one remote host
2970 * This function is deprecated, it is replaced with protected function
2971 * {@link core_course_renderer::frontpage_remote_host()}
2972 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
2974 * @deprecated since 2.5
2976 function print_remote_host($host, $width="100%") {
2977 global $OUTPUT;
2978 debugging('Function print_remote_host() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2980 $linkcss = '';
2982 echo '<div class="coursebox clearfix">';
2983 echo '<div class="info">';
2984 echo '<div class="name">';
2985 echo '<img src="'.$OUTPUT->pix_url('i/mnethost') . '" class="icon" alt="'.get_string('course').'" />';
2986 echo '<a title="'.s($host['name']).'" href="'.s($host['url']).'">'
2987 . s($host['name']).'</a> - ';
2988 echo $host['count'] . ' ' . get_string('courses');
2989 echo '</div>';
2990 echo '</div>';
2991 echo '</div>';
2995 * Recursive function to print out all the categories in a nice format
2996 * with or without courses included
2998 * @deprecated since 2.5
3000 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3002 function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) {
3003 global $PAGE;
3004 debugging('Function print_whole_category_list() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3006 $renderer = $PAGE->get_renderer('core', 'course');
3007 if ($showcourses && $category) {
3008 echo $renderer->course_category($category);
3009 } else if ($showcourses) {
3010 echo $renderer->frontpage_combo_list();
3011 } else {
3012 echo $renderer->frontpage_categories_list();
3017 * Prints the category information.
3019 * @deprecated since 2.5
3021 * This function was only used by {@link print_whole_category_list()} but now
3022 * all course category rendering is moved to core_course_renderer.
3024 * @param stdClass $category
3025 * @param int $depth The depth of the category.
3026 * @param bool $showcourses If set to true course information will also be printed.
3027 * @param array|null $courses An array of courses belonging to the category, or null if you don't have it yet.
3029 function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) {
3030 global $PAGE;
3031 debugging('Function print_category_info() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3033 $renderer = $PAGE->get_renderer('core', 'course');
3034 echo $renderer->course_category($category);
3038 * This function generates a structured array of courses and categories.
3040 * @deprecated since 2.5
3042 * This function is not used any more in moodle core and course renderer does not have render function for it.
3043 * Combo list on the front page is displayed as:
3044 * $renderer = $PAGE->get_renderer('core', 'course');
3045 * echo $renderer->frontpage_combo_list()
3047 * The new class {@link coursecat} stores the information about course category tree
3048 * To get children categories use:
3049 * coursecat::get($id)->get_children()
3050 * To get list of courses use:
3051 * coursecat::get($id)->get_courses()
3053 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3055 * @param int $id
3056 * @param int $depth
3058 function get_course_category_tree($id = 0, $depth = 0) {
3059 global $DB, $CFG;
3060 if (!$depth) {
3061 debugging('Function get_course_category_tree() is deprecated, please use course renderer or coursecat class, see function phpdocs for more info', DEBUG_DEVELOPER);
3064 $categories = array();
3065 $categoryids = array();
3066 $sql = context_helper::get_preload_record_columns_sql('ctx');
3067 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
3068 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
3069 array(CONTEXT_COURSECAT, $id));
3070 foreach ($records as $category) {
3071 context_helper::preload_from_record($category);
3072 if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) {
3073 continue;
3075 $categories[] = $category;
3076 $categoryids[$category->id] = $category;
3077 if (empty($CFG->maxcategorydepth) || $depth <= $CFG->maxcategorydepth) {
3078 list($category->categories, $subcategories) = get_course_category_tree($category->id, $depth+1);
3079 foreach ($subcategories as $subid=>$subcat) {
3080 $categoryids[$subid] = $subcat;
3082 $category->courses = array();
3086 if ($depth > 0) {
3087 // This is a recursive call so return the required array
3088 return array($categories, $categoryids);
3091 if (empty($categoryids)) {
3092 // No categories available (probably all hidden).
3093 return array();
3096 // The depth is 0 this function has just been called so we can finish it off
3098 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
3099 list($catsql, $catparams) = $DB->get_in_or_equal(array_keys($categoryids));
3100 $sql = "SELECT
3101 c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary,c.category
3102 $ccselect
3103 FROM {course} c
3104 $ccjoin
3105 WHERE c.category $catsql ORDER BY c.sortorder ASC";
3106 if ($courses = $DB->get_records_sql($sql, $catparams)) {
3107 // loop throught them
3108 foreach ($courses as $course) {
3109 if ($course->id == SITEID) {
3110 continue;
3112 context_helper::preload_from_record($course);
3113 if (!empty($course->visible) || has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
3114 $categoryids[$course->category]->courses[$course->id] = $course;
3118 return $categories;
3122 * Print courses in category. If category is 0 then all courses are printed.
3124 * @deprecated since 2.5
3126 * To print a generic list of courses use:
3127 * $renderer = $PAGE->get_renderer('core', 'course');
3128 * echo $renderer->courses_list($courses);
3130 * To print list of all courses:
3131 * $renderer = $PAGE->get_renderer('core', 'course');
3132 * echo $renderer->frontpage_available_courses();
3134 * To print list of courses inside category:
3135 * $renderer = $PAGE->get_renderer('core', 'course');
3136 * echo $renderer->course_category($category); // this will also print subcategories
3138 * @param int|stdClass $category category object or id.
3139 * @return bool true if courses found and printed, else false.
3141 function print_courses($category) {
3142 global $CFG, $OUTPUT, $PAGE;
3143 require_once($CFG->libdir. '/coursecatlib.php');
3144 debugging('Function print_courses() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3146 if (!is_object($category) && $category==0) {
3147 $courses = coursecat::get(0)->get_courses(array('recursive' => true, 'summary' => true, 'coursecontacts' => true));
3148 } else {
3149 $courses = coursecat::get($category->id)->get_courses(array('summary' => true, 'coursecontacts' => true));
3152 if ($courses) {
3153 $renderer = $PAGE->get_renderer('core', 'course');
3154 echo $renderer->courses_list($courses);
3155 } else {
3156 echo $OUTPUT->heading(get_string("nocoursesyet"));
3157 $context = context_system::instance();
3158 if (has_capability('moodle/course:create', $context)) {
3159 $options = array();
3160 if (!empty($category->id)) {
3161 $options['category'] = $category->id;
3162 } else {
3163 $options['category'] = $CFG->defaultrequestcategory;
3165 echo html_writer::start_tag('div', array('class'=>'addcoursebutton'));
3166 echo $OUTPUT->single_button(new moodle_url('/course/edit.php', $options), get_string("addnewcourse"));
3167 echo html_writer::end_tag('div');
3168 return false;
3171 return true;
3175 * Print a description of a course, suitable for browsing in a list.
3177 * @deprecated since 2.5
3179 * Please use course renderer to display a course information box.
3180 * $renderer = $PAGE->get_renderer('core', 'course');
3181 * echo $renderer->courses_list($courses); // will print list of courses
3182 * echo $renderer->course_info_box($course); // will print one course wrapped in div.generalbox
3184 * @param object $course the course object.
3185 * @param string $highlightterms Ignored in this deprecated function!
3187 function print_course($course, $highlightterms = '') {
3188 global $PAGE;
3190 debugging('Function print_course() is deprecated, please use course renderer', DEBUG_DEVELOPER);
3191 $renderer = $PAGE->get_renderer('core', 'course');
3192 // Please note, correct would be to use $renderer->coursecat_coursebox() but this function is protected.
3193 // To print list of courses use $renderer->courses_list();
3194 echo $renderer->course_info_box($course);
3198 * Gets an array whose keys are category ids and whose values are arrays of courses in the corresponding category.
3200 * @deprecated since 2.5
3202 * This function is not used any more in moodle core and course renderer does not have render function for it.
3203 * Combo list on the front page is displayed as:
3204 * $renderer = $PAGE->get_renderer('core', 'course');
3205 * echo $renderer->frontpage_combo_list()
3207 * The new class {@link coursecat} stores the information about course category tree
3208 * To get children categories use:
3209 * coursecat::get($id)->get_children()
3210 * To get list of courses use:
3211 * coursecat::get($id)->get_courses()
3213 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
3215 * @param int $categoryid
3216 * @return array
3218 function get_category_courses_array($categoryid = 0) {
3219 debugging('Function get_category_courses_array() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
3220 $tree = get_course_category_tree($categoryid);
3221 $flattened = array();
3222 foreach ($tree as $category) {
3223 get_category_courses_array_recursively($flattened, $category);
3225 return $flattened;
3229 * Recursive function to help flatten the course category tree.
3231 * @deprecated since 2.5
3233 * Was intended to be called from {@link get_category_courses_array()}
3235 * @param array &$flattened An array passed by reference in which to store courses for each category.
3236 * @param stdClass $category The category to get courses for.
3238 function get_category_courses_array_recursively(array &$flattened, $category) {
3239 debugging('Function get_category_courses_array_recursively() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
3240 $flattened[$category->id] = $category->courses;
3241 foreach ($category->categories as $childcategory) {
3242 get_category_courses_array_recursively($flattened, $childcategory);
3247 * Returns a URL based on the context of the current page.
3248 * This URL points to blog/index.php and includes filter parameters appropriate for the current page.
3250 * @param stdclass $context
3251 * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more.
3252 * @todo Remove this in 2.7
3253 * @return string
3255 function blog_get_context_url($context=null) {
3256 global $CFG;
3258 debugging('Function blog_get_context_url() is deprecated, getting params from context is not reliable for blogs.', DEBUG_DEVELOPER);
3259 $viewblogentriesurl = new moodle_url('/blog/index.php');
3261 if (empty($context)) {
3262 global $PAGE;
3263 $context = $PAGE->context;
3266 // Change contextlevel to SYSTEM if viewing the site course
3267 if ($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID) {
3268 $context = context_system::instance();
3271 $filterparam = '';
3272 $strlevel = '';
3274 switch ($context->contextlevel) {
3275 case CONTEXT_SYSTEM:
3276 case CONTEXT_BLOCK:
3277 case CONTEXT_COURSECAT:
3278 break;
3279 case CONTEXT_COURSE:
3280 $filterparam = 'courseid';
3281 $strlevel = get_string('course');
3282 break;
3283 case CONTEXT_MODULE:
3284 $filterparam = 'modid';
3285 $strlevel = $context->get_context_name();
3286 break;
3287 case CONTEXT_USER:
3288 $filterparam = 'userid';
3289 $strlevel = get_string('user');
3290 break;
3293 if (!empty($filterparam)) {
3294 $viewblogentriesurl->param($filterparam, $context->instanceid);
3297 return $viewblogentriesurl;
3301 * Retrieve course records with the course managers and other related records
3302 * that we need for print_course(). This allows print_courses() to do its job
3303 * in a constant number of DB queries, regardless of the number of courses,
3304 * role assignments, etc.
3306 * The returned array is indexed on c.id, and each course will have
3307 * - $course->managers - array containing RA objects that include a $user obj
3308 * with the minimal fields needed for fullname()
3310 * @deprecated since 2.5
3312 * To get list of all courses with course contacts ('managers') use
3313 * coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true));
3315 * To get list of courses inside particular category use
3316 * coursecat::get($id)->get_courses(array('coursecontacts' => true));
3318 * Additionally you can specify sort order, offset and maximum number of courses,
3319 * see {@link coursecat::get_courses()}
3321 * Please note that code of this function is not changed to use coursecat class because
3322 * coursecat::get_courses() returns result in slightly different format. Also note that
3323 * get_courses_wmanagers() DOES NOT check that users are enrolled in the course and
3324 * coursecat::get_courses() does.
3326 * @global object
3327 * @global object
3328 * @global object
3329 * @uses CONTEXT_COURSE
3330 * @uses CONTEXT_SYSTEM
3331 * @uses CONTEXT_COURSECAT
3332 * @uses SITEID
3333 * @param int|string $categoryid Either the categoryid for the courses or 'all'
3334 * @param string $sort A SQL sort field and direction
3335 * @param array $fields An array of additional fields to fetch
3336 * @return array
3338 function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) {
3340 * The plan is to
3342 * - Grab the courses JOINed w/context
3344 * - Grab the interesting course-manager RAs
3345 * JOINed with a base user obj and add them to each course
3347 * So as to do all the work in 2 DB queries. The RA+user JOIN
3348 * ends up being pretty expensive if it happens over _all_
3349 * courses on a large site. (Are we surprised!?)
3351 * So this should _never_ get called with 'all' on a large site.
3354 global $USER, $CFG, $DB;
3355 debugging('Function get_courses_wmanagers() is deprecated, please use coursecat::get_courses()', DEBUG_DEVELOPER);
3357 $params = array();
3358 $allcats = false; // bool flag
3359 if ($categoryid === 'all') {
3360 $categoryclause = '';
3361 $allcats = true;
3362 } elseif (is_numeric($categoryid)) {
3363 $categoryclause = "c.category = :catid";
3364 $params['catid'] = $categoryid;
3365 } else {
3366 debugging("Could not recognise categoryid = $categoryid");
3367 $categoryclause = '';
3370 $basefields = array('id', 'category', 'sortorder',
3371 'shortname', 'fullname', 'idnumber',
3372 'startdate', 'visible',
3373 'newsitems', 'groupmode', 'groupmodeforce');
3375 if (!is_null($fields) && is_string($fields)) {
3376 if (empty($fields)) {
3377 $fields = $basefields;
3378 } else {
3379 // turn the fields from a string to an array that
3380 // get_user_courses_bycap() will like...
3381 $fields = explode(',',$fields);
3382 $fields = array_map('trim', $fields);
3383 $fields = array_unique(array_merge($basefields, $fields));
3385 } elseif (is_array($fields)) {
3386 $fields = array_merge($basefields,$fields);
3388 $coursefields = 'c.' .join(',c.', $fields);
3390 if (empty($sort)) {
3391 $sortstatement = "";
3392 } else {
3393 $sortstatement = "ORDER BY $sort";
3396 $where = 'WHERE c.id != ' . SITEID;
3397 if ($categoryclause !== ''){
3398 $where = "$where AND $categoryclause";
3401 // pull out all courses matching the cat
3402 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
3403 $sql = "SELECT $coursefields $ccselect
3404 FROM {course} c
3405 $ccjoin
3406 $where
3407 $sortstatement";
3409 $catpaths = array();
3410 $catpath = NULL;
3411 if ($courses = $DB->get_records_sql($sql, $params)) {
3412 // loop on courses materialising
3413 // the context, and prepping data to fetch the
3414 // managers efficiently later...
3415 foreach ($courses as $k => $course) {
3416 context_helper::preload_from_record($course);
3417 $coursecontext = context_course::instance($course->id);
3418 $courses[$k] = $course;
3419 $courses[$k]->managers = array();
3420 if ($allcats === false) {
3421 // single cat, so take just the first one...
3422 if ($catpath === NULL) {
3423 $catpath = preg_replace(':/\d+$:', '', $coursecontext->path);
3425 } else {
3426 // chop off the contextid of the course itself
3427 // like dirname() does...
3428 $catpaths[] = preg_replace(':/\d+$:', '', $coursecontext->path);
3431 } else {
3432 return array(); // no courses!
3435 $CFG->coursecontact = trim($CFG->coursecontact);
3436 if (empty($CFG->coursecontact)) {
3437 return $courses;
3440 $managerroles = explode(',', $CFG->coursecontact);
3441 $catctxids = '';
3442 if (count($managerroles)) {
3443 if ($allcats === true) {
3444 $catpaths = array_unique($catpaths);
3445 $ctxids = array();
3446 foreach ($catpaths as $cpath) {
3447 $ctxids = array_merge($ctxids, explode('/',substr($cpath,1)));
3449 $ctxids = array_unique($ctxids);
3450 $catctxids = implode( ',' , $ctxids);
3451 unset($catpaths);
3452 unset($cpath);
3453 } else {
3454 // take the ctx path from the first course
3455 // as all categories will be the same...
3456 $catpath = substr($catpath,1);
3457 $catpath = preg_replace(':/\d+$:','',$catpath);
3458 $catctxids = str_replace('/',',',$catpath);
3460 if ($categoryclause !== '') {
3461 $categoryclause = "AND $categoryclause";
3464 * Note: Here we use a LEFT OUTER JOIN that can
3465 * "optionally" match to avoid passing a ton of context
3466 * ids in an IN() clause. Perhaps a subselect is faster.
3468 * In any case, this SQL is not-so-nice over large sets of
3469 * courses with no $categoryclause.
3472 $sql = "SELECT ctx.path, ctx.instanceid, ctx.contextlevel,
3473 r.id AS roleid, r.name AS rolename, r.shortname AS roleshortname,
3474 rn.name AS rolecoursealias, u.id AS userid, u.firstname, u.lastname
3475 FROM {role_assignments} ra
3476 JOIN {context} ctx ON ra.contextid = ctx.id
3477 JOIN {user} u ON ra.userid = u.id
3478 JOIN {role} r ON ra.roleid = r.id
3479 LEFT JOIN {role_names} rn ON (rn.contextid = ctx.id AND rn.roleid = r.id)
3480 LEFT OUTER JOIN {course} c
3481 ON (ctx.instanceid=c.id AND ctx.contextlevel=".CONTEXT_COURSE.")
3482 WHERE ( c.id IS NOT NULL";
3483 // under certain conditions, $catctxids is NULL
3484 if($catctxids == NULL){
3485 $sql .= ") ";
3486 }else{
3487 $sql .= " OR ra.contextid IN ($catctxids) )";
3490 $sql .= "AND ra.roleid IN ({$CFG->coursecontact})
3491 $categoryclause
3492 ORDER BY r.sortorder ASC, ctx.contextlevel ASC, ra.sortorder ASC";
3493 $rs = $DB->get_recordset_sql($sql, $params);
3495 // This loop is fairly stupid as it stands - might get better
3496 // results doing an initial pass clustering RAs by path.
3497 foreach($rs as $ra) {
3498 $user = new stdClass;
3499 $user->id = $ra->userid; unset($ra->userid);
3500 $user->firstname = $ra->firstname; unset($ra->firstname);
3501 $user->lastname = $ra->lastname; unset($ra->lastname);
3502 $ra->user = $user;
3503 if ($ra->contextlevel == CONTEXT_SYSTEM) {
3504 foreach ($courses as $k => $course) {
3505 $courses[$k]->managers[] = $ra;
3507 } else if ($ra->contextlevel == CONTEXT_COURSECAT) {
3508 if ($allcats === false) {
3509 // It always applies
3510 foreach ($courses as $k => $course) {
3511 $courses[$k]->managers[] = $ra;
3513 } else {
3514 foreach ($courses as $k => $course) {
3515 $coursecontext = context_course::instance($course->id);
3516 // Note that strpos() returns 0 as "matched at pos 0"
3517 if (strpos($coursecontext->path, $ra->path.'/') === 0) {
3518 // Only add it to subpaths
3519 $courses[$k]->managers[] = $ra;
3523 } else { // course-level
3524 if (!array_key_exists($ra->instanceid, $courses)) {
3525 //this course is not in a list, probably a frontpage course
3526 continue;
3528 $courses[$ra->instanceid]->managers[] = $ra;
3531 $rs->close();
3534 return $courses;
3538 * Converts a nested array tree into HTML ul:li [recursive]
3540 * @deprecated since 2.5
3542 * @param array $tree A tree array to convert
3543 * @param int $row Used in identifying the iteration level and in ul classes
3544 * @return string HTML structure
3546 function convert_tree_to_html($tree, $row=0) {
3547 debugging('Function convert_tree_to_html() is deprecated since Moodle 2.5. Consider using class tabtree and core_renderer::render_tabtree()', DEBUG_DEVELOPER);
3549 $str = "\n".'<ul class="tabrow'.$row.'">'."\n";
3551 $first = true;
3552 $count = count($tree);
3554 foreach ($tree as $tab) {
3555 $count--; // countdown to zero
3557 $liclass = '';
3559 if ($first && ($count == 0)) { // Just one in the row
3560 $liclass = 'first last';
3561 $first = false;
3562 } else if ($first) {
3563 $liclass = 'first';
3564 $first = false;
3565 } else if ($count == 0) {
3566 $liclass = 'last';
3569 if ((empty($tab->subtree)) && (!empty($tab->selected))) {
3570 $liclass .= (empty($liclass)) ? 'onerow' : ' onerow';
3573 if ($tab->inactive || $tab->active || $tab->selected) {
3574 if ($tab->selected) {
3575 $liclass .= (empty($liclass)) ? 'here selected' : ' here selected';
3576 } else if ($tab->active) {
3577 $liclass .= (empty($liclass)) ? 'here active' : ' here active';
3581 $str .= (!empty($liclass)) ? '<li class="'.$liclass.'">' : '<li>';
3583 if ($tab->inactive || $tab->active || ($tab->selected && !$tab->linkedwhenselected)) {
3584 // The a tag is used for styling
3585 $str .= '<a class="nolink"><span>'.$tab->text.'</span></a>';
3586 } else {
3587 $str .= '<a href="'.$tab->link.'" title="'.$tab->title.'"><span>'.$tab->text.'</span></a>';
3590 if (!empty($tab->subtree)) {
3591 $str .= convert_tree_to_html($tab->subtree, $row+1);
3592 } else if ($tab->selected) {
3593 $str .= '<div class="tabrow'.($row+1).' empty">&nbsp;</div>'."\n";
3596 $str .= ' </li>'."\n";
3598 $str .= '</ul>'."\n";
3600 return $str;
3604 * Convert nested tabrows to a nested array
3606 * @deprecated since 2.5
3608 * @param array $tabrows A [nested] array of tab row objects
3609 * @param string $selected The tabrow to select (by id)
3610 * @param array $inactive An array of tabrow id's to make inactive
3611 * @param array $activated An array of tabrow id's to make active
3612 * @return array The nested array
3614 function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) {
3616 debugging('Function convert_tabrows_to_tree() is deprecated since Moodle 2.5. Consider using class tabtree', DEBUG_DEVELOPER);
3618 // Work backwards through the rows (bottom to top) collecting the tree as we go.
3619 $tabrows = array_reverse($tabrows);
3621 $subtree = array();
3623 foreach ($tabrows as $row) {
3624 $tree = array();
3626 foreach ($row as $tab) {
3627 $tab->inactive = in_array((string)$tab->id, $inactive);
3628 $tab->active = in_array((string)$tab->id, $activated);
3629 $tab->selected = (string)$tab->id == $selected;
3631 if ($tab->active || $tab->selected) {
3632 if ($subtree) {
3633 $tab->subtree = $subtree;
3636 $tree[] = $tab;
3638 $subtree = $tree;
3641 return $subtree;
3645 * Can handle rotated text. Whether it is safe to use the trickery in textrotate.js.
3647 * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically
3648 * @return bool True for yes, false for no
3650 function can_use_rotated_text() {
3651 debugging('can_use_rotated_text() is deprecated since Moodle 2.5. JS feature detection is used automatically.', DEBUG_DEVELOPER);
3652 return true;
3656 * Get the context instance as an object. This function will create the
3657 * context instance if it does not exist yet.
3659 * @deprecated since 2.2, use context_course::instance() or other relevant class instead
3660 * @todo This will be deleted in Moodle 2.8, refer MDL-34472
3661 * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
3662 * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
3663 * for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
3664 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
3665 * MUST_EXIST means throw exception if no record or multiple records found
3666 * @return context The context object.
3668 function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
3670 debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER);
3672 $instances = (array)$instance;
3673 $contexts = array();
3675 $classname = context_helper::get_class_for_level($contextlevel);
3677 // we do not load multiple contexts any more, PAGE should be responsible for any preloading
3678 foreach ($instances as $inst) {
3679 $contexts[$inst] = $classname::instance($inst, $strictness);
3682 if (is_array($instance)) {
3683 return $contexts;
3684 } else {
3685 return $contexts[$instance];
3690 * Get a context instance as an object, from a given context id.
3692 * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more.
3693 * @todo MDL-34550 This will be deleted in Moodle 2.8
3694 * @see context::instance_by_id($id)
3695 * @param int $id context id
3696 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
3697 * MUST_EXIST means throw exception if no record or multiple records found
3698 * @return context|bool the context object or false if not found.
3700 function get_context_instance_by_id($id, $strictness = IGNORE_MISSING) {
3701 debugging('get_context_instance_by_id() is deprecated, please use context::instance_by_id($id) instead.', DEBUG_DEVELOPER);
3702 return context::instance_by_id($id, $strictness);
3706 * Returns system context or null if can not be created yet.
3708 * @see context_system::instance()
3709 * @deprecated since 2.2
3710 * @param bool $cache use caching
3711 * @return context system context (null if context table not created yet)
3713 function get_system_context($cache = true) {
3714 debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER);
3715 return context_system::instance(0, IGNORE_MISSING, $cache);
3719 * Recursive function which, given a context, find all parent context ids,
3720 * and return the array in reverse order, i.e. parent first, then grand
3721 * parent, etc.
3723 * @see context::get_parent_context_ids()
3724 * @deprecated since 2.2, use $context->get_parent_context_ids() instead
3725 * @param context $context
3726 * @param bool $includeself optional, defaults to false
3727 * @return array
3729 function get_parent_contexts(context $context, $includeself = false) {
3730 debugging('get_parent_contexts() is deprecated, please use $context->get_parent_context_ids() instead.', DEBUG_DEVELOPER);
3731 return $context->get_parent_context_ids($includeself);
3735 * Return the id of the parent of this context, or false if there is no parent (only happens if this
3736 * is the site context.)
3738 * @deprecated since Moodle 2.2
3739 * @see context::get_parent_context()
3740 * @param context $context
3741 * @return integer the id of the parent context.
3743 function get_parent_contextid(context $context) {
3744 debugging('get_parent_contextid() is deprecated, please use $context->get_parent_context() instead.', DEBUG_DEVELOPER);
3746 if ($parent = $context->get_parent_context()) {
3747 return $parent->id;
3748 } else {
3749 return false;
3754 * Recursive function which, given a context, find all its children contexts.
3756 * For course category contexts it will return immediate children only categories and courses.
3757 * It will NOT recurse into courses or child categories.
3758 * If you want to do that, call it on the returned courses/categories.
3760 * When called for a course context, it will return the modules and blocks
3761 * displayed in the course page.
3763 * If called on a user/course/module context it _will_ populate the cache with the appropriate
3764 * contexts ;-)
3766 * @see context::get_child_contexts()
3767 * @deprecated since 2.2
3768 * @param context $context
3769 * @return array Array of child records
3771 function get_child_contexts(context $context) {
3772 debugging('get_child_contexts() is deprecated, please use $context->get_child_contexts() instead.', DEBUG_DEVELOPER);
3773 return $context->get_child_contexts();
3777 * Precreates all contexts including all parents.
3779 * @see context_helper::create_instances()
3780 * @deprecated since 2.2
3781 * @param int $contextlevel empty means all
3782 * @param bool $buildpaths update paths and depths
3783 * @return void
3785 function create_contexts($contextlevel = null, $buildpaths = true) {
3786 debugging('create_contexts() is deprecated, please use context_helper::create_instances() instead.', DEBUG_DEVELOPER);
3787 context_helper::create_instances($contextlevel, $buildpaths);
3791 * Remove stale context records.
3793 * @see context_helper::cleanup_instances()
3794 * @deprecated since 2.2
3795 * @return bool
3797 function cleanup_contexts() {
3798 debugging('cleanup_contexts() is deprecated, please use context_helper::cleanup_instances() instead.', DEBUG_DEVELOPER);
3799 context_helper::cleanup_instances();
3800 return true;
3804 * Populate context.path and context.depth where missing.
3806 * @see context_helper::build_all_paths()
3807 * @deprecated since 2.2
3808 * @param bool $force force a complete rebuild of the path and depth fields, defaults to false
3809 * @return void
3811 function build_context_path($force = false) {
3812 debugging('build_context_path() is deprecated, please use context_helper::build_all_paths() instead.', DEBUG_DEVELOPER);
3813 context_helper::build_all_paths($force);
3817 * Rebuild all related context depth and path caches.
3819 * @see context::reset_paths()
3820 * @deprecated since 2.2
3821 * @param array $fixcontexts array of contexts, strongtyped
3822 * @return void
3824 function rebuild_contexts(array $fixcontexts) {
3825 debugging('rebuild_contexts() is deprecated, please use $context->reset_paths(true) instead.', DEBUG_DEVELOPER);
3826 foreach ($fixcontexts as $fixcontext) {
3827 $fixcontext->reset_paths(false);
3829 context_helper::build_all_paths(false);
3833 * Preloads all contexts relating to a course: course, modules. Block contexts
3834 * are no longer loaded here. The contexts for all the blocks on the current
3835 * page are now efficiently loaded by {@link block_manager::load_blocks()}.
3837 * @deprecated since Moodle 2.2
3838 * @see context_helper::preload_course()
3839 * @param int $courseid Course ID
3840 * @return void
3842 function preload_course_contexts($courseid) {
3843 debugging('preload_course_contexts() is deprecated, please use context_helper::preload_course() instead.', DEBUG_DEVELOPER);
3844 context_helper::preload_course($courseid);
3848 * Update the path field of the context and all dep. subcontexts that follow
3850 * Update the path field of the context and
3851 * all the dependent subcontexts that follow
3852 * the move.
3854 * The most important thing here is to be as
3855 * DB efficient as possible. This op can have a
3856 * massive impact in the DB.
3858 * @deprecated since Moodle 2.2
3859 * @see context::update_moved()
3860 * @param context $context context obj
3861 * @param context $newparent new parent obj
3862 * @return void
3864 function context_moved(context $context, context $newparent) {
3865 debugging('context_moved() is deprecated, please use context::update_moved() instead.', DEBUG_DEVELOPER);
3866 $context->update_moved($newparent);
3870 * Extracts the relevant capabilities given a contextid.
3871 * All case based, example an instance of forum context.
3872 * Will fetch all forum related capabilities, while course contexts
3873 * Will fetch all capabilities
3875 * capabilities
3876 * `name` varchar(150) NOT NULL,
3877 * `captype` varchar(50) NOT NULL,
3878 * `contextlevel` int(10) NOT NULL,
3879 * `component` varchar(100) NOT NULL,
3881 * @see context::get_capabilities()
3882 * @deprecated since 2.2
3883 * @param context $context
3884 * @return array
3886 function fetch_context_capabilities(context $context) {
3887 debugging('fetch_context_capabilities() is deprecated, please use $context->get_capabilities() instead.', DEBUG_DEVELOPER);
3888 return $context->get_capabilities();
3892 * Preloads context information from db record and strips the cached info.
3893 * The db request has to contain both the $join and $select from context_instance_preload_sql()
3895 * @deprecated since 2.2
3896 * @see context_helper::preload_from_record()
3897 * @param stdClass $rec
3898 * @return void (modifies $rec)
3900 function context_instance_preload(stdClass $rec) {
3901 debugging('context_instance_preload() is deprecated, please use context_helper::preload_from_record() instead.', DEBUG_DEVELOPER);
3902 context_helper::preload_from_record($rec);
3906 * Returns context level name
3908 * @deprecated since 2.2
3909 * @see context_helper::get_level_name()
3910 * @param integer $contextlevel $context->context level. One of the CONTEXT_... constants.
3911 * @return string the name for this type of context.
3913 function get_contextlevel_name($contextlevel) {
3914 debugging('get_contextlevel_name() is deprecated, please use context_helper::get_level_name() instead.', DEBUG_DEVELOPER);
3915 return context_helper::get_level_name($contextlevel);
3919 * Prints human readable context identifier.
3921 * @deprecated since 2.2
3922 * @see context::get_context_name()
3923 * @param context $context the context.
3924 * @param boolean $withprefix whether to prefix the name of the context with the
3925 * type of context, e.g. User, Course, Forum, etc.
3926 * @param boolean $short whether to user the short name of the thing. Only applies
3927 * to course contexts
3928 * @return string the human readable context name.
3930 function print_context_name(context $context, $withprefix = true, $short = false) {
3931 debugging('print_context_name() is deprecated, please use $context->get_context_name() instead.', DEBUG_DEVELOPER);
3932 return $context->get_context_name($withprefix, $short);
3936 * Mark a context as dirty (with timestamp) so as to force reloading of the context.
3938 * @deprecated since 2.2, use $context->mark_dirty() instead
3939 * @see context::mark_dirty()
3940 * @param string $path context path
3942 function mark_context_dirty($path) {
3943 global $CFG, $USER, $ACCESSLIB_PRIVATE;
3944 debugging('mark_context_dirty() is deprecated, please use $context->mark_dirty() instead.', DEBUG_DEVELOPER);
3946 if (during_initial_install()) {
3947 return;
3950 // only if it is a non-empty string
3951 if (is_string($path) && $path !== '') {
3952 set_cache_flag('accesslib/dirtycontexts', $path, 1, time()+$CFG->sessiontimeout);
3953 if (isset($ACCESSLIB_PRIVATE->dirtycontexts)) {
3954 $ACCESSLIB_PRIVATE->dirtycontexts[$path] = 1;
3955 } else {
3956 if (CLI_SCRIPT) {
3957 $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1);
3958 } else {
3959 if (isset($USER->access['time'])) {
3960 $ACCESSLIB_PRIVATE->dirtycontexts = get_cache_flags('accesslib/dirtycontexts', $USER->access['time']-2);
3961 } else {
3962 $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1);
3964 // flags not loaded yet, it will be done later in $context->reload_if_dirty()
3971 * Remove a context record and any dependent entries,
3972 * removes context from static context cache too
3974 * @deprecated since Moodle 2.2
3975 * @see context_helper::delete_instance() or context::delete_content()
3976 * @param int $contextlevel
3977 * @param int $instanceid
3978 * @param bool $deleterecord false means keep record for now
3979 * @return bool returns true or throws an exception
3981 function delete_context($contextlevel, $instanceid, $deleterecord = true) {
3982 if ($deleterecord) {
3983 debugging('delete_context() is deprecated, please use context_helper::delete_instance() instead.', DEBUG_DEVELOPER);
3984 context_helper::delete_instance($contextlevel, $instanceid);
3985 } else {
3986 debugging('delete_context() is deprecated, please use $context->delete_content() instead.', DEBUG_DEVELOPER);
3987 $classname = context_helper::get_class_for_level($contextlevel);
3988 if ($context = $classname::instance($instanceid, IGNORE_MISSING)) {
3989 $context->delete_content();
3993 return true;
3997 * Get a URL for a context, if there is a natural one. For example, for
3998 * CONTEXT_COURSE, this is the course page. For CONTEXT_USER it is the
3999 * user profile page.
4001 * @deprecated since 2.2
4002 * @see context::get_url()
4003 * @param context $context the context
4004 * @return moodle_url
4006 function get_context_url(context $context) {
4007 debugging('get_context_url() is deprecated, please use $context->get_url() instead.', DEBUG_DEVELOPER);
4008 return $context->get_url();
4012 * Is this context part of any course? if yes return course context,
4013 * if not return null or throw exception.
4015 * @deprecated since 2.2
4016 * @see context::get_course_context()
4017 * @param context $context
4018 * @return context_course context of the enclosing course, null if not found or exception
4020 function get_course_context(context $context) {
4021 debugging('get_course_context() is deprecated, please use $context->get_course_context(true) instead.', DEBUG_DEVELOPER);
4022 return $context->get_course_context(true);
4026 * Get an array of courses where cap requested is available
4027 * and user is enrolled, this can be relatively slow.
4029 * @deprecated since 2.2
4030 * @see enrol_get_users_courses()
4031 * @param int $userid A user id. By default (null) checks the permissions of the current user.
4032 * @param string $cap - name of the capability
4033 * @param array $accessdata_ignored
4034 * @param bool $doanything_ignored
4035 * @param string $sort - sorting fields - prefix each fieldname with "c."
4036 * @param array $fields - additional fields you are interested in...
4037 * @param int $limit_ignored
4038 * @return array $courses - ordered array of course objects - see notes above
4040 function get_user_courses_bycap($userid, $cap, $accessdata_ignored, $doanything_ignored, $sort = 'c.sortorder ASC', $fields = null, $limit_ignored = 0) {
4042 debugging('get_user_courses_bycap() is deprecated, please use enrol_get_users_courses() instead.', DEBUG_DEVELOPER);
4043 $courses = enrol_get_users_courses($userid, true, $fields, $sort);
4044 foreach ($courses as $id=>$course) {
4045 $context = context_course::instance($id);
4046 if (!has_capability($cap, $context, $userid)) {
4047 unset($courses[$id]);
4051 return $courses;
4055 * This is really slow!!! do not use above course context level
4057 * @deprecated since Moodle 2.2
4058 * @param int $roleid
4059 * @param context $context
4060 * @return array
4062 function get_role_context_caps($roleid, context $context) {
4063 global $DB;
4064 debugging('get_role_context_caps() is deprecated, it is really slow. Don\'t use it.', DEBUG_DEVELOPER);
4066 // This is really slow!!!! - do not use above course context level.
4067 $result = array();
4068 $result[$context->id] = array();
4070 // First emulate the parent context capabilities merging into context.
4071 $searchcontexts = array_reverse($context->get_parent_context_ids(true));
4072 foreach ($searchcontexts as $cid) {
4073 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
4074 foreach ($capabilities as $cap) {
4075 if (!array_key_exists($cap->capability, $result[$context->id])) {
4076 $result[$context->id][$cap->capability] = 0;
4078 $result[$context->id][$cap->capability] += $cap->permission;
4083 // Now go through the contexts below given context.
4084 $searchcontexts = array_keys($context->get_child_contexts());
4085 foreach ($searchcontexts as $cid) {
4086 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
4087 foreach ($capabilities as $cap) {
4088 if (!array_key_exists($cap->contextid, $result)) {
4089 $result[$cap->contextid] = array();
4091 $result[$cap->contextid][$cap->capability] = $cap->permission;
4096 return $result;
4100 * Returns current course id or false if outside of course based on context parameter.
4102 * @see context::get_course_context()
4103 * @deprecated since 2.2
4104 * @param context $context
4105 * @return int|bool related course id or false
4107 function get_courseid_from_context(context $context) {
4108 debugging('get_courseid_from_context() is deprecated, please use $context->get_course_context(false) instead.', DEBUG_DEVELOPER);
4109 if ($coursecontext = $context->get_course_context(false)) {
4110 return $coursecontext->instanceid;
4111 } else {
4112 return false;
4117 * Preloads context information together with instances.
4118 * Use context_instance_preload() to strip the context info from the record and cache the context instance.
4120 * If you are using this methid, you should have something like this:
4122 * list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
4124 * To prevent the use of this deprecated function, replace the line above with something similar to this:
4126 * $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
4128 * $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
4129 * ^ ^ ^ ^
4130 * $params = array('contextlevel' => CONTEXT_COURSE);
4132 * @see context_helper:;get_preload_record_columns_sql()
4133 * @deprecated since 2.2
4134 * @param string $joinon for example 'u.id'
4135 * @param string $contextlevel context level of instance in $joinon
4136 * @param string $tablealias context table alias
4137 * @return array with two values - select and join part
4139 function context_instance_preload_sql($joinon, $contextlevel, $tablealias) {
4140 debugging('context_instance_preload_sql() is deprecated, please use context_helper::get_preload_record_columns_sql() instead.', DEBUG_DEVELOPER);
4141 $select = ", " . context_helper::get_preload_record_columns_sql($tablealias);
4142 $join = "LEFT JOIN {context} $tablealias ON ($tablealias.instanceid = $joinon AND $tablealias.contextlevel = $contextlevel)";
4143 return array($select, $join);
4147 * Gets a string for sql calls, searching for stuff in this context or above.
4149 * @deprecated since 2.2
4150 * @see context::get_parent_context_ids()
4151 * @param context $context
4152 * @return string
4154 function get_related_contexts_string(context $context) {
4155 debugging('get_related_contexts_string() is deprecated, please use $context->get_parent_context_ids(true) instead.', DEBUG_DEVELOPER);
4156 if ($parents = $context->get_parent_context_ids()) {
4157 return (' IN ('.$context->id.','.implode(',', $parents).')');
4158 } else {
4159 return (' ='.$context->id);
4164 * Get a list of all the plugins of a given type that contain a particular file.
4166 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
4167 * @param string $file the name of file that must be present in the plugin.
4168 * (e.g. 'view.php', 'db/install.xml').
4169 * @param bool $include if true (default false), the file will be include_once-ed if found.
4170 * @return array with plugin name as keys (e.g. 'forum', 'courselist') and the path
4171 * to the file relative to dirroot as value (e.g. "$CFG->dirroot/mod/forum/view.php").
4172 * @deprecated since 2.6
4173 * @see core_component::get_plugin_list_with_file()
4175 function get_plugin_list_with_file($plugintype, $file, $include = false) {
4176 debugging('get_plugin_list_with_file() is deprecated, please use core_component::get_plugin_list_with_file() instead.',
4177 DEBUG_DEVELOPER);
4178 return core_component::get_plugin_list_with_file($plugintype, $file, $include);
4182 * Checks to see if is the browser operating system matches the specified brand.
4184 * Known brand: 'Windows','Linux','Macintosh','SGI','SunOS','HP-UX'
4186 * @deprecated since 2.6
4187 * @param string $brand The operating system identifier being tested
4188 * @return bool true if the given brand below to the detected operating system
4190 function check_browser_operating_system($brand) {
4191 debugging('check_browser_operating_system has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4192 return core_useragent::check_browser_operating_system($brand);
4196 * Checks to see if is a browser matches the specified
4197 * brand and is equal or better version.
4199 * @deprecated since 2.6
4200 * @param string $brand The browser identifier being tested
4201 * @param int $version The version of the browser, if not specified any version (except 5.5 for IE for BC reasons)
4202 * @return bool true if the given version is below that of the detected browser
4204 function check_browser_version($brand, $version = null) {
4205 debugging('check_browser_version has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4206 return core_useragent::check_browser_version($brand, $version);
4210 * Returns whether a device/browser combination is mobile, tablet, legacy, default or the result of
4211 * an optional admin specified regular expression. If enabledevicedetection is set to no or not set
4212 * it returns default
4214 * @deprecated since 2.6
4215 * @return string device type
4217 function get_device_type() {
4218 debugging('get_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4219 return core_useragent::get_device_type();
4223 * Returns a list of the device types supporting by Moodle
4225 * @deprecated since 2.6
4226 * @param boolean $incusertypes includes types specified using the devicedetectregex admin setting
4227 * @return array $types
4229 function get_device_type_list($incusertypes = true) {
4230 debugging('get_device_type_list has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4231 return core_useragent::get_device_type_list($incusertypes);
4235 * Returns the theme selected for a particular device or false if none selected.
4237 * @deprecated since 2.6
4238 * @param string $devicetype
4239 * @return string|false The name of the theme to use for the device or the false if not set
4241 function get_selected_theme_for_device_type($devicetype = null) {
4242 debugging('get_selected_theme_for_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4243 return core_useragent::get_device_type_theme($devicetype);
4247 * Returns the name of the device type theme var in $CFG because there is not a convention to allow backwards compatibility.
4249 * @deprecated since 2.6
4250 * @param string $devicetype
4251 * @return string The config variable to use to determine the theme
4253 function get_device_cfg_var_name($devicetype = null) {
4254 debugging('get_device_cfg_var_name has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4255 return core_useragent::get_device_type_cfg_var_name($devicetype);
4259 * Allows the user to switch the device they are seeing the theme for.
4260 * This allows mobile users to switch back to the default theme, or theme for any other device.
4262 * @deprecated since 2.6
4263 * @param string $newdevice The device the user is currently using.
4264 * @return string The device the user has switched to
4266 function set_user_device_type($newdevice) {
4267 debugging('set_user_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4268 return core_useragent::set_user_device_type($newdevice);
4272 * Returns the device the user is currently using, or if the user has chosen to switch devices
4273 * for the current device type the type they have switched to.
4275 * @deprecated since 2.6
4276 * @return string The device the user is currently using or wishes to use
4278 function get_user_device_type() {
4279 debugging('get_user_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4280 return core_useragent::get_user_device_type();
4284 * Returns one or several CSS class names that match the user's browser. These can be put
4285 * in the body tag of the page to apply browser-specific rules without relying on CSS hacks
4287 * @deprecated since 2.6
4288 * @return array An array of browser version classes
4290 function get_browser_version_classes() {
4291 debugging('get_browser_version_classes has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
4292 return core_useragent::get_browser_version_classes();
4296 * Generate a fake user for emails based on support settings
4298 * @deprecated since Moodle 2.6
4299 * @see core_user::get_support_user()
4300 * @return stdClass user info
4302 function generate_email_supportuser() {
4303 debugging('generate_email_supportuser is deprecated, please use core_user::get_support_user');
4304 return core_user::get_support_user();
4308 * Get issued badge details for assertion URL
4310 * @deprecated since Moodle 2.6
4311 * @param string $hash Unique hash of a badge
4312 * @return array Information about issued badge.
4314 function badges_get_issued_badge_info($hash) {
4315 debugging('Function badges_get_issued_badge_info() is deprecated. Please use core_badges_assertion class and methods to generate badge assertion.', DEBUG_DEVELOPER);
4316 $assertion = new core_badges_assertion($hash);
4317 return $assertion->get_badge_assertion();
4321 * Does the user want and can edit using rich text html editor?
4322 * This function does not make sense anymore because a user can directly choose their preferred editor.
4324 * @deprecated since 2.6
4325 * @return bool
4327 function can_use_html_editor() {
4328 debugging('can_use_html_editor has been deprecated please update your code to assume it returns true.', DEBUG_DEVELOPER);
4329 return true;
4334 * Returns an object with counts of failed login attempts
4336 * Returns information about failed login attempts. If the current user is
4337 * an admin, then two numbers are returned: the number of attempts and the
4338 * number of accounts. For non-admins, only the attempts on the given user
4339 * are shown.
4341 * @deprecate since Moodle 2.7, use {@link user_count_login_failures()} instead.
4342 * @global moodle_database $DB
4343 * @uses CONTEXT_SYSTEM
4344 * @param string $mode Either 'admin' or 'everybody'
4345 * @param string $username The username we are searching for
4346 * @param string $lastlogin The date from which we are searching
4347 * @return int
4349 function count_login_failures($mode, $username, $lastlogin) {
4350 global $DB;
4352 debugging('This method has been deprecated. Please use user_count_login_failures() instead.', DEBUG_DEVELOPER);
4354 $params = array('mode'=>$mode, 'username'=>$username, 'lastlogin'=>$lastlogin);
4355 $select = "module='login' AND action='error' AND time > :lastlogin";
4357 $count = new stdClass();
4359 if (is_siteadmin()) {
4360 if ($count->attempts = $DB->count_records_select('log', $select, $params)) {
4361 $count->accounts = $DB->count_records_select('log', $select, $params, 'COUNT(DISTINCT info)');
4362 return $count;
4364 } else if ($mode == 'everybody') {
4365 if ($count->attempts = $DB->count_records_select('log', "$select AND info = :username", $params)) {
4366 return $count;
4369 return NULL;
4373 * Returns whether ajax is enabled/allowed or not.
4374 * This function is deprecated and always returns true.
4376 * @param array $unused - not used any more.
4377 * @return bool
4378 * @deprecated since 2.7 MDL-33099 - please do not use this function any more.
4379 * @todo MDL-44088 This will be removed in Moodle 2.9.
4381 function ajaxenabled(array $browsers = null) {
4382 debugging('ajaxenabled() is deprecated - please update your code to assume it returns true.', DEBUG_DEVELOPER);
4383 return true;
4387 * Determine whether a course module is visible within a course,
4388 * this is different from instance_is_visible() - faster and visibility for user
4390 * @global object
4391 * @global object
4392 * @uses DEBUG_DEVELOPER
4393 * @uses CONTEXT_MODULE
4394 * @param object $cm object
4395 * @param int $userid empty means current user
4396 * @return bool Success
4397 * @deprecated Since Moodle 2.7
4399 function coursemodule_visible_for_user($cm, $userid=0) {
4400 debugging('coursemodule_visible_for_user() deprecated since Moodle 2.7. ' .
4401 'Replace with \core_availability\info_module::is_user_visible().');
4402 return \core_availability\info_module::is_user_visible($cm, $userid, false);