3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * deprecatedlib.php - Old functions retained only for backward compatibility
21 * Old functions retained only for backward compatibility. New code should not
22 * use any of these functions.
25 * @subpackage deprecated
26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31 defined('MOODLE_INTERNAL') ||
die();
33 /* === Functions that needs to be kept longer in deprecated lib than normal time period === */
36 * Add an entry to the legacy log table.
38 * @deprecated since 2.7 use new events instead
40 * @param int $courseid The course id
41 * @param string $module The module name e.g. forum, journal, resource, course, user etc
42 * @param string $action 'view', 'update', 'add' or 'delete', possibly followed by another word to clarify.
43 * @param string $url The file and parameters used to see the results of the action
44 * @param string $info Additional description information
45 * @param int $cm The course_module->id if there is one
46 * @param int|stdClass $user If log regards $user other than $USER
49 function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user=0) {
50 debugging('add_to_log() has been deprecated, please rewrite your code to the new events API', DEBUG_DEVELOPER
);
52 // This is a nasty hack that allows us to put all the legacy stuff into legacy storage,
53 // this way we may move all the legacy settings there too.
54 $manager = get_log_manager();
55 if (method_exists($manager, 'legacy_add_to_log')) {
56 $manager->legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user);
61 * @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.');
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) {
87 // NOTE: do not add any other debugging here, keep forever.
89 $subsystems = core_component
::get_core_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) {
103 $subsystems[$k] = substr($v, $dlength+
1);
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) {
120 // NOTE: do not add any other debugging here, keep forever.
122 $types = core_component
::get_plugin_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';
137 $types[$k] = substr($v, $dlength+
1);
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 === '') {
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 === '') {
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;
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)) {
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 ===
408 function check_gd_version() {
409 throw new coding_exception('check_gd_version() is removed, GD extension is always available now');
415 function update_login_count() {
416 throw new coding_exception('update_login_count() is removed, all calls need to be removed');
422 function reset_login_count() {
423 throw new coding_exception('reset_login_count() is removed, all calls need to be removed');
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.');
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.
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
511 if (empty($zipfilename)) {
515 //If no extension, error
516 if (empty($extension)) {
521 $zipfile = cleardoubleslashes($zipfile);
523 //Check zipfile exists
524 if (!file_exists($zipfile)) {
528 //If no destination, passed let's go with the same directory
529 if (empty($destination)) {
530 $destination = $zippath;
534 $destpath = rtrim(cleardoubleslashes($destination), "/");
536 //Check destination path exists
537 if (!is_dir($destpath)) {
541 $packer = get_file_packer('application/zip');
543 $result = $packer->extract_to_pathname($zipfile, $destpath);
545 if ($result === false) {
549 foreach ($result as $status) {
550 if ($status !== true) {
559 * Zip an array of files/dirs to a destination zip file
560 * Both parameters must be FULL paths to the files/dirs
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
580 if (empty($destfilename)) {
584 //If no extension, add it
585 if (empty($extension)) {
587 $destfilename = $destfilename.'.'.$extension;
590 //Check destination path exists
591 if (!is_dir($destpath)) {
595 //Check destination path is writable. TODO!!
597 //Clean destination filename
598 $destfilename = clean_filename($destfilename);
600 //Now check and prepare every file
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
615 //See if the file/dir is in the same directory than the rest
616 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
619 //Add the file to the array
620 $files[] = $tempfile;
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
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');
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.
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 * @deprecated since Moodle 2.0
773 * When using this function, you should
776 * @param bool $unused No longer used.
777 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
778 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
779 * @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.
780 * @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.
781 * @param string $name Name to use for the textarea element.
782 * @param string $value Initial content to display in the textarea.
783 * @param int $obsolete deprecated
784 * @param bool $return If false, will output string. If true, will return string value.
785 * @param string $id CSS ID to add to the textarea element.
786 * @return string|void depending on the value of $return
788 function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
789 /// $width and height are legacy fields and no longer used as pixels like they used to be.
790 /// However, you can set them to zero to override the mincols and minrows values below.
792 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
793 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
805 if ($height && ($rows < $minrows)) {
808 if ($width && ($cols < $mincols)) {
812 editors_head_setup();
813 $editor = editors_get_preferred_editor(FORMAT_HTML
);
814 $editor->set_text($value);
815 $editor->use_editor($id, array('legacy'=>true));
817 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'" spellcheck="true">'."\n";
818 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
819 $str .= '</textarea>'."\n";
828 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
829 * provide this function with the language strings for sortasc and sortdesc.
831 * @deprecated use $OUTPUT->arrow() instead.
832 * @todo final deprecation of this function once MDL-45448 is resolved
834 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
837 * @param string $direction 'up' or 'down'
838 * @param string $strsort The language string used for the alt attribute of this image
839 * @param bool $return Whether to print directly or return the html string
840 * @return string|void depending on $return
843 function print_arrow($direction='up', $strsort=null, $return=false) {
846 debugging('print_arrow() is deprecated. Please use $OUTPUT->arrow() instead.', DEBUG_DEVELOPER
);
848 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
854 switch ($direction) {
869 // Prepare language string
871 if (empty($strsort) && !empty($sortdir)) {
872 $strsort = get_string('sort' . $sortdir, 'grades');
875 $return = ' ' . $OUTPUT->pix_icon('t/' . $direction, $strsort) . ' ';
885 * @deprecated since Moodle 2.0
887 function choose_from_menu() {
888 throw new coding_exception('choose_from_menu() is removed. Please change your code to use html_writer::select().');
892 * @deprecated use $OUTPUT->help_icon_scale($courseid, $scale) instead.
894 function print_scale_menu_helpbutton() {
895 throw new coding_exception('print_scale_menu_helpbutton() can not be used any more. '.
896 'Please use $OUTPUT->help_icon_scale($courseid, $scale) instead.');
900 * @deprecated use html_writer::checkbox() instead.
902 function print_checkbox() {
903 throw new coding_exception('print_checkbox() can not be used any more. Please use html_writer::checkbox() instead.');
907 * Prints the 'update this xxx' button that appears on module pages.
909 * @deprecated since Moodle 3.2
911 * @param string $cmid the course_module id.
912 * @param string $ignored not used any more. (Used to be courseid.)
913 * @param string $string the module name - get_string('modulename', 'xxx')
914 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
916 function update_module_button($cmid, $ignored, $string) {
917 global $CFG, $OUTPUT;
919 debugging('update_module_button() has been deprecated and should not be used anymore. Activity modules should not add the ' .
920 'edit module button, the link is already available in the Administration block. Themes can choose to display the link ' .
921 'in the buttons row consistently for all module types.', DEBUG_DEVELOPER
);
923 if (has_capability('moodle/course:manageactivities', context_module
::instance($cmid))) {
924 $string = get_string('updatethis', '', $string);
926 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
927 return $OUTPUT->single_button($url, $string);
934 * @deprecated use $OUTPUT->navbar() instead
936 function print_navigation () {
937 throw new coding_exception('print_navigation() can not be used any more, please update use $OUTPUT->navbar() instead.');
941 * @deprecated Please use $PAGE->navabar methods instead.
943 function build_navigation() {
944 throw new coding_exception('build_navigation() can not be used any more, please use $PAGE->navbar methods instead.');
948 * @deprecated not relevant with global navigation in Moodle 2.x+
951 throw new coding_exception('navmenu() can not be used any more, it is no longer relevant with global navigation.');
954 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
958 * @deprecated please use calendar_event::create() instead.
960 function add_event() {
961 throw new coding_exception('add_event() can not be used any more, please use calendar_event::create() instead.');
965 * @deprecated please calendar_event->update() instead.
967 function update_event() {
968 throw new coding_exception('update_event() is removed, please use calendar_event->update() instead.');
972 * @deprecated please use calendar_event->delete() instead.
974 function delete_event() {
975 throw new coding_exception('delete_event() can not be used any more, please use '.
976 'calendar_event->delete() instead.');
980 * @deprecated please use calendar_event->toggle_visibility(false) instead.
982 function hide_event() {
983 throw new coding_exception('hide_event() can not be used any more, please use '.
984 'calendar_event->toggle_visibility(false) instead.');
988 * @deprecated please use calendar_event->toggle_visibility(true) instead.
990 function show_event() {
991 throw new coding_exception('show_event() can not be used any more, please use '.
992 'calendar_event->toggle_visibility(true) instead.');
996 * @deprecated since Moodle 2.2 use core_text::xxxx() instead.
998 function textlib_get_instance() {
999 throw new coding_exception('textlib_get_instance() can not be used any more, please use '.
1000 'core_text::functioname() instead.');
1004 * @deprecated since 2.4
1006 function get_generic_section_name() {
1007 throw new coding_exception('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base');
1011 * @deprecated since 2.4
1013 function get_all_sections() {
1014 throw new coding_exception('get_all_sections() is removed. See phpdocs for this function');
1018 * @deprecated since 2.4
1020 function add_mod_to_section() {
1021 throw new coding_exception('Function add_mod_to_section() is removed, please use course_add_cm_to_section()');
1025 * @deprecated since 2.4
1027 function get_all_mods() {
1028 throw new coding_exception('Function get_all_mods() is removed. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details');
1032 * @deprecated since 2.4
1034 function get_course_section() {
1035 throw new coding_exception('Function get_course_section() is removed. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.');
1039 * @deprecated since 2.4
1041 function format_weeks_get_section_dates() {
1042 throw new coding_exception('Function format_weeks_get_section_dates() is removed. It is not recommended to'.
1043 ' use it outside of format_weeks plugin');
1047 * @deprecated since 2.5
1049 function get_print_section_cm_text() {
1050 throw new coding_exception('Function get_print_section_cm_text() is removed. Please use '.
1051 'cm_info::get_formatted_content() and cm_info::get_formatted_name()');
1055 * @deprecated since 2.5
1057 function print_section_add_menus() {
1058 throw new coding_exception('Function print_section_add_menus() is removed. Please use course renderer '.
1059 'function course_section_add_cm_control()');
1063 * @deprecated since 2.5. Please use:
1064 * $courserenderer = $PAGE->get_renderer('core', 'course');
1065 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
1066 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
1068 function make_editing_buttons() {
1069 throw new coding_exception('Function make_editing_buttons() is removed, please see PHPdocs in '.
1070 'lib/deprecatedlib.php on how to replace it');
1074 * @deprecated since 2.5
1076 function print_section() {
1077 throw new coding_exception('Function print_section() is removed. Please use course renderer function '.
1078 'course_section_cm_list() instead.');
1082 * @deprecated since 2.5
1084 function print_overview() {
1085 throw new coding_exception('Function print_overview() is removed. Use block course_overview to display this information');
1089 * @deprecated since 2.5
1091 function print_recent_activity() {
1092 throw new coding_exception('Function print_recent_activity() is removed. It is not recommended to'.
1093 ' use it outside of block_recent_activity');
1097 * @deprecated since 2.5
1099 function delete_course_module() {
1100 throw new coding_exception('Function delete_course_module() is removed. Please use course_delete_module() instead.');
1104 * @deprecated since 2.5
1106 function update_category_button() {
1107 throw new coding_exception('Function update_category_button() is removed. Pages to view '.
1108 'and edit courses are now separate and no longer depend on editing mode.');
1112 * @deprecated since 2.5
1114 function make_categories_list() {
1115 throw new coding_exception('Global function make_categories_list() is removed. Please use '.
1116 'coursecat::make_categories_list() and coursecat::get_parents()');
1120 * @deprecated since 2.5
1122 function category_delete_move() {
1123 throw new coding_exception('Function category_delete_move() is removed. Please use coursecat::delete_move() instead.');
1127 * @deprecated since 2.5
1129 function category_delete_full() {
1130 throw new coding_exception('Function category_delete_full() is removed. Please use coursecat::delete_full() instead.');
1134 * @deprecated since 2.5
1136 function move_category() {
1137 throw new coding_exception('Function move_category() is removed. Please use coursecat::change_parent() instead.');
1141 * @deprecated since 2.5
1143 function course_category_hide() {
1144 throw new coding_exception('Function course_category_hide() is removed. Please use coursecat::hide() instead.');
1148 * @deprecated since 2.5
1150 function course_category_show() {
1151 throw new coding_exception('Function course_category_show() is removed. Please use coursecat::show() instead.');
1155 * @deprecated since 2.5. Please use coursecat::get($catid, IGNORE_MISSING) or coursecat::get($catid, MUST_EXIST).
1157 function get_course_category() {
1158 throw new coding_exception('Function get_course_category() is removed. Please use coursecat::get(), see phpdocs for more details');
1162 * @deprecated since 2.5
1164 function create_course_category() {
1165 throw new coding_exception('Function create_course_category() is removed. Please use coursecat::create()');
1169 * @deprecated since 2.5. Please use coursecat::get() and coursecat::get_children()
1171 function get_all_subcategories() {
1172 throw new coding_exception('Function get_all_subcategories() is removed. Please use appropriate methods() ' .
1173 'of coursecat class.');
1177 * @deprecated since 2.5. Please use coursecat::get($parentid)->get_children().
1179 function get_child_categories() {
1180 throw new coding_exception('Function get_child_categories() is removed. Use coursecat::get_children().');
1184 * @deprecated since 2.5
1186 function get_categories() {
1187 throw new coding_exception('Function get_categories() is removed. Please use ' .
1188 'appropriate functions from class coursecat');
1192 * @deprecated since 2.5
1194 function print_course_search() {
1195 throw new coding_exception('Function print_course_search() is removed, please use course renderer');
1199 * @deprecated since 2.5
1201 function print_my_moodle() {
1202 throw new coding_exception('Function print_my_moodle() is removed, please use course renderer ' .
1203 'function frontpage_my_courses()');
1207 * @deprecated since 2.5
1209 function print_remote_course() {
1210 throw new coding_exception('Function print_remote_course() is removed, please use course renderer');
1214 * @deprecated since 2.5
1216 function print_remote_host() {
1217 throw new coding_exception('Function print_remote_host() is removed, please use course renderer');
1221 * @deprecated since 2.5
1223 function print_whole_category_list() {
1224 throw new coding_exception('Function print_whole_category_list() is removed, please use course renderer');
1228 * @deprecated since 2.5
1230 function print_category_info() {
1231 throw new coding_exception('Function print_category_info() is removed, please use course renderer');
1235 * @deprecated since 2.5
1237 function get_course_category_tree() {
1238 throw new coding_exception('Function get_course_category_tree() is removed, please use course ' .
1239 'renderer or coursecat class, see function phpdocs for more info');
1243 * @deprecated since 2.5
1245 function print_courses() {
1246 throw new coding_exception('Function print_courses() is removed, please use course renderer');
1250 * @deprecated since 2.5
1252 function print_course() {
1253 throw new coding_exception('Function print_course() is removed, please use course renderer');
1257 * @deprecated since 2.5
1259 function get_category_courses_array() {
1260 throw new coding_exception('Function get_category_courses_array() is removed, please use methods of coursecat class');
1264 * @deprecated since 2.5
1266 function get_category_courses_array_recursively() {
1267 throw new coding_exception('Function get_category_courses_array_recursively() is removed, please use methods of coursecat class', DEBUG_DEVELOPER
);
1271 * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more.
1273 function blog_get_context_url() {
1274 throw new coding_exception('Function blog_get_context_url() is removed, getting params from context is not reliable for blogs.');
1278 * @deprecated since 2.5
1280 function get_courses_wmanagers() {
1281 throw new coding_exception('Function get_courses_wmanagers() is removed, please use coursecat::get_courses()');
1285 * @deprecated since 2.5
1287 function convert_tree_to_html() {
1288 throw new coding_exception('Function convert_tree_to_html() is removed. Consider using class tabtree and core_renderer::render_tabtree()');
1292 * @deprecated since 2.5
1294 function convert_tabrows_to_tree() {
1295 throw new coding_exception('Function convert_tabrows_to_tree() is removed. Consider using class tabtree');
1299 * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically
1301 function can_use_rotated_text() {
1302 debugging('can_use_rotated_text() is removed. JS feature detection is used automatically.');
1306 * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more.
1308 function get_context_instance_by_id() {
1309 throw new coding_exception('get_context_instance_by_id() is now removed, please use context::instance_by_id($id) instead.');
1313 * Returns system context or null if can not be created yet.
1315 * @see context_system::instance()
1316 * @deprecated since 2.2
1317 * @param bool $cache use caching
1318 * @return context system context (null if context table not created yet)
1320 function get_system_context($cache = true) {
1321 debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER
);
1322 return context_system
::instance(0, IGNORE_MISSING
, $cache);
1326 * @deprecated since 2.2, use $context->get_parent_context_ids() instead
1328 function get_parent_contexts() {
1329 throw new coding_exception('get_parent_contexts() is removed, please use $context->get_parent_context_ids() instead.');
1333 * @deprecated since Moodle 2.2
1335 function get_parent_contextid() {
1336 throw new coding_exception('get_parent_contextid() is removed, please use $context->get_parent_context() instead.');
1340 * @deprecated since 2.2
1342 function get_child_contexts() {
1343 throw new coding_exception('get_child_contexts() is removed, please use $context->get_child_contexts() instead.');
1347 * @deprecated since 2.2
1349 function create_contexts() {
1350 throw new coding_exception('create_contexts() is removed, please use context_helper::create_instances() instead.');
1354 * @deprecated since 2.2
1356 function cleanup_contexts() {
1357 throw new coding_exception('cleanup_contexts() is removed, please use context_helper::cleanup_instances() instead.');
1361 * @deprecated since 2.2
1363 function build_context_path() {
1364 throw new coding_exception('build_context_path() is removed, please use context_helper::build_all_paths() instead.');
1368 * @deprecated since 2.2
1370 function rebuild_contexts() {
1371 throw new coding_exception('rebuild_contexts() is removed, please use $context->reset_paths(true) instead.');
1375 * @deprecated since Moodle 2.2
1377 function preload_course_contexts() {
1378 throw new coding_exception('preload_course_contexts() is removed, please use context_helper::preload_course() instead.');
1382 * @deprecated since Moodle 2.2
1384 function context_moved() {
1385 throw new coding_exception('context_moved() is removed, please use context::update_moved() instead.');
1389 * @deprecated since 2.2
1391 function fetch_context_capabilities() {
1392 throw new coding_exception('fetch_context_capabilities() is removed, please use $context->get_capabilities() instead.');
1396 * @deprecated since 2.2
1398 function context_instance_preload() {
1399 throw new coding_exception('context_instance_preload() is removed, please use context_helper::preload_from_record() instead.');
1403 * @deprecated since 2.2
1405 function get_contextlevel_name() {
1406 throw new coding_exception('get_contextlevel_name() is removed, please use context_helper::get_level_name() instead.');
1410 * @deprecated since 2.2
1412 function print_context_name() {
1413 throw new coding_exception('print_context_name() is removed, please use $context->get_context_name() instead.');
1417 * @deprecated since 2.2, use $context->mark_dirty() instead
1419 function mark_context_dirty() {
1420 throw new coding_exception('mark_context_dirty() is removed, please use $context->mark_dirty() instead.');
1424 * @deprecated since Moodle 2.2
1426 function delete_context() {
1427 throw new coding_exception('delete_context() is removed, please use context_helper::delete_instance() ' .
1428 'or $context->delete_content() instead.');
1432 * @deprecated since 2.2
1434 function get_context_url() {
1435 throw new coding_exception('get_context_url() is removed, please use $context->get_url() instead.');
1439 * @deprecated since 2.2
1441 function get_course_context() {
1442 throw new coding_exception('get_course_context() is removed, please use $context->get_course_context(true) instead.');
1446 * @deprecated since 2.2
1448 function get_user_courses_bycap() {
1449 throw new coding_exception('get_user_courses_bycap() is removed, please use enrol_get_users_courses() instead.');
1453 * @deprecated since Moodle 2.2
1455 function get_role_context_caps() {
1456 throw new coding_exception('get_role_context_caps() is removed, it is really slow. Don\'t use it.');
1460 * @deprecated since 2.2
1462 function get_courseid_from_context() {
1463 throw new coding_exception('get_courseid_from_context() is removed, please use $context->get_course_context(false) instead.');
1467 * @deprecated since 2.2
1469 function context_instance_preload_sql() {
1470 throw new coding_exception('context_instance_preload_sql() is removed, please use context_helper::get_preload_record_columns_sql() instead.');
1474 * @deprecated since 2.2
1476 function get_related_contexts_string() {
1477 throw new coding_exception('get_related_contexts_string() is removed, please use $context->get_parent_context_ids(true) instead.');
1481 * @deprecated since 2.6
1483 function get_plugin_list_with_file() {
1484 throw new coding_exception('get_plugin_list_with_file() is removed, please use core_component::get_plugin_list_with_file() instead.');
1488 * @deprecated since 2.6
1490 function check_browser_operating_system() {
1491 throw new coding_exception('check_browser_operating_system is removed, please update your code to use core_useragent instead.');
1495 * @deprecated since 2.6
1497 function check_browser_version() {
1498 throw new coding_exception('check_browser_version is removed, please update your code to use core_useragent instead.');
1502 * @deprecated since 2.6
1504 function get_device_type() {
1505 throw new coding_exception('get_device_type is removed, please update your code to use core_useragent instead.');
1509 * @deprecated since 2.6
1511 function get_device_type_list() {
1512 throw new coding_exception('get_device_type_list is removed, please update your code to use core_useragent instead.');
1516 * @deprecated since 2.6
1518 function get_selected_theme_for_device_type() {
1519 throw new coding_exception('get_selected_theme_for_device_type is removed, please update your code to use core_useragent instead.');
1523 * @deprecated since 2.6
1525 function get_device_cfg_var_name() {
1526 throw new coding_exception('get_device_cfg_var_name is removed, please update your code to use core_useragent instead.');
1530 * @deprecated since 2.6
1532 function set_user_device_type() {
1533 throw new coding_exception('set_user_device_type is removed, please update your code to use core_useragent instead.');
1537 * @deprecated since 2.6
1539 function get_user_device_type() {
1540 throw new coding_exception('get_user_device_type is removed, please update your code to use core_useragent instead.');
1544 * @deprecated since 2.6
1546 function get_browser_version_classes() {
1547 throw new coding_exception('get_browser_version_classes is removed, please update your code to use core_useragent instead.');
1551 * @deprecated since Moodle 2.6
1553 function generate_email_supportuser() {
1554 throw new coding_exception('generate_email_supportuser is removed, please use core_user::get_support_user');
1558 * @deprecated since Moodle 2.6
1560 function badges_get_issued_badge_info() {
1561 throw new coding_exception('Function badges_get_issued_badge_info() is removed. Please use core_badges_assertion class and methods to generate badge assertion.');
1565 * @deprecated since 2.6
1567 function can_use_html_editor() {
1568 throw new coding_exception('can_use_html_editor is removed, please update your code to assume it returns true.');
1573 * @deprecated since Moodle 2.7, use {@link user_count_login_failures()} instead.
1575 function count_login_failures() {
1576 throw new coding_exception('count_login_failures() can not be used any more, please use user_count_login_failures().');
1580 * @deprecated since 2.7 MDL-33099/MDL-44088 - please do not use this function any more.
1582 function ajaxenabled() {
1583 throw new coding_exception('ajaxenabled() can not be used anymore. Update your code to work with JS at all times.');
1587 * @deprecated Since Moodle 2.7 MDL-44070
1589 function coursemodule_visible_for_user() {
1590 throw new coding_exception('coursemodule_visible_for_user() can not be used any more,
1591 please use \core_availability\info_module::is_user_visible()');
1595 * @deprecated since Moodle 2.8 MDL-36014, MDL-35618 this functionality is removed
1597 function enrol_cohort_get_cohorts() {
1598 throw new coding_exception('Function enrol_cohort_get_cohorts() is removed, use '.
1599 'cohort_get_available_cohorts() instead');
1603 * @deprecated since Moodle 2.8 MDL-36014 please use cohort_can_view_cohort()
1605 function enrol_cohort_can_view_cohort() {
1606 throw new coding_exception('Function enrol_cohort_can_view_cohort() is removed, use cohort_can_view_cohort() instead');
1610 * @deprecated since Moodle 2.8 MDL-36014 use cohort_get_available_cohorts() instead
1612 function cohort_get_visible_list() {
1613 throw new coding_exception('Function cohort_get_visible_list() is removed. Please use function cohort_get_available_cohorts() ".
1614 "that correctly checks capabilities.');
1618 * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
1620 function enrol_cohort_enrol_all_users() {
1621 throw new coding_exception('enrol_cohort_enrol_all_users() is removed. This functionality is moved to enrol_manual.');
1625 * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
1627 function enrol_cohort_search_cohorts() {
1628 throw new coding_exception('enrol_cohort_search_cohorts() is removed. This functionality is moved to enrol_manual.');
1631 /* === Apis deprecated in since Moodle 2.9 === */
1634 * @deprecated since Moodle 2.9 MDL-49371 - please do not use this function any more.
1636 function message_current_user_is_involved() {
1637 throw new coding_exception('message_current_user_is_involved() can not be used any more.');
1641 * @deprecated since Moodle 2.9 MDL-45898 - please do not use this function any more.
1643 function profile_display_badges() {
1644 throw new coding_exception('profile_display_badges() can not be used any more.');
1648 * @deprecated since Moodle 2.9 MDL-45774 - Please do not use this function any more.
1650 function useredit_shared_definition_preferences() {
1651 throw new coding_exception('useredit_shared_definition_preferences() can not be used any more.');
1656 * @deprecated since Moodle 2.9
1658 function calendar_normalize_tz() {
1659 throw new coding_exception('calendar_normalize_tz() can not be used any more, please use core_date::normalise_timezone() instead.');
1663 * @deprecated since Moodle 2.9
1665 function get_user_timezone_offset() {
1666 throw new coding_exception('get_user_timezone_offset() can not be used any more, please use standard PHP DateTimeZone class instead');
1671 * @deprecated since Moodle 2.9
1673 function get_timezone_offset() {
1674 throw new coding_exception('get_timezone_offset() can not be used any more, please use standard PHP DateTimeZone class instead');
1678 * @deprecated since Moodle 2.9
1680 function get_list_of_timezones() {
1681 throw new coding_exception('get_list_of_timezones() can not be used any more, please use core_date::get_list_of_timezones() instead');
1685 * @deprecated since Moodle 2.9
1687 function update_timezone_records() {
1688 throw new coding_exception('update_timezone_records() can not be used any more, please use standard PHP DateTime class instead');
1692 * @deprecated since Moodle 2.9
1694 function calculate_user_dst_table() {
1695 throw new coding_exception('calculate_user_dst_table() can not be used any more, please use standard PHP DateTime class instead');
1699 * @deprecated since Moodle 2.9
1701 function dst_changes_for_year() {
1702 throw new coding_exception('dst_changes_for_year() can not be used any more, please use standard DateTime class instead');
1706 * @deprecated since Moodle 2.9
1708 function get_timezone_record() {
1709 throw new coding_exception('get_timezone_record() can not be used any more, please use standard PHP DateTime class instead');
1712 /* === Apis deprecated since Moodle 3.0 === */
1714 * @deprecated since Moodle 3.0 MDL-49360 - please do not use this function any more.
1716 function get_referer() {
1717 throw new coding_exception('get_referer() can not be used any more. Please use get_local_referer() instead.');
1721 * @deprecated since Moodle 3.0 use \core_useragent::is_web_crawler instead.
1723 function is_web_crawler() {
1724 throw new coding_exception('is_web_crawler() can not be used any more. Please use core_useragent::is_web_crawler() instead.');
1728 * @deprecated since Moodle 3.0 MDL-50287 - please do not use this function any more.
1730 function completion_cron() {
1731 throw new coding_exception('completion_cron() can not be used any more. Functionality has been moved to scheduled tasks.');
1735 * @deprecated since 3.0
1737 function coursetag_get_tags() {
1738 throw new coding_exception('Function coursetag_get_tags() can not be used any more. ' .
1739 'Userid is no longer used for tagging courses.');
1743 * @deprecated since 3.0
1745 function coursetag_get_all_tags() {
1746 throw new coding_exception('Function coursetag_get_all_tags() can not be used any more. Userid is no ' .
1747 'longer used for tagging courses.');
1751 * @deprecated since 3.0
1753 function coursetag_get_jscript() {
1754 throw new coding_exception('Function coursetag_get_jscript() can not be used any more and is obsolete.');
1758 * @deprecated since 3.0
1760 function coursetag_get_jscript_links() {
1761 throw new coding_exception('Function coursetag_get_jscript_links() can not be used any more and is obsolete.');
1765 * @deprecated since 3.0
1767 function coursetag_get_records() {
1768 throw new coding_exception('Function coursetag_get_records() can not be used any more. ' .
1769 'Userid is no longer used for tagging courses.');
1773 * @deprecated since 3.0
1775 function coursetag_store_keywords() {
1776 throw new coding_exception('Function coursetag_store_keywords() can not be used any more. ' .
1777 'Userid is no longer used for tagging courses.');
1781 * @deprecated since 3.0
1783 function coursetag_delete_keyword() {
1784 throw new coding_exception('Function coursetag_delete_keyword() can not be used any more. ' .
1785 'Userid is no longer used for tagging courses.');
1789 * @deprecated since 3.0
1791 function coursetag_get_tagged_courses() {
1792 throw new coding_exception('Function coursetag_get_tagged_courses() can not be used any more. ' .
1793 'Userid is no longer used for tagging courses.');
1797 * @deprecated since 3.0
1799 function coursetag_delete_course_tags() {
1800 throw new coding_exception('Function coursetag_delete_course_tags() is deprecated. ' .
1801 'Use core_tag_tag::remove_all_item_tags().');
1805 * @deprecated since 3.1. Use core_tag_tag::get($tagid)->update() instead
1807 function tag_type_set() {
1808 throw new coding_exception('tag_type_set() can not be used anymore. Please use ' .
1809 'core_tag_tag::get($tagid)->update().');
1813 * @deprecated since 3.1. Use core_tag_tag::get($tagid)->update() instead
1815 function tag_description_set() {
1816 throw new coding_exception('tag_description_set() can not be used anymore. Please use ' .
1817 'core_tag_tag::get($tagid)->update().');
1821 * @deprecated since 3.1. Use core_tag_tag::get_item_tags() instead
1823 function tag_get_tags() {
1824 throw new coding_exception('tag_get_tags() can not be used anymore. Please use ' .
1825 'core_tag_tag::get_item_tags().');
1829 * @deprecated since 3.1
1831 function tag_get_tags_array() {
1832 throw new coding_exception('tag_get_tags_array() can not be used anymore. Please use ' .
1833 'core_tag_tag::get_item_tags_array().');
1837 * @deprecated since 3.1. Use core_tag_tag::get_item_tags_array() or $OUTPUT->tag_list(core_tag_tag::get_item_tags())
1839 function tag_get_tags_csv() {
1840 throw new coding_exception('tag_get_tags_csv() can not be used anymore. Please use ' .
1841 'core_tag_tag::get_item_tags_array() or $OUTPUT->tag_list(core_tag_tag::get_item_tags()).');
1845 * @deprecated since 3.1. Use core_tag_tag::get_item_tags() instead
1847 function tag_get_tags_ids() {
1848 throw new coding_exception('tag_get_tags_ids() can not be used anymore. Please consider using ' .
1849 'core_tag_tag::get_item_tags() or similar methods.');
1853 * @deprecated since 3.1. Use core_tag_tag::get_by_name() or core_tag_tag::get_by_name_bulk()
1855 function tag_get_id() {
1856 throw new coding_exception('tag_get_id() can not be used anymore. Please use ' .
1857 'core_tag_tag::get_by_name() or core_tag_tag::get_by_name_bulk()');
1861 * @deprecated since 3.1. Use core_tag_tag::get($tagid)->update() instead
1863 function tag_rename() {
1864 throw new coding_exception('tag_rename() can not be used anymore. Please use ' .
1865 'core_tag_tag::get($tagid)->update()');
1869 * @deprecated since 3.1. Use core_tag_tag::remove_item_tag() instead
1871 function tag_delete_instance() {
1872 throw new coding_exception('tag_delete_instance() can not be used anymore. Please use ' .
1873 'core_tag_tag::remove_item_tag()');
1877 * @deprecated since 3.1. Use core_tag_tag::get_by_name()->get_tagged_items() instead
1879 function tag_find_records() {
1880 throw new coding_exception('tag_find_records() can not be used anymore. Please use ' .
1881 'core_tag_tag::get_by_name()->get_tagged_items()');
1885 * @deprecated since 3.1
1887 function tag_add() {
1888 throw new coding_exception('tag_add() can not be used anymore. You can use ' .
1889 'core_tag_tag::create_if_missing(), however it should not be necessary since tags are ' .
1890 'created automatically when assigned to items');
1894 * @deprecated since 3.1. Use core_tag_tag::set_item_tags() or core_tag_tag::add_item_tag() instead
1896 function tag_assign() {
1897 throw new coding_exception('tag_assign() can not be used anymore. Please use ' .
1898 'core_tag_tag::set_item_tags() or core_tag_tag::add_item_tag() instead. Tag instance ' .
1899 'ordering should not be set manually');
1903 * @deprecated since 3.1. Use core_tag_tag::get($tagid)->count_tagged_items() instead
1905 function tag_record_count() {
1906 throw new coding_exception('tag_record_count() can not be used anymore. Please use ' .
1907 'core_tag_tag::get($tagid)->count_tagged_items().');
1911 * @deprecated since 3.1. Use core_tag_tag::get($tagid)->is_item_tagged_with() instead
1913 function tag_record_tagged_with() {
1914 throw new coding_exception('tag_record_tagged_with() can not be used anymore. Please use ' .
1915 'core_tag_tag::get($tagid)->is_item_tagged_with().');
1919 * @deprecated since 3.1. Use core_tag_tag::get($tagid)->flag() instead
1921 function tag_set_flag() {
1922 throw new coding_exception('tag_set_flag() can not be used anymore. Please use ' .
1923 'core_tag_tag::get($tagid)->flag()');
1927 * @deprecated since 3.1. Use core_tag_tag::get($tagid)->reset_flag() instead
1929 function tag_unset_flag() {
1930 throw new coding_exception('tag_unset_flag() can not be used anymore. Please use ' .
1931 'core_tag_tag::get($tagid)->reset_flag()');
1935 * @deprecated since 3.1
1937 function tag_print_cloud() {
1938 throw new coding_exception('tag_print_cloud() can not be used anymore. Please use ' .
1939 'core_tag_collection::get_tag_cloud(), templateable core_tag\output\tagcloud and ' .
1940 'template core_tag/tagcloud.');
1944 * @deprecated since 3.0
1946 function tag_autocomplete() {
1947 throw new coding_exception('tag_autocomplete() can not be used anymore. New form ' .
1948 'element "tags" does proper autocomplete.');
1952 * @deprecated since 3.1
1954 function tag_print_description_box() {
1955 throw new coding_exception('tag_print_description_box() can not be used anymore. ' .
1956 'See core_tag_renderer for similar code');
1960 * @deprecated since 3.1
1962 function tag_print_management_box() {
1963 throw new coding_exception('tag_print_management_box() can not be used anymore. ' .
1964 'See core_tag_renderer for similar code');
1968 * @deprecated since 3.1
1970 function tag_print_search_box() {
1971 throw new coding_exception('tag_print_search_box() can not be used anymore. ' .
1972 'See core_tag_renderer for similar code');
1976 * @deprecated since 3.1
1978 function tag_print_search_results() {
1979 throw new coding_exception('tag_print_search_results() can not be used anymore. ' .
1980 'In /tag/search.php the search results are printed using the core_tag/tagcloud template.');
1984 * @deprecated since 3.1
1986 function tag_print_tagged_users_table() {
1987 throw new coding_exception('tag_print_tagged_users_table() can not be used anymore. ' .
1988 'See core_user_renderer for similar code');
1992 * @deprecated since 3.1
1994 function tag_print_user_box() {
1995 throw new coding_exception('tag_print_user_box() can not be used anymore. ' .
1996 'See core_user_renderer for similar code');
2000 * @deprecated since 3.1
2002 function tag_print_user_list() {
2003 throw new coding_exception('tag_print_user_list() can not be used anymore. ' .
2004 'See core_user_renderer for similar code');
2008 * @deprecated since 3.1
2010 function tag_display_name() {
2011 throw new coding_exception('tag_display_name() can not be used anymore. Please use ' .
2012 'core_tag_tag::make_display_name().');
2017 * @deprecated since 3.1
2019 function tag_normalize() {
2020 throw new coding_exception('tag_normalize() can not be used anymore. Please use ' .
2021 'core_tag_tag::normalize().');
2025 * @deprecated since 3.1
2027 function tag_get_related_tags_csv() {
2028 throw new coding_exception('tag_get_related_tags_csv() can not be used anymore. Please ' .
2029 'consider looping through array or using $OUTPUT->tag_list(core_tag_tag::get_item_tags()).');
2033 * @deprecated since 3.1
2035 function tag_set() {
2036 throw new coding_exception('tag_set() can not be used anymore. Please use ' .
2037 'core_tag_tag::set_item_tags().');
2041 * @deprecated since 3.1
2043 function tag_set_add() {
2044 throw new coding_exception('tag_set_add() can not be used anymore. Please use ' .
2045 'core_tag_tag::add_item_tag().');
2049 * @deprecated since 3.1
2051 function tag_set_delete() {
2052 throw new coding_exception('tag_set_delete() can not be used anymore. Please use ' .
2053 'core_tag_tag::remove_item_tag().');
2057 * @deprecated since 3.1
2059 function tag_get() {
2060 throw new coding_exception('tag_get() can not be used anymore. Please use ' .
2061 'core_tag_tag::get() or core_tag_tag::get_by_name().');
2065 * @deprecated since 3.1
2067 function tag_get_related_tags() {
2068 throw new coding_exception('tag_get_related_tags() can not be used anymore. Please use ' .
2069 'core_tag_tag::get_correlated_tags(), core_tag_tag::get_related_tags() or ' .
2070 'core_tag_tag::get_manual_related_tags().');
2074 * @deprecated since 3.1
2076 function tag_delete() {
2077 throw new coding_exception('tag_delete() can not be used anymore. Please use ' .
2078 'core_tag_tag::delete_tags().');
2082 * @deprecated since 3.1
2084 function tag_delete_instances() {
2085 throw new coding_exception('tag_delete_instances() can not be used anymore. Please use ' .
2086 'core_tag_tag::delete_instances().');
2090 * @deprecated since 3.1
2092 function tag_cleanup() {
2093 throw new coding_exception('tag_cleanup() can not be used anymore. Please use ' .
2094 '\core\task\tag_cron_task::cleanup().');
2098 * @deprecated since 3.1
2100 function tag_bulk_delete_instances() {
2101 throw new coding_exception('tag_bulk_delete_instances() can not be used anymore. Please use ' .
2102 '\core\task\tag_cron_task::bulk_delete_instances().');
2107 * @deprecated since 3.1
2109 function tag_compute_correlations() {
2110 throw new coding_exception('tag_compute_correlations() can not be used anymore. Please use ' .
2111 'use \core\task\tag_cron_task::compute_correlations().');
2115 * @deprecated since 3.1
2117 function tag_process_computed_correlation() {
2118 throw new coding_exception('tag_process_computed_correlation() can not be used anymore. Please use ' .
2119 'use \core\task\tag_cron_task::process_computed_correlation().');
2123 * @deprecated since 3.1
2125 function tag_cron() {
2126 throw new coding_exception('tag_cron() can not be used anymore. Please use ' .
2127 'use \core\task\tag_cron_task::execute().');
2131 * @deprecated since 3.1
2133 function tag_find_tags() {
2134 throw new coding_exception('tag_find_tags() can not be used anymore.');
2138 * @deprecated since 3.1
2140 function tag_get_name() {
2141 throw new coding_exception('tag_get_name() can not be used anymore.');
2145 * @deprecated since 3.1
2147 function tag_get_correlated() {
2148 throw new coding_exception('tag_get_correlated() can not be used anymore. Please use ' .
2149 'use core_tag_tag::get_correlated_tags().');
2154 * @deprecated since 3.1
2156 function tag_cloud_sort() {
2157 throw new coding_exception('tag_cloud_sort() can not be used anymore. Similar method can ' .
2158 'be found in core_tag_collection::cloud_sort().');
2162 * @deprecated since Moodle 3.1
2164 function events_load_def() {
2165 throw new coding_exception('events_load_def() has been deprecated along with all Events 1 API in favour of Events 2 API.');
2170 * @deprecated since Moodle 3.1
2172 function events_queue_handler() {
2173 throw new coding_exception('events_queue_handler() has been deprecated along with all Events 1 API in favour of Events 2 API.');
2177 * @deprecated since Moodle 3.1
2179 function events_dispatch() {
2180 throw new coding_exception('events_dispatch() has been deprecated along with all Events 1 API in favour of Events 2 API.');
2184 * @deprecated since Moodle 3.1
2186 function events_process_queued_handler() {
2187 throw new coding_exception(
2188 'events_process_queued_handler() has been deprecated along with all Events 1 API in favour of Events 2 API.'
2193 * @deprecated since Moodle 3.1
2195 function events_update_definition() {
2196 throw new coding_exception(
2197 'events_update_definition has been deprecated along with all Events 1 API in favour of Events 2 API.'
2202 * @deprecated since Moodle 3.1
2204 function events_cron() {
2205 throw new coding_exception('events_cron() has been deprecated along with all Events 1 API in favour of Events 2 API.');
2209 * @deprecated since Moodle 3.1
2211 function events_trigger_legacy() {
2212 throw new coding_exception('events_trigger_legacy() has been deprecated along with all Events 1 API in favour of Events 2 API.');
2216 * @deprecated since Moodle 3.1
2218 function events_is_registered() {
2219 throw new coding_exception('events_is_registered() has been deprecated along with all Events 1 API in favour of Events 2 API.');
2223 * @deprecated since Moodle 3.1
2225 function events_pending_count() {
2226 throw new coding_exception('events_pending_count() has been deprecated along with all Events 1 API in favour of Events 2 API.');
2230 * @deprecated since Moodle 3.0 - this is a part of clamav plugin now.
2232 function clam_message_admins() {
2233 throw new coding_exception('clam_message_admins() can not be used anymore. Please use ' .
2234 'message_admins() method of \antivirus_clamav\scanner class.');
2238 * @deprecated since Moodle 3.0 - this is a part of clamav plugin now.
2240 function get_clam_error_code() {
2241 throw new coding_exception('get_clam_error_code() can not be used anymore. Please use ' .
2242 'get_clam_error_code() method of \antivirus_clamav\scanner class.');
2246 * @deprecated since 3.1
2248 function course_get_cm_rename_action() {
2249 throw new coding_exception('course_get_cm_rename_action() can not be used anymore. Please use ' .
2250 'inplace_editable https://docs.moodle.org/dev/Inplace_editable.');
2255 * @deprecated since Moodle 3.1
2257 function course_scale_used() {
2258 throw new coding_exception('course_scale_used() can not be used anymore. Plugins can ' .
2259 'implement <modname>_scale_used_anywhere, all implementations of <modname>_scale_used are now ignored');
2263 * @deprecated since Moodle 3.1
2265 function site_scale_used() {
2266 throw new coding_exception('site_scale_used() can not be used anymore. Plugins can implement ' .
2267 '<modname>_scale_used_anywhere, all implementations of <modname>_scale_used are now ignored');
2271 * @deprecated since Moodle 3.1. Use external_api::external_function_info().
2273 function external_function_info() {
2274 throw new coding_exception('external_function_info() can not be used any'.
2275 'more. Please use external_api::external_function_info() instead.');
2279 * Retrieves an array of records from a CSV file and places
2280 * them into a given table structure
2281 * This function is deprecated. Please use csv_import_reader() instead.
2283 * @deprecated since Moodle 3.2 MDL-55126
2284 * @todo MDL-55195 for final deprecation in Moodle 3.6
2285 * @see csv_import_reader::load_csv_content()
2286 * @global stdClass $CFG
2287 * @global moodle_database $DB
2288 * @param string $file The path to a CSV file
2289 * @param string $table The table to retrieve columns from
2290 * @return bool|array Returns an array of CSV records or false
2292 function get_records_csv($file, $table) {
2295 debugging('get_records_csv() is deprecated. Please use lib/csvlib.class.php csv_import_reader() instead.');
2297 if (!$metacolumns = $DB->get_columns($table)) {
2301 if(!($handle = @fopen
($file, 'r'))) {
2302 print_error('get_records_csv failed to open '.$file);
2305 $fieldnames = fgetcsv($handle, 4096);
2306 if(empty($fieldnames)) {
2313 foreach($metacolumns as $metacolumn) {
2314 $ord = array_search($metacolumn->name
, $fieldnames);
2316 $columns[$metacolumn->name
] = $ord;
2322 while (($data = fgetcsv($handle, 4096)) !== false) {
2323 $item = new stdClass
;
2324 foreach($columns as $name => $ord) {
2325 $item->$name = $data[$ord];
2335 * Create a file with CSV contents
2336 * This function is deprecated. Please use download_as_dataformat() instead.
2338 * @deprecated since Moodle 3.2 MDL-55126
2339 * @todo MDL-55195 for final deprecation in Moodle 3.6
2340 * @see download_as_dataformat (lib/dataformatlib.php)
2341 * @global stdClass $CFG
2342 * @global moodle_database $DB
2343 * @param string $file The file to put the CSV content into
2344 * @param array $records An array of records to write to a CSV file
2345 * @param string $table The table to get columns from
2346 * @return bool success
2348 function put_records_csv($file, $records, $table = NULL) {
2351 debugging('put_records_csv() is deprecated. Please use lib/dataformatlib.php download_as_dataformat()');
2353 if (empty($records)) {
2357 $metacolumns = NULL;
2358 if ($table !== NULL && !$metacolumns = $DB->get_columns($table)) {
2364 if(!($fp = @fopen
($CFG->tempdir
.'/'.$file, 'w'))) {
2365 print_error('put_records_csv failed to open '.$file);
2368 $proto = reset($records);
2369 if(is_object($proto)) {
2370 $fields_records = array_keys(get_object_vars($proto));
2372 else if(is_array($proto)) {
2373 $fields_records = array_keys($proto);
2380 if(!empty($metacolumns)) {
2381 $fields_table = array_map(create_function('$a', 'return $a->name;'), $metacolumns);
2382 $fields = array_intersect($fields_records, $fields_table);
2385 $fields = $fields_records;
2388 fwrite($fp, implode(',', $fields));
2389 fwrite($fp, "\r\n");
2391 foreach($records as $record) {
2392 $array = (array)$record;
2394 foreach($fields as $field) {
2395 if(strpos($array[$field], ',')) {
2396 $values[] = '"'.str_replace('"', '\"', $array[$field]).'"';
2399 $values[] = $array[$field];
2402 fwrite($fp, implode(',', $values)."\r\n");
2406 @chmod
($CFG->tempdir
.'/'.$file, $CFG->filepermissions
);
2411 * Determines if the given value is a valid CSS colour.
2413 * A CSS colour can be one of the following:
2414 * - Hex colour: #AA66BB
2415 * - RGB colour: rgb(0-255, 0-255, 0-255)
2416 * - RGBA colour: rgba(0-255, 0-255, 0-255, 0-1)
2417 * - HSL colour: hsl(0-360, 0-100%, 0-100%)
2418 * - HSLA colour: hsla(0-360, 0-100%, 0-100%, 0-1)
2420 * Or a recognised browser colour mapping {@link css_optimiser::$htmlcolours}
2422 * @deprecated since Moodle 3.2
2423 * @todo MDL-56173 for final deprecation in Moodle 3.6
2424 * @param string $value The colour value to check
2427 function css_is_colour($value) {
2428 debugging('css_is_colour() is deprecated without a replacement. Please copy the implementation '.
2429 'into your plugin if you need this functionality.', DEBUG_DEVELOPER
);
2431 $value = trim($value);
2433 $hex = '/^#([a-fA-F0-9]{1,3}|[a-fA-F0-9]{6})$/';
2434 $rgb = '#^rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$#i';
2435 $rgba = '#^rgba\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1}(\.\d+)?)\s*\)$#i';
2436 $hsl = '#^hsl\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\%\s*,\s*(\d{1,3})\%\s*\)$#i';
2437 $hsla = '#^hsla\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\%\s*,\s*(\d{1,3})\%\s*,\s*(\d{1}(\.\d+)?)\s*\)$#i';
2439 if (in_array(strtolower($value), array('inherit'))) {
2441 } else if (preg_match($hex, $value)) {
2443 } else if (in_array(strtolower($value), array_keys(css_optimiser
::$htmlcolours))) {
2445 } else if (preg_match($rgb, $value, $m) && $m[1] < 256 && $m[2] < 256 && $m[3] < 256) {
2446 // It is an RGB colour.
2448 } else if (preg_match($rgba, $value, $m) && $m[1] < 256 && $m[2] < 256 && $m[3] < 256) {
2449 // It is an RGBA colour.
2451 } else if (preg_match($hsl, $value, $m) && $m[1] <= 360 && $m[2] <= 100 && $m[3] <= 100) {
2452 // It is an HSL colour.
2454 } else if (preg_match($hsla, $value, $m) && $m[1] <= 360 && $m[2] <= 100 && $m[3] <= 100) {
2455 // It is an HSLA colour.
2458 // Doesn't look like a colour.
2463 * Returns true is the passed value looks like a CSS width.
2464 * In order to pass this test the value must be purely numerical or end with a
2465 * valid CSS unit term.
2467 * @param string|int $value
2469 * @deprecated since Moodle 3.2
2470 * @todo MDL-56173 for final deprecation in Moodle 3.6
2472 function css_is_width($value) {
2473 debugging('css_is_width() is deprecated without a replacement. Please copy the implementation '.
2474 'into your plugin if you need this functionality.', DEBUG_DEVELOPER
);
2476 $value = trim($value);
2477 if (in_array(strtolower($value), array('auto', 'inherit'))) {
2480 if ((string)$value === '0' ||
preg_match('#^(\-\s*)?(\d*\.)?(\d+)\s*(em|px|pt|\%|in|cm|mm|ex|pc)$#i', $value)) {
2487 * A simple sorting function to sort two array values on the number of items they contain
2492 * @deprecated since Moodle 3.2
2493 * @todo MDL-56173 for final deprecation in Moodle 3.6
2495 function css_sort_by_count(array $a, array $b) {
2496 debugging('css_sort_by_count() is deprecated without a replacement. Please copy the implementation '.
2497 'into your plugin if you need this functionality.', DEBUG_DEVELOPER
);
2504 return ($a > $b) ?
-1 : 1;
2508 * A basic CSS optimiser that strips out unwanted things and then processes CSS organising and cleaning styles.
2509 * @deprecated since Moodle 3.2
2510 * @todo MDL-56173 for final deprecation in Moodle 3.6
2512 class css_optimiser
{
2514 * An array of the common HTML colours that are supported by most browsers.
2516 * This reference table is used to allow us to unify colours, and will aid
2517 * us in identifying buggy CSS using unsupported colours.
2520 * @deprecated since Moodle 3.2
2521 * @todo MDL-56173 for final deprecation in Moodle 3.6
2523 public static $htmlcolours = array(
2524 'aliceblue' => '#F0F8FF',
2525 'antiquewhite' => '#FAEBD7',
2526 'aqua' => '#00FFFF',
2527 'aquamarine' => '#7FFFD4',
2528 'azure' => '#F0FFFF',
2529 'beige' => '#F5F5DC',
2530 'bisque' => '#FFE4C4',
2531 'black' => '#000000',
2532 'blanchedalmond' => '#FFEBCD',
2533 'blue' => '#0000FF',
2534 'blueviolet' => '#8A2BE2',
2535 'brown' => '#A52A2A',
2536 'burlywood' => '#DEB887',
2537 'cadetblue' => '#5F9EA0',
2538 'chartreuse' => '#7FFF00',
2539 'chocolate' => '#D2691E',
2540 'coral' => '#FF7F50',
2541 'cornflowerblue' => '#6495ED',
2542 'cornsilk' => '#FFF8DC',
2543 'crimson' => '#DC143C',
2544 'cyan' => '#00FFFF',
2545 'darkblue' => '#00008B',
2546 'darkcyan' => '#008B8B',
2547 'darkgoldenrod' => '#B8860B',
2548 'darkgray' => '#A9A9A9',
2549 'darkgrey' => '#A9A9A9',
2550 'darkgreen' => '#006400',
2551 'darkKhaki' => '#BDB76B',
2552 'darkmagenta' => '#8B008B',
2553 'darkolivegreen' => '#556B2F',
2554 'arkorange' => '#FF8C00',
2555 'darkorchid' => '#9932CC',
2556 'darkred' => '#8B0000',
2557 'darksalmon' => '#E9967A',
2558 'darkseagreen' => '#8FBC8F',
2559 'darkslateblue' => '#483D8B',
2560 'darkslategray' => '#2F4F4F',
2561 'darkslategrey' => '#2F4F4F',
2562 'darkturquoise' => '#00CED1',
2563 'darkviolet' => '#9400D3',
2564 'deeppink' => '#FF1493',
2565 'deepskyblue' => '#00BFFF',
2566 'dimgray' => '#696969',
2567 'dimgrey' => '#696969',
2568 'dodgerblue' => '#1E90FF',
2569 'firebrick' => '#B22222',
2570 'floralwhite' => '#FFFAF0',
2571 'forestgreen' => '#228B22',
2572 'fuchsia' => '#FF00FF',
2573 'gainsboro' => '#DCDCDC',
2574 'ghostwhite' => '#F8F8FF',
2575 'gold' => '#FFD700',
2576 'goldenrod' => '#DAA520',
2577 'gray' => '#808080',
2578 'grey' => '#808080',
2579 'green' => '#008000',
2580 'greenyellow' => '#ADFF2F',
2581 'honeydew' => '#F0FFF0',
2582 'hotpink' => '#FF69B4',
2583 'indianred ' => '#CD5C5C',
2584 'indigo ' => '#4B0082',
2585 'ivory' => '#FFFFF0',
2586 'khaki' => '#F0E68C',
2587 'lavender' => '#E6E6FA',
2588 'lavenderblush' => '#FFF0F5',
2589 'lawngreen' => '#7CFC00',
2590 'lemonchiffon' => '#FFFACD',
2591 'lightblue' => '#ADD8E6',
2592 'lightcoral' => '#F08080',
2593 'lightcyan' => '#E0FFFF',
2594 'lightgoldenrodyellow' => '#FAFAD2',
2595 'lightgray' => '#D3D3D3',
2596 'lightgrey' => '#D3D3D3',
2597 'lightgreen' => '#90EE90',
2598 'lightpink' => '#FFB6C1',
2599 'lightsalmon' => '#FFA07A',
2600 'lightseagreen' => '#20B2AA',
2601 'lightskyblue' => '#87CEFA',
2602 'lightslategray' => '#778899',
2603 'lightslategrey' => '#778899',
2604 'lightsteelblue' => '#B0C4DE',
2605 'lightyellow' => '#FFFFE0',
2606 'lime' => '#00FF00',
2607 'limegreen' => '#32CD32',
2608 'linen' => '#FAF0E6',
2609 'magenta' => '#FF00FF',
2610 'maroon' => '#800000',
2611 'mediumaquamarine' => '#66CDAA',
2612 'mediumblue' => '#0000CD',
2613 'mediumorchid' => '#BA55D3',
2614 'mediumpurple' => '#9370D8',
2615 'mediumseagreen' => '#3CB371',
2616 'mediumslateblue' => '#7B68EE',
2617 'mediumspringgreen' => '#00FA9A',
2618 'mediumturquoise' => '#48D1CC',
2619 'mediumvioletred' => '#C71585',
2620 'midnightblue' => '#191970',
2621 'mintcream' => '#F5FFFA',
2622 'mistyrose' => '#FFE4E1',
2623 'moccasin' => '#FFE4B5',
2624 'navajowhite' => '#FFDEAD',
2625 'navy' => '#000080',
2626 'oldlace' => '#FDF5E6',
2627 'olive' => '#808000',
2628 'olivedrab' => '#6B8E23',
2629 'orange' => '#FFA500',
2630 'orangered' => '#FF4500',
2631 'orchid' => '#DA70D6',
2632 'palegoldenrod' => '#EEE8AA',
2633 'palegreen' => '#98FB98',
2634 'paleturquoise' => '#AFEEEE',
2635 'palevioletred' => '#D87093',
2636 'papayawhip' => '#FFEFD5',
2637 'peachpuff' => '#FFDAB9',
2638 'peru' => '#CD853F',
2639 'pink' => '#FFC0CB',
2640 'plum' => '#DDA0DD',
2641 'powderblue' => '#B0E0E6',
2642 'purple' => '#800080',
2644 'rosybrown' => '#BC8F8F',
2645 'royalblue' => '#4169E1',
2646 'saddlebrown' => '#8B4513',
2647 'salmon' => '#FA8072',
2648 'sandybrown' => '#F4A460',
2649 'seagreen' => '#2E8B57',
2650 'seashell' => '#FFF5EE',
2651 'sienna' => '#A0522D',
2652 'silver' => '#C0C0C0',
2653 'skyblue' => '#87CEEB',
2654 'slateblue' => '#6A5ACD',
2655 'slategray' => '#708090',
2656 'slategrey' => '#708090',
2657 'snow' => '#FFFAFA',
2658 'springgreen' => '#00FF7F',
2659 'steelblue' => '#4682B4',
2661 'teal' => '#008080',
2662 'thistle' => '#D8BFD8',
2663 'tomato' => '#FF6347',
2664 'transparent' => 'transparent',
2665 'turquoise' => '#40E0D0',
2666 'violet' => '#EE82EE',
2667 'wheat' => '#F5DEB3',
2668 'white' => '#FFFFFF',
2669 'whitesmoke' => '#F5F5F5',
2670 'yellow' => '#FFFF00',
2671 'yellowgreen' => '#9ACD32'
2675 * Used to orocesses incoming CSS optimising it and then returning it. Now just returns
2676 * what is sent to it. Do not use.
2678 * @param string $css The raw CSS to optimise
2679 * @return string The optimised CSS
2680 * @deprecated since Moodle 3.2
2681 * @todo MDL-56173 for final deprecation in Moodle 3.6
2683 public function process($css) {
2684 debugging('class css_optimiser is deprecated and no longer does anything, '.
2685 'please consider using stylelint to optimise your css.', DEBUG_DEVELOPER
);
2692 * Load the course contexts for all of the users courses
2694 * @deprecated since Moodle 3.2
2695 * @param array $courses array of course objects. The courses the user is enrolled in.
2696 * @return array of course contexts
2698 function message_get_course_contexts($courses) {
2699 debugging('message_get_course_contexts() is deprecated and is no longer used.', DEBUG_DEVELOPER
);
2701 $coursecontexts = array();
2703 foreach($courses as $course) {
2704 $coursecontexts[$course->id
] = context_course
::instance($course->id
);
2707 return $coursecontexts;
2711 * strip off action parameters like 'removecontact'
2713 * @deprecated since Moodle 3.2
2714 * @param moodle_url/string $moodleurl a URL. Typically the current page URL.
2715 * @return string the URL minus parameters that perform actions (like adding/removing/blocking a contact).
2717 function message_remove_url_params($moodleurl) {
2718 debugging('message_remove_url_params() is deprecated and is no longer used.', DEBUG_DEVELOPER
);
2720 $newurl = new moodle_url($moodleurl);
2721 $newurl->remove_params('addcontact','removecontact','blockcontact','unblockcontact');
2722 return $newurl->out();
2726 * Count the number of messages with a field having a specified value.
2727 * if $field is empty then return count of the whole array
2728 * if $field is non-existent then return 0
2730 * @deprecated since Moodle 3.2
2731 * @param array $messagearray array of message objects
2732 * @param string $field the field to inspect on the message objects
2733 * @param string $value the value to test the field against
2735 function message_count_messages($messagearray, $field='', $value='') {
2736 debugging('message_count_messages() is deprecated and is no longer used.', DEBUG_DEVELOPER
);
2738 if (!is_array($messagearray)) return 0;
2739 if ($field == '' or empty($messagearray)) return count($messagearray);
2742 foreach ($messagearray as $message) {
2743 $count +
= ($message->$field == $value) ?
1 : 0;
2749 * Count the number of users blocked by $user1
2751 * @deprecated since Moodle 3.2
2752 * @param object $user1 user object
2753 * @return int the number of blocked users
2755 function message_count_blocked_users($user1=null) {
2756 debugging('message_count_blocked_users() is deprecated, please use \core_message\api::count_blocked_users() instead.',
2759 return \core_message\api
::count_blocked_users($user1);
2763 * Print a message contact link
2765 * @deprecated since Moodle 3.2
2766 * @param int $userid the ID of the user to apply to action to
2767 * @param string $linktype can be add, remove, block or unblock
2768 * @param bool $return if true return the link as a string. If false echo the link.
2769 * @param string $script the URL to send the user to when the link is clicked. If null, the current page.
2770 * @param bool $text include text next to the icons?
2771 * @param bool $icon include a graphical icon?
2772 * @return string if $return is true otherwise bool
2774 function message_contact_link($userid, $linktype='add', $return=false, $script=null, $text=false, $icon=true) {
2775 debugging('message_contact_link() is deprecated and is no longer used.', DEBUG_DEVELOPER
);
2777 global $OUTPUT, $PAGE;
2779 //hold onto the strings as we're probably creating a bunch of links
2782 if (empty($script)) {
2783 //strip off previous action params like 'removecontact'
2784 $script = message_remove_url_params($PAGE->url
);
2787 if (empty($str->blockcontact
)) {
2788 $str = new stdClass();
2789 $str->blockcontact
= get_string('blockcontact', 'message');
2790 $str->unblockcontact
= get_string('unblockcontact', 'message');
2791 $str->removecontact
= get_string('removecontact', 'message');
2792 $str->addcontact
= get_string('addcontact', 'message');
2795 $command = $linktype.'contact';
2796 $string = $str->{$command};
2798 $safealttext = s($string);
2801 if (!empty($text)) {
2802 $safestring = $safealttext;
2808 switch ($linktype) {
2810 $iconpath = 't/block';
2813 $iconpath = 't/unblock';
2816 $iconpath = 't/removecontact';
2820 $iconpath = 't/addcontact';
2823 $img = $OUTPUT->pix_icon($iconpath, $safealttext);
2826 $output = '<span class="'.$linktype.'contact">'.
2827 '<a href="'.$script.'&'.$command.'='.$userid.
2828 '&sesskey='.sesskey().'" title="'.$safealttext.'">'.
2830 $safestring.'</a></span>';
2841 * @deprecated since Moodle 3.2
2843 function message_get_recent_notifications($user, $limitfrom=0, $limitto=100) {
2844 throw new coding_exception('message_get_recent_notifications() can not be used any more.', DEBUG_DEVELOPER
);
2848 * echo or return a link to take the user to the full message history between themselves and another user
2850 * @deprecated since Moodle 3.2
2851 * @param int $userid1 the ID of the user displayed on the left (usually the current user)
2852 * @param int $userid2 the ID of the other user
2853 * @param bool $return true to return the link as a string. False to echo the link.
2854 * @param string $keywords any keywords to highlight in the message history
2855 * @param string $position anchor name to jump to within the message history
2856 * @param string $linktext optionally specify the link text
2857 * @return string|bool. Returns a string if $return is true. Otherwise returns a boolean.
2859 function message_history_link($userid1, $userid2, $return=false, $keywords='', $position='', $linktext='') {
2860 debugging('message_history_link() is deprecated and is no longer used.', DEBUG_DEVELOPER
);
2862 global $OUTPUT, $PAGE;
2863 static $strmessagehistory;
2865 if (empty($strmessagehistory)) {
2866 $strmessagehistory = get_string('messagehistory', 'message');
2870 $position = "#$position";
2873 $keywords = "&search=".urlencode($keywords);
2876 if ($linktext == 'icon') { // Icon only
2877 $fulllink = $OUTPUT->pix_icon('t/messages', $strmessagehistory);
2878 } else if ($linktext == 'both') { // Icon and standard name
2879 $fulllink = $OUTPUT->pix_icon('t/messages', '');
2880 $fulllink .= ' '.$strmessagehistory;
2881 } else if ($linktext) { // Custom name
2882 $fulllink = $linktext;
2883 } else { // Standard name only
2884 $fulllink = $strmessagehistory;
2887 $popupoptions = array(
2891 'location' => false,
2893 'scrollbars' => true,
2894 'resizable' => true);
2896 $link = new moodle_url('/message/index.php?history='.MESSAGE_HISTORY_ALL
."&user1=$userid1&user2=$userid2$keywords$position");
2897 if ($PAGE->url
&& $PAGE->url
->get_param('viewing')) {
2898 $link->param('viewing', $PAGE->url
->get_param('viewing'));
2901 $str = $OUTPUT->action_link($link, $fulllink, $action, array('title' => $strmessagehistory));
2903 $str = '<span class="history">'.$str.'</span>';
2914 * @deprecated since Moodle 3.2
2916 function message_search($searchterms, $fromme=true, $tome=true, $courseid='none', $userid=0) {
2917 throw new coding_exception('message_search() can not be used any more.', DEBUG_DEVELOPER
);
2921 * Given a message object that we already know has a long message
2922 * this function truncates the message nicely to the first
2923 * sane place between $CFG->forum_longpost and $CFG->forum_shortpost
2925 * @deprecated since Moodle 3.2
2926 * @param string $message the message
2927 * @param int $minlength the minimum length to trim the message to
2928 * @return string the shortened message
2930 function message_shorten_message($message, $minlength = 0) {
2931 debugging('message_shorten_message() is deprecated and is no longer used.', DEBUG_DEVELOPER
);
2935 $length = strlen($message);
2939 if ($minlength == 0) $minlength = MESSAGE_SHORTLENGTH
;
2942 for ($i=0; $i<$length; $i++
) {
2943 $char = $message[$i];
2955 if ($char == '.' or $char == ' ') {
2965 if ($count > $minlength) {
2975 return substr($message, 0, $truncate);
2979 * Given a string and an array of keywords, this function looks
2980 * for the first keyword in the string, and then chops out a
2981 * small section from the text that shows that word in context.
2983 * @deprecated since Moodle 3.2
2984 * @param string $message the text to search
2985 * @param array $keywords array of keywords to find
2987 function message_get_fragment($message, $keywords) {
2988 debugging('message_get_fragment() is deprecated and is no longer used.', DEBUG_DEVELOPER
);
2991 $halfsize = (int)($fullsize/2);
2993 $message = strip_tags($message);
2995 foreach ($keywords as $keyword) { // Just get the first one
2996 if ($keyword !== '') {
3000 if (empty($keyword)) { // None found, so just return start of message
3001 return message_shorten_message($message, 30);
3004 $leadin = $leadout = '';
3006 /// Find the start of the fragment
3008 $length = strlen($message);
3010 $pos = strpos($message, $keyword);
3011 if ($pos > $halfsize) {
3012 $start = $pos - $halfsize;
3015 /// Find the end of the fragment
3016 $end = $start +
$fullsize;
3017 if ($end > $length) {
3023 /// Pull out the fragment and format it
3025 $fragment = substr($message, $start, $end - $start);
3026 $fragment = $leadin.highlight(implode(' ',$keywords), $fragment).$leadout;
3031 * @deprecated since Moodle 3.2
3033 function message_get_history($user1, $user2, $limitnum=0, $viewingnewmessages=false) {
3034 throw new coding_exception('message_get_history() can not be used any more.', DEBUG_DEVELOPER
);
3038 * Constructs the add/remove contact link to display next to other users
3040 * @deprecated since Moodle 3.2
3041 * @param bool $incontactlist is the user a contact
3042 * @param bool $isblocked is the user blocked
3043 * @param stdClass $contact contact object
3044 * @param string $script the URL to send the user to when the link is clicked. If null, the current page.
3045 * @param bool $text include text next to the icons?
3046 * @param bool $icon include a graphical icon?
3049 function message_get_contact_add_remove_link($incontactlist, $isblocked, $contact, $script=null, $text=false, $icon=true) {
3050 debugging('message_get_contact_add_remove_link() is deprecated and is no longer used.', DEBUG_DEVELOPER
);
3055 $strcontact = message_contact_link($contact->id
, 'remove', true, $script, $text, $icon);
3056 } else if ($isblocked) {
3057 $strcontact = message_contact_link($contact->id
, 'add', true, $script, $text, $icon);
3059 $strcontact = message_contact_link($contact->id
, 'add', true, $script, $text, $icon);
3066 * Constructs the block contact link to display next to other users
3068 * @deprecated since Moodle 3.2
3069 * @param bool $incontactlist is the user a contact?
3070 * @param bool $isblocked is the user blocked?
3071 * @param stdClass $contact contact object
3072 * @param string $script the URL to send the user to when the link is clicked. If null, the current page.
3073 * @param bool $text include text next to the icons?
3074 * @param bool $icon include a graphical icon?
3077 function message_get_contact_block_link($incontactlist, $isblocked, $contact, $script=null, $text=false, $icon=true) {
3078 debugging('message_get_contact_block_link() is deprecated and is no longer used.', DEBUG_DEVELOPER
);
3082 //commented out to allow the user to block a contact without having to remove them first
3083 /*if ($incontactlist) {
3087 $strblock = message_contact_link($contact->id
, 'unblock', true, $script, $text, $icon);
3089 $strblock = message_contact_link($contact->id
, 'block', true, $script, $text, $icon);
3096 * marks ALL messages being sent from $fromuserid to $touserid as read
3098 * @deprecated since Moodle 3.2
3099 * @param int $touserid the id of the message recipient
3100 * @param int $fromuserid the id of the message sender
3103 function message_mark_messages_read($touserid, $fromuserid) {
3104 debugging('message_mark_messages_read() is deprecated and is no longer used, please use
3105 \core_message\api::mark_all_messages_as_read() instead.', DEBUG_DEVELOPER
);
3107 \core_message\api
::mark_all_messages_as_read($touserid, $fromuserid);
3111 * Return a list of page types
3113 * @deprecated since Moodle 3.2
3114 * @param string $pagetype current page type
3115 * @param stdClass $parentcontext Block's parent context
3116 * @param stdClass $currentcontext Current context of block
3118 function message_page_type_list($pagetype, $parentcontext, $currentcontext) {
3119 debugging('message_page_type_list() is deprecated and is no longer used.', DEBUG_DEVELOPER
);
3121 return array('messages-*'=>get_string('page-message-x', 'message'));
3125 * Determines if a user is permitted to send another user a private message.
3126 * If no sender is provided then it defaults to the logged in user.
3128 * @deprecated since Moodle 3.2
3129 * @param object $recipient User object.
3130 * @param object $sender User object.
3131 * @return bool true if user is permitted, false otherwise.
3133 function message_can_post_message($recipient, $sender = null) {
3134 debugging('message_can_post_message() is deprecated and is no longer used, please use
3135 \core_message\api::can_post_message() instead.', DEBUG_DEVELOPER
);
3137 return \core_message\api
::can_post_message($recipient, $sender);
3141 * Checks if the recipient is allowing messages from users that aren't a
3142 * contact. If not then it checks to make sure the sender is in the
3143 * recipient's contacts.
3145 * @deprecated since Moodle 3.2
3146 * @param object $recipient User object.
3147 * @param object $sender User object.
3148 * @return bool true if $sender is blocked, false otherwise.
3150 function message_is_user_non_contact_blocked($recipient, $sender = null) {
3151 debugging('message_is_user_non_contact_blocked() is deprecated and is no longer used, please use
3152 \core_message\api::is_user_non_contact_blocked() instead.', DEBUG_DEVELOPER
);
3154 return \core_message\api
::is_user_non_contact_blocked($recipient, $sender);
3158 * Checks if the recipient has specifically blocked the sending user.
3160 * Note: This function will always return false if the sender has the
3161 * readallmessages capability at the system context level.
3163 * @deprecated since Moodle 3.2
3164 * @param object $recipient User object.
3165 * @param object $sender User object.
3166 * @return bool true if $sender is blocked, false otherwise.
3168 function message_is_user_blocked($recipient, $sender = null) {
3169 debugging('message_is_user_blocked() is deprecated and is no longer used, please use
3170 \core_message\api::is_user_blocked() instead.', DEBUG_DEVELOPER
);
3173 if ($sender !== null && isset($sender->id
)) {
3174 $senderid = $sender->id
;
3176 return \core_message\api
::is_user_blocked($recipient->id
, $senderid);
3182 * @deprecated since 3.2
3184 function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100,
3185 $url="", $modname="", $modid=0, $modaction="", $groupid=0) {
3186 debugging(__FUNCTION__
. '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER
);
3188 global $CFG, $DB, $OUTPUT;
3190 if (!$logs = build_logs_array($course, $user, $date, $order, $page*$perpage, $perpage,
3191 $modname, $modid, $modaction, $groupid)) {
3192 echo $OUTPUT->notification("No logs found!");
3193 echo $OUTPUT->footer();
3199 if ($course->id
== SITEID
) {
3201 if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
3202 foreach ($ccc as $cc) {
3203 $courses[$cc->id
] = $cc->shortname
;
3207 $courses[$course->id
] = $course->shortname
;
3210 $totalcount = $logs['totalcount'];
3213 $strftimedatetime = get_string("strftimedatetime");
3215 echo "<div class=\"info\">\n";
3216 print_string("displayingrecords", "", $totalcount);
3219 echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage");
3221 $table = new html_table();
3222 $table->classes
= array('logtable','generaltable');
3223 $table->align
= array('right', 'left', 'left');
3224 $table->head
= array(
3226 get_string('ip_address'),
3227 get_string('fullnameuser'),
3228 get_string('action'),
3231 $table->data
= array();
3233 if ($course->id
== SITEID
) {
3234 array_unshift($table->align
, 'left');
3235 array_unshift($table->head
, get_string('course'));
3238 // Make sure that the logs array is an array, even it is empty, to avoid warnings from the foreach.
3239 if (empty($logs['logs'])) {
3240 $logs['logs'] = array();
3243 foreach ($logs['logs'] as $log) {
3245 if (isset($ldcache[$log->module
][$log->action
])) {
3246 $ld = $ldcache[$log->module
][$log->action
];
3248 $ld = $DB->get_record('log_display', array('module'=>$log->module
, 'action'=>$log->action
));
3249 $ldcache[$log->module
][$log->action
] = $ld;
3251 if ($ld && is_numeric($log->info
)) {
3252 // ugly hack to make sure fullname is shown correctly
3253 if ($ld->mtable
== 'user' && $ld->field
== $DB->sql_concat('firstname', "' '" , 'lastname')) {
3254 $log->info
= fullname($DB->get_record($ld->mtable
, array('id'=>$log->info
)), true);
3256 $log->info
= $DB->get_field($ld->mtable
, $ld->field
, array('id'=>$log->info
));
3261 $log->info
= format_string($log->info
);
3263 // If $log->url has been trimmed short by the db size restriction
3264 // code in add_to_log, keep a note so we don't add a link to a broken url
3265 $brokenurl=(core_text
::strlen($log->url
)==100 && core_text
::substr($log->url
,97)=='...');
3268 if ($course->id
== SITEID
) {
3269 if (empty($log->course
)) {
3270 $row[] = get_string('site');
3272 $row[] = "<a href=\"{$CFG->wwwroot}/course/view.php?id={$log->course}\">". format_string($courses[$log->course
])."</a>";
3276 $row[] = userdate($log->time
, '%a').' '.userdate($log->time
, $strftimedatetime);
3278 $link = new moodle_url("/iplookup/index.php?ip=$log->ip&user=$log->userid");
3279 $row[] = $OUTPUT->action_link($link, $log->ip
, new popup_action('click', $link, 'iplookup', array('height' => 440, 'width' => 700)));
3281 $row[] = html_writer
::link(new moodle_url("/user/view.php?id={$log->userid}&course={$log->course}"), fullname($log, has_capability('moodle/site:viewfullnames', context_course
::instance($course->id
))));
3283 $displayaction="$log->module $log->action";
3285 $row[] = $displayaction;
3287 $link = make_log_url($log->module
,$log->url
);
3288 $row[] = $OUTPUT->action_link($link, $displayaction, new popup_action('click', $link, 'fromloglive'), array('height' => 440, 'width' => 700));
3290 $row[] = $log->info
;
3291 $table->data
[] = $row;
3294 echo html_writer
::table($table);
3295 echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage");
3299 * Display MNET logs.
3301 * @deprecated since 3.2
3303 function print_mnet_log($hostid, $course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100,
3304 $url="", $modname="", $modid=0, $modaction="", $groupid=0) {
3305 debugging(__FUNCTION__
. '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER
);
3307 global $CFG, $DB, $OUTPUT;
3309 if (!$logs = build_mnet_logs_array($hostid, $course, $user, $date, $order, $page*$perpage, $perpage,
3310 $modname, $modid, $modaction, $groupid)) {
3311 echo $OUTPUT->notification("No logs found!");
3312 echo $OUTPUT->footer();
3316 if ($course->id
== SITEID
) {
3318 if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname,c.visible')) {
3319 foreach ($ccc as $cc) {
3320 $courses[$cc->id
] = $cc->shortname
;
3325 $totalcount = $logs['totalcount'];
3328 $strftimedatetime = get_string("strftimedatetime");
3330 echo "<div class=\"info\">\n";
3331 print_string("displayingrecords", "", $totalcount);
3334 echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage");
3336 echo "<table class=\"logtable\" cellpadding=\"3\" cellspacing=\"0\">\n";
3338 if ($course->id
== SITEID
) {
3339 echo "<th class=\"c0 header\">".get_string('course')."</th>\n";
3341 echo "<th class=\"c1 header\">".get_string('time')."</th>\n";
3342 echo "<th class=\"c2 header\">".get_string('ip_address')."</th>\n";
3343 echo "<th class=\"c3 header\">".get_string('fullnameuser')."</th>\n";
3344 echo "<th class=\"c4 header\">".get_string('action')."</th>\n";
3345 echo "<th class=\"c5 header\">".get_string('info')."</th>\n";
3348 if (empty($logs['logs'])) {
3354 foreach ($logs['logs'] as $log) {
3356 $log->info
= $log->coursename
;
3357 $row = ($row +
1) %
2;
3359 if (isset($ldcache[$log->module
][$log->action
])) {
3360 $ld = $ldcache[$log->module
][$log->action
];
3362 $ld = $DB->get_record('log_display', array('module'=>$log->module
, 'action'=>$log->action
));
3363 $ldcache[$log->module
][$log->action
] = $ld;
3365 if (0 && $ld && !empty($log->info
)) {
3366 // ugly hack to make sure fullname is shown correctly
3367 if (($ld->mtable
== 'user') and ($ld->field
== $DB->sql_concat('firstname', "' '" , 'lastname'))) {
3368 $log->info
= fullname($DB->get_record($ld->mtable
, array('id'=>$log->info
)), true);
3370 $log->info
= $DB->get_field($ld->mtable
, $ld->field
, array('id'=>$log->info
));
3375 $log->info
= format_string($log->info
);
3377 echo '<tr class="r'.$row.'">';
3378 if ($course->id
== SITEID
) {
3379 $courseshortname = format_string($courses[$log->course
], true, array('context' => context_course
::instance(SITEID
)));
3380 echo "<td class=\"r$row c0\" >\n";
3381 echo " <a href=\"{$CFG->wwwroot}/course/view.php?id={$log->course}\">".$courseshortname."</a>\n";
3384 echo "<td class=\"r$row c1\" align=\"right\">".userdate($log->time
, '%a').
3385 ' '.userdate($log->time
, $strftimedatetime)."</td>\n";
3386 echo "<td class=\"r$row c2\" >\n";
3387 $link = new moodle_url("/iplookup/index.php?ip=$log->ip&user=$log->userid");
3388 echo $OUTPUT->action_link($link, $log->ip
, new popup_action('click', $link, 'iplookup', array('height' => 400, 'width' => 700)));
3390 $fullname = fullname($log, has_capability('moodle/site:viewfullnames', context_course
::instance($course->id
)));
3391 echo "<td class=\"r$row c3\" >\n";
3392 echo " <a href=\"$CFG->wwwroot/user/view.php?id={$log->userid}\">$fullname</a>\n";
3394 echo "<td class=\"r$row c4\">\n";
3395 echo $log->action
.': '.$log->module
;
3397 echo "<td class=\"r$row c5\">{$log->info}</td>\n";
3402 echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage");
3406 * Display logs in CSV format.
3408 * @deprecated since 3.2
3410 function print_log_csv($course, $user, $date, $order='l.time DESC', $modname,
3411 $modid, $modaction, $groupid) {
3412 debugging(__FUNCTION__
. '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER
);
3416 require_once($CFG->libdir
. '/csvlib.class.php');
3418 $csvexporter = new csv_export_writer('tab');
3421 $header[] = get_string('course');
3422 $header[] = get_string('time');
3423 $header[] = get_string('ip_address');
3424 $header[] = get_string('fullnameuser');
3425 $header[] = get_string('action');
3426 $header[] = get_string('info');
3428 if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
3429 $modname, $modid, $modaction, $groupid)) {
3435 if ($course->id
== SITEID
) {
3437 if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
3438 foreach ($ccc as $cc) {
3439 $courses[$cc->id
] = $cc->shortname
;
3443 $courses[$course->id
] = $course->shortname
;
3448 $tt = getdate(time());
3449 $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
3451 $strftimedatetime = get_string("strftimedatetime");
3453 $csvexporter->set_filename('logs', '.txt');
3454 $title = array(get_string('savedat').userdate(time(), $strftimedatetime));
3455 $csvexporter->add_data($title);
3456 $csvexporter->add_data($header);
3458 if (empty($logs['logs'])) {
3462 foreach ($logs['logs'] as $log) {
3463 if (isset($ldcache[$log->module
][$log->action
])) {
3464 $ld = $ldcache[$log->module
][$log->action
];
3466 $ld = $DB->get_record('log_display', array('module'=>$log->module
, 'action'=>$log->action
));
3467 $ldcache[$log->module
][$log->action
] = $ld;
3469 if ($ld && is_numeric($log->info
)) {
3470 // ugly hack to make sure fullname is shown correctly
3471 if (($ld->mtable
== 'user') and ($ld->field
== $DB->sql_concat('firstname', "' '" , 'lastname'))) {
3472 $log->info
= fullname($DB->get_record($ld->mtable
, array('id'=>$log->info
)), true);
3474 $log->info
= $DB->get_field($ld->mtable
, $ld->field
, array('id'=>$log->info
));
3479 $log->info
= format_string($log->info
);
3480 $log->info
= strip_tags(urldecode($log->info
)); // Some XSS protection
3482 $coursecontext = context_course
::instance($course->id
);
3483 $firstField = format_string($courses[$log->course
], true, array('context' => $coursecontext));
3484 $fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
3485 $actionurl = $CFG->wwwroot
. make_log_url($log->module
,$log->url
);
3486 $row = array($firstField, userdate($log->time
, $strftimedatetime), $log->ip
, $fullname, $log->module
.' '.$log->action
.' ('.$actionurl.')', $log->info
);
3487 $csvexporter->add_data($row);
3489 $csvexporter->download_file();
3494 * Display logs in XLS format.
3496 * @deprecated since 3.2
3498 function print_log_xls($course, $user, $date, $order='l.time DESC', $modname,
3499 $modid, $modaction, $groupid) {
3500 debugging(__FUNCTION__
. '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER
);
3504 require_once("$CFG->libdir/excellib.class.php");
3506 if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
3507 $modname, $modid, $modaction, $groupid)) {
3513 if ($course->id
== SITEID
) {
3515 if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
3516 foreach ($ccc as $cc) {
3517 $courses[$cc->id
] = $cc->shortname
;
3521 $courses[$course->id
] = $course->shortname
;
3526 $tt = getdate(time());
3527 $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
3529 $strftimedatetime = get_string("strftimedatetime");
3531 $nroPages = ceil(count($logs)/(EXCELROWS
-FIRSTUSEDEXCELROW+
1));
3532 $filename = 'logs_'.userdate(time(),get_string('backupnameformat', 'langconfig'),99,false);
3533 $filename .= '.xls';
3535 $workbook = new MoodleExcelWorkbook('-');
3536 $workbook->send($filename);
3538 $worksheet = array();
3539 $headers = array(get_string('course'), get_string('time'), get_string('ip_address'),
3540 get_string('fullnameuser'), get_string('action'), get_string('info'));
3542 // Creating worksheets
3543 for ($wsnumber = 1; $wsnumber <= $nroPages; $wsnumber++
) {
3544 $sheettitle = get_string('logs').' '.$wsnumber.'-'.$nroPages;
3545 $worksheet[$wsnumber] = $workbook->add_worksheet($sheettitle);
3546 $worksheet[$wsnumber]->set_column(1, 1, 30);
3547 $worksheet[$wsnumber]->write_string(0, 0, get_string('savedat').
3548 userdate(time(), $strftimedatetime));
3550 foreach ($headers as $item) {
3551 $worksheet[$wsnumber]->write(FIRSTUSEDEXCELROW
-1,$col,$item,'');
3556 if (empty($logs['logs'])) {
3561 $formatDate =& $workbook->add_format();
3562 $formatDate->set_num_format(get_string('log_excel_date_format'));
3564 $row = FIRSTUSEDEXCELROW
;
3566 $myxls =& $worksheet[$wsnumber];
3567 foreach ($logs['logs'] as $log) {
3568 if (isset($ldcache[$log->module
][$log->action
])) {
3569 $ld = $ldcache[$log->module
][$log->action
];
3571 $ld = $DB->get_record('log_display', array('module'=>$log->module
, 'action'=>$log->action
));
3572 $ldcache[$log->module
][$log->action
] = $ld;
3574 if ($ld && is_numeric($log->info
)) {
3575 // ugly hack to make sure fullname is shown correctly
3576 if (($ld->mtable
== 'user') and ($ld->field
== $DB->sql_concat('firstname', "' '" , 'lastname'))) {
3577 $log->info
= fullname($DB->get_record($ld->mtable
, array('id'=>$log->info
)), true);
3579 $log->info
= $DB->get_field($ld->mtable
, $ld->field
, array('id'=>$log->info
));
3584 $log->info
= format_string($log->info
);
3585 $log->info
= strip_tags(urldecode($log->info
)); // Some XSS protection
3588 if ($row > EXCELROWS
) {
3590 $myxls =& $worksheet[$wsnumber];
3591 $row = FIRSTUSEDEXCELROW
;
3595 $coursecontext = context_course
::instance($course->id
);
3597 $myxls->write($row, 0, format_string($courses[$log->course
], true, array('context' => $coursecontext)), '');
3598 $myxls->write_date($row, 1, $log->time
, $formatDate); // write_date() does conversion/timezone support. MDL-14934
3599 $myxls->write($row, 2, $log->ip
, '');
3600 $fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
3601 $myxls->write($row, 3, $fullname, '');
3602 $actionurl = $CFG->wwwroot
. make_log_url($log->module
,$log->url
);
3603 $myxls->write($row, 4, $log->module
.' '.$log->action
.' ('.$actionurl.')', '');
3604 $myxls->write($row, 5, $log->info
, '');
3614 * Display logs in ODS format.
3616 * @deprecated since 3.2
3618 function print_log_ods($course, $user, $date, $order='l.time DESC', $modname,
3619 $modid, $modaction, $groupid) {
3620 debugging(__FUNCTION__
. '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER
);
3624 require_once("$CFG->libdir/odslib.class.php");
3626 if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
3627 $modname, $modid, $modaction, $groupid)) {
3633 if ($course->id
== SITEID
) {
3635 if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
3636 foreach ($ccc as $cc) {
3637 $courses[$cc->id
] = $cc->shortname
;
3641 $courses[$course->id
] = $course->shortname
;
3646 $strftimedatetime = get_string("strftimedatetime");
3648 $nroPages = ceil(count($logs)/(EXCELROWS
-FIRSTUSEDEXCELROW+
1));
3649 $filename = 'logs_'.userdate(time(),get_string('backupnameformat', 'langconfig'),99,false);
3650 $filename .= '.ods';
3652 $workbook = new MoodleODSWorkbook('-');
3653 $workbook->send($filename);
3655 $worksheet = array();
3656 $headers = array(get_string('course'), get_string('time'), get_string('ip_address'),
3657 get_string('fullnameuser'), get_string('action'), get_string('info'));
3659 // Creating worksheets
3660 for ($wsnumber = 1; $wsnumber <= $nroPages; $wsnumber++
) {
3661 $sheettitle = get_string('logs').' '.$wsnumber.'-'.$nroPages;
3662 $worksheet[$wsnumber] = $workbook->add_worksheet($sheettitle);
3663 $worksheet[$wsnumber]->set_column(1, 1, 30);
3664 $worksheet[$wsnumber]->write_string(0, 0, get_string('savedat').
3665 userdate(time(), $strftimedatetime));
3667 foreach ($headers as $item) {
3668 $worksheet[$wsnumber]->write(FIRSTUSEDEXCELROW
-1,$col,$item,'');
3673 if (empty($logs['logs'])) {
3678 $formatDate =& $workbook->add_format();
3679 $formatDate->set_num_format(get_string('log_excel_date_format'));
3681 $row = FIRSTUSEDEXCELROW
;
3683 $myxls =& $worksheet[$wsnumber];
3684 foreach ($logs['logs'] as $log) {
3685 if (isset($ldcache[$log->module
][$log->action
])) {
3686 $ld = $ldcache[$log->module
][$log->action
];
3688 $ld = $DB->get_record('log_display', array('module'=>$log->module
, 'action'=>$log->action
));
3689 $ldcache[$log->module
][$log->action
] = $ld;
3691 if ($ld && is_numeric($log->info
)) {
3692 // ugly hack to make sure fullname is shown correctly
3693 if (($ld->mtable
== 'user') and ($ld->field
== $DB->sql_concat('firstname', "' '" , 'lastname'))) {
3694 $log->info
= fullname($DB->get_record($ld->mtable
, array('id'=>$log->info
)), true);
3696 $log->info
= $DB->get_field($ld->mtable
, $ld->field
, array('id'=>$log->info
));
3701 $log->info
= format_string($log->info
);
3702 $log->info
= strip_tags(urldecode($log->info
)); // Some XSS protection
3705 if ($row > EXCELROWS
) {
3707 $myxls =& $worksheet[$wsnumber];
3708 $row = FIRSTUSEDEXCELROW
;
3712 $coursecontext = context_course
::instance($course->id
);
3714 $myxls->write_string($row, 0, format_string($courses[$log->course
], true, array('context' => $coursecontext)));
3715 $myxls->write_date($row, 1, $log->time
);
3716 $myxls->write_string($row, 2, $log->ip
);
3717 $fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
3718 $myxls->write_string($row, 3, $fullname);
3719 $actionurl = $CFG->wwwroot
. make_log_url($log->module
,$log->url
);
3720 $myxls->write_string($row, 4, $log->module
.' '.$log->action
.' ('.$actionurl.')');
3721 $myxls->write_string($row, 5, $log->info
);
3731 * Build an array of logs.
3733 * @deprecated since 3.2
3735 function build_logs_array($course, $user=0, $date=0, $order="l.time ASC", $limitfrom='', $limitnum='',
3736 $modname="", $modid=0, $modaction="", $groupid=0) {
3737 global $DB, $SESSION, $USER;
3739 debugging(__FUNCTION__
. '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER
);
3740 // It is assumed that $date is the GMT time of midnight for that day,
3741 // and so the next 86400 seconds worth of logs are printed.
3743 // Setup for group handling.
3745 // If the group mode is separate, and this user does not have editing privileges,
3746 // then only the user's group can be viewed.
3747 if ($course->groupmode
== SEPARATEGROUPS
and !has_capability('moodle/course:managegroups', context_course
::instance($course->id
))) {
3748 if (isset($SESSION->currentgroup
[$course->id
])) {
3749 $groupid = $SESSION->currentgroup
[$course->id
];
3751 $groupid = groups_get_all_groups($course->id
, $USER->id
);
3752 if (is_array($groupid)) {
3753 $groupid = array_shift(array_keys($groupid));
3754 $SESSION->currentgroup
[$course->id
] = $groupid;
3760 // If this course doesn't have groups, no groupid can be specified.
3761 else if (!$course->groupmode
) {
3768 if ($course->id
!= SITEID ||
$modid != 0) {
3769 $joins[] = "l.course = :courseid";
3770 $params['courseid'] = $course->id
;
3774 $joins[] = "l.module = :modname";
3775 $params['modname'] = $modname;
3778 if ('site_errors' === $modid) {
3779 $joins[] = "( l.action='error' OR l.action='infected' )";
3780 } else if ($modid) {
3781 $joins[] = "l.cmid = :modid";
3782 $params['modid'] = $modid;
3786 $firstletter = substr($modaction, 0, 1);
3787 if ($firstletter == '-') {
3788 $joins[] = $DB->sql_like('l.action', ':modaction', false, true, true);
3789 $params['modaction'] = '%'.substr($modaction, 1).'%';
3791 $joins[] = $DB->sql_like('l.action', ':modaction', false);
3792 $params['modaction'] = '%'.$modaction.'%';
3797 /// Getting all members of a group.
3798 if ($groupid and !$user) {
3799 if ($gusers = groups_get_members($groupid)) {
3800 $gusers = array_keys($gusers);
3801 $joins[] = 'l.userid IN (' . implode(',', $gusers) . ')';
3803 $joins[] = 'l.userid = 0'; // No users in groups, so we want something that will always be false.
3807 $joins[] = "l.userid = :userid";
3808 $params['userid'] = $user;
3812 $enddate = $date +
86400;
3813 $joins[] = "l.time > :date AND l.time < :enddate";
3814 $params['date'] = $date;
3815 $params['enddate'] = $enddate;
3818 $selector = implode(' AND ', $joins);
3820 $totalcount = 0; // Initialise
3822 $result['logs'] = get_logs($selector, $params, $order, $limitfrom, $limitnum, $totalcount);
3823 $result['totalcount'] = $totalcount;
3828 * Select all log records for a given course and user.
3830 * @deprecated since 3.2
3831 * @param int $userid The id of the user as found in the 'user' table.
3832 * @param int $courseid The id of the course as found in the 'course' table.
3833 * @param string $coursestart unix timestamp representing course start date and time.
3836 function get_logs_usercourse($userid, $courseid, $coursestart) {
3839 debugging(__FUNCTION__
. '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER
);
3845 $courseselect = "AND course = :courseid";
3846 $params['courseid'] = $courseid;
3848 $params['userid'] = $userid;
3849 // We have to sanitize this param ourselves here instead of relying on DB.
3850 // Postgres complains if you use name parameter or column alias in GROUP BY.
3851 // See MDL-27696 and 51c3e85 for details.
3852 $coursestart = (int)$coursestart;
3854 return $DB->get_records_sql("SELECT FLOOR((time - $coursestart)/". DAYSECS
.") AS day, COUNT(*) AS num
3856 WHERE userid = :userid
3857 AND time > $coursestart $courseselect
3858 GROUP BY FLOOR((time - $coursestart)/". DAYSECS
.")", $params);
3862 * Select all log records for a given course, user, and day.
3864 * @deprecated since 3.2
3865 * @param int $userid The id of the user as found in the 'user' table.
3866 * @param int $courseid The id of the course as found in the 'course' table.
3867 * @param string $daystart unix timestamp of the start of the day for which the logs needs to be retrived
3870 function get_logs_userday($userid, $courseid, $daystart) {
3873 debugging(__FUNCTION__
. '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER
);
3875 $params = array('userid'=>$userid);
3879 $courseselect = "AND course = :courseid";
3880 $params['courseid'] = $courseid;
3882 // Note: unfortunately pg complains if you use name parameter or column alias in GROUP BY.
3883 $daystart = (int) $daystart;
3885 return $DB->get_records_sql("SELECT FLOOR((time - $daystart)/". HOURSECS
.") AS hour, COUNT(*) AS num
3887 WHERE userid = :userid
3888 AND time > $daystart $courseselect
3889 GROUP BY FLOOR((time - $daystart)/". HOURSECS
.") ", $params);
3893 * Select all log records based on SQL criteria.
3895 * @deprecated since 3.2
3896 * @param string $select SQL select criteria
3897 * @param array $params named sql type params
3898 * @param string $order SQL order by clause to sort the records returned
3899 * @param string $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set)
3900 * @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set)
3901 * @param int $totalcount Passed in by reference.
3904 function get_logs($select, array $params=null, $order='l.time DESC', $limitfrom='', $limitnum='', &$totalcount) {
3907 debugging(__FUNCTION__
. '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER
);
3910 $order = "ORDER BY $order";
3914 $select = "WHERE $select";
3917 $sql = "SELECT COUNT(*)
3921 $totalcount = $DB->count_records_sql($sql, $params);
3922 $allnames = get_all_user_name_fields(true, 'u');
3923 $sql = "SELECT l.*, $allnames, u.picture
3925 LEFT JOIN {user} u ON l.userid = u.id
3929 return $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
3933 * Renders a hidden password field so that browsers won't incorrectly autofill password fields with the user's password.
3935 * @deprecated since Moodle 3.2 MDL-53048
3937 function prevent_form_autofill_password() {
3938 debugging('prevent_form_autofill_password has been deprecated and is no longer in use.', DEBUG_DEVELOPER
);
3943 * @deprecated since Moodle 3.3 MDL-57370
3945 function message_get_recent_conversations($userorid, $limitfrom = 0, $limitto = 100) {
3946 throw new coding_exception('message_get_recent_conversations() can not be used any more. ' .
3947 'Please use \core_message\api::get_conversations() instead.', DEBUG_DEVELOPER
);
3951 * Display calendar preference button.
3953 * @param stdClass $course course object
3954 * @deprecated since Moodle 3.2
3955 * @return string return preference button in html
3957 function calendar_preferences_button(stdClass
$course) {
3958 debugging('This should no longer be used, the calendar preferences are now linked to the user preferences page.');
3962 // Guests have no preferences.
3963 if (!isloggedin() ||
isguestuser()) {
3967 return $OUTPUT->single_button(new moodle_url('/user/calendar.php'), get_string("preferences", "calendar"));
3971 * Return the name of the weekday
3973 * @deprecated since 3.3
3974 * @todo The final deprecation of this function will take place in Moodle 3.7 - see MDL-57617.
3975 * @param string $englishname
3976 * @return string of the weekeday
3978 function calendar_wday_name($englishname) {
3979 debugging(__FUNCTION__
. '() is deprecated and no longer used in core.', DEBUG_DEVELOPER
);
3980 return get_string(strtolower($englishname), 'calendar');
3984 * Get the upcoming event block.
3986 * @deprecated since 3.3
3987 * @todo The final deprecation of this function will take place in Moodle 3.7 - see MDL-57617.
3988 * @param array $events list of events
3989 * @param moodle_url|string $linkhref link to event referer
3990 * @param boolean $showcourselink whether links to courses should be shown
3991 * @return string|null $content html block content
3993 function calendar_get_block_upcoming($events, $linkhref = null, $showcourselink = false) {
3997 __FUNCTION__
. '() has been deprecated. ' .
3998 'Please see block_calendar_upcoming::get_content() for the correct API usage.',
4002 require_once($CFG->dirroot
. '/blocks/moodleblock.class.php');
4003 require_once($CFG->dirroot
. '/blocks/calendar_upcoming/block_calendar_upcoming.php');
4004 return block_calendar_upcoming
::get_upcoming_content($events, $linkhref, $showcourselink);
4008 * Display month selector options.
4010 * @deprecated since 3.3
4011 * @todo The final deprecation of this function will take place in Moodle 3.7 - see MDL-57617.
4012 * @param string $name for the select element
4013 * @param string|array $selected options for select elements
4015 function calendar_print_month_selector($name, $selected) {
4016 debugging(__FUNCTION__
. '() is deprecated and no longer used in core.', DEBUG_DEVELOPER
);
4018 for ($i = 1; $i <= 12; $i++
) {
4019 $months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), '%B');
4021 echo html_writer
::label(get_string('months'), 'menu'. $name, false, array('class' => 'accesshide'));
4022 echo html_writer
::select($months, $name, $selected, false);
4026 * Update calendar subscriptions.
4028 * @deprecated since 3.3
4029 * @todo The final deprecation of this function will take place in Moodle 3.7 - see MDL-57617.
4032 function calendar_cron() {
4033 debugging(__FUNCTION__
. '() is deprecated and should not be used. Please use the core\task\calendar_cron_task instead.',
4038 require_once($CFG->dirroot
. '/calendar/lib.php');
4039 // In order to execute this we need bennu.
4040 require_once($CFG->libdir
.'/bennu/bennu.inc.php');
4042 mtrace('Updating calendar subscriptions:');
4043 cron_trace_time_and_memory();
4046 $subscriptions = $DB->get_records_sql('SELECT * FROM {event_subscriptions} WHERE pollinterval > 0
4047 AND lastupdated + pollinterval < ?', array($time));
4048 foreach ($subscriptions as $sub) {
4049 mtrace("Updating calendar subscription {$sub->name} in course {$sub->courseid}");
4051 $log = calendar_update_subscription_events($sub->id
);
4052 mtrace(trim(strip_tags($log)));
4053 } catch (moodle_exception
$ex) {
4054 mtrace('Error updating calendar subscription: ' . $ex->getMessage());
4058 mtrace('Finished updating calendar subscriptions.');
4064 * @deprecated since Moodle 3.4 and removed immediately. MDL-49398.
4066 function load_course_context() {
4067 throw new coding_exception('load_course_context() is removed. Do not use private functions or data structures.');
4071 * @deprecated since Moodle 3.4 and removed immediately. MDL-49398.
4073 function load_role_access_by_context() {
4074 throw new coding_exception('load_role_access_by_context() is removed. Do not use private functions or data structures.');
4078 * @deprecated since Moodle 3.4 and removed immediately. MDL-49398.
4080 function dedupe_user_access() {
4081 throw new coding_exception('dedupe_user_access() is removed. Do not use private functions or data structures.');
4085 * Previous internal API, it was not supposed to be used anywhere.
4086 * Return a nested array showing role assignments
4087 * and all relevant role capabilities for the user.
4089 * [ra] => [/path][roleid]=roleid
4090 * [rdef] => ["$contextpath:$roleid"][capability]=permission
4093 * @deprecated since Moodle 3.4. MDL-49398.
4094 * @param int $userid - the id of the user
4095 * @return array access info array
4097 function get_user_access_sitewide($userid) {
4098 debugging('get_user_access_sitewide() is deprecated. Do not use private functions or data structures.', DEBUG_DEVELOPER
);
4100 $accessdata = get_user_accessdata($userid);
4101 $accessdata['rdef'] = array();
4104 foreach ($accessdata['ra'] as $path => $pathroles) {
4105 $roles = array_merge($pathroles, $roles);
4108 $rdefs = get_role_definitions($roles);
4110 foreach ($rdefs as $roleid => $rdef) {
4111 foreach ($rdef as $path => $caps) {
4112 $accessdata['rdef']["$path:$roleid"] = $caps;
4120 * Generates the HTML for a miniature calendar.
4122 * @param array $courses list of course to list events from
4123 * @param array $groups list of group
4124 * @param array $users user's info
4125 * @param int|bool $calmonth calendar month in numeric, default is set to false
4126 * @param int|bool $calyear calendar month in numeric, default is set to false
4127 * @param string|bool $placement the place/page the calendar is set to appear - passed on the the controls function
4128 * @param int|bool $courseid id of the course the calendar is displayed on - passed on the the controls function
4129 * @param int $time the unixtimestamp representing the date we want to view, this is used instead of $calmonth
4130 * and $calyear to support multiple calendars
4131 * @return string $content return html table for mini calendar
4132 * @deprecated since Moodle 3.4. MDL-59333
4134 function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyear = false, $placement = false,
4135 $courseid = false, $time = 0) {
4138 debugging('calendar_get_mini() has been deprecated. Please update your code to use calendar_get_view.',
4141 if (!empty($calmonth) && !empty($calyear)) {
4142 // Do this check for backwards compatibility.
4143 // The core should be passing a timestamp rather than month and year.
4144 // If a month and year are passed they will be in Gregorian.
4145 // Ensure it is a valid date, else we will just set it to the current timestamp.
4146 if (checkdate($calmonth, 1, $calyear)) {
4147 $time = make_timestamp($calyear, $calmonth, 1);
4151 } else if (empty($time)) {
4152 // Get the current date in the calendar type being used.
4156 if ($courseid == SITEID
) {
4157 $course = get_site();
4159 $course = get_course($courseid);
4161 $calendar = new calendar_information(0, 0, 0, $time);
4162 $calendar->prepare_for_view($course, $courses);
4164 $renderer = $PAGE->get_renderer('core_calendar');
4165 list($data, $template) = calendar_get_view($calendar, 'mini');
4166 return $renderer->render_from_template($template, $data);
4170 * Gets the calendar upcoming event.
4172 * @param array $courses array of courses
4173 * @param array|int|bool $groups array of groups, group id or boolean for all/no group events
4174 * @param array|int|bool $users array of users, user id or boolean for all/no user events
4175 * @param int $daysinfuture number of days in the future we 'll look
4176 * @param int $maxevents maximum number of events
4177 * @param int $fromtime start time
4178 * @return array $output array of upcoming events
4179 * @deprecated since Moodle 3.4. MDL-59333
4181 function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime=0) {
4183 'calendar_get_upcoming() has been deprecated. ' .
4184 'Please see block_calendar_upcoming::get_content() for the correct API usage.',
4190 $display = new \stdClass
;
4191 $display->range
= $daysinfuture; // How many days in the future we 'll look.
4192 $display->maxevents
= $maxevents;
4197 $now = time(); // We 'll need this later.
4198 $usermidnighttoday = usergetmidnight($now);
4201 $display->tstart
= $fromtime;
4203 $display->tstart
= $usermidnighttoday;
4206 // This works correctly with respect to the user's DST, but it is accurate
4207 // only because $fromtime is always the exact midnight of some day!
4208 $display->tend
= usergetmidnight($display->tstart + DAYSECS
* $display->range +
3 * HOURSECS
) - 1;
4210 // Get the events matching our criteria.
4211 $events = calendar_get_legacy_events($display->tstart
, $display->tend
, $users, $groups, $courses);
4213 // This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after
4214 // possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month
4215 // will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra
4216 // arguments to this function.
4217 $hrefparams = array();
4218 if (!empty($courses)) {
4219 $courses = array_diff($courses, array(SITEID
));
4220 if (count($courses) == 1) {
4221 $hrefparams['course'] = reset($courses);
4225 if ($events !== false) {
4226 foreach ($events as $event) {
4227 if (!empty($event->modulename
)) {
4228 $instances = get_fast_modinfo($event->courseid
)->get_instances_of($event->modulename
);
4229 if (empty($instances[$event->instance
]->uservisible
)) {
4234 if ($processed >= $display->maxevents
) {
4238 $event->time
= calendar_format_event_time($event, $now, $hrefparams);
4248 * Creates a record in the role_allow_override table
4250 * @param int $sroleid source roleid
4251 * @param int $troleid target roleid
4253 * @deprecated since Moodle 3.4. MDL-50666
4255 function allow_override($sroleid, $troleid) {
4256 debugging('allow_override() has been deprecated. Please update your code to use core_role_set_override_allowed.',
4259 core_role_set_override_allowed($sroleid, $troleid);
4263 * Creates a record in the role_allow_assign table
4265 * @param int $fromroleid source roleid
4266 * @param int $targetroleid target roleid
4268 * @deprecated since Moodle 3.4. MDL-50666
4270 function allow_assign($fromroleid, $targetroleid) {
4271 debugging('allow_assign() has been deprecated. Please update your code to use core_role_set_assign_allowed.',
4274 core_role_set_assign_allowed($fromroleid, $targetroleid);
4278 * Creates a record in the role_allow_switch table
4280 * @param int $fromroleid source roleid
4281 * @param int $targetroleid target roleid
4283 * @deprecated since Moodle 3.4. MDL-50666
4285 function allow_switch($fromroleid, $targetroleid) {
4286 debugging('allow_switch() has been deprecated. Please update your code to use core_role_set_switch_allowed.',
4289 core_role_set_switch_allowed($fromroleid, $targetroleid);
4293 * Organise categories into a single parent category (called the 'Top' category) per context.
4295 * @param array $categories List of question categories in the format of ["$categoryid,$contextid" => $category].
4296 * @param array $pcontexts List of context ids.
4298 * @deprecated since Moodle 3.5. MDL-61132
4300 function question_add_tops($categories, $pcontexts) {
4301 debugging('question_add_tops() has been deprecated. You may want to pass $top = true to get_categories_for_contexts().',
4305 foreach ($pcontexts as $contextid) {
4306 $topcat = question_get_top_category($contextid, true);
4307 $context = context
::instance_by_id($contextid);
4309 $newcat = new stdClass();
4310 $newcat->id
= "{$topcat->id},$contextid";
4311 $newcat->name
= get_string('topfor', 'question', $context->get_context_name(false));
4312 $newcat->parent
= 0;
4313 $newcat->contextid
= $contextid;
4314 $topcats["{$topcat->id},$contextid"] = $newcat;
4316 // Put topcats in at beginning of array - they'll be sorted into different contexts later.
4317 return array_merge($topcats, $categories);
4321 * Checks if the question category is the highest-level category in the context that can be edited, and has no siblings.
4323 * @param int $categoryid a category id.
4325 * @deprecated since Moodle 3.5. MDL-61132
4327 function question_is_only_toplevel_category_in_context($categoryid) {
4328 debugging('question_is_only_toplevel_category_in_context() has been deprecated. '
4329 . 'Please update your code to use question_is_only_child_of_top_category_in_context() instead.',
4332 return question_is_only_child_of_top_category_in_context($categoryid);
4336 * Moves messages from a particular user from the message table (unread messages) to message_read
4337 * This is typically only used when a user is deleted
4339 * @param object $userid User id
4340 * @return boolean success
4341 * @deprecated since Moodle 3.5
4343 function message_move_userfrom_unread2read($userid) {
4344 debugging('message_move_userfrom_unread2read() is deprecated and is no longer used.', DEBUG_DEVELOPER
);
4348 // Move all unread messages from message table to message_read.
4349 if ($messages = $DB->get_records_select('message', 'useridfrom = ?', array($userid), 'timecreated')) {
4350 foreach ($messages as $message) {
4351 message_mark_message_read($message, 0); // Set timeread to 0 as the message was never read.
4358 * Retrieve users blocked by $user1
4360 * @param object $user1 the user whose messages are being viewed
4361 * @param object $user2 the user $user1 is talking to. If they are being blocked
4362 * they will have a variable called 'isblocked' added to their user object
4363 * @return array the users blocked by $user1
4364 * @deprecated since Moodle 3.5
4366 function message_get_blocked_users($user1=null, $user2=null) {
4367 debugging('message_get_blocked_users() is deprecated, please use \core_message\api::get_blocked_users() instead.',
4372 if (empty($user1)) {
4373 $user1 = new stdClass();
4374 $user1->id
= $USER->id
;
4377 return \core_message\api
::get_blocked_users($user1->id
);
4381 * Retrieve $user1's contacts (online, offline and strangers)
4383 * @param object $user1 the user whose messages are being viewed
4384 * @param object $user2 the user $user1 is talking to. If they are a contact
4385 * they will have a variable called 'iscontact' added to their user object
4386 * @return array containing 3 arrays. array($onlinecontacts, $offlinecontacts, $strangers)
4387 * @deprecated since Moodle 3.5
4389 function message_get_contacts($user1=null, $user2=null) {
4390 debugging('message_get_contacts() is deprecated and is no longer used.', DEBUG_DEVELOPER
);
4392 global $DB, $CFG, $USER;
4394 if (empty($user1)) {
4398 if (!empty($user2)) {
4399 $user2->iscontact
= false;
4402 $timetoshowusers = 300; // Seconds default.
4403 if (isset($CFG->block_online_users_timetosee
)) {
4404 $timetoshowusers = $CFG->block_online_users_timetosee
* 60;
4407 // Rime which a user is counting as being active since.
4408 $timefrom = time() - $timetoshowusers;
4410 // People in our contactlist who are online.
4411 $onlinecontacts = array();
4412 // People in our contactlist who are offline.
4413 $offlinecontacts = array();
4414 // People who are not in our contactlist but have sent us a message.
4415 $strangers = array();
4417 // Get all in our contact list who are not blocked in our and count messages we have waiting from each of them.
4418 $rs = \core_message\api
::get_contacts_with_unread_message_count($user1->id
);
4419 foreach ($rs as $rd) {
4420 if ($rd->lastaccess
>= $timefrom) {
4421 // They have been active recently, so are counted online.
4422 $onlinecontacts[] = $rd;
4425 $offlinecontacts[] = $rd;
4428 if (!empty($user2) && $user2->id
== $rd->id
) {
4429 $user2->iscontact
= true;
4433 // Get messages from anyone who isn't in our contact list and count the number of messages we have from each of them.
4434 $rs = \core_message\api
::get_non_contacts_with_unread_message_count($user1->id
);
4435 // Add user id as array index, so supportuser and noreply user don't get duplicated (if they are real users).
4436 foreach ($rs as $rd) {
4437 $strangers[$rd->id
] = $rd;
4440 // Add noreply user and support user to the list, if they don't exist.
4441 $supportuser = core_user
::get_support_user();
4442 if (!isset($strangers[$supportuser->id
]) && !$supportuser->deleted
) {
4443 $supportuser->messagecount
= message_count_unread_messages($USER, $supportuser);
4444 if ($supportuser->messagecount
> 0) {
4445 $strangers[$supportuser->id
] = $supportuser;
4449 $noreplyuser = core_user
::get_noreply_user();
4450 if (!isset($strangers[$noreplyuser->id
]) && !$noreplyuser->deleted
) {
4451 $noreplyuser->messagecount
= message_count_unread_messages($USER, $noreplyuser);
4452 if ($noreplyuser->messagecount
> 0) {
4453 $strangers[$noreplyuser->id
] = $noreplyuser;
4457 return array($onlinecontacts, $offlinecontacts, $strangers);
4461 * Mark a single message as read
4463 * @param stdClass $message An object with an object property ie $message->id which is an id in the message table
4464 * @param int $timeread the timestamp for when the message should be marked read. Usually time().
4465 * @param bool $messageworkingempty Is the message_working table already confirmed empty for this message?
4466 * @return int the ID of the message in the messags table
4467 * @deprecated since Moodle 3.5
4469 function message_mark_message_read($message, $timeread, $messageworkingempty=false) {
4470 debugging('message_mark_message_read() is deprecated, please use \core_message\api::mark_message_as_read()
4471 or \core_message\api::mark_notification_as_read().', DEBUG_DEVELOPER
);
4473 if (!empty($message->notification
)) {
4474 \core_message\api
::mark_notification_as_read($message, $timeread);
4476 \core_message\api
::mark_message_as_read($message->useridto
, $message, $timeread);
4479 return $message->id
;
4484 * Checks if a user can delete a message.
4486 * @param stdClass $message the message to delete
4487 * @param string $userid the user id of who we want to delete the message for (this may be done by the admin
4488 * but will still seem as if it was by the user)
4489 * @return bool Returns true if a user can delete the message, false otherwise.
4490 * @deprecated since Moodle 3.5
4492 function message_can_delete_message($message, $userid) {
4493 debugging('message_can_delete_message() is deprecated, please use \core_message\api::can_delete_message() instead.',
4496 return \core_message\api
::can_delete_message($userid, $message->id
);
4500 * Deletes a message.
4502 * This function does not verify any permissions.
4504 * @param stdClass $message the message to delete
4505 * @param string $userid the user id of who we want to delete the message for (this may be done by the admin
4506 * but will still seem as if it was by the user)
4508 * @deprecated since Moodle 3.5
4510 function message_delete_message($message, $userid) {
4511 debugging('message_delete_message() is deprecated, please use \core_message\api::delete_message() instead.',
4514 return \core_message\api
::delete_message($userid, $message->id
);
4518 * Get all of the allowed types for all of the courses and groups
4519 * the logged in user belongs to.
4521 * The returned array will optionally have 5 keys:
4522 * 'user' : true if the logged in user can create user events
4523 * 'site' : true if the logged in user can create site events
4524 * 'category' : array of course categories that the user can create events for
4525 * 'course' : array of courses that the user can create events for
4526 * 'group': array of groups that the user can create events for
4527 * 'groupcourses' : array of courses that the groups belong to (can
4528 * be different from the list in 'course'.
4529 * @deprecated since 3.6
4530 * @return array The array of allowed types.
4532 function calendar_get_all_allowed_types() {
4533 debugging('calendar_get_all_allowed_types() is deprecated. Please use calendar_get_allowed_types() instead.',
4536 global $CFG, $USER, $DB;
4538 require_once($CFG->libdir
. '/enrollib.php');
4542 $allowed = new stdClass();
4544 calendar_get_allowed_types($allowed);
4546 if ($allowed->user
) {
4547 $types['user'] = true;
4550 if ($allowed->site
) {
4551 $types['site'] = true;
4554 if (coursecat
::has_manage_capability_on_any()) {
4555 $types['category'] = coursecat
::make_categories_list('moodle/category:manage');
4558 // This function warms the context cache for the course so the calls
4559 // to load the course context in calendar_get_allowed_types don't result
4560 // in additional DB queries.
4561 $courses = calendar_get_default_courses(null, 'id, groupmode, groupmodeforce', true);
4563 // We want to pre-fetch all of the groups for each course in a single
4564 // query to avoid calendar_get_allowed_types from hitting the DB for
4565 // each separate course.
4566 $groups = groups_get_all_groups_for_courses($courses);
4568 foreach ($courses as $course) {
4569 $coursegroups = isset($groups[$course->id
]) ?
$groups[$course->id
] : null;
4570 calendar_get_allowed_types($allowed, $course, $coursegroups);
4572 if (!empty($allowed->courses
)) {
4573 $types['course'][$course->id
] = $course;
4576 if (!empty($allowed->groups
)) {
4577 $types['groupcourses'][$course->id
] = $course;
4579 if (!isset($types['group'])) {
4580 $types['group'] = array_values($allowed->groups
);
4582 $types['group'] = array_merge($types['group'], array_values($allowed->groups
));
4591 * Gets array of all groups in a set of course.
4594 * @param array $courses Array of course objects or course ids.
4595 * @return array Array of groups indexed by course id.
4597 function groups_get_all_groups_for_courses($courses) {
4600 if (empty($courses)) {
4607 foreach ($courses as $course) {
4608 $courseid = is_object($course) ?
$course->id
: $course;
4609 $groups[$courseid] = [];
4610 $courseids[] = $courseid;
4619 'g.descriptionformat',
4627 $groupsmembersfields = [
4636 $concatidsql = $DB->sql_concat_join("'-'", ['g.id', 'COALESCE(gm.id, 0)']) . ' AS uniqid';
4637 list($courseidsql, $params) = $DB->get_in_or_equal($courseids);
4638 $groupfieldssql = implode(',', $groupfields);
4639 $groupmembersfieldssql = implode(',', $groupsmembersfields);
4640 $sql = "SELECT {$concatidsql}, {$groupfieldssql}, {$groupmembersfieldssql}
4642 LEFT JOIN {groups_members} gm
4643 ON gm.groupid = g.id
4644 WHERE g.courseid {$courseidsql}";
4646 $results = $DB->get_records_sql($sql, $params);
4648 // The results will come back as a flat dataset thanks to the left
4649 // join so we will need to do some post processing to blow it out
4650 // into a more usable data structure.
4652 // This loop will extract the distinct groups from the result set
4653 // and add it's list of members to the object as a property called
4654 // 'members'. Then each group will be added to the result set indexed
4655 // by it's course id.
4657 // The resulting data structure for $groups should be:
4660 // '1' => (object) [
4662 // <rest of group properties>
4664 // '1' => (object) [
4665 // <group member properties>
4667 // '2' => (object) [
4668 // <group member properties>
4672 // '2' => (object) [
4674 // <rest of group properties>
4676 // '1' => (object) [
4677 // <group member properties>
4679 // '3' => (object) [
4680 // <group member properties>
4687 foreach ($results as $key => $result) {
4688 $groupid = $result->gid
;
4689 $courseid = $result->courseid
;
4690 $coursegroups = $groups[$courseid];
4691 $groupsmembersid = $result->gmid
;
4692 $reducefunc = function($carry, $field) use ($result) {
4693 // Iterate over the groups properties and pull
4694 // them out into a separate object.
4695 list($prefix, $field) = explode('.', $field);
4697 if (property_exists($result, $field)) {
4698 $carry[$field] = $result->{$field};
4704 if (isset($coursegroups[$groupid])) {
4705 $group = $coursegroups[$groupid];
4711 $group = (object) array_reduce(
4718 if (!empty($groupsmembersid)) {
4719 $initial = ['id' => $groupsmembersid];
4720 $groupsmembers = (object) array_reduce(
4721 $groupsmembersfields,
4726 $group->members
[$groupsmembers->userid
] = $groupsmembers;
4729 $coursegroups[$groupid] = $group;
4730 $groups[$courseid] = $coursegroups;
4737 * Gets the capabilities that have been cached in the database for this
4739 * @deprecated since Moodle 3.6. Please use the Events 2 API.
4740 * @todo final deprecation. To be removed in Moodle 4.0
4742 * @access protected To be used from eventslib only
4744 * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
4745 * @return array of events
4747 function events_get_cached($component) {
4750 debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
4753 $cachedhandlers = array();
4755 if ($storedhandlers = $DB->get_records('events_handlers', array('component'=>$component))) {
4756 foreach ($storedhandlers as $handler) {
4757 $cachedhandlers[$handler->eventname
] = array (
4758 'id' => $handler->id
,
4759 'handlerfile' => $handler->handlerfile
,
4760 'handlerfunction' => $handler->handlerfunction
,
4761 'schedule' => $handler->schedule
,
4762 'internal' => $handler->internal
);
4766 return $cachedhandlers;
4770 * Remove all event handlers and queued events
4771 * @deprecated since Moodle 3.6. Please use the Events 2 API.
4772 * @todo final deprecation. To be removed in Moodle 4.0
4775 * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
4777 function events_uninstall($component) {
4778 debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
4780 $cachedhandlers = events_get_cached($component);
4781 events_cleanup($component, $cachedhandlers);
4783 events_get_handlers('reset');
4787 * Deletes cached events that are no longer needed by the component.
4788 * @deprecated since Moodle 3.6. Please use the Events 2 API.
4789 * @todo final deprecation. To be removed in Moodle 4.0
4791 * @access protected To be used from eventslib only
4793 * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
4794 * @param array $cachedhandlers array of the cached events definitions that will be
4795 * @return int number of unused handlers that have been removed
4797 function events_cleanup($component, $cachedhandlers) {
4799 debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
4802 foreach ($cachedhandlers as $eventname => $cachedhandler) {
4803 if ($qhandlers = $DB->get_records('events_queue_handlers', array('handlerid'=>$cachedhandler['id']))) {
4804 //debugging("Removing pending events from queue before deleting of event handler: $component - $eventname");
4805 foreach ($qhandlers as $qhandler) {
4806 events_dequeue($qhandler);
4809 $DB->delete_records('events_handlers', array('eventname'=>$eventname, 'component'=>$component));
4813 return $deletecount;
4817 * Removes this queued handler from the events_queued_handler table
4819 * Removes events_queue record from events_queue if no more references to this event object exists
4820 * @deprecated since Moodle 3.6. Please use the Events 2 API.
4821 * @todo final deprecation. To be removed in Moodle 4.0
4823 * @access protected To be used from eventslib only
4825 * @param stdClass $qhandler A row from the events_queued_handler table
4827 function events_dequeue($qhandler) {
4829 debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
4831 // first delete the queue handler
4832 $DB->delete_records('events_queue_handlers', array('id'=>$qhandler->id
));
4834 // if no more queued handler is pointing to the same event - delete the event too
4835 if (!$DB->record_exists('events_queue_handlers', array('queuedeventid'=>$qhandler->queuedeventid
))) {
4836 $DB->delete_records('events_queue', array('id'=>$qhandler->queuedeventid
));
4841 * Returns handlers for given event. Uses caching for better perf.
4842 * @deprecated since Moodle 3.6. Please use the Events 2 API.
4843 * @todo final deprecation. To be removed in Moodle 4.0
4845 * @access protected To be used from eventslib only
4847 * @staticvar array $handlers
4848 * @param string $eventname name of event or 'reset'
4849 * @return array|false array of handlers or false otherwise
4851 function events_get_handlers($eventname) {
4853 static $handlers = array();
4854 debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
4857 if ($eventname === 'reset') {
4858 $handlers = array();
4862 if (!array_key_exists($eventname, $handlers)) {
4863 $handlers[$eventname] = $DB->get_records('events_handlers', array('eventname'=>$eventname));
4866 return $handlers[$eventname];