3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * deprecatedlib.php - Old functions retained only for backward compatibility
21 * Old functions retained only for backward compatibility. New code should not
22 * use any of these functions.
25 * @subpackage deprecated
26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31 defined('MOODLE_INTERNAL') ||
die();
33 /* === Functions that needs to be kept longer in deprecated lib than normal time period === */
36 * Add an entry to the legacy log table.
38 * @deprecated since 2.7 use new events instead
40 * @param int $courseid The course id
41 * @param string $module The module name e.g. forum, journal, resource, course, user etc
42 * @param string $action 'view', 'update', 'add' or 'delete', possibly followed by another word to clarify.
43 * @param string $url The file and parameters used to see the results of the action
44 * @param string $info Additional description information
45 * @param int $cm The course_module->id if there is one
46 * @param int|stdClass $user If log regards $user other than $USER
49 function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user=0) {
50 debugging('add_to_log() has been deprecated, please rewrite your code to the new events API', DEBUG_DEVELOPER
);
52 // This is a nasty hack that allows us to put all the legacy stuff into legacy storage,
53 // this way we may move all the legacy settings there too.
54 $manager = get_log_manager();
55 if (method_exists($manager, 'legacy_add_to_log')) {
56 $manager->legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user);
61 * Function to call all event handlers when triggering an event
63 * @deprecated since 2.6
65 * @param string $eventname name of the event
66 * @param mixed $eventdata event data object
67 * @return int number of failed events
69 function events_trigger($eventname, $eventdata) {
70 debugging('events_trigger() is deprecated, please use new events instead', DEBUG_DEVELOPER
);
71 return events_trigger_legacy($eventname, $eventdata);
75 * List all core subsystems and their location
77 * This is a whitelist of components that are part of the core and their
78 * language strings are defined in /lang/en/<<subsystem>>.php. If a given
79 * plugin is not listed here and it does not have proper plugintype prefix,
80 * then it is considered as course activity module.
82 * The location is optionally dirroot relative path. NULL means there is no special
83 * directory for this subsystem. If the location is set, the subsystem's
84 * renderer.php is expected to be there.
86 * @deprecated since 2.6, use core_component::get_core_subsystems()
88 * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons
89 * @return array of (string)name => (string|null)location
91 function get_core_subsystems($fullpaths = false) {
94 // NOTE: do not add any other debugging here, keep forever.
96 $subsystems = core_component
::get_core_subsystems();
102 debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER
);
104 $dlength = strlen($CFG->dirroot
);
106 foreach ($subsystems as $k => $v) {
110 $subsystems[$k] = substr($v, $dlength+
1);
117 * Lists all plugin types.
119 * @deprecated since 2.6, use core_component::get_plugin_types()
121 * @param bool $fullpaths false means relative paths from dirroot
122 * @return array Array of strings - name=>location
124 function get_plugin_types($fullpaths = true) {
127 // NOTE: do not add any other debugging here, keep forever.
129 $types = core_component
::get_plugin_types();
135 debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER
);
137 $dlength = strlen($CFG->dirroot
);
139 foreach ($types as $k => $v) {
140 if ($k === 'theme') {
141 $types[$k] = 'theme';
144 $types[$k] = substr($v, $dlength+
1);
151 * Use when listing real plugins of one type.
153 * @deprecated since 2.6, use core_component::get_plugin_list()
155 * @param string $plugintype type of plugin
156 * @return array name=>fulllocation pairs of plugins of given type
158 function get_plugin_list($plugintype) {
160 // NOTE: do not add any other debugging here, keep forever.
162 if ($plugintype === '') {
166 return core_component
::get_plugin_list($plugintype);
170 * Get a list of all the plugins of a given type that define a certain class
171 * in a certain file. The plugin component names and class names are returned.
173 * @deprecated since 2.6, use core_component::get_plugin_list_with_class()
175 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
176 * @param string $class the part of the name of the class after the
177 * frankenstyle prefix. e.g 'thing' if you are looking for classes with
178 * names like report_courselist_thing. If you are looking for classes with
179 * the same name as the plugin name (e.g. qtype_multichoice) then pass ''.
180 * @param string $file the name of file within the plugin that defines the class.
181 * @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum')
182 * and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice').
184 function get_plugin_list_with_class($plugintype, $class, $file) {
186 // NOTE: do not add any other debugging here, keep forever.
188 return core_component
::get_plugin_list_with_class($plugintype, $class, $file);
192 * Returns the exact absolute path to plugin directory.
194 * @deprecated since 2.6, use core_component::get_plugin_directory()
196 * @param string $plugintype type of plugin
197 * @param string $name name of the plugin
198 * @return string full path to plugin directory; NULL if not found
200 function get_plugin_directory($plugintype, $name) {
202 // NOTE: do not add any other debugging here, keep forever.
204 if ($plugintype === '') {
208 return core_component
::get_plugin_directory($plugintype, $name);
212 * Normalize the component name using the "frankenstyle" names.
214 * @deprecated since 2.6, use core_component::normalize_component()
216 * @param string $component
217 * @return array as (string)$type => (string)$plugin
219 function normalize_component($component) {
221 // NOTE: do not add any other debugging here, keep forever.
223 return core_component
::normalize_component($component);
227 * Return exact absolute path to a plugin directory.
229 * @deprecated since 2.6, use core_component::normalize_component()
231 * @param string $component name such as 'moodle', 'mod_forum'
232 * @return string full path to component directory; NULL if not found
234 function get_component_directory($component) {
236 // NOTE: do not add any other debugging here, keep forever.
238 return core_component
::get_component_directory($component);
242 * Get the context instance as an object. This function will create the
243 * context instance if it does not exist yet.
245 * @deprecated since 2.2, use context_course::instance() or other relevant class instead
246 * @todo This will be deleted in Moodle 2.8, refer MDL-34472
247 * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
248 * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
249 * for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
250 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
251 * MUST_EXIST means throw exception if no record or multiple records found
252 * @return context The context object.
254 function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING
) {
256 debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER
);
258 $instances = (array)$instance;
261 $classname = context_helper
::get_class_for_level($contextlevel);
263 // we do not load multiple contexts any more, PAGE should be responsible for any preloading
264 foreach ($instances as $inst) {
265 $contexts[$inst] = $classname::instance($inst, $strictness);
268 if (is_array($instance)) {
271 return $contexts[$instance];
274 /* === End of long term deprecated api list === */
277 * Adds a file upload to the log table so that clam can resolve the filename to the user later if necessary
279 * @deprecated since 2.7 - use new file picker instead
282 function clam_log_upload($newfilepath, $course=null, $nourl=false) {
283 throw new coding_exception('clam_log_upload() can not be used any more, please use file picker instead');
287 * This function logs to error_log and to the log table that an infected file has been found and what's happened to it.
289 * @deprecated since 2.7 - use new file picker instead
292 function clam_log_infected($oldfilepath='', $newfilepath='', $userid=0) {
293 throw new coding_exception('clam_log_infected() can not be used any more, please use file picker instead');
297 * Some of the modules allow moving attachments (glossary), in which case we need to hunt down an original log and change the path.
299 * @deprecated since 2.7 - use new file picker instead
302 function clam_change_log($oldpath, $newpath, $update=true) {
303 throw new coding_exception('clam_change_log() can not be used any more, please use file picker instead');
307 * Replaces the given file with a string.
309 * @deprecated since 2.7 - infected files are now deleted in file picker
312 function clam_replace_infected_file($file) {
313 throw new coding_exception('clam_replace_infected_file() can not be used any more, please use file picker instead');
317 * Deals with an infected file - either moves it to a quarantinedir
318 * (specified in CFG->quarantinedir) or deletes it.
320 * If moving it fails, it deletes it.
322 * @deprecated since 2.7
324 function clam_handle_infected_file($file, $userid=0, $basiconly=false) {
325 throw new coding_exception('clam_handle_infected_file() can not be used any more, please use file picker instead');
329 * If $CFG->runclamonupload is set, we scan a given file. (called from {@link preprocess_files()})
331 * @deprecated since 2.7
333 function clam_scan_moodle_file(&$file, $course) {
334 throw new coding_exception('clam_scan_moodle_file() can not be used any more, please use file picker instead');
339 * Checks whether the password compatibility library will work with the current
340 * version of PHP. This cannot be done using PHP version numbers since the fix
341 * has been backported to earlier versions in some distributions.
343 * See https://github.com/ircmaxell/password_compat/issues/10 for more details.
345 * @deprecated since 2.7 PHP 5.4.x should be always compatible.
348 function password_compat_not_supported() {
349 throw new coding_exception('Do not use password_compat_not_supported() - bcrypt is now always available');
353 * Factory method that was returning moodle_session object.
355 * @deprecated since 2.6
357 function session_get_instance() {
358 throw new coding_exception('session_get_instance() is removed, use \core\session\manager instead');
362 * Returns true if legacy session used.
364 * @deprecated since 2.6
366 function session_is_legacy() {
367 throw new coding_exception('session_is_legacy() is removed, do not use any more');
371 * Terminates all sessions, auth hooks are not executed.
373 * @deprecated since 2.6
375 function session_kill_all() {
376 throw new coding_exception('session_kill_all() is removed, use \core\session\manager::kill_all_sessions() instead');
380 * Mark session as accessed, prevents timeouts.
382 * @deprecated since 2.6
384 function session_touch($sid) {
385 throw new coding_exception('session_touch() is removed, use \core\session\manager::touch_session() instead');
389 * Terminates one sessions, auth hooks are not executed.
391 * @deprecated since 2.6
393 function session_kill($sid) {
394 throw new coding_exception('session_kill() is removed, use \core\session\manager::kill_session() instead');
398 * Terminates all sessions of one user, auth hooks are not executed.
400 * @deprecated since 2.6
402 function session_kill_user($userid) {
403 throw new coding_exception('session_kill_user() is removed, use \core\session\manager::kill_user_sessions() instead');
407 * Setup $USER object - called during login, loginas, etc.
409 * Call sync_user_enrolments() manually after log-in, or log-in-as.
411 * @deprecated since 2.6
413 function session_set_user($user) {
414 throw new coding_exception('session_set_user() is removed, use \core\session\manager::set_user() instead');
418 * Is current $USER logged-in-as somebody else?
419 * @deprecated since 2.6
421 function session_is_loggedinas() {
422 throw new coding_exception('session_is_loggedinas() is removed, use \core\session\manager::is_loggedinas() instead');
426 * Returns the $USER object ignoring current login-as session
427 * @deprecated since 2.6
429 function session_get_realuser() {
430 throw new coding_exception('session_get_realuser() is removed, use \core\session\manager::get_realuser() instead');
434 * Login as another user - no security checks here.
435 * @deprecated since 2.6
437 function session_loginas($userid, $context) {
438 throw new coding_exception('session_loginas() is removed, use \core\session\manager::loginas() instead');
442 * Minify JavaScript files.
444 * @deprecated since 2.6
446 function js_minify($files) {
447 throw new coding_exception('js_minify() is removed, use core_minify::js_files() or core_minify::js() instead.');
453 * @deprecated since 2.6
455 function css_minify_css($files) {
456 throw new coding_exception('css_minify_css() is removed, use core_minify::css_files() or core_minify::css() instead.');
459 // === Deprecated before 2.6.0 ===
462 * Hack to find out the GD version by parsing phpinfo output
464 function check_gd_version() {
465 throw new coding_exception('check_gd_version() is removed, GD extension is always available now');
469 * Not used any more, the account lockout handling is now
470 * part of authenticate_user_login().
473 function update_login_count() {
474 throw new coding_exception('update_login_count() is removed, all calls need to be removed');
478 * Not used any more, replaced by proper account lockout.
481 function reset_login_count() {
482 throw new coding_exception('reset_login_count() is removed, all calls need to be removed');
488 function update_log_display_entry($module, $action, $mtable, $field) {
490 throw new coding_exception('The update_log_display_entry() is removed, please use db/log.php description file instead.');
494 * @deprecated use the text formatting in a standard way instead (http://docs.moodle.org/dev/Output_functions)
495 * this was abused mostly for embedding of attachments
497 function filter_text($text, $courseid = NULL) {
498 throw new coding_exception('filter_text() can not be used anymore, use format_text(), format_string() etc instead.');
502 * @deprecated use $PAGE->https_required() instead
504 function httpsrequired() {
505 throw new coding_exception('httpsrequired() can not be used any more use $PAGE->https_required() instead.');
509 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
511 * @deprecated use moodle_url factory methods instead
513 * @param string $path Physical path to a file
514 * @param array $options associative array of GET variables to append to the URL
515 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
516 * @return string URL to file
518 function get_file_url($path, $options=null, $type='coursefile') {
521 $path = str_replace('//', '/', $path);
522 $path = trim($path, '/'); // no leading and trailing slashes
527 $url = $CFG->wwwroot
."/question/exportfile.php";
530 $url = $CFG->wwwroot
."/rss/file.php";
532 case 'httpscoursefile':
533 $url = $CFG->httpswwwroot
."/file.php";
537 $url = $CFG->wwwroot
."/file.php";
540 if ($CFG->slasharguments
) {
541 $parts = explode('/', $path);
542 foreach ($parts as $key => $part) {
543 /// anchor dash character should not be encoded
544 $subparts = explode('#', $part);
545 $subparts = array_map('rawurlencode', $subparts);
546 $parts[$key] = implode('#', $subparts);
548 $path = implode('/', $parts);
549 $ffurl = $url.'/'.$path;
552 $path = rawurlencode('/'.$path);
553 $ffurl = $url.'?file='.$path;
554 $separator = '&';
558 foreach ($options as $name=>$value) {
559 $ffurl = $ffurl.$separator.$name.'='.$value;
560 $separator = '&';
568 * @deprecated use get_enrolled_users($context) instead.
570 function get_course_participants($courseid) {
571 throw new coding_exception('get_course_participants() can not be used any more, use get_enrolled_users() instead.');
575 * @deprecated use is_enrolled($context, $userid) instead.
577 function is_course_participant($userid, $courseid) {
578 throw new coding_exception('is_course_participant() can not be used any more, use is_enrolled() instead.');
584 function get_recent_enrolments($courseid, $timestart) {
585 throw new coding_exception('get_recent_enrolments() is removed as it returned inaccurate results.');
589 * @deprecated use clean_param($string, PARAM_FILE) instead.
591 function detect_munged_arguments($string, $allowdots=1) {
592 throw new coding_exception('detect_munged_arguments() can not be used any more, please use clean_param(,PARAM_FILE) instead.');
597 * Unzip one zip file to a destination dir
598 * Both parameters must be FULL paths
599 * If destination isn't specified, it will be the
600 * SAME directory where the zip file resides.
603 * @param string $zipfile The zip file to unzip
604 * @param string $destination The location to unzip to
605 * @param bool $showstatus_ignored Unused
607 function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
610 //Extract everything from zipfile
611 $path_parts = pathinfo(cleardoubleslashes($zipfile));
612 $zippath = $path_parts["dirname"]; //The path of the zip file
613 $zipfilename = $path_parts["basename"]; //The name of the zip file
614 $extension = $path_parts["extension"]; //The extension of the file
617 if (empty($zipfilename)) {
621 //If no extension, error
622 if (empty($extension)) {
627 $zipfile = cleardoubleslashes($zipfile);
629 //Check zipfile exists
630 if (!file_exists($zipfile)) {
634 //If no destination, passed let's go with the same directory
635 if (empty($destination)) {
636 $destination = $zippath;
640 $destpath = rtrim(cleardoubleslashes($destination), "/");
642 //Check destination path exists
643 if (!is_dir($destpath)) {
647 $packer = get_file_packer('application/zip');
649 $result = $packer->extract_to_pathname($zipfile, $destpath);
651 if ($result === false) {
655 foreach ($result as $status) {
656 if ($status !== true) {
665 * Zip an array of files/dirs to a destination zip file
666 * Both parameters must be FULL paths to the files/dirs
669 * @param array $originalfiles Files to zip
670 * @param string $destination The destination path
671 * @return bool Outcome
673 function zip_files ($originalfiles, $destination) {
676 //Extract everything from destination
677 $path_parts = pathinfo(cleardoubleslashes($destination));
678 $destpath = $path_parts["dirname"]; //The path of the zip file
679 $destfilename = $path_parts["basename"]; //The name of the zip file
680 $extension = $path_parts["extension"]; //The extension of the file
683 if (empty($destfilename)) {
687 //If no extension, add it
688 if (empty($extension)) {
690 $destfilename = $destfilename.'.'.$extension;
693 //Check destination path exists
694 if (!is_dir($destpath)) {
698 //Check destination path is writable. TODO!!
700 //Clean destination filename
701 $destfilename = clean_filename($destfilename);
703 //Now check and prepare every file
707 foreach ($originalfiles as $file) { //Iterate over each file
708 //Check for every file
709 $tempfile = cleardoubleslashes($file); // no doubleslashes!
710 //Calculate the base path for all files if it isn't set
711 if ($origpath === NULL) {
712 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
714 //See if the file is readable
715 if (!is_readable($tempfile)) { //Is readable
718 //See if the file/dir is in the same directory than the rest
719 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
722 //Add the file to the array
723 $files[] = $tempfile;
727 $start = strlen($origpath)+
1;
728 foreach($files as $file) {
729 $zipfiles[substr($file, $start)] = $file;
732 $packer = get_file_packer('application/zip');
734 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
738 * @deprecated use groups_get_all_groups() instead.
740 function mygroupid($courseid) {
741 throw new coding_exception('mygroupid() can not be used any more, please use groups_get_all_groups() instead.');
746 * Returns the current group mode for a given course or activity module
748 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
750 * @deprecated since Moodle 2.0 MDL-14617 - please do not use this function any more.
751 * @todo MDL-50273 This will be deleted in Moodle 3.2.
753 * @param object $course Course Object
754 * @param object $cm Course Manager Object
755 * @return mixed $course->groupmode
757 function groupmode($course, $cm=null) {
759 debugging('groupmode() is deprecated, please use groups_get_* instead', DEBUG_DEVELOPER
);
760 if (isset($cm->groupmode
) && empty($course->groupmodeforce
)) {
761 return $cm->groupmode
;
763 return $course->groupmode
;
767 * Sets the current group in the session variable
768 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
769 * Sets currentgroup[$courseid] in the session variable appropriately.
770 * Does not do any permission checking.
772 * @deprecated Since year 2006 - please do not use this function any more.
773 * @todo MDL-50273 This will be deleted in Moodle 3.2.
777 * @param int $courseid The course being examined - relates to id field in
779 * @param int $groupid The group being examined.
780 * @return int Current group id which was set by this function
782 function set_current_group($courseid, $groupid) {
785 debugging('set_current_group() is deprecated, please use $SESSION->currentgroup[$courseid] instead', DEBUG_DEVELOPER
);
786 return $SESSION->currentgroup
[$courseid] = $groupid;
790 * Gets the current group - either from the session variable or from the database.
792 * @deprecated Since year 2006 - please do not use this function any more.
793 * @todo MDL-50273 This will be deleted in Moodle 3.2.
796 * @param int $courseid The course being examined - relates to id field in
798 * @param bool $full If true, the return value is a full record object.
799 * If false, just the id of the record.
802 function get_current_group($courseid, $full = false) {
805 debugging('get_current_group() is deprecated, please use groups_get_* instead', DEBUG_DEVELOPER
);
806 if (isset($SESSION->currentgroup
[$courseid])) {
808 return groups_get_group($SESSION->currentgroup
[$courseid]);
810 return $SESSION->currentgroup
[$courseid];
814 $mygroupid = mygroupid($courseid);
815 if (is_array($mygroupid)) {
816 $mygroupid = array_shift($mygroupid);
817 set_current_group($courseid, $mygroupid);
819 return groups_get_group($mygroupid);
833 * @deprecated Since Moodle 2.8
835 function groups_filter_users_by_course_module_visible($cm, $users) {
836 throw new coding_exception('groups_filter_users_by_course_module_visible() is removed. ' .
837 'Replace with a call to \core_availability\info_module::filter_user_list(), ' .
838 'which does basically the same thing but includes other restrictions such ' .
839 'as profile restrictions.');
843 * @deprecated Since Moodle 2.8
845 function groups_course_module_visible($cm, $userid=null) {
846 throw new coding_exception('groups_course_module_visible() is removed, use $cm->uservisible to decide whether the current
847 user can ' . 'access an activity.', DEBUG_DEVELOPER
);
851 * @deprecated since 2.0
853 function error($message, $link='') {
854 throw new coding_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a removed, please call
855 print_error() instead of error()');
860 * @deprecated use $PAGE->theme->name instead.
862 function current_theme() {
863 throw new coding_exception('current_theme() can not be used any more, please use $PAGE->theme->name instead');
869 function formerr($error) {
870 throw new coding_exception('formerr() is removed. Please change your code to use $OUTPUT->error_text($string).');
874 * @deprecated use $OUTPUT->skip_link_target() in instead.
876 function skip_main_destination() {
877 throw new coding_exception('skip_main_destination() can not be used any more, please use $OUTPUT->skip_link_target() instead.');
881 * @deprecated use $OUTPUT->container() instead.
883 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
884 throw new coding_exception('print_container() can not be used any more. Please use $OUTPUT->container() instead.');
888 * @deprecated use $OUTPUT->container_start() instead.
890 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
891 throw new coding_exception('print_container_start() can not be used any more. Please use $OUTPUT->container_start() instead.');
895 * @deprecated use $OUTPUT->container_end() instead.
897 function print_container_end($return=false) {
898 throw new coding_exception('print_container_end() can not be used any more. Please use $OUTPUT->container_end() instead.');
902 * Print a bold message in an optional color.
904 * @deprecated use $OUTPUT->notification instead.
905 * @param string $message The message to print out
906 * @param string $style Optional style to display message text in
907 * @param string $align Alignment option
908 * @param bool $return whether to return an output string or echo now
909 * @return string|bool Depending on $result
911 function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
914 if ($classes == 'green') {
915 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER
);
916 $classes = 'notifysuccess'; // Backward compatible with old color system
919 $output = $OUTPUT->notification($message, $classes);
928 * @deprecated use $OUTPUT->continue_button() instead.
930 function print_continue($link, $return = false) {
931 throw new coding_exception('print_continue() can not be used any more. Please use $OUTPUT->continue_button() instead.');
935 * @deprecated use $PAGE methods instead.
937 function print_header($title='', $heading='', $navigation='', $focus='',
938 $meta='', $cache=true, $button=' ', $menu=null,
939 $usexml=false, $bodytags='', $return=false) {
941 throw new coding_exception('print_header() can not be used any more. Please use $PAGE methods instead.');
945 * @deprecated use $PAGE methods instead.
947 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
948 $cache=true, $button=' ', $menu='', $usexml=false, $bodytags='', $return=false) {
950 throw new coding_exception('print_header_simple() can not be used any more. Please use $PAGE methods instead.');
954 * @deprecated use $OUTPUT->block() instead.
956 function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
957 throw new coding_exception('print_side_block() can not be used any more, please use $OUTPUT->block() instead.');
961 * Prints a basic textarea field.
963 * @deprecated since Moodle 2.0
965 * When using this function, you should
968 * @param bool $unused No longer used.
969 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
970 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
971 * @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.
972 * @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.
973 * @param string $name Name to use for the textarea element.
974 * @param string $value Initial content to display in the textarea.
975 * @param int $obsolete deprecated
976 * @param bool $return If false, will output string. If true, will return string value.
977 * @param string $id CSS ID to add to the textarea element.
978 * @return string|void depending on the value of $return
980 function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
981 /// $width and height are legacy fields and no longer used as pixels like they used to be.
982 /// However, you can set them to zero to override the mincols and minrows values below.
984 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
985 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
997 if ($height && ($rows < $minrows)) {
1000 if ($width && ($cols < $mincols)) {
1004 editors_head_setup();
1005 $editor = editors_get_preferred_editor(FORMAT_HTML
);
1006 $editor->set_text($value);
1007 $editor->use_editor($id, array('legacy'=>true));
1009 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'" spellcheck="true">'."\n";
1010 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
1011 $str .= '</textarea>'."\n";
1020 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
1021 * provide this function with the language strings for sortasc and sortdesc.
1023 * @deprecated use $OUTPUT->arrow() instead.
1024 * @todo final deprecation of this function once MDL-45448 is resolved
1026 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
1029 * @param string $direction 'up' or 'down'
1030 * @param string $strsort The language string used for the alt attribute of this image
1031 * @param bool $return Whether to print directly or return the html string
1032 * @return string|void depending on $return
1035 function print_arrow($direction='up', $strsort=null, $return=false) {
1038 debugging('print_arrow() is deprecated. Please use $OUTPUT->arrow() instead.', DEBUG_DEVELOPER
);
1040 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
1046 switch ($direction) {
1061 // Prepare language string
1063 if (empty($strsort) && !empty($sortdir)) {
1064 $strsort = get_string('sort' . $sortdir, 'grades');
1067 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
1077 * @deprecated since Moodle 2.0
1079 function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
1080 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
1081 $id='', $listbox=false, $multiple=false, $class='') {
1082 throw new coding_exception('choose_from_menu() is removed. Please change your code to use html_writer::select().');
1087 * @deprecated use $OUTPUT->help_icon_scale($courseid, $scale) instead.
1089 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
1090 throw new coding_exception('print_scale_menu_helpbutton() can not be used any more. '.
1091 'Please use $OUTPUT->help_icon_scale($courseid, $scale) instead.');
1095 * @deprecated use html_writer::checkbox() instead.
1097 function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
1098 throw new coding_exception('print_checkbox() can not be used any more. Please use html_writer::checkbox() instead.');
1102 * Prints the 'update this xxx' button that appears on module pages.
1104 * @deprecated since Moodle 2.0
1106 * @param string $cmid the course_module id.
1107 * @param string $ignored not used any more. (Used to be courseid.)
1108 * @param string $string the module name - get_string('modulename', 'xxx')
1109 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
1111 function update_module_button($cmid, $ignored, $string) {
1112 global $CFG, $OUTPUT;
1114 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
1116 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
1118 if (has_capability('moodle/course:manageactivities', context_module
::instance($cmid))) {
1119 $string = get_string('updatethis', '', $string);
1121 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
1122 return $OUTPUT->single_button($url, $string);
1129 * @deprecated use $OUTPUT->navbar() instead
1131 function print_navigation ($navigation, $separator=0, $return=false) {
1132 throw new coding_exception('print_navigation() can not be used any more, please update use $OUTPUT->navbar() instead.');
1136 * @deprecated Please use $PAGE->navabar methods instead.
1138 function build_navigation($extranavlinks, $cm = null) {
1139 throw new coding_exception('build_navigation() can not be used any more, please use $PAGE->navbar methods instead.');
1143 * @deprecated not relevant with global navigation in Moodle 2.x+
1145 function navmenu($course, $cm=NULL, $targetwindow='self') {
1146 throw new coding_exception('navmenu() can not be used any more, it is no longer relevant with global navigation.');
1149 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
1153 * @deprecated please use calendar_event::create() instead.
1155 function add_event($event) {
1156 throw new coding_exception('add_event() can not be used any more, please use calendar_event::create() instead.');
1160 * @deprecated please calendar_event->update() instead.
1162 function update_event($event) {
1163 throw new coding_exception('update_event() is removed, please use calendar_event->update() instead.');
1167 * @deprecated please use calendar_event->delete() instead.
1169 function delete_event($id) {
1170 throw new coding_exception('delete_event() can not be used any more, please use '.
1171 'calendar_event->delete() instead.');
1175 * @deprecated please use calendar_event->toggle_visibility(false) instead.
1177 function hide_event($event) {
1178 throw new coding_exception('hide_event() can not be used any more, please use '.
1179 'calendar_event->toggle_visibility(false) instead.');
1183 * @deprecated please use calendar_event->toggle_visibility(true) instead.
1185 function show_event($event) {
1186 throw new coding_exception('show_event() can not be used any more, please use '.
1187 'calendar_event->toggle_visibility(true) instead.');
1191 * @deprecated since Moodle 2.2 use core_text::xxxx() instead.
1194 function textlib_get_instance() {
1195 throw new coding_exception('textlib_get_instance() can not be used any more, please use '.
1196 'core_text::functioname() instead.');
1200 * @deprecated since 2.4
1201 * @see get_section_name()
1202 * @see format_base::get_section_name()
1205 function get_generic_section_name($format, stdClass
$section) {
1206 throw new coding_exception('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base');
1210 * Returns an array of sections for the requested course id
1212 * It is usually not recommended to display the list of sections used
1213 * in course because the course format may have it's own way to do it.
1215 * If you need to just display the name of the section please call:
1216 * get_section_name($course, $section)
1217 * {@link get_section_name()}
1218 * from 2.4 $section may also be just the field course_sections.section
1220 * If you need the list of all sections it is more efficient to get this data by calling
1221 * $modinfo = get_fast_modinfo($courseorid);
1222 * $sections = $modinfo->get_section_info_all()
1223 * {@link get_fast_modinfo()}
1224 * {@link course_modinfo::get_section_info_all()}
1226 * Information about one section (instance of section_info):
1227 * get_fast_modinfo($courseorid)->get_sections_info($section)
1228 * {@link course_modinfo::get_section_info()}
1230 * @deprecated since 2.4
1232 function get_all_sections($courseid) {
1234 throw new coding_exception('get_all_sections() is removed. See phpdocs for this function');
1238 * This function is deprecated, please use {@link course_add_cm_to_section()}
1239 * Note that course_add_cm_to_section() also updates field course_modules.section and
1240 * calls rebuild_course_cache()
1242 * @deprecated since 2.4
1244 function add_mod_to_section($mod, $beforemod = null) {
1245 throw new coding_exception('Function add_mod_to_section() is removed, please use course_add_cm_to_section()');
1249 * Returns a number of useful structures for course displays
1251 * Function get_all_mods() is deprecated in 2.4
1254 * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
1258 * $mods = get_fast_modinfo($courseorid)->get_cms();
1259 * $modnames = get_module_types_names();
1260 * $modnamesplural = get_module_types_names(true);
1261 * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names();
1264 * @deprecated since 2.4
1266 function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
1267 throw new coding_exception('Function get_all_mods() is removed. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details');
1271 * Returns course section - creates new if does not exist yet
1273 * This function is deprecated. To create a course section call:
1274 * course_create_sections_if_missing($courseorid, $sections);
1275 * to get the section call:
1276 * get_fast_modinfo($courseorid)->get_section_info($sectionnum);
1278 * @see course_create_sections_if_missing()
1279 * @see get_fast_modinfo()
1280 * @deprecated since 2.4
1282 function get_course_section($section, $courseid) {
1283 throw new coding_exception('Function get_course_section() is removed. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.');
1287 * @deprecated since 2.4
1288 * @see format_weeks::get_section_dates()
1290 function format_weeks_get_section_dates($section, $course) {
1291 throw new coding_exception('Function format_weeks_get_section_dates() is removed. It is not recommended to'.
1292 ' use it outside of format_weeks plugin');
1296 * Deprecated. Instead of:
1297 * list($content, $name) = get_print_section_cm_text($cm, $course);
1299 * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
1300 * $name = $cm->get_formatted_name();
1302 * @deprecated since 2.5
1303 * @see cm_info::get_formatted_content()
1304 * @see cm_info::get_formatted_name()
1306 function get_print_section_cm_text(cm_info
$cm, $course) {
1307 throw new coding_exception('Function get_print_section_cm_text() is removed. Please use '.
1308 'cm_info::get_formatted_content() and cm_info::get_formatted_name()');
1312 * Deprecated. Please use:
1313 * $courserenderer = $PAGE->get_renderer('core', 'course');
1314 * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
1315 * array('inblock' => $vertical));
1318 * @deprecated since 2.5
1319 * @see core_course_renderer::course_section_add_cm_control()
1321 function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
1322 throw new coding_exception('Function print_section_add_menus() is removed. Please use course renderer '.
1323 'function course_section_add_cm_control()');
1327 * Deprecated. Please use:
1328 * $courserenderer = $PAGE->get_renderer('core', 'course');
1329 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
1330 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
1332 * @deprecated since 2.5
1333 * @see course_get_cm_edit_actions()
1334 * @see core_course_renderer->course_section_cm_edit_actions()
1336 function make_editing_buttons(stdClass
$mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
1337 throw new coding_exception('Function make_editing_buttons() is removed, please see PHPdocs in '.
1338 'lib/deprecatedlib.php on how to replace it');
1342 * Deprecated. Please use:
1343 * $courserenderer = $PAGE->get_renderer('core', 'course');
1344 * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn,
1345 * array('hidecompletion' => $hidecompletion));
1347 * @deprecated since 2.5
1348 * @see core_course_renderer::course_section_cm_list()
1350 function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
1351 throw new coding_exception('Function print_section() is removed. Please use course renderer function '.
1352 'course_section_cm_list() instead.');
1356 * @deprecated since 2.5
1358 function print_overview($courses, array $remote_courses=array()) {
1359 throw new coding_exception('Function print_overview() is removed. Use block course_overview to display this information');
1363 * @deprecated since 2.5
1365 function print_recent_activity($course) {
1366 throw new coding_exception('Function print_recent_activity() is removed. It is not recommended to'.
1367 ' use it outside of block_recent_activity');
1371 * @deprecated since 2.5
1373 function delete_course_module($id) {
1374 throw new coding_exception('Function delete_course_module() is removed. Please use course_delete_module() instead.');
1378 * @deprecated since 2.5
1380 function update_category_button($categoryid = 0) {
1381 throw new coding_exception('Function update_category_button() is removed. Pages to view '.
1382 'and edit courses are now separate and no longer depend on editing mode.');
1386 * This function is deprecated! For list of categories use
1387 * coursecat::make_all_categories($requiredcapability, $excludeid, $separator)
1388 * For parents of one particular category use
1389 * coursecat::get($id)->get_parents()
1391 * @deprecated since 2.5
1393 function make_categories_list(&$list, &$parents, $requiredcapability = '',
1394 $excludeid = 0, $category = NULL, $path = "") {
1395 throw new coding_exception('Global function make_categories_list() is removed. Please use '.
1396 'coursecat::make_categories_list() and coursecat::get_parents()');
1400 * @deprecated since 2.5
1402 function category_delete_move($category, $newparentid, $showfeedback=true) {
1403 throw new coding_exception('Function category_delete_move() is removed. Please use coursecat::delete_move() instead.');
1407 * @deprecated since 2.5
1409 function category_delete_full($category, $showfeedback=true) {
1410 throw new coding_exception('Function category_delete_full() is removed. Please use coursecat::delete_full() instead.');
1414 * This function is deprecated. Please use
1415 * $coursecat = coursecat::get($category->id);
1416 * if ($coursecat->can_change_parent($newparentcat->id)) {
1417 * $coursecat->change_parent($newparentcat->id);
1420 * Alternatively you can use
1421 * $coursecat->update(array('parent' => $newparentcat->id));
1423 * @see coursecat::change_parent()
1424 * @see coursecat::update()
1425 * @deprecated since 2.5
1427 function move_category($category, $newparentcat) {
1428 throw new coding_exception('Function move_category() is removed. Please use coursecat::change_parent() instead.');
1432 * This function is deprecated. Please use
1433 * coursecat::get($category->id)->hide();
1435 * @see coursecat::hide()
1436 * @deprecated since 2.5
1438 function course_category_hide($category) {
1439 throw new coding_exception('Function course_category_hide() is removed. Please use coursecat::hide() instead.');
1443 * This function is deprecated. Please use
1444 * coursecat::get($category->id)->show();
1446 * @see coursecat::show()
1447 * @deprecated since 2.5
1449 function course_category_show($category) {
1450 throw new coding_exception('Function course_category_show() is removed. Please use coursecat::show() instead.');
1454 * This function is deprecated.
1455 * To get the category with the specified it please use:
1456 * coursecat::get($catid, IGNORE_MISSING);
1458 * coursecat::get($catid, MUST_EXIST);
1460 * To get the first available category please use
1461 * coursecat::get_default();
1463 * @deprecated since 2.5
1465 function get_course_category($catid=0) {
1466 throw new coding_exception('Function get_course_category() is removed. Please use coursecat::get(), see phpdocs for more details');
1470 * This function is deprecated. It is replaced with the method create() in class coursecat.
1471 * {@link coursecat::create()} also verifies the data, fixes sortorder and logs the action
1473 * @deprecated since 2.5
1475 function create_course_category($category) {
1476 throw new coding_exception('Function create_course_category() is removed. Please use coursecat::create(), see phpdocs for more details');
1480 * This function is deprecated.
1482 * To get visible children categories of the given category use:
1483 * coursecat::get($categoryid)->get_children();
1484 * This function will return the array or coursecat objects, on each of them
1485 * you can call get_children() again
1487 * @see coursecat::get()
1488 * @see coursecat::get_children()
1490 * @deprecated since 2.5
1492 function get_all_subcategories($catid) {
1493 throw new coding_exception('Function get_all_subcategories() is removed. Please use appropriate methods() of coursecat
1494 class. See phpdocs for more details');
1498 * This function is deprecated. Please use functions in class coursecat:
1499 * - coursecat::get($parentid)->has_children()
1500 * tells if the category has children (visible or not to the current user)
1502 * - coursecat::get($parentid)->get_children()
1503 * returns an array of coursecat objects, each of them represents a children category visible
1504 * to the current user (i.e. visible=1 or user has capability to view hidden categories)
1506 * - coursecat::get($parentid)->get_children_count()
1507 * returns number of children categories visible to the current user
1509 * - coursecat::count_all()
1510 * returns total count of all categories in the system (both visible and not)
1512 * - coursecat::get_default()
1513 * returns the first category (usually to be used if count_all() == 1)
1515 * @deprecated since 2.5
1517 function get_child_categories($parentid) {
1518 throw new coding_exception('Function get_child_categories() is removed. Use coursecat::get_children() or see phpdocs for
1524 * @deprecated since 2.5
1526 * This function is deprecated. Use appropriate functions from class coursecat.
1529 * coursecat::get($categoryid)->get_children()
1530 * - returns all children of the specified category as instances of class
1531 * coursecat, which means on each of them method get_children() can be called again.
1532 * Only categories visible to the current user are returned.
1534 * coursecat::get(0)->get_children()
1535 * - returns all top-level categories visible to the current user.
1537 * Sort fields can be specified, see phpdocs to {@link coursecat::get_children()}
1539 * coursecat::make_categories_list()
1540 * - returns an array of all categories id/names in the system.
1541 * Also only returns categories visible to current user and can additionally be
1542 * filetered by capability, see phpdocs to {@link coursecat::make_categories_list()}
1544 * make_categories_options()
1545 * - Returns full course categories tree to be used in html_writer::select()
1547 * Also see functions {@link coursecat::get_children_count()}, {@link coursecat::count_all()},
1548 * {@link coursecat::get_default()}
1550 function get_categories($parent='none', $sort=NULL, $shallow=true) {
1551 throw new coding_exception('Function get_categories() is removed. Please use coursecat::get_children() or see phpdocs for other alternatives');
1555 * This function is deprecated, please use course renderer:
1556 * $renderer = $PAGE->get_renderer('core', 'course');
1557 * echo $renderer->course_search_form($value, $format);
1559 * @deprecated since 2.5
1561 function print_course_search($value="", $return=false, $format="plain") {
1562 throw new coding_exception('Function print_course_search() is removed, please use course renderer');
1566 * This function is deprecated, please use:
1567 * $renderer = $PAGE->get_renderer('core', 'course');
1568 * echo $renderer->frontpage_my_courses()
1570 * @deprecated since 2.5
1572 function print_my_moodle() {
1573 throw new coding_exception('Function print_my_moodle() is removed, please use course renderer function frontpage_my_courses()');
1577 * This function is deprecated, it is replaced with protected function
1578 * {@link core_course_renderer::frontpage_remote_course()}
1579 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
1581 * @deprecated since 2.5
1583 function print_remote_course($course, $width="100%") {
1584 throw new coding_exception('Function print_remote_course() is removed, please use course renderer');
1588 * This function is deprecated, it is replaced with protected function
1589 * {@link core_course_renderer::frontpage_remote_host()}
1590 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
1592 * @deprecated since 2.5
1594 function print_remote_host($host, $width="100%") {
1595 throw new coding_exception('Function print_remote_host() is removed, please use course renderer');
1599 * @deprecated since 2.5
1601 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
1603 function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) {
1604 throw new coding_exception('Function print_whole_category_list() is removed, please use course renderer');
1608 * @deprecated since 2.5
1610 function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) {
1611 throw new coding_exception('Function print_category_info() is removed, please use course renderer');
1615 * @deprecated since 2.5
1617 * This function is not used any more in moodle core and course renderer does not have render function for it.
1618 * Combo list on the front page is displayed as:
1619 * $renderer = $PAGE->get_renderer('core', 'course');
1620 * echo $renderer->frontpage_combo_list()
1622 * The new class {@link coursecat} stores the information about course category tree
1623 * To get children categories use:
1624 * coursecat::get($id)->get_children()
1625 * To get list of courses use:
1626 * coursecat::get($id)->get_courses()
1628 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
1630 function get_course_category_tree($id = 0, $depth = 0) {
1631 throw new coding_exception('Function get_course_category_tree() is removed, please use course renderer or coursecat class,
1632 see function phpdocs for more info');
1636 * @deprecated since 2.5
1638 * To print a generic list of courses use:
1639 * $renderer = $PAGE->get_renderer('core', 'course');
1640 * echo $renderer->courses_list($courses);
1642 * To print list of all courses:
1643 * $renderer = $PAGE->get_renderer('core', 'course');
1644 * echo $renderer->frontpage_available_courses();
1646 * To print list of courses inside category:
1647 * $renderer = $PAGE->get_renderer('core', 'course');
1648 * echo $renderer->course_category($category); // this will also print subcategories
1650 function print_courses($category) {
1651 throw new coding_exception('Function print_courses() is removed, please use course renderer');
1655 * @deprecated since 2.5
1657 * Please use course renderer to display a course information box.
1658 * $renderer = $PAGE->get_renderer('core', 'course');
1659 * echo $renderer->courses_list($courses); // will print list of courses
1660 * echo $renderer->course_info_box($course); // will print one course wrapped in div.generalbox
1662 function print_course($course, $highlightterms = '') {
1663 throw new coding_exception('Function print_course() is removed, please use course renderer');
1667 * @deprecated since 2.5
1669 * This function is not used any more in moodle core and course renderer does not have render function for it.
1670 * Combo list on the front page is displayed as:
1671 * $renderer = $PAGE->get_renderer('core', 'course');
1672 * echo $renderer->frontpage_combo_list()
1674 * The new class {@link coursecat} stores the information about course category tree
1675 * To get children categories use:
1676 * coursecat::get($id)->get_children()
1677 * To get list of courses use:
1678 * coursecat::get($id)->get_courses()
1680 function get_category_courses_array($categoryid = 0) {
1681 throw new coding_exception('Function get_category_courses_array() is removed, please use methods of coursecat class');
1685 * @deprecated since 2.5
1687 function get_category_courses_array_recursively(array &$flattened, $category) {
1688 throw new coding_exception('Function get_category_courses_array_recursively() is removed, please use methods of coursecat class', DEBUG_DEVELOPER
);
1692 * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more.
1694 function blog_get_context_url($context=null) {
1695 throw new coding_exception('Function blog_get_context_url() is removed, getting params from context is not reliable for blogs.');
1699 * @deprecated since 2.5
1701 * To get list of all courses with course contacts ('managers') use
1702 * coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true));
1704 * To get list of courses inside particular category use
1705 * coursecat::get($id)->get_courses(array('coursecontacts' => true));
1707 * Additionally you can specify sort order, offset and maximum number of courses,
1708 * see {@link coursecat::get_courses()}
1710 function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) {
1711 throw new coding_exception('Function get_courses_wmanagers() is removed, please use coursecat::get_courses()');
1715 * @deprecated since 2.5
1717 function convert_tree_to_html($tree, $row=0) {
1718 throw new coding_exception('Function convert_tree_to_html() is removed. Consider using class tabtree and core_renderer::render_tabtree()');
1722 * @deprecated since 2.5
1724 function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) {
1725 throw new coding_exception('Function convert_tabrows_to_tree() is removed. Consider using class tabtree');
1729 * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically
1731 function can_use_rotated_text() {
1732 debugging('can_use_rotated_text() is removed. JS feature detection is used automatically.');
1736 * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more.
1737 * @see context::instance_by_id($id)
1739 function get_context_instance_by_id($id, $strictness = IGNORE_MISSING
) {
1740 throw new coding_exception('get_context_instance_by_id() is now removed, please use context::instance_by_id($id) instead.');
1744 * Returns system context or null if can not be created yet.
1746 * @see context_system::instance()
1747 * @deprecated since 2.2
1748 * @param bool $cache use caching
1749 * @return context system context (null if context table not created yet)
1751 function get_system_context($cache = true) {
1752 debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER
);
1753 return context_system
::instance(0, IGNORE_MISSING
, $cache);
1757 * @see context::get_parent_context_ids()
1758 * @deprecated since 2.2, use $context->get_parent_context_ids() instead
1760 function get_parent_contexts(context
$context, $includeself = false) {
1761 throw new coding_exception('get_parent_contexts() is removed, please use $context->get_parent_context_ids() instead.');
1765 * @deprecated since Moodle 2.2
1766 * @see context::get_parent_context()
1768 function get_parent_contextid(context
$context) {
1769 throw new coding_exception('get_parent_contextid() is removed, please use $context->get_parent_context() instead.');
1773 * @see context::get_child_contexts()
1774 * @deprecated since 2.2
1776 function get_child_contexts(context
$context) {
1777 throw new coding_exception('get_child_contexts() is removed, please use $context->get_child_contexts() instead.');
1781 * @see context_helper::create_instances()
1782 * @deprecated since 2.2
1784 function create_contexts($contextlevel = null, $buildpaths = true) {
1785 throw new coding_exception('create_contexts() is removed, please use context_helper::create_instances() instead.');
1789 * @see context_helper::cleanup_instances()
1790 * @deprecated since 2.2
1792 function cleanup_contexts() {
1793 throw new coding_exception('cleanup_contexts() is removed, please use context_helper::cleanup_instances() instead.');
1797 * Populate context.path and context.depth where missing.
1799 * @deprecated since 2.2
1801 function build_context_path($force = false) {
1802 throw new coding_exception('build_context_path() is removed, please use context_helper::build_all_paths() instead.');
1806 * @deprecated since 2.2
1808 function rebuild_contexts(array $fixcontexts) {
1809 throw new coding_exception('rebuild_contexts() is removed, please use $context->reset_paths(true) instead.');
1813 * @deprecated since Moodle 2.2
1814 * @see context_helper::preload_course()
1816 function preload_course_contexts($courseid) {
1817 throw new coding_exception('preload_course_contexts() is removed, please use context_helper::preload_course() instead.');
1821 * @deprecated since Moodle 2.2
1822 * @see context::update_moved()
1824 function context_moved(context
$context, context
$newparent) {
1825 throw new coding_exception('context_moved() is removed, please use context::update_moved() instead.');
1829 * @see context::get_capabilities()
1830 * @deprecated since 2.2
1832 function fetch_context_capabilities(context
$context) {
1833 throw new coding_exception('fetch_context_capabilities() is removed, please use $context->get_capabilities() instead.');
1837 * @deprecated since 2.2
1838 * @see context_helper::preload_from_record()
1840 function context_instance_preload(stdClass
$rec) {
1841 throw new coding_exception('context_instance_preload() is removed, please use context_helper::preload_from_record() instead.');
1845 * Returns context level name
1847 * @deprecated since 2.2
1848 * @see context_helper::get_level_name()
1850 function get_contextlevel_name($contextlevel) {
1851 throw new coding_exception('get_contextlevel_name() is removed, please use context_helper::get_level_name() instead.');
1855 * @deprecated since 2.2
1856 * @see context::get_context_name()
1858 function print_context_name(context
$context, $withprefix = true, $short = false) {
1859 throw new coding_exception('print_context_name() is removed, please use $context->get_context_name() instead.');
1863 * @deprecated since 2.2, use $context->mark_dirty() instead
1864 * @see context::mark_dirty()
1866 function mark_context_dirty($path) {
1867 throw new coding_exception('mark_context_dirty() is removed, please use $context->mark_dirty() instead.');
1871 * @deprecated since Moodle 2.2
1872 * @see context_helper::delete_instance() or context::delete_content()
1874 function delete_context($contextlevel, $instanceid, $deleterecord = true) {
1875 if ($deleterecord) {
1876 throw new coding_exception('delete_context() is removed, please use context_helper::delete_instance() instead.');
1878 throw new coding_exception('delete_context() is removed, please use $context->delete_content() instead.');
1883 * @deprecated since 2.2
1884 * @see context::get_url()
1886 function get_context_url(context
$context) {
1887 throw new coding_exception('get_context_url() is removed, please use $context->get_url() instead.');
1891 * @deprecated since 2.2
1892 * @see context::get_course_context()
1894 function get_course_context(context
$context) {
1895 throw new coding_exception('get_course_context() is removed, please use $context->get_course_context(true) instead.');
1899 * @deprecated since 2.2
1900 * @see enrol_get_users_courses()
1902 function get_user_courses_bycap($userid, $cap, $accessdata_ignored, $doanything_ignored, $sort = 'c.sortorder ASC', $fields = null, $limit_ignored = 0) {
1904 throw new coding_exception('get_user_courses_bycap() is removed, please use enrol_get_users_courses() instead.');
1908 * @deprecated since Moodle 2.2
1910 function get_role_context_caps($roleid, context
$context) {
1911 throw new coding_exception('get_role_context_caps() is removed, it is really slow. Don\'t use it.');
1915 * @see context::get_course_context()
1916 * @deprecated since 2.2
1918 function get_courseid_from_context(context
$context) {
1919 throw new coding_exception('get_courseid_from_context() is removed, please use $context->get_course_context(false) instead.');
1923 * If you are using this methid, you should have something like this:
1925 * list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
1927 * To prevent the use of this deprecated function, replace the line above with something similar to this:
1929 * $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
1931 * $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
1933 * $params = array('contextlevel' => CONTEXT_COURSE);
1935 * @see context_helper:;get_preload_record_columns_sql()
1936 * @deprecated since 2.2
1938 function context_instance_preload_sql($joinon, $contextlevel, $tablealias) {
1939 throw new coding_exception('context_instance_preload_sql() is removed, please use context_helper::get_preload_record_columns_sql() instead.');
1943 * @deprecated since 2.2
1944 * @see context::get_parent_context_ids()
1946 function get_related_contexts_string(context
$context) {
1947 throw new coding_exception('get_related_contexts_string() is removed, please use $context->get_parent_context_ids(true) instead.');
1951 * @deprecated since 2.6
1952 * @see core_component::get_plugin_list_with_file()
1954 function get_plugin_list_with_file($plugintype, $file, $include = false) {
1955 throw new coding_exception('get_plugin_list_with_file() is removed, please use core_component::get_plugin_list_with_file() instead.');
1959 * @deprecated since 2.6
1961 function check_browser_operating_system($brand) {
1962 throw new coding_exception('check_browser_operating_system is removed, please update your code to use core_useragent instead.');
1966 * @deprecated since 2.6
1968 function check_browser_version($brand, $version = null) {
1969 throw new coding_exception('check_browser_version is removed, please update your code to use core_useragent instead.');
1973 * @deprecated since 2.6
1975 function get_device_type() {
1976 throw new coding_exception('get_device_type is removed, please update your code to use core_useragent instead.');
1980 * @deprecated since 2.6
1982 function get_device_type_list($incusertypes = true) {
1983 throw new coding_exception('get_device_type_list is removed, please update your code to use core_useragent instead.');
1987 * @deprecated since 2.6
1989 function get_selected_theme_for_device_type($devicetype = null) {
1990 throw new coding_exception('get_selected_theme_for_device_type is removed, please update your code to use core_useragent instead.');
1994 * @deprecated since 2.6
1996 function get_device_cfg_var_name($devicetype = null) {
1997 throw new coding_exception('get_device_cfg_var_name is removed, please update your code to use core_useragent instead.');
2001 * @deprecated since 2.6
2003 function set_user_device_type($newdevice) {
2004 throw new coding_exception('set_user_device_type is removed, please update your code to use core_useragent instead.');
2008 * @deprecated since 2.6
2010 function get_user_device_type() {
2011 throw new coding_exception('get_user_device_type is removed, please update your code to use core_useragent instead.');
2015 * @deprecated since 2.6
2017 function get_browser_version_classes() {
2018 throw new coding_exception('get_browser_version_classes is removed, please update your code to use core_useragent instead.');
2022 * @deprecated since Moodle 2.6
2023 * @see core_user::get_support_user()
2025 function generate_email_supportuser() {
2026 throw new coding_exception('generate_email_supportuser is removed, please use core_user::get_support_user');
2030 * @deprecated since Moodle 2.6
2032 function badges_get_issued_badge_info($hash) {
2033 throw new coding_exception('Function badges_get_issued_badge_info() is removed. Please use core_badges_assertion class and methods to generate badge assertion.');
2037 * @deprecated since 2.6
2039 function can_use_html_editor() {
2040 throw new coding_exception('can_use_html_editor is removed, please update your code to assume it returns true.');
2045 * @deprecated since Moodle 2.7, use {@link user_count_login_failures()} instead.
2047 function count_login_failures($mode, $username, $lastlogin) {
2048 throw new coding_exception('count_login_failures() can not be used any more, please use user_count_login_failures().');
2052 * @deprecated since 2.7 MDL-33099/MDL-44088 - please do not use this function any more.
2054 function ajaxenabled(array $browsers = null) {
2055 throw new coding_exception('ajaxenabled() can not be used anymore. Update your code to work with JS at all times.');
2059 * @deprecated Since Moodle 2.7 MDL-44070
2061 function coursemodule_visible_for_user($cm, $userid=0) {
2062 throw new coding_exception('coursemodule_visible_for_user() can not be used any more,
2063 please use \core_availability\info_module::is_user_visible()');
2067 * @deprecated since Moodle 2.8 MDL-36014, MDL-35618 this functionality is removed
2069 function enrol_cohort_get_cohorts(course_enrolment_manager
$manager) {
2070 throw new coding_exception('Function enrol_cohort_get_cohorts() is removed, use enrol_cohort_search_cohorts() or '.
2071 'cohort_get_available_cohorts() instead');
2075 * This function is deprecated, use {@link cohort_can_view_cohort()} instead since it also
2076 * takes into account current context
2078 * @deprecated since Moodle 2.8 MDL-36014 please use cohort_can_view_cohort()
2080 function enrol_cohort_can_view_cohort($cohortid) {
2081 throw new coding_exception('Function enrol_cohort_can_view_cohort() is removed, use cohort_can_view_cohort() instead');
2085 * It is advisable to use {@link cohort_get_available_cohorts()} instead.
2087 * @deprecated since Moodle 2.8 MDL-36014 use cohort_get_available_cohorts() instead
2089 function cohort_get_visible_list($course, $onlyenrolled=true) {
2090 throw new coding_exception('Function cohort_get_visible_list() is removed. Please use function cohort_get_available_cohorts() ".
2091 "that correctly checks capabilities.');
2095 * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
2097 function enrol_cohort_enrol_all_users(course_enrolment_manager
$manager, $cohortid, $roleid) {
2098 throw new coding_exception('enrol_cohort_enrol_all_users() is removed. This functionality is moved to enrol_manual.');
2102 * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
2104 function enrol_cohort_search_cohorts(course_enrolment_manager
$manager, $offset = 0, $limit = 25, $search = '') {
2105 throw new coding_exception('enrol_cohort_search_cohorts() is removed. This functionality is moved to enrol_manual.');
2108 /* === Apis deprecated in since Moodle 2.9 === */
2111 * Is $USER one of the supplied users?
2113 * $user2 will be null if viewing a user's recent conversations
2115 * @deprecated since Moodle 2.9 MDL-49371 - please do not use this function any more.
2116 * @todo MDL-49290 This will be deleted in Moodle 3.1.
2117 * @param stdClass the first user
2118 * @param stdClass the second user or null
2119 * @return bool True if the current user is one of either $user1 or $user2
2121 function message_current_user_is_involved($user1, $user2) {
2124 debugging('message_current_user_is_involved() is deprecated, please do not use this function.', DEBUG_DEVELOPER
);
2126 if (empty($user1->id
) ||
(!empty($user2) && empty($user2->id
))) {
2127 throw new coding_exception('Invalid user object detected. Missing id.');
2130 if ($user1->id
!= $USER->id
&& (empty($user2) ||
$user2->id
!= $USER->id
)) {
2137 * Print badges on user profile page.
2139 * @deprecated since Moodle 2.9 MDL-45898 - please do not use this function any more.
2140 * @param int $userid User ID.
2141 * @param int $courseid Course if we need to filter badges (optional).
2143 function profile_display_badges($userid, $courseid = 0) {
2144 global $CFG, $PAGE, $USER, $SITE;
2145 require_once($CFG->dirroot
. '/badges/renderer.php');
2147 debugging('profile_display_badges() is deprecated.', DEBUG_DEVELOPER
);
2148 $context = context_user
::instance($userid);
2150 if ($USER->id
== $userid ||
has_capability('moodle/badges:viewotherbadges', $context)) {
2151 $records = badges_get_user_badges($userid, $courseid, null, null, null, true);
2152 $renderer = new core_badges_renderer($PAGE, '');
2154 // Print local badges.
2156 $left = get_string('localbadgesp', 'badges', format_string($SITE->fullname
));
2157 $right = $renderer->print_badges_list($records, $userid, true);
2158 echo html_writer
::tag('dt', $left);
2159 echo html_writer
::tag('dd', $right);
2162 // Print external badges.
2163 if ($courseid == 0 && !empty($CFG->badges_allowexternalbackpack
)) {
2164 $backpack = get_backpack_settings($userid);
2165 if (isset($backpack->totalbadges
) && $backpack->totalbadges
!== 0) {
2166 $left = get_string('externalbadgesp', 'badges');
2167 $right = $renderer->print_badges_list($backpack->badges
, $userid, true, true);
2168 echo html_writer
::tag('dt', $left);
2169 echo html_writer
::tag('dd', $right);
2176 * Adds user preferences elements to user edit form.
2178 * @deprecated since Moodle 2.9 MDL-45774 - Please do not use this function any more.
2179 * @todo MDL-49784 Remove this function in Moodle 3.1
2180 * @param stdClass $user
2181 * @param moodleform $mform
2182 * @param array|null $editoroptions
2183 * @param array|null $filemanageroptions
2185 function useredit_shared_definition_preferences($user, &$mform, $editoroptions = null, $filemanageroptions = null) {
2188 debugging('useredit_shared_definition_preferences() is deprecated.', DEBUG_DEVELOPER
, backtrace
);
2191 $choices['0'] = get_string('emaildisplayno');
2192 $choices['1'] = get_string('emaildisplayyes');
2193 $choices['2'] = get_string('emaildisplaycourse');
2194 $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
2195 $mform->setDefault('maildisplay', $CFG->defaultpreference_maildisplay
);
2198 $choices['0'] = get_string('textformat');
2199 $choices['1'] = get_string('htmlformat');
2200 $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
2201 $mform->setDefault('mailformat', $CFG->defaultpreference_mailformat
);
2203 if (!empty($CFG->allowusermailcharset
)) {
2205 $charsets = get_list_of_charsets();
2206 if (!empty($CFG->sitemailcharset
)) {
2207 $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset
.')';
2209 $choices['0'] = get_string('site').' (UTF-8)';
2211 $choices = array_merge($choices, $charsets);
2212 $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
2216 $choices['0'] = get_string('emaildigestoff');
2217 $choices['1'] = get_string('emaildigestcomplete');
2218 $choices['2'] = get_string('emaildigestsubjects');
2219 $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
2220 $mform->setDefault('maildigest', $CFG->defaultpreference_maildigest
);
2221 $mform->addHelpButton('maildigest', 'emaildigest');
2224 $choices['1'] = get_string('autosubscribeyes');
2225 $choices['0'] = get_string('autosubscribeno');
2226 $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
2227 $mform->setDefault('autosubscribe', $CFG->defaultpreference_autosubscribe
);
2229 if (!empty($CFG->forum_trackreadposts
)) {
2231 $choices['0'] = get_string('trackforumsno');
2232 $choices['1'] = get_string('trackforumsyes');
2233 $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
2234 $mform->setDefault('trackforums', $CFG->defaultpreference_trackforums
);
2237 $editors = editors_get_enabled();
2238 if (count($editors) > 1) {
2239 $choices = array('' => get_string('defaulteditor'));
2241 foreach (array_keys($editors) as $editor) {
2242 if (!$firsteditor) {
2243 $firsteditor = $editor;
2245 $choices[$editor] = get_string('pluginname', 'editor_' . $editor);
2247 $mform->addElement('select', 'preference_htmleditor', get_string('textediting'), $choices);
2248 $mform->setDefault('preference_htmleditor', '');
2250 // Empty string means use the first chosen text editor.
2251 $mform->addElement('hidden', 'preference_htmleditor');
2252 $mform->setDefault('preference_htmleditor', '');
2253 $mform->setType('preference_htmleditor', PARAM_PLUGIN
);
2256 $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
2257 $mform->setDefault('lang', $CFG->lang
);
2263 * Convert region timezone to php supported timezone
2265 * @deprecated since Moodle 2.9
2266 * @param string $tz value from ical file
2267 * @return string $tz php supported timezone
2269 function calendar_normalize_tz($tz) {
2270 debugging('calendar_normalize_tz() is deprecated, use core_date::normalise_timezone() instead', DEBUG_DEVELOPER
);
2271 return core_date
::normalise_timezone($tz);
2275 * Returns a float which represents the user's timezone difference from GMT in hours
2276 * Checks various settings and picks the most dominant of those which have a value
2277 * @deprecated since Moodle 2.9
2278 * @param float|int|string $tz timezone user timezone
2281 function get_user_timezone_offset($tz = 99) {
2282 debugging('get_user_timezone_offset() is deprecated, use PHP DateTimeZone instead', DEBUG_DEVELOPER
);
2283 $tz = core_date
::get_user_timezone($tz);
2284 $date = new DateTime('now', new DateTimeZone($tz));
2285 return ($date->getOffset() - dst_offset_on(time(), $tz)) / (3600.0);
2289 * Returns an int which represents the systems's timezone difference from GMT in seconds
2290 * @deprecated since Moodle 2.9
2291 * @param float|int|string $tz timezone for which offset is required.
2292 * {@link http://docs.moodle.org/dev/Time_API#Timezone}
2293 * @return int|bool if found, false is timezone 99 or error
2295 function get_timezone_offset($tz) {
2296 debugging('get_timezone_offset() is deprecated, use PHP DateTimeZone instead', DEBUG_DEVELOPER
);
2297 $date = new DateTime('now', new DateTimeZone(core_date
::normalise_timezone($tz)));
2298 return $date->getOffset() - dst_offset_on(time(), $tz);
2302 * Returns a list of timezones in the current language.
2303 * @deprecated since Moodle 2.9
2306 function get_list_of_timezones() {
2307 debugging('get_list_of_timezones() is deprecated, use core_date::get_list_of_timezones() instead', DEBUG_DEVELOPER
);
2308 return core_date
::get_list_of_timezones();
2312 * Previous internal API, it was not supposed to be used anywhere.
2313 * @deprecated since Moodle 2.9
2314 * @param array $timezones
2316 function update_timezone_records($timezones) {
2317 debugging('update_timezone_records() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER
);
2321 * Previous internal API, it was not supposed to be used anywhere.
2322 * @deprecated since Moodle 2.9
2323 * @param int $fromyear
2324 * @param int $toyear
2325 * @param mixed $strtimezone
2328 function calculate_user_dst_table($fromyear = null, $toyear = null, $strtimezone = null) {
2329 debugging('calculate_user_dst_table() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER
);
2334 * Previous internal API, it was not supposed to be used anywhere.
2335 * @deprecated since Moodle 2.9
2336 * @param int|string $year
2337 * @param mixed $timezone
2340 function dst_changes_for_year($year, $timezone) {
2341 debugging('dst_changes_for_year() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER
);
2346 * Previous internal API, it was not supposed to be used anywhere.
2347 * @deprecated since Moodle 2.9
2348 * @param string $timezonename
2351 function get_timezone_record($timezonename) {
2352 debugging('get_timezone_record() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER
);
2356 /* === Apis deprecated since Moodle 3.0 === */
2358 * Returns the URL of the HTTP_REFERER, less the querystring portion if required.
2360 * @deprecated since Moodle 3.0 MDL-49360 - please do not use this function any more.
2361 * @todo Remove this function in Moodle 3.2
2362 * @param boolean $stripquery if true, also removes the query part of the url.
2363 * @return string The resulting referer or empty string.
2365 function get_referer($stripquery = true) {
2366 debugging('get_referer() is deprecated. Please use get_local_referer() instead.', DEBUG_DEVELOPER
);
2367 if (isset($_SERVER['HTTP_REFERER'])) {
2369 return strip_querystring($_SERVER['HTTP_REFERER']);
2371 return $_SERVER['HTTP_REFERER'];
2379 * Checks if current user is a web crawler.
2381 * This list can not be made complete, this is not a security
2382 * restriction, we make the list only to help these sites
2383 * especially when automatic guest login is disabled.
2385 * If admin needs security they should enable forcelogin
2386 * and disable guest access!!
2389 * @deprecated since Moodle 3.0 use \core_useragent::is_web_crawler instead.
2391 function is_web_crawler() {
2392 debugging('is_web_crawler() has been deprecated, please use core_useragent::is_web_crawler() instead.', DEBUG_DEVELOPER
);
2393 return core_useragent
::is_web_crawler();
2397 * Update user's course completion statuses
2399 * First update all criteria completions, then aggregate all criteria completions
2400 * and update overall course completions.
2402 * @deprecated since Moodle 3.0 MDL-50287 - please do not use this function any more.
2403 * @todo Remove this function in Moodle 3.2 MDL-51226.
2405 function completion_cron() {
2407 require_once($CFG->dirroot
.'/completion/cron.php');
2409 debugging('completion_cron() is deprecated. Functionality has been moved to scheduled tasks.', DEBUG_DEVELOPER
);
2410 completion_cron_mark_started();
2412 completion_cron_criteria();
2414 completion_cron_completions();
2418 * Returns an ordered array of tags associated with visible courses
2419 * (boosted replacement of get_all_tags() allowing association with user and tagtype).
2421 * @deprecated since 3.0
2424 * @param int $courseid A course id. Passing 0 will return all distinct tags for all visible courses
2425 * @param int $userid (optional) the user id, a default of 0 will return all users tags for the course
2426 * @param string $tagtype (optional) The type of tag, empty string returns all types. Currently (Moodle 2.2) there are two
2427 * types of tags which are used within Moodle, they are 'official' and 'default'.
2428 * @param int $numtags (optional) number of tags to display, default of 80 is set in the block, 0 returns all
2429 * @param string $unused (optional) was selected sorting, moved to tag_print_cloud()
2432 function coursetag_get_tags($courseid, $userid=0, $tagtype='', $numtags=0, $unused = '') {
2433 debugging('Function coursetag_get_tags() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER
);
2437 // get visible course ids
2438 $courselist = array();
2439 if ($courseid === 0) {
2440 if ($courses = $DB->get_records_select('course', 'visible=1 AND category>0', null, '', 'id')) {
2441 foreach ($courses as $key => $value) {
2442 $courselist[] = $key;
2447 // get tags from the db ordered by highest count first
2449 $sql = "SELECT id as tkey, name, id, tagtype, rawname, f.timemodified, flag, count
2451 (SELECT tagid, MAX(timemodified) as timemodified, COUNT(id) as count
2453 WHERE itemtype = 'course' ";
2455 if ($courseid > 0) {
2456 $sql .= " AND itemid = :courseid ";
2457 $params['courseid'] = $courseid;
2459 if (!empty($courselist)) {
2460 list($usql, $uparams) = $DB->get_in_or_equal($courselist, SQL_PARAMS_NAMED
);
2461 $sql .= "AND itemid $usql ";
2462 $params = $params +
$uparams;
2467 $sql .= " AND tiuserid = :userid ";
2468 $params['userid'] = $userid;
2471 $sql .= " GROUP BY tagid) f
2472 WHERE t.id = f.tagid ";
2473 if ($tagtype != '') {
2474 $sql .= "AND tagtype = :tagtype ";
2475 $params['tagtype'] = $tagtype;
2477 $sql .= "ORDER BY count DESC, name ASC";
2479 // limit the number of tags for output
2480 if ($numtags == 0) {
2481 $tags = $DB->get_records_sql($sql, $params);
2483 $tags = $DB->get_records_sql($sql, $params, 0, $numtags);
2486 // prepare the return
2489 // avoid print_tag_cloud()'s ksort upsetting ordering by setting the key here
2490 foreach ($tags as $value) {
2500 * Returns an ordered array of tags
2501 * (replaces popular_tags_count() allowing sorting).
2503 * @deprecated since 3.0
2506 * @param string $unused (optional) was selected sorting - moved to tag_print_cloud()
2507 * @param int $numtags (optional) number of tags to display, default of 20 is set in the block, 0 returns all
2510 function coursetag_get_all_tags($unused='', $numtags=0) {
2511 debugging('Function coursetag_get_all_tag() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER
);
2515 // note that this selects all tags except for courses that are not visible
2516 $sql = "SELECT id, name, tagtype, rawname, f.timemodified, flag, count
2518 (SELECT tagid, MAX(timemodified) as timemodified, COUNT(id) as count
2519 FROM {tag_instance} WHERE tagid NOT IN
2520 (SELECT tagid FROM {tag_instance} ti, {course} c
2522 AND ti.itemtype = 'course'
2523 AND ti.itemid = c.id)
2525 WHERE t.id = f.tagid
2526 ORDER BY count DESC, name ASC";
2527 if ($numtags == 0) {
2528 $tags = $DB->get_records_sql($sql);
2530 $tags = $DB->get_records_sql($sql, null, 0, $numtags);
2535 foreach ($tags as $value) {
2544 * Returns javascript for use in tags block and supporting pages
2546 * @deprecated since 3.0
2551 function coursetag_get_jscript() {
2552 debugging('Function coursetag_get_jscript() is deprecated and obsolete.', DEBUG_DEVELOPER
);
2557 * Returns javascript to create the links in the tag block footer.
2559 * @deprecated since 3.0
2562 * @param string $elementid the element to attach the footer to
2563 * @param array $coursetagslinks links arrays each consisting of 'title', 'onclick' and 'text' elements
2564 * @return string always returns a blank string
2566 function coursetag_get_jscript_links($elementid, $coursetagslinks) {
2567 debugging('Function coursetag_get_jscript_links() is deprecated and obsolete.', DEBUG_DEVELOPER
);
2572 * Returns all tags created by a user for a course
2574 * @deprecated since 3.0
2577 * @param int $courseid tags are returned for the course that has this courseid
2578 * @param int $userid return tags which were created by this user
2580 function coursetag_get_records($courseid, $userid) {
2581 debugging('Function coursetag_get_records() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER
);
2585 $sql = "SELECT t.id, name, rawname
2586 FROM {tag} t, {tag_instance} ti
2587 WHERE t.id = ti.tagid
2588 AND ti.tiuserid = :userid
2589 AND ti.itemid = :courseid
2592 return $DB->get_records_sql($sql, array('userid'=>$userid, 'courseid'=>$courseid));
2596 * Stores a tag for a course for a user
2598 * @deprecated since 3.0
2601 * @param array $tags simple array of keywords to be stored
2602 * @param int $courseid the id of the course we wish to store a tag for
2603 * @param int $userid the id of the user we wish to store a tag for
2604 * @param string $tagtype official or default only
2605 * @param string $myurl (optional) for logging creation of course tags
2607 function coursetag_store_keywords($tags, $courseid, $userid=0, $tagtype='official', $myurl='') {
2608 debugging('Function coursetag_store_keywords() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER
);
2611 require_once $CFG->dirroot
.'/tag/lib.php';
2613 if (is_array($tags) and !empty($tags)) {
2614 foreach ($tags as $tag) {
2616 if (strlen($tag) > 0) {
2617 //tag_set_add('course', $courseid, $tag, $userid); //deletes official tags
2619 //add tag if does not exist
2620 if (!$tagid = tag_get_id($tag)) {
2621 $tag_id_array = tag_add(array($tag), $tagtype);
2622 $tagid = $tag_id_array[core_text
::strtolower($tag)];
2626 if ($current_ids = tag_get_tags_ids('course', $courseid)) {
2628 $ordering = key($current_ids) +
1;
2631 tag_type_set($tagid, $tagtype);
2633 //tag_instance entry
2634 tag_assign('course', $courseid, $tagid, $ordering, $userid, 'core', context_course
::instance($courseid)->id
);
2642 * Deletes a personal tag for a user for a course.
2644 * @deprecated since 3.0
2647 * @param int $tagid the tag we wish to delete
2648 * @param int $userid the user that the tag is associated with
2649 * @param int $courseid the course that the tag is associated with
2651 function coursetag_delete_keyword($tagid, $userid, $courseid) {
2652 debugging('Function coursetag_delete_keyword() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER
);
2654 tag_delete_instance('course', $courseid, $tagid, $userid);
2658 * Get courses tagged with a tag
2660 * @deprecated since 3.0
2664 * @return array of course objects
2666 function coursetag_get_tagged_courses($tagid) {
2667 debugging('Function coursetag_get_tagged_courses() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER
);
2673 $ctxselect = context_helper
::get_preload_record_columns_sql('ctx');
2675 $sql = "SELECT c.*, $ctxselect
2677 JOIN {tag_instance} t ON t.itemid = c.id
2678 JOIN {context} ctx ON ctx.instanceid = c.id
2679 WHERE t.tagid = :tagid AND
2680 t.itemtype = 'course' AND
2681 ctx.contextlevel = :contextlevel
2682 ORDER BY c.sortorder ASC";
2683 $params = array('tagid' => $tagid, 'contextlevel' => CONTEXT_COURSE
);
2684 $rs = $DB->get_recordset_sql($sql, $params);
2685 foreach ($rs as $course) {
2686 context_helper
::preload_from_record($course);
2687 if ($course->visible
== 1 ||
has_capability('moodle/course:viewhiddencourses', context_course
::instance($course->id
))) {
2688 $courses[$course->id
] = $course;
2695 * Course tagging function used only during the deletion of a course (called by lib/moodlelib.php) to clean up associated tags
2698 * @deprecated since 3.0
2699 * @param int $courseid the course we wish to delete tag instances from
2700 * @param bool $showfeedback if we should output a notification of the delete to the end user
2702 function coursetag_delete_course_tags($courseid, $showfeedback=false) {
2703 debugging('Function coursetag_delete_course_tags() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER
);
2705 global $DB, $OUTPUT;
2707 if ($taginstances = $DB->get_recordset_select('tag_instance', "itemtype = 'course' AND itemid = :courseid",
2708 array('courseid' => $courseid), '', 'tagid, tiuserid')) {
2710 foreach ($taginstances as $record) {
2711 tag_delete_instance('course', $courseid, $record->tagid
, $record->tiuserid
);
2713 $taginstances->close();
2716 if ($showfeedback) {
2717 echo $OUTPUT->notification(get_string('deletedcoursetags', 'tag'), 'notifysuccess');
2722 * Function that returns tags that start with some text, for use by the autocomplete feature
2725 * @deprecated since 3.0
2727 * @param string $text string that the tag names will be matched against
2728 * @return mixed an array of objects, or false if no records were found or an error occured.
2730 function tag_autocomplete($text) {
2731 debugging('Function tag_autocomplete() is deprecated without replacement. ' .
2732 'New form element "tags" does proper autocomplete.', DEBUG_DEVELOPER
);
2734 return $DB->get_records_sql("SELECT tg.id, tg.name, tg.rawname
2736 WHERE tg.name LIKE ?", array(core_text
::strtolower($text)."%"));
2740 * Add includes (js and css) into uploaded files before returning them,
2741 * useful for themes and utf.js includes.
2743 * @param string $text text to search and replace
2744 * @return string text
2745 * @deprecated Moodle 3.0.5 See MDL-29738
2747 function file_modify_html_header($text) {
2748 debugging('file_modify_html_header() is deprecated and will not be replaced.', DEBUG_DEVELOPER
);