Merge branch 'MDL-66750_37' of https://github.com/timhunt/moodle into MOODLE_37_STABLE
[moodle.git] / lib / deprecatedlib.php
blobe43c610dcb219a3734a488c31afbf0cf00d349d4
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 /* === Functions that needs to be kept longer in deprecated lib than normal time period === */
35 /**
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
47 * @return void
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);
60 /**
61 * @deprecated since 2.6
63 function events_trigger() {
64 throw new coding_exception('events_trigger() has been deprecated along with all Events 1 API in favour of Events 2 API.');
67 /**
68 * List all core subsystems and their location
70 * This is a whitelist of components that are part of the core and their
71 * language strings are defined in /lang/en/<<subsystem>>.php. If a given
72 * plugin is not listed here and it does not have proper plugintype prefix,
73 * then it is considered as course activity module.
75 * The location is optionally dirroot relative path. NULL means there is no special
76 * directory for this subsystem. If the location is set, the subsystem's
77 * renderer.php is expected to be there.
79 * @deprecated since 2.6, use core_component::get_core_subsystems()
81 * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons
82 * @return array of (string)name => (string|null)location
84 function get_core_subsystems($fullpaths = false) {
85 global $CFG;
87 // NOTE: do not add any other debugging here, keep forever.
89 $subsystems = core_component::get_core_subsystems();
91 if ($fullpaths) {
92 return $subsystems;
95 debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
97 $dlength = strlen($CFG->dirroot);
99 foreach ($subsystems as $k => $v) {
100 if ($v === null) {
101 continue;
103 $subsystems[$k] = substr($v, $dlength+1);
106 return $subsystems;
110 * Lists all plugin types.
112 * @deprecated since 2.6, use core_component::get_plugin_types()
114 * @param bool $fullpaths false means relative paths from dirroot
115 * @return array Array of strings - name=>location
117 function get_plugin_types($fullpaths = true) {
118 global $CFG;
120 // NOTE: do not add any other debugging here, keep forever.
122 $types = core_component::get_plugin_types();
124 if ($fullpaths) {
125 return $types;
128 debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
130 $dlength = strlen($CFG->dirroot);
132 foreach ($types as $k => $v) {
133 if ($k === 'theme') {
134 $types[$k] = 'theme';
135 continue;
137 $types[$k] = substr($v, $dlength+1);
140 return $types;
144 * Use when listing real plugins of one type.
146 * @deprecated since 2.6, use core_component::get_plugin_list()
148 * @param string $plugintype type of plugin
149 * @return array name=>fulllocation pairs of plugins of given type
151 function get_plugin_list($plugintype) {
153 // NOTE: do not add any other debugging here, keep forever.
155 if ($plugintype === '') {
156 $plugintype = 'mod';
159 return core_component::get_plugin_list($plugintype);
163 * Get a list of all the plugins of a given type that define a certain class
164 * in a certain file. The plugin component names and class names are returned.
166 * @deprecated since 2.6, use core_component::get_plugin_list_with_class()
168 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
169 * @param string $class the part of the name of the class after the
170 * frankenstyle prefix. e.g 'thing' if you are looking for classes with
171 * names like report_courselist_thing. If you are looking for classes with
172 * the same name as the plugin name (e.g. qtype_multichoice) then pass ''.
173 * @param string $file the name of file within the plugin that defines the class.
174 * @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum')
175 * and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice').
177 function get_plugin_list_with_class($plugintype, $class, $file) {
179 // NOTE: do not add any other debugging here, keep forever.
181 return core_component::get_plugin_list_with_class($plugintype, $class, $file);
185 * Returns the exact absolute path to plugin directory.
187 * @deprecated since 2.6, use core_component::get_plugin_directory()
189 * @param string $plugintype type of plugin
190 * @param string $name name of the plugin
191 * @return string full path to plugin directory; NULL if not found
193 function get_plugin_directory($plugintype, $name) {
195 // NOTE: do not add any other debugging here, keep forever.
197 if ($plugintype === '') {
198 $plugintype = 'mod';
201 return core_component::get_plugin_directory($plugintype, $name);
205 * Normalize the component name using the "frankenstyle" names.
207 * @deprecated since 2.6, use core_component::normalize_component()
209 * @param string $component
210 * @return array two-items list of [(string)type, (string|null)name]
212 function normalize_component($component) {
214 // NOTE: do not add any other debugging here, keep forever.
216 return core_component::normalize_component($component);
220 * Return exact absolute path to a plugin directory.
222 * @deprecated since 2.6, use core_component::normalize_component()
224 * @param string $component name such as 'moodle', 'mod_forum'
225 * @return string full path to component directory; NULL if not found
227 function get_component_directory($component) {
229 // NOTE: do not add any other debugging here, keep forever.
231 return core_component::get_component_directory($component);
235 * Get the context instance as an object. This function will create the
236 * context instance if it does not exist yet.
238 * @deprecated since 2.2, use context_course::instance() or other relevant class instead
239 * @todo This will be deleted in Moodle 2.8, refer MDL-34472
240 * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
241 * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
242 * for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
243 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
244 * MUST_EXIST means throw exception if no record or multiple records found
245 * @return context The context object.
247 function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
249 debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER);
251 $instances = (array)$instance;
252 $contexts = array();
254 $classname = context_helper::get_class_for_level($contextlevel);
256 // we do not load multiple contexts any more, PAGE should be responsible for any preloading
257 foreach ($instances as $inst) {
258 $contexts[$inst] = $classname::instance($inst, $strictness);
261 if (is_array($instance)) {
262 return $contexts;
263 } else {
264 return $contexts[$instance];
267 /* === End of long term deprecated api list === */
270 * @deprecated since 2.7 - use new file picker instead
272 function clam_log_upload() {
273 throw new coding_exception('clam_log_upload() can not be used any more, please use file picker instead');
277 * @deprecated since 2.7 - use new file picker instead
279 function clam_log_infected() {
280 throw new coding_exception('clam_log_infected() can not be used any more, please use file picker instead');
284 * @deprecated since 2.7 - use new file picker instead
286 function clam_change_log() {
287 throw new coding_exception('clam_change_log() can not be used any more, please use file picker instead');
291 * @deprecated since 2.7 - infected files are now deleted in file picker
293 function clam_replace_infected_file() {
294 throw new coding_exception('clam_replace_infected_file() can not be used any more, please use file picker instead');
298 * @deprecated since 2.7
300 function clam_handle_infected_file() {
301 throw new coding_exception('clam_handle_infected_file() can not be used any more, please use file picker instead');
305 * @deprecated since 2.7
307 function clam_scan_moodle_file() {
308 throw new coding_exception('clam_scan_moodle_file() can not be used any more, please use file picker instead');
313 * @deprecated since 2.7 PHP 5.4.x should be always compatible.
315 function password_compat_not_supported() {
316 throw new coding_exception('Do not use password_compat_not_supported() - bcrypt is now always available');
320 * @deprecated since 2.6
322 function session_get_instance() {
323 throw new coding_exception('session_get_instance() is removed, use \core\session\manager instead');
327 * @deprecated since 2.6
329 function session_is_legacy() {
330 throw new coding_exception('session_is_legacy() is removed, do not use any more');
334 * @deprecated since 2.6
336 function session_kill_all() {
337 throw new coding_exception('session_kill_all() is removed, use \core\session\manager::kill_all_sessions() instead');
341 * @deprecated since 2.6
343 function session_touch() {
344 throw new coding_exception('session_touch() is removed, use \core\session\manager::touch_session() instead');
348 * @deprecated since 2.6
350 function session_kill() {
351 throw new coding_exception('session_kill() is removed, use \core\session\manager::kill_session() instead');
355 * @deprecated since 2.6
357 function session_kill_user() {
358 throw new coding_exception('session_kill_user() is removed, use \core\session\manager::kill_user_sessions() instead');
362 * @deprecated since 2.6
364 function session_set_user() {
365 throw new coding_exception('session_set_user() is removed, use \core\session\manager::set_user() instead');
369 * @deprecated since 2.6
371 function session_is_loggedinas() {
372 throw new coding_exception('session_is_loggedinas() is removed, use \core\session\manager::is_loggedinas() instead');
376 * @deprecated since 2.6
378 function session_get_realuser() {
379 throw new coding_exception('session_get_realuser() is removed, use \core\session\manager::get_realuser() instead');
383 * @deprecated since 2.6
385 function session_loginas() {
386 throw new coding_exception('session_loginas() is removed, use \core\session\manager::loginas() instead');
390 * @deprecated since 2.6
392 function js_minify() {
393 throw new coding_exception('js_minify() is removed, use core_minify::js_files() or core_minify::js() instead.');
397 * @deprecated since 2.6
399 function css_minify_css() {
400 throw new coding_exception('css_minify_css() is removed, use core_minify::css_files() or core_minify::css() instead.');
403 // === Deprecated before 2.6.0 ===
406 * @deprecated
408 function check_gd_version() {
409 throw new coding_exception('check_gd_version() is removed, GD extension is always available now');
413 * @deprecated
415 function update_login_count() {
416 throw new coding_exception('update_login_count() is removed, all calls need to be removed');
420 * @deprecated
422 function reset_login_count() {
423 throw new coding_exception('reset_login_count() is removed, all calls need to be removed');
427 * @deprecated
429 function update_log_display_entry() {
431 throw new coding_exception('The update_log_display_entry() is removed, please use db/log.php description file instead.');
435 * @deprecated use the text formatting in a standard way instead (http://docs.moodle.org/dev/Output_functions)
436 * this was abused mostly for embedding of attachments
438 function filter_text() {
439 throw new coding_exception('filter_text() can not be used anymore, use format_text(), format_string() etc instead.');
443 * @deprecated Loginhttps is no longer supported
445 function httpsrequired() {
446 throw new coding_exception('httpsrequired() can not be used any more. Loginhttps is no longer supported.');
450 * @deprecated since 3.1 - replacement legacy file API methods can be found on the moodle_url class, for example:
451 * The moodle_url::make_legacyfile_url() method can be used to generate a legacy course file url. To generate
452 * course module file.php url the moodle_url::make_file_url() should be used.
454 function get_file_url() {
455 throw new coding_exception('get_file_url() can not be used anymore. Please use ' .
456 'moodle_url factory methods instead.');
460 * @deprecated use get_enrolled_users($context) instead.
462 function get_course_participants() {
463 throw new coding_exception('get_course_participants() can not be used any more, use get_enrolled_users() instead.');
467 * @deprecated use is_enrolled($context, $userid) instead.
469 function is_course_participant() {
470 throw new coding_exception('is_course_participant() can not be used any more, use is_enrolled() instead.');
474 * @deprecated
476 function get_recent_enrolments() {
477 throw new coding_exception('get_recent_enrolments() is removed as it returned inaccurate results.');
481 * @deprecated use clean_param($string, PARAM_FILE) instead.
483 function detect_munged_arguments() {
484 throw new coding_exception('detect_munged_arguments() can not be used any more, please use clean_param(,PARAM_FILE) instead.');
489 * Unzip one zip file to a destination dir
490 * Both parameters must be FULL paths
491 * If destination isn't specified, it will be the
492 * SAME directory where the zip file resides.
494 * @global object
495 * @param string $zipfile The zip file to unzip
496 * @param string $destination The location to unzip to
497 * @param bool $showstatus_ignored Unused
498 * @deprecated since 2.0 MDL-15919
500 function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
501 debugging(__FUNCTION__ . '() is deprecated. '
502 . 'Please use the application/zip file_packer implementation instead.', DEBUG_DEVELOPER);
504 // Extract everything from zipfile.
505 $path_parts = pathinfo(cleardoubleslashes($zipfile));
506 $zippath = $path_parts["dirname"]; //The path of the zip file
507 $zipfilename = $path_parts["basename"]; //The name of the zip file
508 $extension = $path_parts["extension"]; //The extension of the file
510 //If no file, error
511 if (empty($zipfilename)) {
512 return false;
515 //If no extension, error
516 if (empty($extension)) {
517 return false;
520 //Clear $zipfile
521 $zipfile = cleardoubleslashes($zipfile);
523 //Check zipfile exists
524 if (!file_exists($zipfile)) {
525 return false;
528 //If no destination, passed let's go with the same directory
529 if (empty($destination)) {
530 $destination = $zippath;
533 //Clear $destination
534 $destpath = rtrim(cleardoubleslashes($destination), "/");
536 //Check destination path exists
537 if (!is_dir($destpath)) {
538 return false;
541 $packer = get_file_packer('application/zip');
543 $result = $packer->extract_to_pathname($zipfile, $destpath);
545 if ($result === false) {
546 return false;
549 foreach ($result as $status) {
550 if ($status !== true) {
551 return false;
555 return true;
559 * Zip an array of files/dirs to a destination zip file
560 * Both parameters must be FULL paths to the files/dirs
562 * @global object
563 * @param array $originalfiles Files to zip
564 * @param string $destination The destination path
565 * @return bool Outcome
567 * @deprecated since 2.0 MDL-15919
569 function zip_files($originalfiles, $destination) {
570 debugging(__FUNCTION__ . '() is deprecated. '
571 . 'Please use the application/zip file_packer implementation instead.', DEBUG_DEVELOPER);
573 // Extract everything from destination.
574 $path_parts = pathinfo(cleardoubleslashes($destination));
575 $destpath = $path_parts["dirname"]; //The path of the zip file
576 $destfilename = $path_parts["basename"]; //The name of the zip file
577 $extension = $path_parts["extension"]; //The extension of the file
579 //If no file, error
580 if (empty($destfilename)) {
581 return false;
584 //If no extension, add it
585 if (empty($extension)) {
586 $extension = 'zip';
587 $destfilename = $destfilename.'.'.$extension;
590 //Check destination path exists
591 if (!is_dir($destpath)) {
592 return false;
595 //Check destination path is writable. TODO!!
597 //Clean destination filename
598 $destfilename = clean_filename($destfilename);
600 //Now check and prepare every file
601 $files = array();
602 $origpath = NULL;
604 foreach ($originalfiles as $file) { //Iterate over each file
605 //Check for every file
606 $tempfile = cleardoubleslashes($file); // no doubleslashes!
607 //Calculate the base path for all files if it isn't set
608 if ($origpath === NULL) {
609 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
611 //See if the file is readable
612 if (!is_readable($tempfile)) { //Is readable
613 continue;
615 //See if the file/dir is in the same directory than the rest
616 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
617 continue;
619 //Add the file to the array
620 $files[] = $tempfile;
623 $zipfiles = array();
624 $start = strlen($origpath)+1;
625 foreach($files as $file) {
626 $zipfiles[substr($file, $start)] = $file;
629 $packer = get_file_packer('application/zip');
631 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
635 * @deprecated use groups_get_all_groups() instead.
637 function mygroupid() {
638 throw new coding_exception('mygroupid() can not be used any more, please use groups_get_all_groups() instead.');
642 * @deprecated since Moodle 2.0 MDL-14617 - please do not use this function any more.
644 function groupmode() {
645 throw new coding_exception('groupmode() can not be used any more, please use groups_get_* instead.');
649 * @deprecated Since year 2006 - please do not use this function any more.
651 function set_current_group() {
652 throw new coding_exception('set_current_group() can not be used anymore, please use $SESSION->currentgroup[$courseid] instead');
656 * @deprecated Since year 2006 - please do not use this function any more.
658 function get_current_group() {
659 throw new coding_exception('get_current_group() can not be used any more, please use groups_get_* instead');
663 * @deprecated Since Moodle 2.8
665 function groups_filter_users_by_course_module_visible() {
666 throw new coding_exception('groups_filter_users_by_course_module_visible() is removed. ' .
667 'Replace with a call to \core_availability\info_module::filter_user_list(), ' .
668 'which does basically the same thing but includes other restrictions such ' .
669 'as profile restrictions.');
673 * @deprecated Since Moodle 2.8
675 function groups_course_module_visible() {
676 throw new coding_exception('groups_course_module_visible() is removed, use $cm->uservisible to decide whether the current
677 user can ' . 'access an activity.', DEBUG_DEVELOPER);
681 * @deprecated since 2.0
683 function error() {
684 throw new coding_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a removed, please call
685 print_error() instead of error()');
690 * @deprecated use $PAGE->theme->name instead.
692 function current_theme() {
693 throw new coding_exception('current_theme() can not be used any more, please use $PAGE->theme->name instead');
697 * @deprecated
699 function formerr() {
700 throw new coding_exception('formerr() is removed. Please change your code to use $OUTPUT->error_text($string).');
704 * @deprecated use $OUTPUT->skip_link_target() in instead.
706 function skip_main_destination() {
707 throw new coding_exception('skip_main_destination() can not be used any more, please use $OUTPUT->skip_link_target() instead.');
711 * @deprecated use $OUTPUT->container() instead.
713 function print_container() {
714 throw new coding_exception('print_container() can not be used any more. Please use $OUTPUT->container() instead.');
718 * @deprecated use $OUTPUT->container_start() instead.
720 function print_container_start() {
721 throw new coding_exception('print_container_start() can not be used any more. Please use $OUTPUT->container_start() instead.');
725 * @deprecated use $OUTPUT->container_end() instead.
727 function print_container_end() {
728 throw new coding_exception('print_container_end() can not be used any more. Please use $OUTPUT->container_end() instead.');
732 * @deprecated since Moodle 2.0 MDL-19077 - use $OUTPUT->notification instead.
734 function notify() {
735 throw new coding_exception('notify() is removed, please use $OUTPUT->notification() instead');
739 * @deprecated use $OUTPUT->continue_button() instead.
741 function print_continue() {
742 throw new coding_exception('print_continue() can not be used any more. Please use $OUTPUT->continue_button() instead.');
746 * @deprecated use $PAGE methods instead.
748 function print_header() {
750 throw new coding_exception('print_header() can not be used any more. Please use $PAGE methods instead.');
754 * @deprecated use $PAGE methods instead.
756 function print_header_simple() {
758 throw new coding_exception('print_header_simple() can not be used any more. Please use $PAGE methods instead.');
762 * @deprecated use $OUTPUT->block() instead.
764 function print_side_block() {
765 throw new coding_exception('print_side_block() can not be used any more, please use $OUTPUT->block() instead.');
769 * Prints a basic textarea field.
771 * This was 'deprecated' in 2.0, but not properly (there was no alternative) so the
772 * debugging message was commented out.
774 * @deprecated since Moodle 3.6
776 * When using this function, you should
778 * @global object
779 * @param bool $unused No longer used.
780 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
781 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
782 * @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.
783 * @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.
784 * @param string $name Name to use for the textarea element.
785 * @param string $value Initial content to display in the textarea.
786 * @param int $obsolete deprecated
787 * @param bool $return If false, will output string. If true, will return string value.
788 * @param string $id CSS ID to add to the textarea element.
789 * @return string|void depending on the value of $return
791 function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
792 /// $width and height are legacy fields and no longer used as pixels like they used to be.
793 /// However, you can set them to zero to override the mincols and minrows values below.
795 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
796 debugging('print_textarea() is deprecated. Please use $OUTPUT->print_textarea() instead.', DEBUG_DEVELOPER);
798 global $OUTPUT;
800 $mincols = 65;
801 $minrows = 10;
803 if ($id === '') {
804 $id = 'edit-'.$name;
807 if ($height && ($rows < $minrows)) {
808 $rows = $minrows;
810 if ($width && ($cols < $mincols)) {
811 $cols = $mincols;
814 $textarea = $OUTPUT->print_textarea($name, $id, $value, $rows, $cols);
815 if ($return) {
816 return $textarea;
819 echo $textarea;
823 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
824 * provide this function with the language strings for sortasc and sortdesc.
826 * @deprecated use $OUTPUT->arrow() instead.
827 * @todo final deprecation of this function once MDL-45448 is resolved
829 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
831 * @global object
832 * @param string $direction 'up' or 'down'
833 * @param string $strsort The language string used for the alt attribute of this image
834 * @param bool $return Whether to print directly or return the html string
835 * @return string|void depending on $return
838 function print_arrow($direction='up', $strsort=null, $return=false) {
839 global $OUTPUT;
841 debugging('print_arrow() is deprecated. Please use $OUTPUT->arrow() instead.', DEBUG_DEVELOPER);
843 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
844 return null;
847 $return = null;
849 switch ($direction) {
850 case 'up':
851 $sortdir = 'asc';
852 break;
853 case 'down':
854 $sortdir = 'desc';
855 break;
856 case 'move':
857 $sortdir = 'asc';
858 break;
859 default:
860 $sortdir = null;
861 break;
864 // Prepare language string
865 $strsort = '';
866 if (empty($strsort) && !empty($sortdir)) {
867 $strsort = get_string('sort' . $sortdir, 'grades');
870 $return = ' ' . $OUTPUT->pix_icon('t/' . $direction, $strsort) . ' ';
872 if ($return) {
873 return $return;
874 } else {
875 echo $return;
880 * @deprecated since Moodle 2.0
882 function choose_from_menu() {
883 throw new coding_exception('choose_from_menu() is removed. Please change your code to use html_writer::select().');
887 * @deprecated use $OUTPUT->help_icon_scale($courseid, $scale) instead.
889 function print_scale_menu_helpbutton() {
890 throw new coding_exception('print_scale_menu_helpbutton() can not be used any more. '.
891 'Please use $OUTPUT->help_icon_scale($courseid, $scale) instead.');
895 * @deprecated use html_writer::checkbox() instead.
897 function print_checkbox() {
898 throw new coding_exception('print_checkbox() can not be used any more. Please use html_writer::checkbox() instead.');
902 * @deprecated since Moodle 3.2
904 function update_module_button() {
905 throw new coding_exception('update_module_button() can not be used anymore. Activity modules should ' .
906 'not add the edit module button, the link is already available in the Administration block. Themes ' .
907 'can choose to display the link in the buttons row consistently for all module types.');
911 * @deprecated use $OUTPUT->navbar() instead
913 function print_navigation () {
914 throw new coding_exception('print_navigation() can not be used any more, please update use $OUTPUT->navbar() instead.');
918 * @deprecated Please use $PAGE->navabar methods instead.
920 function build_navigation() {
921 throw new coding_exception('build_navigation() can not be used any more, please use $PAGE->navbar methods instead.');
925 * @deprecated not relevant with global navigation in Moodle 2.x+
927 function navmenu() {
928 throw new coding_exception('navmenu() can not be used any more, it is no longer relevant with global navigation.');
931 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
935 * @deprecated please use calendar_event::create() instead.
937 function add_event() {
938 throw new coding_exception('add_event() can not be used any more, please use calendar_event::create() instead.');
942 * @deprecated please calendar_event->update() instead.
944 function update_event() {
945 throw new coding_exception('update_event() is removed, please use calendar_event->update() instead.');
949 * @deprecated please use calendar_event->delete() instead.
951 function delete_event() {
952 throw new coding_exception('delete_event() can not be used any more, please use '.
953 'calendar_event->delete() instead.');
957 * @deprecated please use calendar_event->toggle_visibility(false) instead.
959 function hide_event() {
960 throw new coding_exception('hide_event() can not be used any more, please use '.
961 'calendar_event->toggle_visibility(false) instead.');
965 * @deprecated please use calendar_event->toggle_visibility(true) instead.
967 function show_event() {
968 throw new coding_exception('show_event() can not be used any more, please use '.
969 'calendar_event->toggle_visibility(true) instead.');
973 * @deprecated since Moodle 2.2 use core_text::xxxx() instead.
975 function textlib_get_instance() {
976 throw new coding_exception('textlib_get_instance() can not be used any more, please use '.
977 'core_text::functioname() instead.');
981 * @deprecated since 2.4
983 function get_generic_section_name() {
984 throw new coding_exception('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base');
988 * @deprecated since 2.4
990 function get_all_sections() {
991 throw new coding_exception('get_all_sections() is removed. See phpdocs for this function');
995 * @deprecated since 2.4
997 function add_mod_to_section() {
998 throw new coding_exception('Function add_mod_to_section() is removed, please use course_add_cm_to_section()');
1002 * @deprecated since 2.4
1004 function get_all_mods() {
1005 throw new coding_exception('Function get_all_mods() is removed. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details');
1009 * @deprecated since 2.4
1011 function get_course_section() {
1012 throw new coding_exception('Function get_course_section() is removed. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.');
1016 * @deprecated since 2.4
1018 function format_weeks_get_section_dates() {
1019 throw new coding_exception('Function format_weeks_get_section_dates() is removed. It is not recommended to'.
1020 ' use it outside of format_weeks plugin');
1024 * @deprecated since 2.5
1026 function get_print_section_cm_text() {
1027 throw new coding_exception('Function get_print_section_cm_text() is removed. Please use '.
1028 'cm_info::get_formatted_content() and cm_info::get_formatted_name()');
1032 * @deprecated since 2.5
1034 function print_section_add_menus() {
1035 throw new coding_exception('Function print_section_add_menus() is removed. Please use course renderer '.
1036 'function course_section_add_cm_control()');
1040 * @deprecated since 2.5. Please use:
1041 * $courserenderer = $PAGE->get_renderer('core', 'course');
1042 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
1043 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
1045 function make_editing_buttons() {
1046 throw new coding_exception('Function make_editing_buttons() is removed, please see PHPdocs in '.
1047 'lib/deprecatedlib.php on how to replace it');
1051 * @deprecated since 2.5
1053 function print_section() {
1054 throw new coding_exception('Function print_section() is removed. Please use course renderer function '.
1055 'course_section_cm_list() instead.');
1059 * @deprecated since 2.5
1061 function print_overview() {
1062 throw new coding_exception('Function print_overview() is removed. Use block course_overview to display this information');
1066 * @deprecated since 2.5
1068 function print_recent_activity() {
1069 throw new coding_exception('Function print_recent_activity() is removed. It is not recommended to'.
1070 ' use it outside of block_recent_activity');
1074 * @deprecated since 2.5
1076 function delete_course_module() {
1077 throw new coding_exception('Function delete_course_module() is removed. Please use course_delete_module() instead.');
1081 * @deprecated since 2.5
1083 function update_category_button() {
1084 throw new coding_exception('Function update_category_button() is removed. Pages to view '.
1085 'and edit courses are now separate and no longer depend on editing mode.');
1089 * @deprecated since 2.5
1091 function make_categories_list() {
1092 throw new coding_exception('Global function make_categories_list() is removed. Please use '.
1093 'core_course_category::make_categories_list() and core_course_category::get_parents()');
1097 * @deprecated since 2.5
1099 function category_delete_move() {
1100 throw new coding_exception('Function category_delete_move() is removed. Please use ' .
1101 'core_course_category::delete_move() instead.');
1105 * @deprecated since 2.5
1107 function category_delete_full() {
1108 throw new coding_exception('Function category_delete_full() is removed. Please use ' .
1109 'core_course_category::delete_full() instead.');
1113 * @deprecated since 2.5
1115 function move_category() {
1116 throw new coding_exception('Function move_category() is removed. Please use core_course_category::change_parent() instead.');
1120 * @deprecated since 2.5
1122 function course_category_hide() {
1123 throw new coding_exception('Function course_category_hide() is removed. Please use core_course_category::hide() instead.');
1127 * @deprecated since 2.5
1129 function course_category_show() {
1130 throw new coding_exception('Function course_category_show() is removed. Please use core_course_category::show() instead.');
1134 * @deprecated since 2.5. Please use core_course_category::get($catid, IGNORE_MISSING) or
1135 * core_course_category::get($catid, MUST_EXIST).
1137 function get_course_category() {
1138 throw new coding_exception('Function get_course_category() is removed. Please use core_course_category::get(), ' .
1139 'see phpdocs for more details');
1143 * @deprecated since 2.5
1145 function create_course_category() {
1146 throw new coding_exception('Function create_course_category() is removed. Please use core_course_category::create(), ' .
1147 'see phpdocs for more details');
1151 * @deprecated since 2.5. Please use core_course_category::get() and core_course_category::get_children()
1153 function get_all_subcategories() {
1154 throw new coding_exception('Function get_all_subcategories() is removed. Please use appropriate methods() '.
1155 'of core_course_category class. See phpdocs for more details');
1159 * @deprecated since 2.5. Please use core_course_category::get($parentid)->get_children().
1161 function get_child_categories() {
1162 throw new coding_exception('Function get_child_categories() is removed. Use core_course_category::get_children() or see ' .
1163 'phpdocs for more details.');
1167 * @deprecated since 2.5
1169 function get_categories() {
1170 throw new coding_exception('Function get_categories() is removed. Please use ' .
1171 'appropriate functions from class core_course_category');
1175 * @deprecated since 2.5
1177 function print_course_search() {
1178 throw new coding_exception('Function print_course_search() is removed, please use course renderer');
1182 * @deprecated since 2.5
1184 function print_my_moodle() {
1185 throw new coding_exception('Function print_my_moodle() is removed, please use course renderer ' .
1186 'function frontpage_my_courses()');
1190 * @deprecated since 2.5
1192 function print_remote_course() {
1193 throw new coding_exception('Function print_remote_course() is removed, please use course renderer');
1197 * @deprecated since 2.5
1199 function print_remote_host() {
1200 throw new coding_exception('Function print_remote_host() is removed, please use course renderer');
1204 * @deprecated since 2.5
1206 function print_whole_category_list() {
1207 throw new coding_exception('Function print_whole_category_list() is removed, please use course renderer');
1211 * @deprecated since 2.5
1213 function print_category_info() {
1214 throw new coding_exception('Function print_category_info() is removed, please use course renderer');
1218 * @deprecated since 2.5
1220 function get_course_category_tree() {
1221 throw new coding_exception('Function get_course_category_tree() is removed, please use course ' .
1222 'renderer or core_course_category class, see function phpdocs for more info');
1226 * @deprecated since 2.5
1228 function print_courses() {
1229 throw new coding_exception('Function print_courses() is removed, please use course renderer');
1233 * @deprecated since 2.5
1235 function print_course() {
1236 throw new coding_exception('Function print_course() is removed, please use course renderer');
1240 * @deprecated since 2.5
1242 function get_category_courses_array() {
1243 throw new coding_exception('Function get_category_courses_array() is removed, please use methods of ' .
1244 'core_course_category class');
1248 * @deprecated since 2.5
1250 function get_category_courses_array_recursively() {
1251 throw new coding_exception('Function get_category_courses_array_recursively() is removed, please use ' .
1252 'methods of core_course_category class', DEBUG_DEVELOPER);
1256 * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more.
1258 function blog_get_context_url() {
1259 throw new coding_exception('Function blog_get_context_url() is removed, getting params from context is not reliable for blogs.');
1263 * @deprecated since 2.5
1265 function get_courses_wmanagers() {
1266 throw new coding_exception('Function get_courses_wmanagers() is removed, please use ' .
1267 'core_course_category::get_courses()');
1271 * @deprecated since 2.5
1273 function convert_tree_to_html() {
1274 throw new coding_exception('Function convert_tree_to_html() is removed. Consider using class tabtree and core_renderer::render_tabtree()');
1278 * @deprecated since 2.5
1280 function convert_tabrows_to_tree() {
1281 throw new coding_exception('Function convert_tabrows_to_tree() is removed. Consider using class tabtree');
1285 * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically
1287 function can_use_rotated_text() {
1288 debugging('can_use_rotated_text() is removed. JS feature detection is used automatically.');
1292 * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more.
1294 function get_context_instance_by_id() {
1295 throw new coding_exception('get_context_instance_by_id() is now removed, please use context::instance_by_id($id) instead.');
1299 * Returns system context or null if can not be created yet.
1301 * @see context_system::instance()
1302 * @deprecated since 2.2
1303 * @param bool $cache use caching
1304 * @return context system context (null if context table not created yet)
1306 function get_system_context($cache = true) {
1307 debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER);
1308 return context_system::instance(0, IGNORE_MISSING, $cache);
1312 * @deprecated since 2.2, use $context->get_parent_context_ids() instead
1314 function get_parent_contexts() {
1315 throw new coding_exception('get_parent_contexts() is removed, please use $context->get_parent_context_ids() instead.');
1319 * @deprecated since Moodle 2.2
1321 function get_parent_contextid() {
1322 throw new coding_exception('get_parent_contextid() is removed, please use $context->get_parent_context() instead.');
1326 * @deprecated since 2.2
1328 function get_child_contexts() {
1329 throw new coding_exception('get_child_contexts() is removed, please use $context->get_child_contexts() instead.');
1333 * @deprecated since 2.2
1335 function create_contexts() {
1336 throw new coding_exception('create_contexts() is removed, please use context_helper::create_instances() instead.');
1340 * @deprecated since 2.2
1342 function cleanup_contexts() {
1343 throw new coding_exception('cleanup_contexts() is removed, please use context_helper::cleanup_instances() instead.');
1347 * @deprecated since 2.2
1349 function build_context_path() {
1350 throw new coding_exception('build_context_path() is removed, please use context_helper::build_all_paths() instead.');
1354 * @deprecated since 2.2
1356 function rebuild_contexts() {
1357 throw new coding_exception('rebuild_contexts() is removed, please use $context->reset_paths(true) instead.');
1361 * @deprecated since Moodle 2.2
1363 function preload_course_contexts() {
1364 throw new coding_exception('preload_course_contexts() is removed, please use context_helper::preload_course() instead.');
1368 * @deprecated since Moodle 2.2
1370 function context_moved() {
1371 throw new coding_exception('context_moved() is removed, please use context::update_moved() instead.');
1375 * @deprecated since 2.2
1377 function fetch_context_capabilities() {
1378 throw new coding_exception('fetch_context_capabilities() is removed, please use $context->get_capabilities() instead.');
1382 * @deprecated since 2.2
1384 function context_instance_preload() {
1385 throw new coding_exception('context_instance_preload() is removed, please use context_helper::preload_from_record() instead.');
1389 * @deprecated since 2.2
1391 function get_contextlevel_name() {
1392 throw new coding_exception('get_contextlevel_name() is removed, please use context_helper::get_level_name() instead.');
1396 * @deprecated since 2.2
1398 function print_context_name() {
1399 throw new coding_exception('print_context_name() is removed, please use $context->get_context_name() instead.');
1403 * @deprecated since 2.2, use $context->mark_dirty() instead
1405 function mark_context_dirty() {
1406 throw new coding_exception('mark_context_dirty() is removed, please use $context->mark_dirty() instead.');
1410 * @deprecated since Moodle 2.2
1412 function delete_context() {
1413 throw new coding_exception('delete_context() is removed, please use context_helper::delete_instance() ' .
1414 'or $context->delete_content() instead.');
1418 * @deprecated since 2.2
1420 function get_context_url() {
1421 throw new coding_exception('get_context_url() is removed, please use $context->get_url() instead.');
1425 * @deprecated since 2.2
1427 function get_course_context() {
1428 throw new coding_exception('get_course_context() is removed, please use $context->get_course_context(true) instead.');
1432 * @deprecated since 2.2
1434 function get_user_courses_bycap() {
1435 throw new coding_exception('get_user_courses_bycap() is removed, please use enrol_get_users_courses() instead.');
1439 * @deprecated since Moodle 2.2
1441 function get_role_context_caps() {
1442 throw new coding_exception('get_role_context_caps() is removed, it is really slow. Don\'t use it.');
1446 * @deprecated since 2.2
1448 function get_courseid_from_context() {
1449 throw new coding_exception('get_courseid_from_context() is removed, please use $context->get_course_context(false) instead.');
1453 * @deprecated since 2.2
1455 function context_instance_preload_sql() {
1456 throw new coding_exception('context_instance_preload_sql() is removed, please use context_helper::get_preload_record_columns_sql() instead.');
1460 * @deprecated since 2.2
1462 function get_related_contexts_string() {
1463 throw new coding_exception('get_related_contexts_string() is removed, please use $context->get_parent_context_ids(true) instead.');
1467 * @deprecated since 2.6
1469 function get_plugin_list_with_file() {
1470 throw new coding_exception('get_plugin_list_with_file() is removed, please use core_component::get_plugin_list_with_file() instead.');
1474 * @deprecated since 2.6
1476 function check_browser_operating_system() {
1477 throw new coding_exception('check_browser_operating_system is removed, please update your code to use core_useragent instead.');
1481 * @deprecated since 2.6
1483 function check_browser_version() {
1484 throw new coding_exception('check_browser_version is removed, please update your code to use core_useragent instead.');
1488 * @deprecated since 2.6
1490 function get_device_type() {
1491 throw new coding_exception('get_device_type is removed, please update your code to use core_useragent instead.');
1495 * @deprecated since 2.6
1497 function get_device_type_list() {
1498 throw new coding_exception('get_device_type_list is removed, please update your code to use core_useragent instead.');
1502 * @deprecated since 2.6
1504 function get_selected_theme_for_device_type() {
1505 throw new coding_exception('get_selected_theme_for_device_type is removed, please update your code to use core_useragent instead.');
1509 * @deprecated since 2.6
1511 function get_device_cfg_var_name() {
1512 throw new coding_exception('get_device_cfg_var_name is removed, please update your code to use core_useragent instead.');
1516 * @deprecated since 2.6
1518 function set_user_device_type() {
1519 throw new coding_exception('set_user_device_type is removed, please update your code to use core_useragent instead.');
1523 * @deprecated since 2.6
1525 function get_user_device_type() {
1526 throw new coding_exception('get_user_device_type is removed, please update your code to use core_useragent instead.');
1530 * @deprecated since 2.6
1532 function get_browser_version_classes() {
1533 throw new coding_exception('get_browser_version_classes is removed, please update your code to use core_useragent instead.');
1537 * @deprecated since Moodle 2.6
1539 function generate_email_supportuser() {
1540 throw new coding_exception('generate_email_supportuser is removed, please use core_user::get_support_user');
1544 * @deprecated since Moodle 2.6
1546 function badges_get_issued_badge_info() {
1547 throw new coding_exception('Function badges_get_issued_badge_info() is removed. Please use core_badges_assertion class and methods to generate badge assertion.');
1551 * @deprecated since 2.6
1553 function can_use_html_editor() {
1554 throw new coding_exception('can_use_html_editor is removed, please update your code to assume it returns true.');
1559 * @deprecated since Moodle 2.7, use {@link user_count_login_failures()} instead.
1561 function count_login_failures() {
1562 throw new coding_exception('count_login_failures() can not be used any more, please use user_count_login_failures().');
1566 * @deprecated since 2.7 MDL-33099/MDL-44088 - please do not use this function any more.
1568 function ajaxenabled() {
1569 throw new coding_exception('ajaxenabled() can not be used anymore. Update your code to work with JS at all times.');
1573 * @deprecated Since Moodle 2.7 MDL-44070
1575 function coursemodule_visible_for_user() {
1576 throw new coding_exception('coursemodule_visible_for_user() can not be used any more,
1577 please use \core_availability\info_module::is_user_visible()');
1581 * @deprecated since Moodle 2.8 MDL-36014, MDL-35618 this functionality is removed
1583 function enrol_cohort_get_cohorts() {
1584 throw new coding_exception('Function enrol_cohort_get_cohorts() is removed, use '.
1585 'cohort_get_available_cohorts() instead');
1589 * @deprecated since Moodle 2.8 MDL-36014 please use cohort_can_view_cohort()
1591 function enrol_cohort_can_view_cohort() {
1592 throw new coding_exception('Function enrol_cohort_can_view_cohort() is removed, use cohort_can_view_cohort() instead');
1596 * @deprecated since Moodle 2.8 MDL-36014 use cohort_get_available_cohorts() instead
1598 function cohort_get_visible_list() {
1599 throw new coding_exception('Function cohort_get_visible_list() is removed. Please use function cohort_get_available_cohorts() ".
1600 "that correctly checks capabilities.');
1604 * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
1606 function enrol_cohort_enrol_all_users() {
1607 throw new coding_exception('enrol_cohort_enrol_all_users() is removed. This functionality is moved to enrol_manual.');
1611 * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
1613 function enrol_cohort_search_cohorts() {
1614 throw new coding_exception('enrol_cohort_search_cohorts() is removed. This functionality is moved to enrol_manual.');
1617 /* === Apis deprecated in since Moodle 2.9 === */
1620 * @deprecated since Moodle 2.9 MDL-49371 - please do not use this function any more.
1622 function message_current_user_is_involved() {
1623 throw new coding_exception('message_current_user_is_involved() can not be used any more.');
1627 * @deprecated since Moodle 2.9 MDL-45898 - please do not use this function any more.
1629 function profile_display_badges() {
1630 throw new coding_exception('profile_display_badges() can not be used any more.');
1634 * @deprecated since Moodle 2.9 MDL-45774 - Please do not use this function any more.
1636 function useredit_shared_definition_preferences() {
1637 throw new coding_exception('useredit_shared_definition_preferences() can not be used any more.');
1642 * @deprecated since Moodle 2.9
1644 function calendar_normalize_tz() {
1645 throw new coding_exception('calendar_normalize_tz() can not be used any more, please use core_date::normalise_timezone() instead.');
1649 * @deprecated since Moodle 2.9
1651 function get_user_timezone_offset() {
1652 throw new coding_exception('get_user_timezone_offset() can not be used any more, please use standard PHP DateTimeZone class instead');
1657 * @deprecated since Moodle 2.9
1659 function get_timezone_offset() {
1660 throw new coding_exception('get_timezone_offset() can not be used any more, please use standard PHP DateTimeZone class instead');
1664 * @deprecated since Moodle 2.9
1666 function get_list_of_timezones() {
1667 throw new coding_exception('get_list_of_timezones() can not be used any more, please use core_date::get_list_of_timezones() instead');
1671 * @deprecated since Moodle 2.9
1673 function update_timezone_records() {
1674 throw new coding_exception('update_timezone_records() can not be used any more, please use standard PHP DateTime class instead');
1678 * @deprecated since Moodle 2.9
1680 function calculate_user_dst_table() {
1681 throw new coding_exception('calculate_user_dst_table() can not be used any more, please use standard PHP DateTime class instead');
1685 * @deprecated since Moodle 2.9
1687 function dst_changes_for_year() {
1688 throw new coding_exception('dst_changes_for_year() can not be used any more, please use standard DateTime class instead');
1692 * @deprecated since Moodle 2.9
1694 function get_timezone_record() {
1695 throw new coding_exception('get_timezone_record() can not be used any more, please use standard PHP DateTime class instead');
1698 /* === Apis deprecated since Moodle 3.0 === */
1700 * @deprecated since Moodle 3.0 MDL-49360 - please do not use this function any more.
1702 function get_referer() {
1703 throw new coding_exception('get_referer() can not be used any more. Please use get_local_referer() instead.');
1707 * @deprecated since Moodle 3.0 use \core_useragent::is_web_crawler instead.
1709 function is_web_crawler() {
1710 throw new coding_exception('is_web_crawler() can not be used any more. Please use core_useragent::is_web_crawler() instead.');
1714 * @deprecated since Moodle 3.0 MDL-50287 - please do not use this function any more.
1716 function completion_cron() {
1717 throw new coding_exception('completion_cron() can not be used any more. Functionality has been moved to scheduled tasks.');
1721 * @deprecated since 3.0
1723 function coursetag_get_tags() {
1724 throw new coding_exception('Function coursetag_get_tags() can not be used any more. ' .
1725 'Userid is no longer used for tagging courses.');
1729 * @deprecated since 3.0
1731 function coursetag_get_all_tags() {
1732 throw new coding_exception('Function coursetag_get_all_tags() can not be used any more. Userid is no ' .
1733 'longer used for tagging courses.');
1737 * @deprecated since 3.0
1739 function coursetag_get_jscript() {
1740 throw new coding_exception('Function coursetag_get_jscript() can not be used any more and is obsolete.');
1744 * @deprecated since 3.0
1746 function coursetag_get_jscript_links() {
1747 throw new coding_exception('Function coursetag_get_jscript_links() can not be used any more and is obsolete.');
1751 * @deprecated since 3.0
1753 function coursetag_get_records() {
1754 throw new coding_exception('Function coursetag_get_records() can not be used any more. ' .
1755 'Userid is no longer used for tagging courses.');
1759 * @deprecated since 3.0
1761 function coursetag_store_keywords() {
1762 throw new coding_exception('Function coursetag_store_keywords() can not be used any more. ' .
1763 'Userid is no longer used for tagging courses.');
1767 * @deprecated since 3.0
1769 function coursetag_delete_keyword() {
1770 throw new coding_exception('Function coursetag_delete_keyword() can not be used any more. ' .
1771 'Userid is no longer used for tagging courses.');
1775 * @deprecated since 3.0
1777 function coursetag_get_tagged_courses() {
1778 throw new coding_exception('Function coursetag_get_tagged_courses() can not be used any more. ' .
1779 'Userid is no longer used for tagging courses.');
1783 * @deprecated since 3.0
1785 function coursetag_delete_course_tags() {
1786 throw new coding_exception('Function coursetag_delete_course_tags() is deprecated. ' .
1787 'Use core_tag_tag::remove_all_item_tags().');
1791 * @deprecated since 3.1. Use core_tag_tag::get($tagid)->update() instead
1793 function tag_type_set() {
1794 throw new coding_exception('tag_type_set() can not be used anymore. Please use ' .
1795 'core_tag_tag::get($tagid)->update().');
1799 * @deprecated since 3.1. Use core_tag_tag::get($tagid)->update() instead
1801 function tag_description_set() {
1802 throw new coding_exception('tag_description_set() can not be used anymore. Please use ' .
1803 'core_tag_tag::get($tagid)->update().');
1807 * @deprecated since 3.1. Use core_tag_tag::get_item_tags() instead
1809 function tag_get_tags() {
1810 throw new coding_exception('tag_get_tags() can not be used anymore. Please use ' .
1811 'core_tag_tag::get_item_tags().');
1815 * @deprecated since 3.1
1817 function tag_get_tags_array() {
1818 throw new coding_exception('tag_get_tags_array() can not be used anymore. Please use ' .
1819 'core_tag_tag::get_item_tags_array().');
1823 * @deprecated since 3.1. Use core_tag_tag::get_item_tags_array() or $OUTPUT->tag_list(core_tag_tag::get_item_tags())
1825 function tag_get_tags_csv() {
1826 throw new coding_exception('tag_get_tags_csv() can not be used anymore. Please use ' .
1827 'core_tag_tag::get_item_tags_array() or $OUTPUT->tag_list(core_tag_tag::get_item_tags()).');
1831 * @deprecated since 3.1. Use core_tag_tag::get_item_tags() instead
1833 function tag_get_tags_ids() {
1834 throw new coding_exception('tag_get_tags_ids() can not be used anymore. Please consider using ' .
1835 'core_tag_tag::get_item_tags() or similar methods.');
1839 * @deprecated since 3.1. Use core_tag_tag::get_by_name() or core_tag_tag::get_by_name_bulk()
1841 function tag_get_id() {
1842 throw new coding_exception('tag_get_id() can not be used anymore. Please use ' .
1843 'core_tag_tag::get_by_name() or core_tag_tag::get_by_name_bulk()');
1847 * @deprecated since 3.1. Use core_tag_tag::get($tagid)->update() instead
1849 function tag_rename() {
1850 throw new coding_exception('tag_rename() can not be used anymore. Please use ' .
1851 'core_tag_tag::get($tagid)->update()');
1855 * @deprecated since 3.1. Use core_tag_tag::remove_item_tag() instead
1857 function tag_delete_instance() {
1858 throw new coding_exception('tag_delete_instance() can not be used anymore. Please use ' .
1859 'core_tag_tag::remove_item_tag()');
1863 * @deprecated since 3.1. Use core_tag_tag::get_by_name()->get_tagged_items() instead
1865 function tag_find_records() {
1866 throw new coding_exception('tag_find_records() can not be used anymore. Please use ' .
1867 'core_tag_tag::get_by_name()->get_tagged_items()');
1871 * @deprecated since 3.1
1873 function tag_add() {
1874 throw new coding_exception('tag_add() can not be used anymore. You can use ' .
1875 'core_tag_tag::create_if_missing(), however it should not be necessary since tags are ' .
1876 'created automatically when assigned to items');
1880 * @deprecated since 3.1. Use core_tag_tag::set_item_tags() or core_tag_tag::add_item_tag() instead
1882 function tag_assign() {
1883 throw new coding_exception('tag_assign() can not be used anymore. Please use ' .
1884 'core_tag_tag::set_item_tags() or core_tag_tag::add_item_tag() instead. Tag instance ' .
1885 'ordering should not be set manually');
1889 * @deprecated since 3.1. Use core_tag_tag::get($tagid)->count_tagged_items() instead
1891 function tag_record_count() {
1892 throw new coding_exception('tag_record_count() can not be used anymore. Please use ' .
1893 'core_tag_tag::get($tagid)->count_tagged_items().');
1897 * @deprecated since 3.1. Use core_tag_tag::get($tagid)->is_item_tagged_with() instead
1899 function tag_record_tagged_with() {
1900 throw new coding_exception('tag_record_tagged_with() can not be used anymore. Please use ' .
1901 'core_tag_tag::get($tagid)->is_item_tagged_with().');
1905 * @deprecated since 3.1. Use core_tag_tag::get($tagid)->flag() instead
1907 function tag_set_flag() {
1908 throw new coding_exception('tag_set_flag() can not be used anymore. Please use ' .
1909 'core_tag_tag::get($tagid)->flag()');
1913 * @deprecated since 3.1. Use core_tag_tag::get($tagid)->reset_flag() instead
1915 function tag_unset_flag() {
1916 throw new coding_exception('tag_unset_flag() can not be used anymore. Please use ' .
1917 'core_tag_tag::get($tagid)->reset_flag()');
1921 * @deprecated since 3.1
1923 function tag_print_cloud() {
1924 throw new coding_exception('tag_print_cloud() can not be used anymore. Please use ' .
1925 'core_tag_collection::get_tag_cloud(), templateable core_tag\output\tagcloud and ' .
1926 'template core_tag/tagcloud.');
1930 * @deprecated since 3.0
1932 function tag_autocomplete() {
1933 throw new coding_exception('tag_autocomplete() can not be used anymore. New form ' .
1934 'element "tags" does proper autocomplete.');
1938 * @deprecated since 3.1
1940 function tag_print_description_box() {
1941 throw new coding_exception('tag_print_description_box() can not be used anymore. ' .
1942 'See core_tag_renderer for similar code');
1946 * @deprecated since 3.1
1948 function tag_print_management_box() {
1949 throw new coding_exception('tag_print_management_box() can not be used anymore. ' .
1950 'See core_tag_renderer for similar code');
1954 * @deprecated since 3.1
1956 function tag_print_search_box() {
1957 throw new coding_exception('tag_print_search_box() can not be used anymore. ' .
1958 'See core_tag_renderer for similar code');
1962 * @deprecated since 3.1
1964 function tag_print_search_results() {
1965 throw new coding_exception('tag_print_search_results() can not be used anymore. ' .
1966 'In /tag/search.php the search results are printed using the core_tag/tagcloud template.');
1970 * @deprecated since 3.1
1972 function tag_print_tagged_users_table() {
1973 throw new coding_exception('tag_print_tagged_users_table() can not be used anymore. ' .
1974 'See core_user_renderer for similar code');
1978 * @deprecated since 3.1
1980 function tag_print_user_box() {
1981 throw new coding_exception('tag_print_user_box() can not be used anymore. ' .
1982 'See core_user_renderer for similar code');
1986 * @deprecated since 3.1
1988 function tag_print_user_list() {
1989 throw new coding_exception('tag_print_user_list() can not be used anymore. ' .
1990 'See core_user_renderer for similar code');
1994 * @deprecated since 3.1
1996 function tag_display_name() {
1997 throw new coding_exception('tag_display_name() can not be used anymore. Please use ' .
1998 'core_tag_tag::make_display_name().');
2003 * @deprecated since 3.1
2005 function tag_normalize() {
2006 throw new coding_exception('tag_normalize() can not be used anymore. Please use ' .
2007 'core_tag_tag::normalize().');
2011 * @deprecated since 3.1
2013 function tag_get_related_tags_csv() {
2014 throw new coding_exception('tag_get_related_tags_csv() can not be used anymore. Please ' .
2015 'consider looping through array or using $OUTPUT->tag_list(core_tag_tag::get_item_tags()).');
2019 * @deprecated since 3.1
2021 function tag_set() {
2022 throw new coding_exception('tag_set() can not be used anymore. Please use ' .
2023 'core_tag_tag::set_item_tags().');
2027 * @deprecated since 3.1
2029 function tag_set_add() {
2030 throw new coding_exception('tag_set_add() can not be used anymore. Please use ' .
2031 'core_tag_tag::add_item_tag().');
2035 * @deprecated since 3.1
2037 function tag_set_delete() {
2038 throw new coding_exception('tag_set_delete() can not be used anymore. Please use ' .
2039 'core_tag_tag::remove_item_tag().');
2043 * @deprecated since 3.1
2045 function tag_get() {
2046 throw new coding_exception('tag_get() can not be used anymore. Please use ' .
2047 'core_tag_tag::get() or core_tag_tag::get_by_name().');
2051 * @deprecated since 3.1
2053 function tag_get_related_tags() {
2054 throw new coding_exception('tag_get_related_tags() can not be used anymore. Please use ' .
2055 'core_tag_tag::get_correlated_tags(), core_tag_tag::get_related_tags() or ' .
2056 'core_tag_tag::get_manual_related_tags().');
2060 * @deprecated since 3.1
2062 function tag_delete() {
2063 throw new coding_exception('tag_delete() can not be used anymore. Please use ' .
2064 'core_tag_tag::delete_tags().');
2068 * @deprecated since 3.1
2070 function tag_delete_instances() {
2071 throw new coding_exception('tag_delete_instances() can not be used anymore. Please use ' .
2072 'core_tag_tag::delete_instances().');
2076 * @deprecated since 3.1
2078 function tag_cleanup() {
2079 throw new coding_exception('tag_cleanup() can not be used anymore. Please use ' .
2080 '\core\task\tag_cron_task::cleanup().');
2084 * @deprecated since 3.1
2086 function tag_bulk_delete_instances() {
2087 throw new coding_exception('tag_bulk_delete_instances() can not be used anymore. Please use ' .
2088 '\core\task\tag_cron_task::bulk_delete_instances().');
2093 * @deprecated since 3.1
2095 function tag_compute_correlations() {
2096 throw new coding_exception('tag_compute_correlations() can not be used anymore. Please use ' .
2097 'use \core\task\tag_cron_task::compute_correlations().');
2101 * @deprecated since 3.1
2103 function tag_process_computed_correlation() {
2104 throw new coding_exception('tag_process_computed_correlation() can not be used anymore. Please use ' .
2105 'use \core\task\tag_cron_task::process_computed_correlation().');
2109 * @deprecated since 3.1
2111 function tag_cron() {
2112 throw new coding_exception('tag_cron() can not be used anymore. Please use ' .
2113 'use \core\task\tag_cron_task::execute().');
2117 * @deprecated since 3.1
2119 function tag_find_tags() {
2120 throw new coding_exception('tag_find_tags() can not be used anymore.');
2124 * @deprecated since 3.1
2126 function tag_get_name() {
2127 throw new coding_exception('tag_get_name() can not be used anymore.');
2131 * @deprecated since 3.1
2133 function tag_get_correlated() {
2134 throw new coding_exception('tag_get_correlated() can not be used anymore. Please use ' .
2135 'use core_tag_tag::get_correlated_tags().');
2140 * @deprecated since 3.1
2142 function tag_cloud_sort() {
2143 throw new coding_exception('tag_cloud_sort() can not be used anymore. Similar method can ' .
2144 'be found in core_tag_collection::cloud_sort().');
2148 * @deprecated since Moodle 3.1
2150 function events_load_def() {
2151 throw new coding_exception('events_load_def() has been deprecated along with all Events 1 API in favour of Events 2 API.');
2156 * @deprecated since Moodle 3.1
2158 function events_queue_handler() {
2159 throw new coding_exception('events_queue_handler() has been deprecated along with all Events 1 API in favour of Events 2 API.');
2163 * @deprecated since Moodle 3.1
2165 function events_dispatch() {
2166 throw new coding_exception('events_dispatch() has been deprecated along with all Events 1 API in favour of Events 2 API.');
2170 * @deprecated since Moodle 3.1
2172 function events_process_queued_handler() {
2173 throw new coding_exception(
2174 'events_process_queued_handler() has been deprecated along with all Events 1 API in favour of Events 2 API.'
2179 * @deprecated since Moodle 3.1
2181 function events_update_definition() {
2182 throw new coding_exception(
2183 'events_update_definition has been deprecated along with all Events 1 API in favour of Events 2 API.'
2188 * @deprecated since Moodle 3.1
2190 function events_cron() {
2191 throw new coding_exception('events_cron() has been deprecated along with all Events 1 API in favour of Events 2 API.');
2195 * @deprecated since Moodle 3.1
2197 function events_trigger_legacy() {
2198 throw new coding_exception('events_trigger_legacy() has been deprecated along with all Events 1 API in favour of Events 2 API.');
2202 * @deprecated since Moodle 3.1
2204 function events_is_registered() {
2205 throw new coding_exception('events_is_registered() has been deprecated along with all Events 1 API in favour of Events 2 API.');
2209 * @deprecated since Moodle 3.1
2211 function events_pending_count() {
2212 throw new coding_exception('events_pending_count() has been deprecated along with all Events 1 API in favour of Events 2 API.');
2216 * @deprecated since Moodle 3.0 - this is a part of clamav plugin now.
2218 function clam_message_admins() {
2219 throw new coding_exception('clam_message_admins() can not be used anymore. Please use ' .
2220 'message_admins() method of \antivirus_clamav\scanner class.');
2224 * @deprecated since Moodle 3.0 - this is a part of clamav plugin now.
2226 function get_clam_error_code() {
2227 throw new coding_exception('get_clam_error_code() can not be used anymore. Please use ' .
2228 'get_clam_error_code() method of \antivirus_clamav\scanner class.');
2232 * @deprecated since 3.1
2234 function course_get_cm_rename_action() {
2235 throw new coding_exception('course_get_cm_rename_action() can not be used anymore. Please use ' .
2236 'inplace_editable https://docs.moodle.org/dev/Inplace_editable.');
2241 * @deprecated since Moodle 3.1
2243 function course_scale_used() {
2244 throw new coding_exception('course_scale_used() can not be used anymore. Plugins can ' .
2245 'implement <modname>_scale_used_anywhere, all implementations of <modname>_scale_used are now ignored');
2249 * @deprecated since Moodle 3.1
2251 function site_scale_used() {
2252 throw new coding_exception('site_scale_used() can not be used anymore. Plugins can implement ' .
2253 '<modname>_scale_used_anywhere, all implementations of <modname>_scale_used are now ignored');
2257 * @deprecated since Moodle 3.1. Use external_api::external_function_info().
2259 function external_function_info() {
2260 throw new coding_exception('external_function_info() can not be used any'.
2261 'more. Please use external_api::external_function_info() instead.');
2265 * @deprecated since Moodle 3.2
2266 * @see csv_import_reader::load_csv_content()
2268 function get_records_csv() {
2269 throw new coding_exception('get_records_csv() can not be used anymore. Please use ' .
2270 'lib/csvlib.class.php csv_import_reader() instead.');
2274 * @deprecated since Moodle 3.2
2275 * @see download_as_dataformat (lib/dataformatlib.php)
2277 function put_records_csv() {
2278 throw new coding_exception('put_records_csv() can not be used anymore. Please use ' .
2279 'lib/dataformatlib.php download_as_dataformat() instead.');
2283 * @deprecated since Moodle 3.2
2285 function css_is_colour() {
2286 throw new coding_exception('css_is_colour() can not be used anymore.');
2290 * @deprecated since Moodle 3.2
2292 function css_is_width() {
2293 throw new coding_exception('css_is_width() can not be used anymore.');
2297 * @deprecated since Moodle 3.2
2299 function css_sort_by_count() {
2300 throw new coding_exception('css_sort_by_count() can not be used anymore.');
2304 * @deprecated since Moodle 3.2
2306 function message_get_course_contexts() {
2307 throw new coding_exception('message_get_course_contexts() can not be used anymore.');
2311 * @deprecated since Moodle 3.2
2313 function message_remove_url_params() {
2314 throw new coding_exception('message_remove_url_params() can not be used anymore.');
2318 * @deprecated since Moodle 3.2
2320 function message_count_messages() {
2321 throw new coding_exception('message_count_messages() can not be used anymore.');
2325 * @deprecated since Moodle 3.2
2327 function message_count_blocked_users() {
2328 throw new coding_exception('message_count_blocked_users() can not be used anymore. Please use ' .
2329 '\core_message\api::count_blocked_users() instead.');
2333 * @deprecated since Moodle 3.2
2335 function message_contact_link() {
2336 throw new coding_exception('message_contact_link() can not be used anymore.');
2340 * @deprecated since Moodle 3.2
2342 function message_get_recent_notifications() {
2343 throw new coding_exception('message_get_recent_notifications() can not be used anymore.');
2347 * @deprecated since Moodle 3.2
2349 function message_history_link() {
2350 throw new coding_exception('message_history_link() can not be used anymore.');
2354 * @deprecated since Moodle 3.2
2356 function message_search() {
2357 throw new coding_exception('message_search() can not be used anymore.');
2361 * @deprecated since Moodle 3.2
2363 function message_shorten_message() {
2364 throw new coding_exception('message_shorten_message() can not be used anymore.');
2368 * @deprecated since Moodle 3.2
2370 function message_get_fragment() {
2371 throw new coding_exception('message_get_fragment() can not be used anymore.');
2375 * @deprecated since Moodle 3.2
2377 function message_get_history() {
2378 throw new coding_exception('message_get_history() can not be used anymore.');
2382 * @deprecated since Moodle 3.2
2384 function message_get_contact_add_remove_link() {
2385 throw new coding_exception('message_get_contact_add_remove_link() can not be used anymore.');
2389 * @deprecated since Moodle 3.2
2391 function message_get_contact_block_link() {
2392 throw new coding_exception('message_get_contact_block_link() can not be used anymore.');
2396 * @deprecated since Moodle 3.2
2398 function message_mark_messages_read() {
2399 throw new coding_exception('message_mark_messages_read() can not be used anymore. Please use ' .
2400 '\core_message\api::mark_all_messages_as_read() instead.');
2404 * @deprecated since Moodle 3.2
2406 function message_page_type_list() {
2407 throw new coding_exception('message_page_type_list() can not be used anymore.');
2411 * @deprecated since Moodle 3.2
2413 function message_can_post_message() {
2414 throw new coding_exception('message_can_post_message() can not be used anymore. Please use ' .
2415 '\core_message\api::can_post_message() instead.');
2419 * @deprecated since Moodle 3.2
2421 function message_is_user_non_contact_blocked() {
2422 throw new coding_exception('message_is_user_non_contact_blocked() can not be used anymore. Please use ' .
2423 '\core_message\api::is_user_non_contact_blocked() instead.');
2427 * @deprecated since Moodle 3.2
2429 function message_is_user_blocked() {
2430 throw new coding_exception('message_is_user_blocked() can not be used anymore. Please use ' .
2431 '\core_message\api::is_user_blocked() instead.');
2435 * @deprecated since Moodle 3.2
2437 function print_log() {
2438 throw new coding_exception('print_log() can not be used anymore. Please use the ' .
2439 'report_log framework instead.');
2443 * @deprecated since Moodle 3.2
2445 function print_mnet_log() {
2446 throw new coding_exception('print_mnet_log() can not be used anymore. Please use the ' .
2447 'report_log framework instead.');
2451 * @deprecated since Moodle 3.2
2453 function print_log_csv() {
2454 throw new coding_exception('print_log_csv() can not be used anymore. Please use the ' .
2455 'report_log framework instead.');
2459 * @deprecated since Moodle 3.2
2461 function print_log_xls() {
2462 throw new coding_exception('print_log_xls() can not be used anymore. Please use the ' .
2463 'report_log framework instead.');
2467 * @deprecated since Moodle 3.2
2469 function print_log_ods() {
2470 throw new coding_exception('print_log_ods() can not be used anymore. Please use the ' .
2471 'report_log framework instead.');
2475 * @deprecated since Moodle 3.2
2477 function build_logs_array() {
2478 throw new coding_exception('build_logs_array() can not be used anymore. Please use the ' .
2479 'report_log framework instead.');
2483 * @deprecated since Moodle 3.2
2485 function get_logs_usercourse() {
2486 throw new coding_exception('get_logs_usercourse() can not be used anymore. Please use the ' .
2487 'report_log framework instead.');
2491 * @deprecated since Moodle 3.2
2493 function get_logs_userday() {
2494 throw new coding_exception('get_logs_userday() can not be used anymore. Please use the ' .
2495 'report_log framework instead.');
2499 * @deprecated since Moodle 3.2
2501 function get_logs() {
2502 throw new coding_exception('get_logs() can not be used anymore. Please use the ' .
2503 'report_log framework instead.');
2507 * @deprecated since Moodle 3.2
2509 function prevent_form_autofill_password() {
2510 throw new coding_exception('prevent_form_autofill_password() can not be used anymore.');
2514 * @deprecated since Moodle 3.3 MDL-57370
2516 function message_get_recent_conversations($userorid, $limitfrom = 0, $limitto = 100) {
2517 throw new coding_exception('message_get_recent_conversations() can not be used any more. ' .
2518 'Please use \core_message\api::get_conversations() instead.', DEBUG_DEVELOPER);
2522 * @deprecated since Moodle 3.2
2524 function calendar_preferences_button() {
2525 throw new coding_exception('calendar_preferences_button() can not be used anymore. The calendar ' .
2526 'preferences are now linked to the user preferences page.');
2530 * Return the name of the weekday
2532 * @deprecated since 3.3
2533 * @todo The final deprecation of this function will take place in Moodle 3.7 - see MDL-57617.
2534 * @param string $englishname
2535 * @return string of the weekeday
2537 function calendar_wday_name($englishname) {
2538 debugging(__FUNCTION__ . '() is deprecated and no longer used in core.', DEBUG_DEVELOPER);
2539 return get_string(strtolower($englishname), 'calendar');
2543 * Get the upcoming event block.
2545 * @deprecated since 3.3
2546 * @todo The final deprecation of this function will take place in Moodle 3.7 - see MDL-57617.
2547 * @param array $events list of events
2548 * @param moodle_url|string $linkhref link to event referer
2549 * @param boolean $showcourselink whether links to courses should be shown
2550 * @return string|null $content html block content
2552 function calendar_get_block_upcoming($events, $linkhref = null, $showcourselink = false) {
2553 global $CFG;
2555 debugging(
2556 __FUNCTION__ . '() has been deprecated. ' .
2557 'Please see block_calendar_upcoming::get_content() for the correct API usage.',
2558 DEBUG_DEVELOPER
2561 require_once($CFG->dirroot . '/blocks/moodleblock.class.php');
2562 require_once($CFG->dirroot . '/blocks/calendar_upcoming/block_calendar_upcoming.php');
2563 return block_calendar_upcoming::get_upcoming_content($events, $linkhref, $showcourselink);
2567 * Display month selector options.
2569 * @deprecated since 3.3
2570 * @todo The final deprecation of this function will take place in Moodle 3.7 - see MDL-57617.
2571 * @param string $name for the select element
2572 * @param string|array $selected options for select elements
2574 function calendar_print_month_selector($name, $selected) {
2575 debugging(__FUNCTION__ . '() is deprecated and no longer used in core.', DEBUG_DEVELOPER);
2576 $months = array();
2577 for ($i = 1; $i <= 12; $i++) {
2578 $months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), '%B');
2580 echo html_writer::label(get_string('months'), 'menu'. $name, false, array('class' => 'accesshide'));
2581 echo html_writer::select($months, $name, $selected, false);
2585 * Update calendar subscriptions.
2587 * @deprecated since 3.3
2588 * @todo The final deprecation of this function will take place in Moodle 3.7 - see MDL-57617.
2589 * @return bool
2591 function calendar_cron() {
2592 debugging(__FUNCTION__ . '() is deprecated and should not be used. Please use the core\task\calendar_cron_task instead.',
2593 DEBUG_DEVELOPER);
2595 global $CFG, $DB;
2597 require_once($CFG->dirroot . '/calendar/lib.php');
2598 // In order to execute this we need bennu.
2599 require_once($CFG->libdir.'/bennu/bennu.inc.php');
2601 mtrace('Updating calendar subscriptions:');
2602 cron_trace_time_and_memory();
2604 $time = time();
2605 $subscriptions = $DB->get_records_sql('SELECT * FROM {event_subscriptions} WHERE pollinterval > 0
2606 AND lastupdated + pollinterval < ?', array($time));
2607 foreach ($subscriptions as $sub) {
2608 mtrace("Updating calendar subscription {$sub->name} in course {$sub->courseid}");
2609 try {
2610 $log = calendar_update_subscription_events($sub->id);
2611 mtrace(trim(strip_tags($log)));
2612 } catch (moodle_exception $ex) {
2613 mtrace('Error updating calendar subscription: ' . $ex->getMessage());
2617 mtrace('Finished updating calendar subscriptions.');
2619 return true;
2623 * @deprecated since Moodle 3.4 and removed immediately. MDL-49398.
2625 function load_course_context() {
2626 throw new coding_exception('load_course_context() is removed. Do not use private functions or data structures.');
2630 * @deprecated since Moodle 3.4 and removed immediately. MDL-49398.
2632 function load_role_access_by_context() {
2633 throw new coding_exception('load_role_access_by_context() is removed. Do not use private functions or data structures.');
2637 * @deprecated since Moodle 3.4 and removed immediately. MDL-49398.
2639 function dedupe_user_access() {
2640 throw new coding_exception('dedupe_user_access() is removed. Do not use private functions or data structures.');
2644 * Previous internal API, it was not supposed to be used anywhere.
2645 * Return a nested array showing role assignments
2646 * and all relevant role capabilities for the user.
2648 * [ra] => [/path][roleid]=roleid
2649 * [rdef] => ["$contextpath:$roleid"][capability]=permission
2651 * @access private
2652 * @deprecated since Moodle 3.4. MDL-49398.
2653 * @param int $userid - the id of the user
2654 * @return array access info array
2656 function get_user_access_sitewide($userid) {
2657 debugging('get_user_access_sitewide() is deprecated. Do not use private functions or data structures.', DEBUG_DEVELOPER);
2659 $accessdata = get_user_accessdata($userid);
2660 $accessdata['rdef'] = array();
2661 $roles = array();
2663 foreach ($accessdata['ra'] as $path => $pathroles) {
2664 $roles = array_merge($pathroles, $roles);
2667 $rdefs = get_role_definitions($roles);
2669 foreach ($rdefs as $roleid => $rdef) {
2670 foreach ($rdef as $path => $caps) {
2671 $accessdata['rdef']["$path:$roleid"] = $caps;
2675 return $accessdata;
2679 * Generates the HTML for a miniature calendar.
2681 * @param array $courses list of course to list events from
2682 * @param array $groups list of group
2683 * @param array $users user's info
2684 * @param int|bool $calmonth calendar month in numeric, default is set to false
2685 * @param int|bool $calyear calendar month in numeric, default is set to false
2686 * @param string|bool $placement the place/page the calendar is set to appear - passed on the the controls function
2687 * @param int|bool $courseid id of the course the calendar is displayed on - passed on the the controls function
2688 * @param int $time the unixtimestamp representing the date we want to view, this is used instead of $calmonth
2689 * and $calyear to support multiple calendars
2690 * @return string $content return html table for mini calendar
2691 * @deprecated since Moodle 3.4. MDL-59333
2693 function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyear = false, $placement = false,
2694 $courseid = false, $time = 0) {
2695 global $PAGE;
2697 debugging('calendar_get_mini() has been deprecated. Please update your code to use calendar_get_view.',
2698 DEBUG_DEVELOPER);
2700 if (!empty($calmonth) && !empty($calyear)) {
2701 // Do this check for backwards compatibility.
2702 // The core should be passing a timestamp rather than month and year.
2703 // If a month and year are passed they will be in Gregorian.
2704 // Ensure it is a valid date, else we will just set it to the current timestamp.
2705 if (checkdate($calmonth, 1, $calyear)) {
2706 $time = make_timestamp($calyear, $calmonth, 1);
2707 } else {
2708 $time = time();
2710 } else if (empty($time)) {
2711 // Get the current date in the calendar type being used.
2712 $time = time();
2715 if ($courseid == SITEID) {
2716 $course = get_site();
2717 } else {
2718 $course = get_course($courseid);
2720 $calendar = new calendar_information(0, 0, 0, $time);
2721 $calendar->prepare_for_view($course, $courses);
2723 $renderer = $PAGE->get_renderer('core_calendar');
2724 list($data, $template) = calendar_get_view($calendar, 'mini');
2725 return $renderer->render_from_template($template, $data);
2729 * Gets the calendar upcoming event.
2731 * @param array $courses array of courses
2732 * @param array|int|bool $groups array of groups, group id or boolean for all/no group events
2733 * @param array|int|bool $users array of users, user id or boolean for all/no user events
2734 * @param int $daysinfuture number of days in the future we 'll look
2735 * @param int $maxevents maximum number of events
2736 * @param int $fromtime start time
2737 * @return array $output array of upcoming events
2738 * @deprecated since Moodle 3.4. MDL-59333
2740 function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime=0) {
2741 debugging(
2742 'calendar_get_upcoming() has been deprecated. ' .
2743 'Please see block_calendar_upcoming::get_content() for the correct API usage.',
2744 DEBUG_DEVELOPER
2747 global $COURSE;
2749 $display = new \stdClass;
2750 $display->range = $daysinfuture; // How many days in the future we 'll look.
2751 $display->maxevents = $maxevents;
2753 $output = array();
2755 $processed = 0;
2756 $now = time(); // We 'll need this later.
2757 $usermidnighttoday = usergetmidnight($now);
2759 if ($fromtime) {
2760 $display->tstart = $fromtime;
2761 } else {
2762 $display->tstart = $usermidnighttoday;
2765 // This works correctly with respect to the user's DST, but it is accurate
2766 // only because $fromtime is always the exact midnight of some day!
2767 $display->tend = usergetmidnight($display->tstart + DAYSECS * $display->range + 3 * HOURSECS) - 1;
2769 // Get the events matching our criteria.
2770 $events = calendar_get_legacy_events($display->tstart, $display->tend, $users, $groups, $courses);
2772 // This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after
2773 // possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month
2774 // will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra
2775 // arguments to this function.
2776 $hrefparams = array();
2777 if (!empty($courses)) {
2778 $courses = array_diff($courses, array(SITEID));
2779 if (count($courses) == 1) {
2780 $hrefparams['course'] = reset($courses);
2784 if ($events !== false) {
2785 foreach ($events as $event) {
2786 if (!empty($event->modulename)) {
2787 $instances = get_fast_modinfo($event->courseid)->get_instances_of($event->modulename);
2788 if (empty($instances[$event->instance]->uservisible)) {
2789 continue;
2793 if ($processed >= $display->maxevents) {
2794 break;
2797 $event->time = calendar_format_event_time($event, $now, $hrefparams);
2798 $output[] = $event;
2799 $processed++;
2803 return $output;
2807 * Creates a record in the role_allow_override table
2809 * @param int $sroleid source roleid
2810 * @param int $troleid target roleid
2811 * @return void
2812 * @deprecated since Moodle 3.4. MDL-50666
2814 function allow_override($sroleid, $troleid) {
2815 debugging('allow_override() has been deprecated. Please update your code to use core_role_set_override_allowed.',
2816 DEBUG_DEVELOPER);
2818 core_role_set_override_allowed($sroleid, $troleid);
2822 * Creates a record in the role_allow_assign table
2824 * @param int $fromroleid source roleid
2825 * @param int $targetroleid target roleid
2826 * @return void
2827 * @deprecated since Moodle 3.4. MDL-50666
2829 function allow_assign($fromroleid, $targetroleid) {
2830 debugging('allow_assign() has been deprecated. Please update your code to use core_role_set_assign_allowed.',
2831 DEBUG_DEVELOPER);
2833 core_role_set_assign_allowed($fromroleid, $targetroleid);
2837 * Creates a record in the role_allow_switch table
2839 * @param int $fromroleid source roleid
2840 * @param int $targetroleid target roleid
2841 * @return void
2842 * @deprecated since Moodle 3.4. MDL-50666
2844 function allow_switch($fromroleid, $targetroleid) {
2845 debugging('allow_switch() has been deprecated. Please update your code to use core_role_set_switch_allowed.',
2846 DEBUG_DEVELOPER);
2848 core_role_set_switch_allowed($fromroleid, $targetroleid);
2852 * Organise categories into a single parent category (called the 'Top' category) per context.
2854 * @param array $categories List of question categories in the format of ["$categoryid,$contextid" => $category].
2855 * @param array $pcontexts List of context ids.
2856 * @return array
2857 * @deprecated since Moodle 3.5. MDL-61132
2859 function question_add_tops($categories, $pcontexts) {
2860 debugging('question_add_tops() has been deprecated. You may want to pass $top = true to get_categories_for_contexts().',
2861 DEBUG_DEVELOPER);
2863 $topcats = array();
2864 foreach ($pcontexts as $contextid) {
2865 $topcat = question_get_top_category($contextid, true);
2866 $context = context::instance_by_id($contextid);
2868 $newcat = new stdClass();
2869 $newcat->id = "{$topcat->id},$contextid";
2870 $newcat->name = get_string('topfor', 'question', $context->get_context_name(false));
2871 $newcat->parent = 0;
2872 $newcat->contextid = $contextid;
2873 $topcats["{$topcat->id},$contextid"] = $newcat;
2875 // Put topcats in at beginning of array - they'll be sorted into different contexts later.
2876 return array_merge($topcats, $categories);
2880 * Checks if the question category is the highest-level category in the context that can be edited, and has no siblings.
2882 * @param int $categoryid a category id.
2883 * @return bool
2884 * @deprecated since Moodle 3.5. MDL-61132
2886 function question_is_only_toplevel_category_in_context($categoryid) {
2887 debugging('question_is_only_toplevel_category_in_context() has been deprecated. '
2888 . 'Please update your code to use question_is_only_child_of_top_category_in_context() instead.',
2889 DEBUG_DEVELOPER);
2891 return question_is_only_child_of_top_category_in_context($categoryid);
2895 * Moves messages from a particular user from the message table (unread messages) to message_read
2896 * This is typically only used when a user is deleted
2898 * @param object $userid User id
2899 * @return boolean success
2900 * @deprecated since Moodle 3.5
2902 function message_move_userfrom_unread2read($userid) {
2903 debugging('message_move_userfrom_unread2read() is deprecated and is no longer used.', DEBUG_DEVELOPER);
2905 global $DB;
2907 // Move all unread messages from message table to message_read.
2908 if ($messages = $DB->get_records_select('message', 'useridfrom = ?', array($userid), 'timecreated')) {
2909 foreach ($messages as $message) {
2910 message_mark_message_read($message, 0); // Set timeread to 0 as the message was never read.
2913 return true;
2917 * Retrieve users blocked by $user1
2919 * @param object $user1 the user whose messages are being viewed
2920 * @param object $user2 the user $user1 is talking to. If they are being blocked
2921 * they will have a variable called 'isblocked' added to their user object
2922 * @return array the users blocked by $user1
2923 * @deprecated since Moodle 3.5
2925 function message_get_blocked_users($user1=null, $user2=null) {
2926 debugging('message_get_blocked_users() is deprecated, please use \core_message\api::get_blocked_users() instead.',
2927 DEBUG_DEVELOPER);
2929 global $USER;
2931 if (empty($user1)) {
2932 $user1 = new stdClass();
2933 $user1->id = $USER->id;
2936 return \core_message\api::get_blocked_users($user1->id);
2940 * Retrieve $user1's contacts (online, offline and strangers)
2942 * @param object $user1 the user whose messages are being viewed
2943 * @param object $user2 the user $user1 is talking to. If they are a contact
2944 * they will have a variable called 'iscontact' added to their user object
2945 * @return array containing 3 arrays. array($onlinecontacts, $offlinecontacts, $strangers)
2946 * @deprecated since Moodle 3.5
2948 function message_get_contacts($user1=null, $user2=null) {
2949 debugging('message_get_contacts() is deprecated and is no longer used.', DEBUG_DEVELOPER);
2951 global $DB, $CFG, $USER;
2953 if (empty($user1)) {
2954 $user1 = $USER;
2957 if (!empty($user2)) {
2958 $user2->iscontact = false;
2961 $timetoshowusers = 300; // Seconds default.
2962 if (isset($CFG->block_online_users_timetosee)) {
2963 $timetoshowusers = $CFG->block_online_users_timetosee * 60;
2966 // Rime which a user is counting as being active since.
2967 $timefrom = time() - $timetoshowusers;
2969 // People in our contactlist who are online.
2970 $onlinecontacts = array();
2971 // People in our contactlist who are offline.
2972 $offlinecontacts = array();
2973 // People who are not in our contactlist but have sent us a message.
2974 $strangers = array();
2976 // Get all in our contact list who are not blocked in our and count messages we have waiting from each of them.
2977 $rs = \core_message\api::get_contacts_with_unread_message_count($user1->id);
2978 foreach ($rs as $rd) {
2979 if ($rd->lastaccess >= $timefrom) {
2980 // They have been active recently, so are counted online.
2981 $onlinecontacts[] = $rd;
2983 } else {
2984 $offlinecontacts[] = $rd;
2987 if (!empty($user2) && $user2->id == $rd->id) {
2988 $user2->iscontact = true;
2992 // Get messages from anyone who isn't in our contact list and count the number of messages we have from each of them.
2993 $rs = \core_message\api::get_non_contacts_with_unread_message_count($user1->id);
2994 // Add user id as array index, so supportuser and noreply user don't get duplicated (if they are real users).
2995 foreach ($rs as $rd) {
2996 $strangers[$rd->id] = $rd;
2999 // Add noreply user and support user to the list, if they don't exist.
3000 $supportuser = core_user::get_support_user();
3001 if (!isset($strangers[$supportuser->id]) && !$supportuser->deleted) {
3002 $supportuser->messagecount = message_count_unread_messages($USER, $supportuser);
3003 if ($supportuser->messagecount > 0) {
3004 $strangers[$supportuser->id] = $supportuser;
3008 $noreplyuser = core_user::get_noreply_user();
3009 if (!isset($strangers[$noreplyuser->id]) && !$noreplyuser->deleted) {
3010 $noreplyuser->messagecount = message_count_unread_messages($USER, $noreplyuser);
3011 if ($noreplyuser->messagecount > 0) {
3012 $strangers[$noreplyuser->id] = $noreplyuser;
3016 return array($onlinecontacts, $offlinecontacts, $strangers);
3020 * Mark a single message as read
3022 * @param stdClass $message An object with an object property ie $message->id which is an id in the message table
3023 * @param int $timeread the timestamp for when the message should be marked read. Usually time().
3024 * @param bool $messageworkingempty Is the message_working table already confirmed empty for this message?
3025 * @return int the ID of the message in the messags table
3026 * @deprecated since Moodle 3.5
3028 function message_mark_message_read($message, $timeread, $messageworkingempty=false) {
3029 debugging('message_mark_message_read() is deprecated, please use \core_message\api::mark_message_as_read()
3030 or \core_message\api::mark_notification_as_read().', DEBUG_DEVELOPER);
3032 if (!empty($message->notification)) {
3033 \core_message\api::mark_notification_as_read($message, $timeread);
3034 } else {
3035 \core_message\api::mark_message_as_read($message->useridto, $message, $timeread);
3038 return $message->id;
3043 * Checks if a user can delete a message.
3045 * @param stdClass $message the message to delete
3046 * @param string $userid the user id of who we want to delete the message for (this may be done by the admin
3047 * but will still seem as if it was by the user)
3048 * @return bool Returns true if a user can delete the message, false otherwise.
3049 * @deprecated since Moodle 3.5
3051 function message_can_delete_message($message, $userid) {
3052 debugging('message_can_delete_message() is deprecated, please use \core_message\api::can_delete_message() instead.',
3053 DEBUG_DEVELOPER);
3055 return \core_message\api::can_delete_message($userid, $message->id);
3059 * Deletes a message.
3061 * This function does not verify any permissions.
3063 * @param stdClass $message the message to delete
3064 * @param string $userid the user id of who we want to delete the message for (this may be done by the admin
3065 * but will still seem as if it was by the user)
3066 * @return bool
3067 * @deprecated since Moodle 3.5
3069 function message_delete_message($message, $userid) {
3070 debugging('message_delete_message() is deprecated, please use \core_message\api::delete_message() instead.',
3071 DEBUG_DEVELOPER);
3073 return \core_message\api::delete_message($userid, $message->id);
3077 * Get all of the allowed types for all of the courses and groups
3078 * the logged in user belongs to.
3080 * The returned array will optionally have 5 keys:
3081 * 'user' : true if the logged in user can create user events
3082 * 'site' : true if the logged in user can create site events
3083 * 'category' : array of course categories that the user can create events for
3084 * 'course' : array of courses that the user can create events for
3085 * 'group': array of groups that the user can create events for
3086 * 'groupcourses' : array of courses that the groups belong to (can
3087 * be different from the list in 'course'.
3088 * @deprecated since 3.6
3089 * @return array The array of allowed types.
3091 function calendar_get_all_allowed_types() {
3092 debugging('calendar_get_all_allowed_types() is deprecated. Please use calendar_get_allowed_types() instead.',
3093 DEBUG_DEVELOPER);
3095 global $CFG, $USER, $DB;
3097 require_once($CFG->libdir . '/enrollib.php');
3099 $types = [];
3101 $allowed = new stdClass();
3103 calendar_get_allowed_types($allowed);
3105 if ($allowed->user) {
3106 $types['user'] = true;
3109 if ($allowed->site) {
3110 $types['site'] = true;
3113 if (core_course_category::has_manage_capability_on_any()) {
3114 $types['category'] = core_course_category::make_categories_list('moodle/category:manage');
3117 // This function warms the context cache for the course so the calls
3118 // to load the course context in calendar_get_allowed_types don't result
3119 // in additional DB queries.
3120 $courses = calendar_get_default_courses(null, 'id, groupmode, groupmodeforce', true);
3122 // We want to pre-fetch all of the groups for each course in a single
3123 // query to avoid calendar_get_allowed_types from hitting the DB for
3124 // each separate course.
3125 $groups = groups_get_all_groups_for_courses($courses);
3127 foreach ($courses as $course) {
3128 $coursegroups = isset($groups[$course->id]) ? $groups[$course->id] : null;
3129 calendar_get_allowed_types($allowed, $course, $coursegroups);
3131 if (!empty($allowed->courses)) {
3132 $types['course'][$course->id] = $course;
3135 if (!empty($allowed->groups)) {
3136 $types['groupcourses'][$course->id] = $course;
3138 if (!isset($types['group'])) {
3139 $types['group'] = array_values($allowed->groups);
3140 } else {
3141 $types['group'] = array_merge($types['group'], array_values($allowed->groups));
3146 return $types;
3150 * Gets array of all groups in a set of course.
3152 * @category group
3153 * @param array $courses Array of course objects or course ids.
3154 * @return array Array of groups indexed by course id.
3156 function groups_get_all_groups_for_courses($courses) {
3157 global $DB;
3159 if (empty($courses)) {
3160 return [];
3163 $groups = [];
3164 $courseids = [];
3166 foreach ($courses as $course) {
3167 $courseid = is_object($course) ? $course->id : $course;
3168 $groups[$courseid] = [];
3169 $courseids[] = $courseid;
3172 $groupfields = [
3173 'g.id as gid',
3174 'g.courseid',
3175 'g.idnumber',
3176 'g.name',
3177 'g.description',
3178 'g.descriptionformat',
3179 'g.enrolmentkey',
3180 'g.picture',
3181 'g.hidepicture',
3182 'g.timecreated',
3183 'g.timemodified'
3186 $groupsmembersfields = [
3187 'gm.id as gmid',
3188 'gm.groupid',
3189 'gm.userid',
3190 'gm.timeadded',
3191 'gm.component',
3192 'gm.itemid'
3195 $concatidsql = $DB->sql_concat_join("'-'", ['g.id', 'COALESCE(gm.id, 0)']) . ' AS uniqid';
3196 list($courseidsql, $params) = $DB->get_in_or_equal($courseids);
3197 $groupfieldssql = implode(',', $groupfields);
3198 $groupmembersfieldssql = implode(',', $groupsmembersfields);
3199 $sql = "SELECT {$concatidsql}, {$groupfieldssql}, {$groupmembersfieldssql}
3200 FROM {groups} g
3201 LEFT JOIN {groups_members} gm
3202 ON gm.groupid = g.id
3203 WHERE g.courseid {$courseidsql}";
3205 $results = $DB->get_records_sql($sql, $params);
3207 // The results will come back as a flat dataset thanks to the left
3208 // join so we will need to do some post processing to blow it out
3209 // into a more usable data structure.
3211 // This loop will extract the distinct groups from the result set
3212 // and add it's list of members to the object as a property called
3213 // 'members'. Then each group will be added to the result set indexed
3214 // by it's course id.
3216 // The resulting data structure for $groups should be:
3217 // $groups = [
3218 // '1' = [
3219 // '1' => (object) [
3220 // 'id' => 1,
3221 // <rest of group properties>
3222 // 'members' => [
3223 // '1' => (object) [
3224 // <group member properties>
3225 // ],
3226 // '2' => (object) [
3227 // <group member properties>
3228 // ]
3229 // ]
3230 // ],
3231 // '2' => (object) [
3232 // 'id' => 2,
3233 // <rest of group properties>
3234 // 'members' => [
3235 // '1' => (object) [
3236 // <group member properties>
3237 // ],
3238 // '3' => (object) [
3239 // <group member properties>
3240 // ]
3241 // ]
3242 // ]
3243 // ]
3244 // ]
3246 foreach ($results as $key => $result) {
3247 $groupid = $result->gid;
3248 $courseid = $result->courseid;
3249 $coursegroups = $groups[$courseid];
3250 $groupsmembersid = $result->gmid;
3251 $reducefunc = function($carry, $field) use ($result) {
3252 // Iterate over the groups properties and pull
3253 // them out into a separate object.
3254 list($prefix, $field) = explode('.', $field);
3256 if (property_exists($result, $field)) {
3257 $carry[$field] = $result->{$field};
3260 return $carry;
3263 if (isset($coursegroups[$groupid])) {
3264 $group = $coursegroups[$groupid];
3265 } else {
3266 $initial = [
3267 'id' => $groupid,
3268 'members' => []
3270 $group = (object) array_reduce(
3271 $groupfields,
3272 $reducefunc,
3273 $initial
3277 if (!empty($groupsmembersid)) {
3278 $initial = ['id' => $groupsmembersid];
3279 $groupsmembers = (object) array_reduce(
3280 $groupsmembersfields,
3281 $reducefunc,
3282 $initial
3285 $group->members[$groupsmembers->userid] = $groupsmembers;
3288 $coursegroups[$groupid] = $group;
3289 $groups[$courseid] = $coursegroups;
3292 return $groups;
3296 * Gets the capabilities that have been cached in the database for this
3297 * component.
3298 * @deprecated since Moodle 3.6. Please use the Events 2 API.
3299 * @todo final deprecation. To be removed in Moodle 4.0
3301 * @access protected To be used from eventslib only
3303 * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
3304 * @return array of events
3306 function events_get_cached($component) {
3307 global $DB;
3309 debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
3310 DEBUG_DEVELOPER);
3312 $cachedhandlers = array();
3314 if ($storedhandlers = $DB->get_records('events_handlers', array('component'=>$component))) {
3315 foreach ($storedhandlers as $handler) {
3316 $cachedhandlers[$handler->eventname] = array (
3317 'id' => $handler->id,
3318 'handlerfile' => $handler->handlerfile,
3319 'handlerfunction' => $handler->handlerfunction,
3320 'schedule' => $handler->schedule,
3321 'internal' => $handler->internal);
3325 return $cachedhandlers;
3329 * Remove all event handlers and queued events
3330 * @deprecated since Moodle 3.6. Please use the Events 2 API.
3331 * @todo final deprecation. To be removed in Moodle 4.0
3333 * @category event
3334 * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
3336 function events_uninstall($component) {
3337 debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
3338 DEBUG_DEVELOPER);
3339 $cachedhandlers = events_get_cached($component);
3340 events_cleanup($component, $cachedhandlers);
3342 events_get_handlers('reset');
3346 * Deletes cached events that are no longer needed by the component.
3347 * @deprecated since Moodle 3.6. Please use the Events 2 API.
3348 * @todo final deprecation. To be removed in Moodle 4.0
3350 * @access protected To be used from eventslib only
3352 * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
3353 * @param array $cachedhandlers array of the cached events definitions that will be
3354 * @return int number of unused handlers that have been removed
3356 function events_cleanup($component, $cachedhandlers) {
3357 global $DB;
3358 debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
3359 DEBUG_DEVELOPER);
3360 $deletecount = 0;
3361 foreach ($cachedhandlers as $eventname => $cachedhandler) {
3362 if ($qhandlers = $DB->get_records('events_queue_handlers', array('handlerid'=>$cachedhandler['id']))) {
3363 //debugging("Removing pending events from queue before deleting of event handler: $component - $eventname");
3364 foreach ($qhandlers as $qhandler) {
3365 events_dequeue($qhandler);
3368 $DB->delete_records('events_handlers', array('eventname'=>$eventname, 'component'=>$component));
3369 $deletecount++;
3372 return $deletecount;
3376 * Removes this queued handler from the events_queued_handler table
3378 * Removes events_queue record from events_queue if no more references to this event object exists
3379 * @deprecated since Moodle 3.6. Please use the Events 2 API.
3380 * @todo final deprecation. To be removed in Moodle 4.0
3382 * @access protected To be used from eventslib only
3384 * @param stdClass $qhandler A row from the events_queued_handler table
3386 function events_dequeue($qhandler) {
3387 global $DB;
3388 debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
3389 DEBUG_DEVELOPER);
3390 // first delete the queue handler
3391 $DB->delete_records('events_queue_handlers', array('id'=>$qhandler->id));
3393 // if no more queued handler is pointing to the same event - delete the event too
3394 if (!$DB->record_exists('events_queue_handlers', array('queuedeventid'=>$qhandler->queuedeventid))) {
3395 $DB->delete_records('events_queue', array('id'=>$qhandler->queuedeventid));
3400 * Returns handlers for given event. Uses caching for better perf.
3401 * @deprecated since Moodle 3.6. Please use the Events 2 API.
3402 * @todo final deprecation. To be removed in Moodle 4.0
3404 * @access protected To be used from eventslib only
3406 * @staticvar array $handlers
3407 * @param string $eventname name of event or 'reset'
3408 * @return array|false array of handlers or false otherwise
3410 function events_get_handlers($eventname) {
3411 global $DB;
3412 static $handlers = array();
3413 debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
3414 DEBUG_DEVELOPER);
3416 if ($eventname === 'reset') {
3417 $handlers = array();
3418 return false;
3421 if (!array_key_exists($eventname, $handlers)) {
3422 $handlers[$eventname] = $DB->get_records('events_handlers', array('eventname'=>$eventname));
3425 return $handlers[$eventname];
3429 * This function finds the roles assigned directly to this context only
3430 * i.e. no roles in parent contexts
3432 * @deprecated since Moodle 3.6. Please use the get_roles_used_in_context().
3433 * @todo final deprecation. To be removed in Moodle 4.0
3434 * @param context $context
3435 * @return array
3437 function get_roles_on_exact_context(context $context) {
3438 debugging('get_roles_on_exact_context() is deprecated, please use get_roles_used_in_context() instead.',
3439 DEBUG_DEVELOPER);
3441 return get_roles_used_in_context($context, false);
3445 * Find out which roles has assignment on this context
3447 * @deprecated since Moodle 3.6. Please use the get_roles_used_in_context().
3448 * @todo final deprecation. To be removed in Moodle 4.0
3449 * @param context $context
3450 * @return array
3452 function get_roles_with_assignment_on_context(context $context) {
3453 debugging('get_roles_with_assignment_on_context() is deprecated, please use get_roles_used_in_context() instead.',
3454 DEBUG_DEVELOPER);
3456 return get_roles_used_in_context($context, false);
3460 * Add the selected user as a contact for the current user
3462 * @deprecated since Moodle 3.6
3463 * @param int $contactid the ID of the user to add as a contact
3464 * @param int $blocked 1 if you wish to block the contact
3465 * @param int $userid the user ID of the user we want to add the contact for, defaults to current user if not specified.
3466 * @return bool/int false if the $contactid isnt a valid user id. True if no changes made.
3467 * Otherwise returns the result of update_record() or insert_record()
3469 function message_add_contact($contactid, $blocked = 0, $userid = 0) {
3470 debugging('message_add_contact() is deprecated. Please use \core_message\api::create_contact_request() instead. ' .
3471 'If you wish to block or unblock a user please use \core_message\api::is_blocked() and ' .
3472 '\core_message\api::block_user() or \core_message\api::unblock_user() respectively.', DEBUG_DEVELOPER);
3474 global $USER, $DB;
3476 if (!$DB->record_exists('user', array('id' => $contactid))) {
3477 return false;
3480 if (empty($userid)) {
3481 $userid = $USER->id;
3484 // Check if a record already exists as we may be changing blocking status.
3485 if (\core_message\api::is_contact($userid, $contactid)) {
3486 $isblocked = \core_message\api::is_blocked($userid, $contactid);
3487 // Check if blocking status has been changed.
3488 if ($isblocked != $blocked) {
3489 if ($blocked == 1) {
3490 if (!$isblocked) {
3491 \core_message\api::block_user($userid, $contactid);
3493 } else {
3494 \core_message\api::unblock_user($userid, $contactid);
3497 return true;
3498 } else {
3499 // No change to blocking status.
3500 return true;
3502 } else {
3503 if ($blocked == 1) {
3504 if (!\core_message\api::is_blocked($userid, $contactid)) {
3505 \core_message\api::block_user($userid, $contactid);
3507 } else {
3508 \core_message\api::unblock_user($userid, $contactid);
3509 if (!\core_message\api::does_contact_request_exist($userid, $contactid)) {
3510 \core_message\api::create_contact_request($userid, $contactid);
3514 return true;
3519 * Remove a contact.
3521 * @deprecated since Moodle 3.6
3522 * @param int $contactid the user ID of the contact to remove
3523 * @param int $userid the user ID of the user we want to remove the contacts for, defaults to current user if not specified.
3524 * @return bool returns the result of delete_records()
3526 function message_remove_contact($contactid, $userid = 0) {
3527 debugging('message_remove_contact() is deprecated. Please use \core_message\api::remove_contact() instead.',
3528 DEBUG_DEVELOPER);
3530 global $USER;
3532 if (empty($userid)) {
3533 $userid = $USER->id;
3536 \core_message\api::remove_contact($userid, $contactid);
3538 return true;
3542 * Unblock a contact.
3544 * @deprecated since Moodle 3.6
3545 * @param int $contactid the user ID of the contact to unblock
3546 * @param int $userid the user ID of the user we want to unblock the contact for, defaults to current user
3547 * if not specified.
3548 * @return bool returns the result of delete_records()
3550 function message_unblock_contact($contactid, $userid = 0) {
3551 debugging('message_unblock_contact() is deprecated. Please use \core_message\api::unblock_user() instead.',
3552 DEBUG_DEVELOPER);
3554 global $DB, $USER;
3556 if (!$DB->record_exists('user', array('id' => $contactid))) {
3557 return false;
3560 if (empty($userid)) {
3561 $userid = $USER->id;
3564 \core_message\api::unblock_user($userid, $contactid);
3566 return true;
3570 * Block a user.
3572 * @deprecated since Moodle 3.6
3573 * @param int $contactid the user ID of the user to block
3574 * @param int $userid the user ID of the user we want to unblock the contact for, defaults to current user
3575 * if not specified.
3576 * @return bool
3578 function message_block_contact($contactid, $userid = 0) {
3579 debugging('message_block_contact() is deprecated. Please use \core_message\api::is_blocked() and ' .
3580 '\core_message\api::block_user() instead.', DEBUG_DEVELOPER);
3582 global $DB, $USER;
3584 if (!$DB->record_exists('user', array('id' => $contactid))) {
3585 return false;
3588 if (empty($userid)) {
3589 $userid = $USER->id;
3592 if (!\core_message\api::is_blocked($userid, $contactid)) {
3593 \core_message\api::block_user($userid, $contactid);
3596 return true;
3600 * Load a user's contact record
3602 * @deprecated since Moodle 3.6
3603 * @param int $contactid the user ID of the user whose contact record you want
3604 * @return array message contacts
3606 function message_get_contact($contactid) {
3607 debugging('message_get_contact() is deprecated. Please use \core_message\api::get_contact() instead.',
3608 DEBUG_DEVELOPER);
3610 global $USER;
3612 return \core_message\api::get_contact($USER->id, $contactid);
3616 * Returns list of courses, for whole site, or category
3618 * Similar to get_courses, but allows paging
3619 * Important: Using c.* for fields is extremely expensive because
3620 * we are using distinct. You almost _NEVER_ need all the fields
3621 * in such a large SELECT
3623 * @deprecated since Moodle 3.7
3624 * @todo The final deprecation of this function will take place in Moodle 41 - see MDL-65319.
3626 * @param string|int $categoryid Either a category id or 'all' for everything
3627 * @param string $sort A field and direction to sort by
3628 * @param string $fields The additional fields to return
3629 * @param int $totalcount Reference for the number of courses
3630 * @param string $limitfrom The course to start from
3631 * @param string $limitnum The number of courses to limit to
3632 * @return array Array of courses
3634 function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c.*",
3635 &$totalcount, $limitfrom="", $limitnum="") {
3636 debugging('Function get_courses_page() is deprecated. Please use core_course_category::get_courses() ' .
3637 'or core_course_category::search_courses()', DEBUG_DEVELOPER);
3638 global $USER, $CFG, $DB;
3640 $params = array();
3642 $categoryselect = "";
3643 if ($categoryid !== "all" && is_numeric($categoryid)) {
3644 $categoryselect = "WHERE c.category = :catid";
3645 $params['catid'] = $categoryid;
3646 } else {
3647 $categoryselect = "";
3650 $ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
3651 $ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
3652 $params['contextlevel'] = CONTEXT_COURSE;
3654 $totalcount = 0;
3655 if (!$limitfrom) {
3656 $limitfrom = 0;
3658 $visiblecourses = array();
3660 $sql = "SELECT $fields $ccselect
3661 FROM {course} c
3662 $ccjoin
3663 $categoryselect
3664 ORDER BY $sort";
3666 // Pull out all course matching the cat.
3667 $rs = $DB->get_recordset_sql($sql, $params);
3668 // Iteration will have to be done inside loop to keep track of the limitfrom and limitnum.
3669 foreach ($rs as $course) {
3670 context_helper::preload_from_record($course);
3671 if (core_course_category::can_view_course_info($course)) {
3672 $totalcount++;
3673 if ($totalcount > $limitfrom && (!$limitnum or count($visiblecourses) < $limitnum)) {
3674 $visiblecourses [$course->id] = $course;
3678 $rs->close();
3679 return $visiblecourses;
3683 * Returns the models that generated insights in the provided context.
3685 * @deprecated since Moodle 3.8 MDL-66091 - please do not use this function any more.
3686 * @todo MDL-65799 This will be deleted in Moodle 4.2
3687 * @see \core_analytics\manager::cached_models_with_insights
3688 * @param \context $context
3689 * @return int[]
3691 function report_insights_context_insights(\context $context) {
3693 debugging('report_insights_context_insights is deprecated. Please use ' .
3694 '\core_analytics\manager::cached_models_with_insights instead', DEBUG_DEVELOPER);
3696 return \core_analytics\manager::cached_models_with_insights($context);