moodle/lib/deprecatedlib.php

5168 lines
170 KiB
PHP

<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* deprecatedlib.php - Old functions retained only for backward compatibility
*
* Old functions retained only for backward compatibility. New code should not
* use any of these functions.
*
* @package core
* @subpackage deprecated
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @deprecated
*/
defined('MOODLE_INTERNAL') || die();
/* === Functions that needs to be kept longer in deprecated lib than normal time period === */
/**
* Add an entry to the legacy log table.
*
* @deprecated since 2.7 use new events instead
*
* @param int $courseid The course id
* @param string $module The module name e.g. forum, journal, resource, course, user etc
* @param string $action 'view', 'update', 'add' or 'delete', possibly followed by another word to clarify.
* @param string $url The file and parameters used to see the results of the action
* @param string $info Additional description information
* @param int $cm The course_module->id if there is one
* @param int|stdClass $user If log regards $user other than $USER
* @return void
*/
function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user=0) {
debugging('add_to_log() has been deprecated, please rewrite your code to the new events API', DEBUG_DEVELOPER);
// This is a nasty hack that allows us to put all the legacy stuff into legacy storage,
// this way we may move all the legacy settings there too.
$manager = get_log_manager();
if (method_exists($manager, 'legacy_add_to_log')) {
$manager->legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user);
}
}
/**
* Function to call all event handlers when triggering an event
*
* @deprecated since 2.6
*
* @param string $eventname name of the event
* @param mixed $eventdata event data object
* @return int number of failed events
*/
function events_trigger($eventname, $eventdata) {
debugging('events_trigger() is deprecated, please use new events instead', DEBUG_DEVELOPER);
return events_trigger_legacy($eventname, $eventdata);
}
/**
* List all core subsystems and their location
*
* This is a whitelist of components that are part of the core and their
* language strings are defined in /lang/en/<<subsystem>>.php. If a given
* plugin is not listed here and it does not have proper plugintype prefix,
* then it is considered as course activity module.
*
* The location is optionally dirroot relative path. NULL means there is no special
* directory for this subsystem. If the location is set, the subsystem's
* renderer.php is expected to be there.
*
* @deprecated since 2.6, use core_component::get_core_subsystems()
*
* @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons
* @return array of (string)name => (string|null)location
*/
function get_core_subsystems($fullpaths = false) {
global $CFG;
// NOTE: do not add any other debugging here, keep forever.
$subsystems = core_component::get_core_subsystems();
if ($fullpaths) {
return $subsystems;
}
debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
$dlength = strlen($CFG->dirroot);
foreach ($subsystems as $k => $v) {
if ($v === null) {
continue;
}
$subsystems[$k] = substr($v, $dlength+1);
}
return $subsystems;
}
/**
* Lists all plugin types.
*
* @deprecated since 2.6, use core_component::get_plugin_types()
*
* @param bool $fullpaths false means relative paths from dirroot
* @return array Array of strings - name=>location
*/
function get_plugin_types($fullpaths = true) {
global $CFG;
// NOTE: do not add any other debugging here, keep forever.
$types = core_component::get_plugin_types();
if ($fullpaths) {
return $types;
}
debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
$dlength = strlen($CFG->dirroot);
foreach ($types as $k => $v) {
if ($k === 'theme') {
$types[$k] = 'theme';
continue;
}
$types[$k] = substr($v, $dlength+1);
}
return $types;
}
/**
* Use when listing real plugins of one type.
*
* @deprecated since 2.6, use core_component::get_plugin_list()
*
* @param string $plugintype type of plugin
* @return array name=>fulllocation pairs of plugins of given type
*/
function get_plugin_list($plugintype) {
// NOTE: do not add any other debugging here, keep forever.
if ($plugintype === '') {
$plugintype = 'mod';
}
return core_component::get_plugin_list($plugintype);
}
/**
* Get a list of all the plugins of a given type that define a certain class
* in a certain file. The plugin component names and class names are returned.
*
* @deprecated since 2.6, use core_component::get_plugin_list_with_class()
*
* @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
* @param string $class the part of the name of the class after the
* frankenstyle prefix. e.g 'thing' if you are looking for classes with
* names like report_courselist_thing. If you are looking for classes with
* the same name as the plugin name (e.g. qtype_multichoice) then pass ''.
* @param string $file the name of file within the plugin that defines the class.
* @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum')
* and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice').
*/
function get_plugin_list_with_class($plugintype, $class, $file) {
// NOTE: do not add any other debugging here, keep forever.
return core_component::get_plugin_list_with_class($plugintype, $class, $file);
}
/**
* Returns the exact absolute path to plugin directory.
*
* @deprecated since 2.6, use core_component::get_plugin_directory()
*
* @param string $plugintype type of plugin
* @param string $name name of the plugin
* @return string full path to plugin directory; NULL if not found
*/
function get_plugin_directory($plugintype, $name) {
// NOTE: do not add any other debugging here, keep forever.
if ($plugintype === '') {
$plugintype = 'mod';
}
return core_component::get_plugin_directory($plugintype, $name);
}
/**
* Normalize the component name using the "frankenstyle" names.
*
* @deprecated since 2.6, use core_component::normalize_component()
*
* @param string $component
* @return array two-items list of [(string)type, (string|null)name]
*/
function normalize_component($component) {
// NOTE: do not add any other debugging here, keep forever.
return core_component::normalize_component($component);
}
/**
* Return exact absolute path to a plugin directory.
*
* @deprecated since 2.6, use core_component::normalize_component()
*
* @param string $component name such as 'moodle', 'mod_forum'
* @return string full path to component directory; NULL if not found
*/
function get_component_directory($component) {
// NOTE: do not add any other debugging here, keep forever.
return core_component::get_component_directory($component);
}
/**
* Get the context instance as an object. This function will create the
* context instance if it does not exist yet.
*
* @deprecated since 2.2, use context_course::instance() or other relevant class instead
* @todo This will be deleted in Moodle 2.8, refer MDL-34472
* @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
* @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
* for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
* @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
* MUST_EXIST means throw exception if no record or multiple records found
* @return context The context object.
*/
function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER);
$instances = (array)$instance;
$contexts = array();
$classname = context_helper::get_class_for_level($contextlevel);
// we do not load multiple contexts any more, PAGE should be responsible for any preloading
foreach ($instances as $inst) {
$contexts[$inst] = $classname::instance($inst, $strictness);
}
if (is_array($instance)) {
return $contexts;
} else {
return $contexts[$instance];
}
}
/* === End of long term deprecated api list === */
/**
* @deprecated since 2.7 - use new file picker instead
*/
function clam_log_upload() {
throw new coding_exception('clam_log_upload() can not be used any more, please use file picker instead');
}
/**
* @deprecated since 2.7 - use new file picker instead
*/
function clam_log_infected() {
throw new coding_exception('clam_log_infected() can not be used any more, please use file picker instead');
}
/**
* @deprecated since 2.7 - use new file picker instead
*/
function clam_change_log() {
throw new coding_exception('clam_change_log() can not be used any more, please use file picker instead');
}
/**
* @deprecated since 2.7 - infected files are now deleted in file picker
*/
function clam_replace_infected_file() {
throw new coding_exception('clam_replace_infected_file() can not be used any more, please use file picker instead');
}
/**
* @deprecated since 2.7
*/
function clam_handle_infected_file() {
throw new coding_exception('clam_handle_infected_file() can not be used any more, please use file picker instead');
}
/**
* @deprecated since 2.7
*/
function clam_scan_moodle_file() {
throw new coding_exception('clam_scan_moodle_file() can not be used any more, please use file picker instead');
}
/**
* @deprecated since 2.7 PHP 5.4.x should be always compatible.
*/
function password_compat_not_supported() {
throw new coding_exception('Do not use password_compat_not_supported() - bcrypt is now always available');
}
/**
* @deprecated since 2.6
*/
function session_get_instance() {
throw new coding_exception('session_get_instance() is removed, use \core\session\manager instead');
}
/**
* @deprecated since 2.6
*/
function session_is_legacy() {
throw new coding_exception('session_is_legacy() is removed, do not use any more');
}
/**
* @deprecated since 2.6
*/
function session_kill_all() {
throw new coding_exception('session_kill_all() is removed, use \core\session\manager::kill_all_sessions() instead');
}
/**
* @deprecated since 2.6
*/
function session_touch() {
throw new coding_exception('session_touch() is removed, use \core\session\manager::touch_session() instead');
}
/**
* @deprecated since 2.6
*/
function session_kill() {
throw new coding_exception('session_kill() is removed, use \core\session\manager::kill_session() instead');
}
/**
* @deprecated since 2.6
*/
function session_kill_user() {
throw new coding_exception('session_kill_user() is removed, use \core\session\manager::kill_user_sessions() instead');
}
/**
* @deprecated since 2.6
*/
function session_set_user() {
throw new coding_exception('session_set_user() is removed, use \core\session\manager::set_user() instead');
}
/**
* @deprecated since 2.6
*/
function session_is_loggedinas() {
throw new coding_exception('session_is_loggedinas() is removed, use \core\session\manager::is_loggedinas() instead');
}
/**
* @deprecated since 2.6
*/
function session_get_realuser() {
throw new coding_exception('session_get_realuser() is removed, use \core\session\manager::get_realuser() instead');
}
/**
* @deprecated since 2.6
*/
function session_loginas() {
throw new coding_exception('session_loginas() is removed, use \core\session\manager::loginas() instead');
}
/**
* @deprecated since 2.6
*/
function js_minify() {
throw new coding_exception('js_minify() is removed, use core_minify::js_files() or core_minify::js() instead.');
}
/**
* @deprecated since 2.6
*/
function css_minify_css() {
throw new coding_exception('css_minify_css() is removed, use core_minify::css_files() or core_minify::css() instead.');
}
// === Deprecated before 2.6.0 ===
/**
* @deprecated
*/
function check_gd_version() {
throw new coding_exception('check_gd_version() is removed, GD extension is always available now');
}
/**
* @deprecated
*/
function update_login_count() {
throw new coding_exception('update_login_count() is removed, all calls need to be removed');
}
/**
* @deprecated
*/
function reset_login_count() {
throw new coding_exception('reset_login_count() is removed, all calls need to be removed');
}
/**
* @deprecated
*/
function update_log_display_entry() {
throw new coding_exception('The update_log_display_entry() is removed, please use db/log.php description file instead.');
}
/**
* @deprecated use the text formatting in a standard way instead (http://docs.moodle.org/dev/Output_functions)
* this was abused mostly for embedding of attachments
*/
function filter_text() {
throw new coding_exception('filter_text() can not be used anymore, use format_text(), format_string() etc instead.');
}
/**
* @deprecated Loginhttps is no longer supported
*/
function httpsrequired() {
throw new coding_exception('httpsrequired() can not be used any more. Loginhttps is no longer supported.');
}
/**
* @deprecated since 3.1 - replacement legacy file API methods can be found on the moodle_url class, for example:
* The moodle_url::make_legacyfile_url() method can be used to generate a legacy course file url. To generate
* course module file.php url the moodle_url::make_file_url() should be used.
*/
function get_file_url() {
throw new coding_exception('get_file_url() can not be used anymore. Please use ' .
'moodle_url factory methods instead.');
}
/**
* @deprecated use get_enrolled_users($context) instead.
*/
function get_course_participants() {
throw new coding_exception('get_course_participants() can not be used any more, use get_enrolled_users() instead.');
}
/**
* @deprecated use is_enrolled($context, $userid) instead.
*/
function is_course_participant() {
throw new coding_exception('is_course_participant() can not be used any more, use is_enrolled() instead.');
}
/**
* @deprecated
*/
function get_recent_enrolments() {
throw new coding_exception('get_recent_enrolments() is removed as it returned inaccurate results.');
}
/**
* @deprecated use clean_param($string, PARAM_FILE) instead.
*/
function detect_munged_arguments() {
throw new coding_exception('detect_munged_arguments() can not be used any more, please use clean_param(,PARAM_FILE) instead.');
}
/**
* Unzip one zip file to a destination dir
* Both parameters must be FULL paths
* If destination isn't specified, it will be the
* SAME directory where the zip file resides.
*
* @global object
* @param string $zipfile The zip file to unzip
* @param string $destination The location to unzip to
* @param bool $showstatus_ignored Unused
* @deprecated since 2.0 MDL-15919
*/
function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
debugging(__FUNCTION__ . '() is deprecated. '
. 'Please use the application/zip file_packer implementation instead.', DEBUG_DEVELOPER);
// Extract everything from zipfile.
$path_parts = pathinfo(cleardoubleslashes($zipfile));
$zippath = $path_parts["dirname"]; //The path of the zip file
$zipfilename = $path_parts["basename"]; //The name of the zip file
$extension = $path_parts["extension"]; //The extension of the file
//If no file, error
if (empty($zipfilename)) {
return false;
}
//If no extension, error
if (empty($extension)) {
return false;
}
//Clear $zipfile
$zipfile = cleardoubleslashes($zipfile);
//Check zipfile exists
if (!file_exists($zipfile)) {
return false;
}
//If no destination, passed let's go with the same directory
if (empty($destination)) {
$destination = $zippath;
}
//Clear $destination
$destpath = rtrim(cleardoubleslashes($destination), "/");
//Check destination path exists
if (!is_dir($destpath)) {
return false;
}
$packer = get_file_packer('application/zip');
$result = $packer->extract_to_pathname($zipfile, $destpath);
if ($result === false) {
return false;
}
foreach ($result as $status) {
if ($status !== true) {
return false;
}
}
return true;
}
/**
* Zip an array of files/dirs to a destination zip file
* Both parameters must be FULL paths to the files/dirs
*
* @global object
* @param array $originalfiles Files to zip
* @param string $destination The destination path
* @return bool Outcome
*
* @deprecated since 2.0 MDL-15919
*/
function zip_files($originalfiles, $destination) {
debugging(__FUNCTION__ . '() is deprecated. '
. 'Please use the application/zip file_packer implementation instead.', DEBUG_DEVELOPER);
// Extract everything from destination.
$path_parts = pathinfo(cleardoubleslashes($destination));
$destpath = $path_parts["dirname"]; //The path of the zip file
$destfilename = $path_parts["basename"]; //The name of the zip file
$extension = $path_parts["extension"]; //The extension of the file
//If no file, error
if (empty($destfilename)) {
return false;
}
//If no extension, add it
if (empty($extension)) {
$extension = 'zip';
$destfilename = $destfilename.'.'.$extension;
}
//Check destination path exists
if (!is_dir($destpath)) {
return false;
}
//Check destination path is writable. TODO!!
//Clean destination filename
$destfilename = clean_filename($destfilename);
//Now check and prepare every file
$files = array();
$origpath = NULL;
foreach ($originalfiles as $file) { //Iterate over each file
//Check for every file
$tempfile = cleardoubleslashes($file); // no doubleslashes!
//Calculate the base path for all files if it isn't set
if ($origpath === NULL) {
$origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
}
//See if the file is readable
if (!is_readable($tempfile)) { //Is readable
continue;
}
//See if the file/dir is in the same directory than the rest
if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
continue;
}
//Add the file to the array
$files[] = $tempfile;
}
$zipfiles = array();
$start = strlen($origpath)+1;
foreach($files as $file) {
$zipfiles[substr($file, $start)] = $file;
}
$packer = get_file_packer('application/zip');
return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
}
/**
* @deprecated use groups_get_all_groups() instead.
*/
function mygroupid() {
throw new coding_exception('mygroupid() can not be used any more, please use groups_get_all_groups() instead.');
}
/**
* @deprecated since Moodle 2.0 MDL-14617 - please do not use this function any more.
*/
function groupmode() {
throw new coding_exception('groupmode() can not be used any more, please use groups_get_* instead.');
}
/**
* @deprecated Since year 2006 - please do not use this function any more.
*/
function set_current_group() {
throw new coding_exception('set_current_group() can not be used anymore, please use $SESSION->currentgroup[$courseid] instead');
}
/**
* @deprecated Since year 2006 - please do not use this function any more.
*/
function get_current_group() {
throw new coding_exception('get_current_group() can not be used any more, please use groups_get_* instead');
}
/**
* @deprecated Since Moodle 2.8
*/
function groups_filter_users_by_course_module_visible() {
throw new coding_exception('groups_filter_users_by_course_module_visible() is removed. ' .
'Replace with a call to \core_availability\info_module::filter_user_list(), ' .
'which does basically the same thing but includes other restrictions such ' .
'as profile restrictions.');
}
/**
* @deprecated Since Moodle 2.8
*/
function groups_course_module_visible() {
throw new coding_exception('groups_course_module_visible() is removed, use $cm->uservisible to decide whether the current
user can ' . 'access an activity.', DEBUG_DEVELOPER);
}
/**
* @deprecated since 2.0
*/
function error() {
throw new coding_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a removed, please call
print_error() instead of error()');
}
/**
* @deprecated use $PAGE->theme->name instead.
*/
function current_theme() {
throw new coding_exception('current_theme() can not be used any more, please use $PAGE->theme->name instead');
}
/**
* @deprecated
*/
function formerr() {
throw new coding_exception('formerr() is removed. Please change your code to use $OUTPUT->error_text($string).');
}
/**
* @deprecated use $OUTPUT->skip_link_target() in instead.
*/
function skip_main_destination() {
throw new coding_exception('skip_main_destination() can not be used any more, please use $OUTPUT->skip_link_target() instead.');
}
/**
* @deprecated use $OUTPUT->container() instead.
*/
function print_container() {
throw new coding_exception('print_container() can not be used any more. Please use $OUTPUT->container() instead.');
}
/**
* @deprecated use $OUTPUT->container_start() instead.
*/
function print_container_start() {
throw new coding_exception('print_container_start() can not be used any more. Please use $OUTPUT->container_start() instead.');
}
/**
* @deprecated use $OUTPUT->container_end() instead.
*/
function print_container_end() {
throw new coding_exception('print_container_end() can not be used any more. Please use $OUTPUT->container_end() instead.');
}
/**
* @deprecated since Moodle 2.0 MDL-19077 - use $OUTPUT->notification instead.
*/
function notify() {
throw new coding_exception('notify() is removed, please use $OUTPUT->notification() instead');
}
/**
* @deprecated use $OUTPUT->continue_button() instead.
*/
function print_continue() {
throw new coding_exception('print_continue() can not be used any more. Please use $OUTPUT->continue_button() instead.');
}
/**
* @deprecated use $PAGE methods instead.
*/
function print_header() {
throw new coding_exception('print_header() can not be used any more. Please use $PAGE methods instead.');
}
/**
* @deprecated use $PAGE methods instead.
*/
function print_header_simple() {
throw new coding_exception('print_header_simple() can not be used any more. Please use $PAGE methods instead.');
}
/**
* @deprecated use $OUTPUT->block() instead.
*/
function print_side_block() {
throw new coding_exception('print_side_block() can not be used any more, please use $OUTPUT->block() instead.');
}
/**
* Prints a basic textarea field.
*
* @deprecated since Moodle 2.0
*
* When using this function, you should
*
* @global object
* @param bool $unused No longer used.
* @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
* @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
* @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.
* @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.
* @param string $name Name to use for the textarea element.
* @param string $value Initial content to display in the textarea.
* @param int $obsolete deprecated
* @param bool $return If false, will output string. If true, will return string value.
* @param string $id CSS ID to add to the textarea element.
* @return string|void depending on the value of $return
*/
function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
/// $width and height are legacy fields and no longer used as pixels like they used to be.
/// However, you can set them to zero to override the mincols and minrows values below.
// Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
// debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
global $CFG;
$mincols = 65;
$minrows = 10;
$str = '';
if ($id === '') {
$id = 'edit-'.$name;
}
if ($height && ($rows < $minrows)) {
$rows = $minrows;
}
if ($width && ($cols < $mincols)) {
$cols = $mincols;
}
editors_head_setup();
$editor = editors_get_preferred_editor(FORMAT_HTML);
$editor->set_text($value);
$editor->use_editor($id, array('legacy'=>true));
$str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'" spellcheck="true">'."\n";
$str .= htmlspecialchars($value); // needed for editing of cleaned text!
$str .= '</textarea>'."\n";
if ($return) {
return $str;
}
echo $str;
}
/**
* Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
* provide this function with the language strings for sortasc and sortdesc.
*
* @deprecated use $OUTPUT->arrow() instead.
* @todo final deprecation of this function once MDL-45448 is resolved
*
* If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
*
* @global object
* @param string $direction 'up' or 'down'
* @param string $strsort The language string used for the alt attribute of this image
* @param bool $return Whether to print directly or return the html string
* @return string|void depending on $return
*
*/
function print_arrow($direction='up', $strsort=null, $return=false) {
global $OUTPUT;
debugging('print_arrow() is deprecated. Please use $OUTPUT->arrow() instead.', DEBUG_DEVELOPER);
if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
return null;
}
$return = null;
switch ($direction) {
case 'up':
$sortdir = 'asc';
break;
case 'down':
$sortdir = 'desc';
break;
case 'move':
$sortdir = 'asc';
break;
default:
$sortdir = null;
break;
}
// Prepare language string
$strsort = '';
if (empty($strsort) && !empty($sortdir)) {
$strsort = get_string('sort' . $sortdir, 'grades');
}
$return = ' ' . $OUTPUT->pix_icon('t/' . $direction, $strsort) . ' ';
if ($return) {
return $return;
} else {
echo $return;
}
}
/**
* @deprecated since Moodle 2.0
*/
function choose_from_menu() {
throw new coding_exception('choose_from_menu() is removed. Please change your code to use html_writer::select().');
}
/**
* @deprecated use $OUTPUT->help_icon_scale($courseid, $scale) instead.
*/
function print_scale_menu_helpbutton() {
throw new coding_exception('print_scale_menu_helpbutton() can not be used any more. '.
'Please use $OUTPUT->help_icon_scale($courseid, $scale) instead.');
}
/**
* @deprecated use html_writer::checkbox() instead.
*/
function print_checkbox() {
throw new coding_exception('print_checkbox() can not be used any more. Please use html_writer::checkbox() instead.');
}
/**
* Prints the 'update this xxx' button that appears on module pages.
*
* @deprecated since Moodle 3.2
*
* @param string $cmid the course_module id.
* @param string $ignored not used any more. (Used to be courseid.)
* @param string $string the module name - get_string('modulename', 'xxx')
* @return string the HTML for the button, if this user has permission to edit it, else an empty string.
*/
function update_module_button($cmid, $ignored, $string) {
global $CFG, $OUTPUT;
debugging('update_module_button() has been deprecated and should not be used anymore. Activity modules should not add the ' .
'edit module button, the link is already available in the Administration block. Themes can choose to display the link ' .
'in the buttons row consistently for all module types.', DEBUG_DEVELOPER);
if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) {
$string = get_string('updatethis', '', $string);
$url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
return $OUTPUT->single_button($url, $string);
} else {
return '';
}
}
/**
* @deprecated use $OUTPUT->navbar() instead
*/
function print_navigation () {
throw new coding_exception('print_navigation() can not be used any more, please update use $OUTPUT->navbar() instead.');
}
/**
* @deprecated Please use $PAGE->navabar methods instead.
*/
function build_navigation() {
throw new coding_exception('build_navigation() can not be used any more, please use $PAGE->navbar methods instead.');
}
/**
* @deprecated not relevant with global navigation in Moodle 2.x+
*/
function navmenu() {
throw new coding_exception('navmenu() can not be used any more, it is no longer relevant with global navigation.');
}
/// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
/**
* @deprecated please use calendar_event::create() instead.
*/
function add_event() {
throw new coding_exception('add_event() can not be used any more, please use calendar_event::create() instead.');
}
/**
* @deprecated please calendar_event->update() instead.
*/
function update_event() {
throw new coding_exception('update_event() is removed, please use calendar_event->update() instead.');
}
/**
* @deprecated please use calendar_event->delete() instead.
*/
function delete_event() {
throw new coding_exception('delete_event() can not be used any more, please use '.
'calendar_event->delete() instead.');
}
/**
* @deprecated please use calendar_event->toggle_visibility(false) instead.
*/
function hide_event() {
throw new coding_exception('hide_event() can not be used any more, please use '.
'calendar_event->toggle_visibility(false) instead.');
}
/**
* @deprecated please use calendar_event->toggle_visibility(true) instead.
*/
function show_event() {
throw new coding_exception('show_event() can not be used any more, please use '.
'calendar_event->toggle_visibility(true) instead.');
}
/**
* @deprecated since Moodle 2.2 use core_text::xxxx() instead.
*/
function textlib_get_instance() {
throw new coding_exception('textlib_get_instance() can not be used any more, please use '.
'core_text::functioname() instead.');
}
/**
* @deprecated since 2.4
*/
function get_generic_section_name() {
throw new coding_exception('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base');
}
/**
* @deprecated since 2.4
*/
function get_all_sections() {
throw new coding_exception('get_all_sections() is removed. See phpdocs for this function');
}
/**
* @deprecated since 2.4
*/
function add_mod_to_section() {
throw new coding_exception('Function add_mod_to_section() is removed, please use course_add_cm_to_section()');
}
/**
* @deprecated since 2.4
*/
function get_all_mods() {
throw new coding_exception('Function get_all_mods() is removed. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details');
}
/**
* @deprecated since 2.4
*/
function get_course_section() {
throw new coding_exception('Function get_course_section() is removed. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.');
}
/**
* @deprecated since 2.4
*/
function format_weeks_get_section_dates() {
throw new coding_exception('Function format_weeks_get_section_dates() is removed. It is not recommended to'.
' use it outside of format_weeks plugin');
}
/**
* @deprecated since 2.5
*/
function get_print_section_cm_text() {
throw new coding_exception('Function get_print_section_cm_text() is removed. Please use '.
'cm_info::get_formatted_content() and cm_info::get_formatted_name()');
}
/**
* @deprecated since 2.5
*/
function print_section_add_menus() {
throw new coding_exception('Function print_section_add_menus() is removed. Please use course renderer '.
'function course_section_add_cm_control()');
}
/**
* @deprecated since 2.5. Please use:
* $courserenderer = $PAGE->get_renderer('core', 'course');
* $actions = course_get_cm_edit_actions($mod, $indent, $section);
* return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
*/
function make_editing_buttons() {
throw new coding_exception('Function make_editing_buttons() is removed, please see PHPdocs in '.
'lib/deprecatedlib.php on how to replace it');
}
/**
* @deprecated since 2.5
*/
function print_section() {
throw new coding_exception('Function print_section() is removed. Please use course renderer function '.
'course_section_cm_list() instead.');
}
/**
* @deprecated since 2.5
*/
function print_overview() {
throw new coding_exception('Function print_overview() is removed. Use block course_overview to display this information');
}
/**
* @deprecated since 2.5
*/
function print_recent_activity() {
throw new coding_exception('Function print_recent_activity() is removed. It is not recommended to'.
' use it outside of block_recent_activity');
}
/**
* @deprecated since 2.5
*/
function delete_course_module() {
throw new coding_exception('Function delete_course_module() is removed. Please use course_delete_module() instead.');
}
/**
* @deprecated since 2.5
*/
function update_category_button() {
throw new coding_exception('Function update_category_button() is removed. Pages to view '.
'and edit courses are now separate and no longer depend on editing mode.');
}
/**
* @deprecated since 2.5
*/
function make_categories_list() {
throw new coding_exception('Global function make_categories_list() is removed. Please use '.
'coursecat::make_categories_list() and coursecat::get_parents()');
}
/**
* @deprecated since 2.5
*/
function category_delete_move() {
throw new coding_exception('Function category_delete_move() is removed. Please use coursecat::delete_move() instead.');
}
/**
* @deprecated since 2.5
*/
function category_delete_full() {
throw new coding_exception('Function category_delete_full() is removed. Please use coursecat::delete_full() instead.');
}
/**
* @deprecated since 2.5
*/
function move_category() {
throw new coding_exception('Function move_category() is removed. Please use coursecat::change_parent() instead.');
}
/**
* @deprecated since 2.5
*/
function course_category_hide() {
throw new coding_exception('Function course_category_hide() is removed. Please use coursecat::hide() instead.');
}
/**
* @deprecated since 2.5
*/
function course_category_show() {
throw new coding_exception('Function course_category_show() is removed. Please use coursecat::show() instead.');
}
/**
* @deprecated since 2.5. Please use coursecat::get($catid, IGNORE_MISSING) or coursecat::get($catid, MUST_EXIST).
*/
function get_course_category() {
throw new coding_exception('Function get_course_category() is removed. Please use coursecat::get(), see phpdocs for more details');
}
/**
* @deprecated since 2.5
*/
function create_course_category() {
throw new coding_exception('Function create_course_category() is removed. Please use coursecat::create()');
}
/**
* @deprecated since 2.5. Please use coursecat::get() and coursecat::get_children()
*/
function get_all_subcategories() {
throw new coding_exception('Function get_all_subcategories() is removed. Please use appropriate methods() ' .
'of coursecat class.');
}
/**
* @deprecated since 2.5. Please use coursecat::get($parentid)->get_children().
*/
function get_child_categories() {
throw new coding_exception('Function get_child_categories() is removed. Use coursecat::get_children().');
}
/**
* @deprecated since 2.5
*/
function get_categories() {
throw new coding_exception('Function get_categories() is removed. Please use ' .
'appropriate functions from class coursecat');
}
/**
* @deprecated since 2.5
*/
function print_course_search() {
throw new coding_exception('Function print_course_search() is removed, please use course renderer');
}
/**
* @deprecated since 2.5
*/
function print_my_moodle() {
throw new coding_exception('Function print_my_moodle() is removed, please use course renderer ' .
'function frontpage_my_courses()');
}
/**
* @deprecated since 2.5
*/
function print_remote_course() {
throw new coding_exception('Function print_remote_course() is removed, please use course renderer');
}
/**
* @deprecated since 2.5
*/
function print_remote_host() {
throw new coding_exception('Function print_remote_host() is removed, please use course renderer');
}
/**
* @deprecated since 2.5
*/
function print_whole_category_list() {
throw new coding_exception('Function print_whole_category_list() is removed, please use course renderer');
}
/**
* @deprecated since 2.5
*/
function print_category_info() {
throw new coding_exception('Function print_category_info() is removed, please use course renderer');
}
/**
* @deprecated since 2.5
*/
function get_course_category_tree() {
throw new coding_exception('Function get_course_category_tree() is removed, please use course ' .
'renderer or coursecat class, see function phpdocs for more info');
}
/**
* @deprecated since 2.5
*/
function print_courses() {
throw new coding_exception('Function print_courses() is removed, please use course renderer');
}
/**
* @deprecated since 2.5
*/
function print_course() {
throw new coding_exception('Function print_course() is removed, please use course renderer');
}
/**
* @deprecated since 2.5
*/
function get_category_courses_array() {
throw new coding_exception('Function get_category_courses_array() is removed, please use methods of coursecat class');
}
/**
* @deprecated since 2.5
*/
function get_category_courses_array_recursively() {
throw new coding_exception('Function get_category_courses_array_recursively() is removed, please use methods of coursecat class', DEBUG_DEVELOPER);
}
/**
* @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more.
*/
function blog_get_context_url() {
throw new coding_exception('Function blog_get_context_url() is removed, getting params from context is not reliable for blogs.');
}
/**
* @deprecated since 2.5
*/
function get_courses_wmanagers() {
throw new coding_exception('Function get_courses_wmanagers() is removed, please use coursecat::get_courses()');
}
/**
* @deprecated since 2.5
*/
function convert_tree_to_html() {
throw new coding_exception('Function convert_tree_to_html() is removed. Consider using class tabtree and core_renderer::render_tabtree()');
}
/**
* @deprecated since 2.5
*/
function convert_tabrows_to_tree() {
throw new coding_exception('Function convert_tabrows_to_tree() is removed. Consider using class tabtree');
}
/**
* @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically
*/
function can_use_rotated_text() {
debugging('can_use_rotated_text() is removed. JS feature detection is used automatically.');
}
/**
* @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more.
*/
function get_context_instance_by_id() {
throw new coding_exception('get_context_instance_by_id() is now removed, please use context::instance_by_id($id) instead.');
}
/**
* Returns system context or null if can not be created yet.
*
* @see context_system::instance()
* @deprecated since 2.2
* @param bool $cache use caching
* @return context system context (null if context table not created yet)
*/
function get_system_context($cache = true) {
debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER);
return context_system::instance(0, IGNORE_MISSING, $cache);
}
/**
* @deprecated since 2.2, use $context->get_parent_context_ids() instead
*/
function get_parent_contexts() {
throw new coding_exception('get_parent_contexts() is removed, please use $context->get_parent_context_ids() instead.');
}
/**
* @deprecated since Moodle 2.2
*/
function get_parent_contextid() {
throw new coding_exception('get_parent_contextid() is removed, please use $context->get_parent_context() instead.');
}
/**
* @deprecated since 2.2
*/
function get_child_contexts() {
throw new coding_exception('get_child_contexts() is removed, please use $context->get_child_contexts() instead.');
}
/**
* @deprecated since 2.2
*/
function create_contexts() {
throw new coding_exception('create_contexts() is removed, please use context_helper::create_instances() instead.');
}
/**
* @deprecated since 2.2
*/
function cleanup_contexts() {
throw new coding_exception('cleanup_contexts() is removed, please use context_helper::cleanup_instances() instead.');
}
/**
* @deprecated since 2.2
*/
function build_context_path() {
throw new coding_exception('build_context_path() is removed, please use context_helper::build_all_paths() instead.');
}
/**
* @deprecated since 2.2
*/
function rebuild_contexts() {
throw new coding_exception('rebuild_contexts() is removed, please use $context->reset_paths(true) instead.');
}
/**
* @deprecated since Moodle 2.2
*/
function preload_course_contexts() {
throw new coding_exception('preload_course_contexts() is removed, please use context_helper::preload_course() instead.');
}
/**
* @deprecated since Moodle 2.2
*/
function context_moved() {
throw new coding_exception('context_moved() is removed, please use context::update_moved() instead.');
}
/**
* @deprecated since 2.2
*/
function fetch_context_capabilities() {
throw new coding_exception('fetch_context_capabilities() is removed, please use $context->get_capabilities() instead.');
}
/**
* @deprecated since 2.2
*/
function context_instance_preload() {
throw new coding_exception('context_instance_preload() is removed, please use context_helper::preload_from_record() instead.');
}
/**
* @deprecated since 2.2
*/
function get_contextlevel_name() {
throw new coding_exception('get_contextlevel_name() is removed, please use context_helper::get_level_name() instead.');
}
/**
* @deprecated since 2.2
*/
function print_context_name() {
throw new coding_exception('print_context_name() is removed, please use $context->get_context_name() instead.');
}
/**
* @deprecated since 2.2, use $context->mark_dirty() instead
*/
function mark_context_dirty() {
throw new coding_exception('mark_context_dirty() is removed, please use $context->mark_dirty() instead.');
}
/**
* @deprecated since Moodle 2.2
*/
function delete_context() {
throw new coding_exception('delete_context() is removed, please use context_helper::delete_instance() ' .
'or $context->delete_content() instead.');
}
/**
* @deprecated since 2.2
*/
function get_context_url() {
throw new coding_exception('get_context_url() is removed, please use $context->get_url() instead.');
}
/**
* @deprecated since 2.2
*/
function get_course_context() {
throw new coding_exception('get_course_context() is removed, please use $context->get_course_context(true) instead.');
}
/**
* @deprecated since 2.2
*/
function get_user_courses_bycap() {
throw new coding_exception('get_user_courses_bycap() is removed, please use enrol_get_users_courses() instead.');
}
/**
* @deprecated since Moodle 2.2
*/
function get_role_context_caps() {
throw new coding_exception('get_role_context_caps() is removed, it is really slow. Don\'t use it.');
}
/**
* @deprecated since 2.2
*/
function get_courseid_from_context() {
throw new coding_exception('get_courseid_from_context() is removed, please use $context->get_course_context(false) instead.');
}
/**
* @deprecated since 2.2
*/
function context_instance_preload_sql() {
throw new coding_exception('context_instance_preload_sql() is removed, please use context_helper::get_preload_record_columns_sql() instead.');
}
/**
* @deprecated since 2.2
*/
function get_related_contexts_string() {
throw new coding_exception('get_related_contexts_string() is removed, please use $context->get_parent_context_ids(true) instead.');
}
/**
* @deprecated since 2.6
*/
function get_plugin_list_with_file() {
throw new coding_exception('get_plugin_list_with_file() is removed, please use core_component::get_plugin_list_with_file() instead.');
}
/**
* @deprecated since 2.6
*/
function check_browser_operating_system() {
throw new coding_exception('check_browser_operating_system is removed, please update your code to use core_useragent instead.');
}
/**
* @deprecated since 2.6
*/
function check_browser_version() {
throw new coding_exception('check_browser_version is removed, please update your code to use core_useragent instead.');
}
/**
* @deprecated since 2.6
*/
function get_device_type() {
throw new coding_exception('get_device_type is removed, please update your code to use core_useragent instead.');
}
/**
* @deprecated since 2.6
*/
function get_device_type_list() {
throw new coding_exception('get_device_type_list is removed, please update your code to use core_useragent instead.');
}
/**
* @deprecated since 2.6
*/
function get_selected_theme_for_device_type() {
throw new coding_exception('get_selected_theme_for_device_type is removed, please update your code to use core_useragent instead.');
}
/**
* @deprecated since 2.6
*/
function get_device_cfg_var_name() {
throw new coding_exception('get_device_cfg_var_name is removed, please update your code to use core_useragent instead.');
}
/**
* @deprecated since 2.6
*/
function set_user_device_type() {
throw new coding_exception('set_user_device_type is removed, please update your code to use core_useragent instead.');
}
/**
* @deprecated since 2.6
*/
function get_user_device_type() {
throw new coding_exception('get_user_device_type is removed, please update your code to use core_useragent instead.');
}
/**
* @deprecated since 2.6
*/
function get_browser_version_classes() {
throw new coding_exception('get_browser_version_classes is removed, please update your code to use core_useragent instead.');
}
/**
* @deprecated since Moodle 2.6
*/
function generate_email_supportuser() {
throw new coding_exception('generate_email_supportuser is removed, please use core_user::get_support_user');
}
/**
* @deprecated since Moodle 2.6
*/
function badges_get_issued_badge_info() {
throw new coding_exception('Function badges_get_issued_badge_info() is removed. Please use core_badges_assertion class and methods to generate badge assertion.');
}
/**
* @deprecated since 2.6
*/
function can_use_html_editor() {
throw new coding_exception('can_use_html_editor is removed, please update your code to assume it returns true.');
}
/**
* @deprecated since Moodle 2.7, use {@link user_count_login_failures()} instead.
*/
function count_login_failures() {
throw new coding_exception('count_login_failures() can not be used any more, please use user_count_login_failures().');
}
/**
* @deprecated since 2.7 MDL-33099/MDL-44088 - please do not use this function any more.
*/
function ajaxenabled() {
throw new coding_exception('ajaxenabled() can not be used anymore. Update your code to work with JS at all times.');
}
/**
* @deprecated Since Moodle 2.7 MDL-44070
*/
function coursemodule_visible_for_user() {
throw new coding_exception('coursemodule_visible_for_user() can not be used any more,
please use \core_availability\info_module::is_user_visible()');
}
/**
* @deprecated since Moodle 2.8 MDL-36014, MDL-35618 this functionality is removed
*/
function enrol_cohort_get_cohorts() {
throw new coding_exception('Function enrol_cohort_get_cohorts() is removed, use '.
'cohort_get_available_cohorts() instead');
}
/**
* @deprecated since Moodle 2.8 MDL-36014 please use cohort_can_view_cohort()
*/
function enrol_cohort_can_view_cohort() {
throw new coding_exception('Function enrol_cohort_can_view_cohort() is removed, use cohort_can_view_cohort() instead');
}
/**
* @deprecated since Moodle 2.8 MDL-36014 use cohort_get_available_cohorts() instead
*/
function cohort_get_visible_list() {
throw new coding_exception('Function cohort_get_visible_list() is removed. Please use function cohort_get_available_cohorts() ".
"that correctly checks capabilities.');
}
/**
* @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
*/
function enrol_cohort_enrol_all_users() {
throw new coding_exception('enrol_cohort_enrol_all_users() is removed. This functionality is moved to enrol_manual.');
}
/**
* @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
*/
function enrol_cohort_search_cohorts() {
throw new coding_exception('enrol_cohort_search_cohorts() is removed. This functionality is moved to enrol_manual.');
}
/* === Apis deprecated in since Moodle 2.9 === */
/**
* @deprecated since Moodle 2.9 MDL-49371 - please do not use this function any more.
*/
function message_current_user_is_involved() {
throw new coding_exception('message_current_user_is_involved() can not be used any more.');
}
/**
* @deprecated since Moodle 2.9 MDL-45898 - please do not use this function any more.
*/
function profile_display_badges() {
throw new coding_exception('profile_display_badges() can not be used any more.');
}
/**
* @deprecated since Moodle 2.9 MDL-45774 - Please do not use this function any more.
*/
function useredit_shared_definition_preferences() {
throw new coding_exception('useredit_shared_definition_preferences() can not be used any more.');
}
/**
* @deprecated since Moodle 2.9
*/
function calendar_normalize_tz() {
throw new coding_exception('calendar_normalize_tz() can not be used any more, please use core_date::normalise_timezone() instead.');
}
/**
* @deprecated since Moodle 2.9
*/
function get_user_timezone_offset() {
throw new coding_exception('get_user_timezone_offset() can not be used any more, please use standard PHP DateTimeZone class instead');
}
/**
* @deprecated since Moodle 2.9
*/
function get_timezone_offset() {
throw new coding_exception('get_timezone_offset() can not be used any more, please use standard PHP DateTimeZone class instead');
}
/**
* @deprecated since Moodle 2.9
*/
function get_list_of_timezones() {
throw new coding_exception('get_list_of_timezones() can not be used any more, please use core_date::get_list_of_timezones() instead');
}
/**
* @deprecated since Moodle 2.9
*/
function update_timezone_records() {
throw new coding_exception('update_timezone_records() can not be used any more, please use standard PHP DateTime class instead');
}
/**
* @deprecated since Moodle 2.9
*/
function calculate_user_dst_table() {
throw new coding_exception('calculate_user_dst_table() can not be used any more, please use standard PHP DateTime class instead');
}
/**
* @deprecated since Moodle 2.9
*/
function dst_changes_for_year() {
throw new coding_exception('dst_changes_for_year() can not be used any more, please use standard DateTime class instead');
}
/**
* @deprecated since Moodle 2.9
*/
function get_timezone_record() {
throw new coding_exception('get_timezone_record() can not be used any more, please use standard PHP DateTime class instead');
}
/* === Apis deprecated since Moodle 3.0 === */
/**
* @deprecated since Moodle 3.0 MDL-49360 - please do not use this function any more.
*/
function get_referer() {
throw new coding_exception('get_referer() can not be used any more. Please use get_local_referer() instead.');
}
/**
* @deprecated since Moodle 3.0 use \core_useragent::is_web_crawler instead.
*/
function is_web_crawler() {
throw new coding_exception('is_web_crawler() can not be used any more. Please use core_useragent::is_web_crawler() instead.');
}
/**
* @deprecated since Moodle 3.0 MDL-50287 - please do not use this function any more.
*/
function completion_cron() {
throw new coding_exception('completion_cron() can not be used any more. Functionality has been moved to scheduled tasks.');
}
/**
* @deprecated since 3.0
*/
function coursetag_get_tags() {
throw new coding_exception('Function coursetag_get_tags() can not be used any more. ' .
'Userid is no longer used for tagging courses.');
}
/**
* @deprecated since 3.0
*/
function coursetag_get_all_tags() {
throw new coding_exception('Function coursetag_get_all_tags() can not be used any more. Userid is no ' .
'longer used for tagging courses.');
}
/**
* @deprecated since 3.0
*/
function coursetag_get_jscript() {
throw new coding_exception('Function coursetag_get_jscript() can not be used any more and is obsolete.');
}
/**
* @deprecated since 3.0
*/
function coursetag_get_jscript_links() {
throw new coding_exception('Function coursetag_get_jscript_links() can not be used any more and is obsolete.');
}
/**
* @deprecated since 3.0
*/
function coursetag_get_records() {
throw new coding_exception('Function coursetag_get_records() can not be used any more. ' .
'Userid is no longer used for tagging courses.');
}
/**
* @deprecated since 3.0
*/
function coursetag_store_keywords() {
throw new coding_exception('Function coursetag_store_keywords() can not be used any more. ' .
'Userid is no longer used for tagging courses.');
}
/**
* @deprecated since 3.0
*/
function coursetag_delete_keyword() {
throw new coding_exception('Function coursetag_delete_keyword() can not be used any more. ' .
'Userid is no longer used for tagging courses.');
}
/**
* @deprecated since 3.0
*/
function coursetag_get_tagged_courses() {
throw new coding_exception('Function coursetag_get_tagged_courses() can not be used any more. ' .
'Userid is no longer used for tagging courses.');
}
/**
* @deprecated since 3.0
*/
function coursetag_delete_course_tags() {
throw new coding_exception('Function coursetag_delete_course_tags() is deprecated. ' .
'Use core_tag_tag::remove_all_item_tags().');
}
/**
* @deprecated since 3.1. Use core_tag_tag::get($tagid)->update() instead
*/
function tag_type_set() {
throw new coding_exception('tag_type_set() can not be used anymore. Please use ' .
'core_tag_tag::get($tagid)->update().');
}
/**
* @deprecated since 3.1. Use core_tag_tag::get($tagid)->update() instead
*/
function tag_description_set() {
throw new coding_exception('tag_description_set() can not be used anymore. Please use ' .
'core_tag_tag::get($tagid)->update().');
}
/**
* @deprecated since 3.1. Use core_tag_tag::get_item_tags() instead
*/
function tag_get_tags() {
throw new coding_exception('tag_get_tags() can not be used anymore. Please use ' .
'core_tag_tag::get_item_tags().');
}
/**
* @deprecated since 3.1
*/
function tag_get_tags_array() {
throw new coding_exception('tag_get_tags_array() can not be used anymore. Please use ' .
'core_tag_tag::get_item_tags_array().');
}
/**
* @deprecated since 3.1. Use core_tag_tag::get_item_tags_array() or $OUTPUT->tag_list(core_tag_tag::get_item_tags())
*/
function tag_get_tags_csv() {
throw new coding_exception('tag_get_tags_csv() can not be used anymore. Please use ' .
'core_tag_tag::get_item_tags_array() or $OUTPUT->tag_list(core_tag_tag::get_item_tags()).');
}
/**
* @deprecated since 3.1. Use core_tag_tag::get_item_tags() instead
*/
function tag_get_tags_ids() {
throw new coding_exception('tag_get_tags_ids() can not be used anymore. Please consider using ' .
'core_tag_tag::get_item_tags() or similar methods.');
}
/**
* @deprecated since 3.1. Use core_tag_tag::get_by_name() or core_tag_tag::get_by_name_bulk()
*/
function tag_get_id() {
throw new coding_exception('tag_get_id() can not be used anymore. Please use ' .
'core_tag_tag::get_by_name() or core_tag_tag::get_by_name_bulk()');
}
/**
* @deprecated since 3.1. Use core_tag_tag::get($tagid)->update() instead
*/
function tag_rename() {
throw new coding_exception('tag_rename() can not be used anymore. Please use ' .
'core_tag_tag::get($tagid)->update()');
}
/**
* @deprecated since 3.1. Use core_tag_tag::remove_item_tag() instead
*/
function tag_delete_instance() {
throw new coding_exception('tag_delete_instance() can not be used anymore. Please use ' .
'core_tag_tag::remove_item_tag()');
}
/**
* @deprecated since 3.1. Use core_tag_tag::get_by_name()->get_tagged_items() instead
*/
function tag_find_records() {
throw new coding_exception('tag_find_records() can not be used anymore. Please use ' .
'core_tag_tag::get_by_name()->get_tagged_items()');
}
/**
* @deprecated since 3.1
*/
function tag_add() {
throw new coding_exception('tag_add() can not be used anymore. You can use ' .
'core_tag_tag::create_if_missing(), however it should not be necessary since tags are ' .
'created automatically when assigned to items');
}
/**
* @deprecated since 3.1. Use core_tag_tag::set_item_tags() or core_tag_tag::add_item_tag() instead
*/
function tag_assign() {
throw new coding_exception('tag_assign() can not be used anymore. Please use ' .
'core_tag_tag::set_item_tags() or core_tag_tag::add_item_tag() instead. Tag instance ' .
'ordering should not be set manually');
}
/**
* @deprecated since 3.1. Use core_tag_tag::get($tagid)->count_tagged_items() instead
*/
function tag_record_count() {
throw new coding_exception('tag_record_count() can not be used anymore. Please use ' .
'core_tag_tag::get($tagid)->count_tagged_items().');
}
/**
* @deprecated since 3.1. Use core_tag_tag::get($tagid)->is_item_tagged_with() instead
*/
function tag_record_tagged_with() {
throw new coding_exception('tag_record_tagged_with() can not be used anymore. Please use ' .
'core_tag_tag::get($tagid)->is_item_tagged_with().');
}
/**
* @deprecated since 3.1. Use core_tag_tag::get($tagid)->flag() instead
*/
function tag_set_flag() {
throw new coding_exception('tag_set_flag() can not be used anymore. Please use ' .
'core_tag_tag::get($tagid)->flag()');
}
/**
* @deprecated since 3.1. Use core_tag_tag::get($tagid)->reset_flag() instead
*/
function tag_unset_flag() {
throw new coding_exception('tag_unset_flag() can not be used anymore. Please use ' .
'core_tag_tag::get($tagid)->reset_flag()');
}
/**
* @deprecated since 3.1
*/
function tag_print_cloud() {
throw new coding_exception('tag_print_cloud() can not be used anymore. Please use ' .
'core_tag_collection::get_tag_cloud(), templateable core_tag\output\tagcloud and ' .
'template core_tag/tagcloud.');
}
/**
* @deprecated since 3.0
*/
function tag_autocomplete() {
throw new coding_exception('tag_autocomplete() can not be used anymore. New form ' .
'element "tags" does proper autocomplete.');
}
/**
* @deprecated since 3.1
*/
function tag_print_description_box() {
throw new coding_exception('tag_print_description_box() can not be used anymore. ' .
'See core_tag_renderer for similar code');
}
/**
* @deprecated since 3.1
*/
function tag_print_management_box() {
throw new coding_exception('tag_print_management_box() can not be used anymore. ' .
'See core_tag_renderer for similar code');
}
/**
* @deprecated since 3.1
*/
function tag_print_search_box() {
throw new coding_exception('tag_print_search_box() can not be used anymore. ' .
'See core_tag_renderer for similar code');
}
/**
* @deprecated since 3.1
*/
function tag_print_search_results() {
throw new coding_exception('tag_print_search_results() can not be used anymore. ' .
'In /tag/search.php the search results are printed using the core_tag/tagcloud template.');
}
/**
* @deprecated since 3.1
*/
function tag_print_tagged_users_table() {
throw new coding_exception('tag_print_tagged_users_table() can not be used anymore. ' .
'See core_user_renderer for similar code');
}
/**
* @deprecated since 3.1
*/
function tag_print_user_box() {
throw new coding_exception('tag_print_user_box() can not be used anymore. ' .
'See core_user_renderer for similar code');
}
/**
* @deprecated since 3.1
*/
function tag_print_user_list() {
throw new coding_exception('tag_print_user_list() can not be used anymore. ' .
'See core_user_renderer for similar code');
}
/**
* @deprecated since 3.1
*/
function tag_display_name() {
throw new coding_exception('tag_display_name() can not be used anymore. Please use ' .
'core_tag_tag::make_display_name().');
}
/**
* @deprecated since 3.1
*/
function tag_normalize() {
throw new coding_exception('tag_normalize() can not be used anymore. Please use ' .
'core_tag_tag::normalize().');
}
/**
* @deprecated since 3.1
*/
function tag_get_related_tags_csv() {
throw new coding_exception('tag_get_related_tags_csv() can not be used anymore. Please ' .
'consider looping through array or using $OUTPUT->tag_list(core_tag_tag::get_item_tags()).');
}
/**
* @deprecated since 3.1
*/
function tag_set() {
throw new coding_exception('tag_set() can not be used anymore. Please use ' .
'core_tag_tag::set_item_tags().');
}
/**
* @deprecated since 3.1
*/
function tag_set_add() {
throw new coding_exception('tag_set_add() can not be used anymore. Please use ' .
'core_tag_tag::add_item_tag().');
}
/**
* @deprecated since 3.1
*/
function tag_set_delete() {
throw new coding_exception('tag_set_delete() can not be used anymore. Please use ' .
'core_tag_tag::remove_item_tag().');
}
/**
* @deprecated since 3.1
*/
function tag_get() {
throw new coding_exception('tag_get() can not be used anymore. Please use ' .
'core_tag_tag::get() or core_tag_tag::get_by_name().');
}
/**
* @deprecated since 3.1
*/
function tag_get_related_tags() {
throw new coding_exception('tag_get_related_tags() can not be used anymore. Please use ' .
'core_tag_tag::get_correlated_tags(), core_tag_tag::get_related_tags() or ' .
'core_tag_tag::get_manual_related_tags().');
}
/**
* @deprecated since 3.1
*/
function tag_delete() {
throw new coding_exception('tag_delete() can not be used anymore. Please use ' .
'core_tag_tag::delete_tags().');
}
/**
* @deprecated since 3.1
*/
function tag_delete_instances() {
throw new coding_exception('tag_delete_instances() can not be used anymore. Please use ' .
'core_tag_tag::delete_instances().');
}
/**
* @deprecated since 3.1
*/
function tag_cleanup() {
throw new coding_exception('tag_cleanup() can not be used anymore. Please use ' .
'\core\task\tag_cron_task::cleanup().');
}
/**
* @deprecated since 3.1
*/
function tag_bulk_delete_instances() {
throw new coding_exception('tag_bulk_delete_instances() can not be used anymore. Please use ' .
'\core\task\tag_cron_task::bulk_delete_instances().');
}
/**
* @deprecated since 3.1
*/
function tag_compute_correlations() {
throw new coding_exception('tag_compute_correlations() can not be used anymore. Please use ' .
'use \core\task\tag_cron_task::compute_correlations().');
}
/**
* @deprecated since 3.1
*/
function tag_process_computed_correlation() {
throw new coding_exception('tag_process_computed_correlation() can not be used anymore. Please use ' .
'use \core\task\tag_cron_task::process_computed_correlation().');
}
/**
* @deprecated since 3.1
*/
function tag_cron() {
throw new coding_exception('tag_cron() can not be used anymore. Please use ' .
'use \core\task\tag_cron_task::execute().');
}
/**
* @deprecated since 3.1
*/
function tag_find_tags() {
throw new coding_exception('tag_find_tags() can not be used anymore.');
}
/**
* @deprecated since 3.1
*/
function tag_get_name() {
throw new coding_exception('tag_get_name() can not be used anymore.');
}
/**
* @deprecated since 3.1
*/
function tag_get_correlated() {
throw new coding_exception('tag_get_correlated() can not be used anymore. Please use ' .
'use core_tag_tag::get_correlated_tags().');
}
/**
* @deprecated since 3.1
*/
function tag_cloud_sort() {
throw new coding_exception('tag_cloud_sort() can not be used anymore. Similar method can ' .
'be found in core_tag_collection::cloud_sort().');
}
/**
* Loads the events definitions for the component (from file). If no
* events are defined for the component, we simply return an empty array.
*
* @access protected To be used from eventslib only
* @deprecated since Moodle 3.1
* @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
* @return array Array of capabilities or empty array if not exists
*/
function events_load_def($component) {
global $CFG;
if ($component === 'unittest') {
$defpath = $CFG->dirroot.'/lib/tests/fixtures/events.php';
} else {
$defpath = core_component::get_component_directory($component).'/db/events.php';
}
$handlers = array();
if (file_exists($defpath)) {
require($defpath);
}
// make sure the definitions are valid and complete; tell devs what is wrong
foreach ($handlers as $eventname => $handler) {
if ($eventname === 'reset') {
debugging("'reset' can not be used as event name.");
unset($handlers['reset']);
continue;
}
if (!is_array($handler)) {
debugging("Handler of '$eventname' must be specified as array'");
unset($handlers[$eventname]);
continue;
}
if (!isset($handler['handlerfile'])) {
debugging("Handler of '$eventname' must include 'handlerfile' key'");
unset($handlers[$eventname]);
continue;
}
if (!isset($handler['handlerfunction'])) {
debugging("Handler of '$eventname' must include 'handlerfunction' key'");
unset($handlers[$eventname]);
continue;
}
if (!isset($handler['schedule'])) {
$handler['schedule'] = 'instant';
}
if ($handler['schedule'] !== 'instant' and $handler['schedule'] !== 'cron') {
debugging("Handler of '$eventname' must include valid 'schedule' type (instant or cron)'");
unset($handlers[$eventname]);
continue;
}
if (!isset($handler['internal'])) {
$handler['internal'] = 1;
}
$handlers[$eventname] = $handler;
}
return $handlers;
}
/**
* Puts a handler on queue
*
* @access protected To be used from eventslib only
* @deprecated since Moodle 3.1
* @param stdClass $handler event handler object from db
* @param stdClass $event event data object
* @param string $errormessage The error message indicating the problem
* @return int id number of new queue handler
*/
function events_queue_handler($handler, $event, $errormessage) {
global $DB;
if ($qhandler = $DB->get_record('events_queue_handlers', array('queuedeventid'=>$event->id, 'handlerid'=>$handler->id))) {
debugging("Please check code: Event id $event->id is already queued in handler id $qhandler->id");
return $qhandler->id;
}
// make a new queue handler
$qhandler = new stdClass();
$qhandler->queuedeventid = $event->id;
$qhandler->handlerid = $handler->id;
$qhandler->errormessage = $errormessage;
$qhandler->timemodified = time();
if ($handler->schedule === 'instant' and $handler->status == 1) {
$qhandler->status = 1; //already one failed attempt to dispatch this event
} else {
$qhandler->status = 0;
}
return $DB->insert_record('events_queue_handlers', $qhandler);
}
/**
* trigger a single event with a specified handler
*
* @access protected To be used from eventslib only
* @deprecated since Moodle 3.1
* @param stdClass $handler This shoudl be a row from the events_handlers table.
* @param stdClass $eventdata An object containing information about the event
* @param string $errormessage error message indicating problem
* @return bool|null True means event processed, false means retry event later; may throw exception, NULL means internal error
*/
function events_dispatch($handler, $eventdata, &$errormessage) {
global $CFG;
debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.', DEBUG_DEVELOPER);
$function = unserialize($handler->handlerfunction);
if (is_callable($function)) {
// oki, no need for includes
} else if (file_exists($CFG->dirroot.$handler->handlerfile)) {
include_once($CFG->dirroot.$handler->handlerfile);
} else {
$errormessage = "Handler file of component $handler->component: $handler->handlerfile can not be found!";
return null;
}
// checks for handler validity
if (is_callable($function)) {
$result = call_user_func($function, $eventdata);
if ($result === false) {
$errormessage = "Handler function of component $handler->component: $handler->handlerfunction requested resending of event!";
return false;
}
return true;
} else {
$errormessage = "Handler function of component $handler->component: $handler->handlerfunction not callable function or class method!";
return null;
}
}
/**
* given a queued handler, call the respective event handler to process the event
*
* @access protected To be used from eventslib only
* @deprecated since Moodle 3.1
* @param stdClass $qhandler events_queued_handler row from db
* @return boolean true means event processed, false means retry later, NULL means fatal failure
*/
function events_process_queued_handler($qhandler) {
global $DB;
// get handler
if (!$handler = $DB->get_record('events_handlers', array('id'=>$qhandler->handlerid))) {
debugging("Error processing queue handler $qhandler->id, missing handler id: $qhandler->handlerid");
//irrecoverable error, remove broken queue handler
events_dequeue($qhandler);
return NULL;
}
// get event object
if (!$event = $DB->get_record('events_queue', array('id'=>$qhandler->queuedeventid))) {
// can't proceed with no event object - might happen when two crons running at the same time
debugging("Error processing queue handler $qhandler->id, missing event id: $qhandler->queuedeventid");
//irrecoverable error, remove broken queue handler
events_dequeue($qhandler);
return NULL;
}
// call the function specified by the handler
try {
$errormessage = 'Unknown error';
if (events_dispatch($handler, unserialize(base64_decode($event->eventdata)), $errormessage)) {
//everything ok
events_dequeue($qhandler);
return true;
}
} catch (Exception $e) {
// the problem here is that we do not want one broken handler to stop all others,
// cron handlers are very tricky because the needed data might have been deleted before the cron execution
$errormessage = "Handler function of component $handler->component: $handler->handlerfunction threw exception :" .
$e->getMessage() . "\n" . format_backtrace($e->getTrace(), true);
if (!empty($e->debuginfo)) {
$errormessage .= $e->debuginfo;
}
}
//dispatching failed
$qh = new stdClass();
$qh->id = $qhandler->id;
$qh->errormessage = $errormessage;
$qh->timemodified = time();
$qh->status = $qhandler->status + 1;
$DB->update_record('events_queue_handlers', $qh);
debugging($errormessage);
return false;
}
/**
* Updates all of the event definitions within the database.
*
* Unfortunately this isn't as simple as removing them all and then readding
* the updated event definitions. Chances are queued items are referencing the
* existing definitions.
*
* Note that the absence of the db/events.php event definition file
* will cause any queued events for the component to be removed from
* the database.
*
* @category event
* @deprecated since Moodle 3.1
* @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
* @return boolean always returns true
*/
function events_update_definition($component='moodle') {
global $DB;
// load event definition from events.php
$filehandlers = events_load_def($component);
if ($filehandlers) {
debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.', DEBUG_DEVELOPER);
}
// load event definitions from db tables
// if we detect an event being already stored, we discard from this array later
// the remaining needs to be removed
$cachedhandlers = events_get_cached($component);
foreach ($filehandlers as $eventname => $filehandler) {
if (!empty($cachedhandlers[$eventname])) {
if ($cachedhandlers[$eventname]['handlerfile'] === $filehandler['handlerfile'] &&
$cachedhandlers[$eventname]['handlerfunction'] === serialize($filehandler['handlerfunction']) &&
$cachedhandlers[$eventname]['schedule'] === $filehandler['schedule'] &&
$cachedhandlers[$eventname]['internal'] == $filehandler['internal']) {
// exact same event handler already present in db, ignore this entry
unset($cachedhandlers[$eventname]);
continue;
} else {
// same event name matches, this event has been updated, update the datebase
$handler = new stdClass();
$handler->id = $cachedhandlers[$eventname]['id'];
$handler->handlerfile = $filehandler['handlerfile'];
$handler->handlerfunction = serialize($filehandler['handlerfunction']); // static class methods stored as array
$handler->schedule = $filehandler['schedule'];
$handler->internal = $filehandler['internal'];
$DB->update_record('events_handlers', $handler);
unset($cachedhandlers[$eventname]);
continue;
}
} else {
// if we are here, this event handler is not present in db (new)
// add it
$handler = new stdClass();
$handler->eventname = $eventname;
$handler->component = $component;
$handler->handlerfile = $filehandler['handlerfile'];
$handler->handlerfunction = serialize($filehandler['handlerfunction']); // static class methods stored as array
$handler->schedule = $filehandler['schedule'];
$handler->status = 0;
$handler->internal = $filehandler['internal'];
$DB->insert_record('events_handlers', $handler);
}
}
// clean up the left overs, the entries in cached events array at this points are deprecated event handlers
// and should be removed, delete from db
events_cleanup($component, $cachedhandlers);
events_get_handlers('reset');
return true;
}
/**
* Events cron will try to empty the events queue by processing all the queued events handlers
*
* @access public Part of the public API
* @deprecated since Moodle 3.1
* @category event
* @param string $eventname empty means all
* @return int number of dispatched events
*/
function events_cron($eventname='') {
global $DB;
$failed = array();
$processed = 0;
if ($eventname) {
$sql = "SELECT qh.*
FROM {events_queue_handlers} qh, {events_handlers} h
WHERE qh.handlerid = h.id AND h.eventname=?
ORDER BY qh.id";
$params = array($eventname);
} else {
$sql = "SELECT *
FROM {events_queue_handlers}
ORDER BY id";
$params = array();
}
$rs = $DB->get_recordset_sql($sql, $params);
if ($rs->valid()) {
debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.', DEBUG_DEVELOPER);
}
foreach ($rs as $qhandler) {
if (isset($failed[$qhandler->handlerid])) {
// do not try to dispatch any later events when one already asked for retry or ended with exception
continue;
}
$status = events_process_queued_handler($qhandler);
if ($status === false) {
// handler is asking for retry, do not send other events to this handler now
$failed[$qhandler->handlerid] = $qhandler->handlerid;
} else if ($status === NULL) {
// means completely broken handler, event data was purged
$failed[$qhandler->handlerid] = $qhandler->handlerid;
} else {
$processed++;
}
}
$rs->close();
// remove events that do not have any handlers waiting
$sql = "SELECT eq.id
FROM {events_queue} eq
LEFT JOIN {events_queue_handlers} qh ON qh.queuedeventid = eq.id
WHERE qh.id IS NULL";
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $event) {
//debugging('Purging stale event '.$event->id);
$DB->delete_records('events_queue', array('id'=>$event->id));
}
$rs->close();
return $processed;
}
/**
* Do not call directly, this is intended to be used from new event base only.
*
* @private
* @deprecated since Moodle 3.1
* @param string $eventname name of the event
* @param mixed $eventdata event data object
* @return int number of failed events
*/
function events_trigger_legacy($eventname, $eventdata) {
global $CFG, $USER, $DB;
$failedcount = 0; // number of failed events.
// pull out all registered event handlers
if ($handlers = events_get_handlers($eventname)) {
foreach ($handlers as $handler) {
$errormessage = '';
if ($handler->schedule === 'instant') {
if ($handler->status) {
//check if previous pending events processed
if (!$DB->record_exists('events_queue_handlers', array('handlerid'=>$handler->id))) {
// ok, queue is empty, lets reset the status back to 0 == ok
$handler->status = 0;
$DB->set_field('events_handlers', 'status', 0, array('id'=>$handler->id));
// reset static handler cache
events_get_handlers('reset');
}
}
// dispatch the event only if instant schedule and status ok
if ($handler->status or (!$handler->internal and $DB->is_transaction_started())) {
// increment the error status counter
$handler->status++;
$DB->set_field('events_handlers', 'status', $handler->status, array('id'=>$handler->id));
// reset static handler cache
events_get_handlers('reset');
} else {
$errormessage = 'Unknown error';
$result = events_dispatch($handler, $eventdata, $errormessage);
if ($result === true) {
// everything is fine - event dispatched
continue;
} else if ($result === false) {
// retry later - set error count to 1 == send next instant into cron queue
$DB->set_field('events_handlers', 'status', 1, array('id'=>$handler->id));
// reset static handler cache
events_get_handlers('reset');
} else {
// internal problem - ignore the event completely
$failedcount ++;
continue;
}
}
// update the failed counter
$failedcount ++;
} else if ($handler->schedule === 'cron') {
//ok - use queueing of events only
} else {
// unknown schedule - ignore event completely
debugging("Unknown handler schedule type: $handler->schedule");
$failedcount ++;
continue;
}
// if even type is not instant, or dispatch asked for retry, queue it
$event = new stdClass();
$event->userid = $USER->id;
$event->eventdata = base64_encode(serialize($eventdata));
$event->timecreated = time();
if (debugging()) {
$dump = '';
$callers = debug_backtrace();
foreach ($callers as $caller) {
if (!isset($caller['line'])) {
$caller['line'] = '?';
}
if (!isset($caller['file'])) {
$caller['file'] = '?';
}
$dump .= 'line ' . $caller['line'] . ' of ' . substr($caller['file'], strlen($CFG->dirroot) + 1);
if (isset($caller['function'])) {
$dump .= ': call to ';
if (isset($caller['class'])) {
$dump .= $caller['class'] . $caller['type'];
}
$dump .= $caller['function'] . '()';
}
$dump .= "\n";
}
$event->stackdump = $dump;
} else {
$event->stackdump = '';
}
$event->id = $DB->insert_record('events_queue', $event);
events_queue_handler($handler, $event, $errormessage);
}
} else {
// No handler found for this event name - this is ok!
}
return $failedcount;
}
/**
* checks if an event is registered for this component
*
* @access public Part of the public API
* @deprecated since Moodle 3.1
* @param string $eventname name of the event
* @param string $component component name, can be mod/data or moodle
* @return bool
*/
function events_is_registered($eventname, $component) {
global $DB;
debugging('events_is_registered() has been deprecated along with all Events 1 API in favour of Events 2 API,' .
' please use it instead.', DEBUG_DEVELOPER);
return $DB->record_exists('events_handlers', array('component'=>$component, 'eventname'=>$eventname));
}
/**
* checks if an event is queued for processing - either cron handlers attached or failed instant handlers
*
* @access public Part of the public API
* @deprecated since Moodle 3.1
* @param string $eventname name of the event
* @return int number of queued events
*/
function events_pending_count($eventname) {
global $DB;
debugging('events_pending_count() has been deprecated along with all Events 1 API in favour of Events 2 API,' .
' please use it instead.', DEBUG_DEVELOPER);
$sql = "SELECT COUNT('x')
FROM {events_queue_handlers} qh
JOIN {events_handlers} h ON h.id = qh.handlerid
WHERE h.eventname = ?";
return $DB->count_records_sql($sql, array($eventname));
}
/**
* @deprecated since Moodle 3.0 - this is a part of clamav plugin now.
*/
function clam_message_admins() {
throw new coding_exception('clam_message_admins() can not be used anymore. Please use ' .
'message_admins() method of \antivirus_clamav\scanner class.');
}
/**
* @deprecated since Moodle 3.0 - this is a part of clamav plugin now.
*/
function get_clam_error_code() {
throw new coding_exception('get_clam_error_code() can not be used anymore. Please use ' .
'get_clam_error_code() method of \antivirus_clamav\scanner class.');
}
/**
* @deprecated since 3.1
*/
function course_get_cm_rename_action() {
throw new coding_exception('course_get_cm_rename_action() can not be used anymore. Please use ' .
'inplace_editable https://docs.moodle.org/dev/Inplace_editable.');
}
/**
* @deprecated since Moodle 3.1
*/
function course_scale_used() {
throw new coding_exception('course_scale_used() can not be used anymore. Plugins can ' .
'implement <modname>_scale_used_anywhere, all implementations of <modname>_scale_used are now ignored');
}
/**
* @deprecated since Moodle 3.1
*/
function site_scale_used() {
throw new coding_exception('site_scale_used() can not be used anymore. Plugins can implement ' .
'<modname>_scale_used_anywhere, all implementations of <modname>_scale_used are now ignored');
}
/**
* @deprecated since Moodle 3.1. Use external_api::external_function_info().
*/
function external_function_info() {
throw new coding_exception('external_function_info() can not be used any'.
'more. Please use external_api::external_function_info() instead.');
}
/**
* Retrieves an array of records from a CSV file and places
* them into a given table structure
* This function is deprecated. Please use csv_import_reader() instead.
*
* @deprecated since Moodle 3.2 MDL-55126
* @todo MDL-55195 for final deprecation in Moodle 3.6
* @see csv_import_reader::load_csv_content()
* @global stdClass $CFG
* @global moodle_database $DB
* @param string $file The path to a CSV file
* @param string $table The table to retrieve columns from
* @return bool|array Returns an array of CSV records or false
*/
function get_records_csv($file, $table) {
global $CFG, $DB;
debugging('get_records_csv() is deprecated. Please use lib/csvlib.class.php csv_import_reader() instead.');
if (!$metacolumns = $DB->get_columns($table)) {
return false;
}
if(!($handle = @fopen($file, 'r'))) {
print_error('get_records_csv failed to open '.$file);
}
$fieldnames = fgetcsv($handle, 4096);
if(empty($fieldnames)) {
fclose($handle);
return false;
}
$columns = array();
foreach($metacolumns as $metacolumn) {
$ord = array_search($metacolumn->name, $fieldnames);
if(is_int($ord)) {
$columns[$metacolumn->name] = $ord;
}
}
$rows = array();
while (($data = fgetcsv($handle, 4096)) !== false) {
$item = new stdClass;
foreach($columns as $name => $ord) {
$item->$name = $data[$ord];
}
$rows[] = $item;
}
fclose($handle);
return $rows;
}
/**
* Create a file with CSV contents
* This function is deprecated. Please use download_as_dataformat() instead.
*
* @deprecated since Moodle 3.2 MDL-55126
* @todo MDL-55195 for final deprecation in Moodle 3.6
* @see download_as_dataformat (lib/dataformatlib.php)
* @global stdClass $CFG
* @global moodle_database $DB
* @param string $file The file to put the CSV content into
* @param array $records An array of records to write to a CSV file
* @param string $table The table to get columns from
* @return bool success
*/
function put_records_csv($file, $records, $table = NULL) {
global $CFG, $DB;
debugging('put_records_csv() is deprecated. Please use lib/dataformatlib.php download_as_dataformat()');
if (empty($records)) {
return true;
}
$metacolumns = NULL;
if ($table !== NULL && !$metacolumns = $DB->get_columns($table)) {
return false;
}
echo "x";
if(!($fp = @fopen($CFG->tempdir.'/'.$file, 'w'))) {
print_error('put_records_csv failed to open '.$file);
}
$proto = reset($records);
if(is_object($proto)) {
$fields_records = array_keys(get_object_vars($proto));
}
else if(is_array($proto)) {
$fields_records = array_keys($proto);
}
else {
return false;
}
echo "x";
if(!empty($metacolumns)) {
$fields_table = array_map(create_function('$a', 'return $a->name;'), $metacolumns);
$fields = array_intersect($fields_records, $fields_table);
}
else {
$fields = $fields_records;
}
fwrite($fp, implode(',', $fields));
fwrite($fp, "\r\n");
foreach($records as $record) {
$array = (array)$record;
$values = array();
foreach($fields as $field) {
if(strpos($array[$field], ',')) {
$values[] = '"'.str_replace('"', '\"', $array[$field]).'"';
}
else {
$values[] = $array[$field];
}
}
fwrite($fp, implode(',', $values)."\r\n");
}
fclose($fp);
@chmod($CFG->tempdir.'/'.$file, $CFG->filepermissions);
return true;
}
/**
* Determines if the given value is a valid CSS colour.
*
* A CSS colour can be one of the following:
* - Hex colour: #AA66BB
* - RGB colour: rgb(0-255, 0-255, 0-255)
* - RGBA colour: rgba(0-255, 0-255, 0-255, 0-1)
* - HSL colour: hsl(0-360, 0-100%, 0-100%)
* - HSLA colour: hsla(0-360, 0-100%, 0-100%, 0-1)
*
* Or a recognised browser colour mapping {@link css_optimiser::$htmlcolours}
*
* @deprecated since Moodle 3.2
* @todo MDL-56173 for final deprecation in Moodle 3.6
* @param string $value The colour value to check
* @return bool
*/
function css_is_colour($value) {
debugging('css_is_colour() is deprecated without a replacement. Please copy the implementation '.
'into your plugin if you need this functionality.', DEBUG_DEVELOPER);
$value = trim($value);
$hex = '/^#([a-fA-F0-9]{1,3}|[a-fA-F0-9]{6})$/';
$rgb = '#^rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$#i';
$rgba = '#^rgba\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1}(\.\d+)?)\s*\)$#i';
$hsl = '#^hsl\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\%\s*,\s*(\d{1,3})\%\s*\)$#i';
$hsla = '#^hsla\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\%\s*,\s*(\d{1,3})\%\s*,\s*(\d{1}(\.\d+)?)\s*\)$#i';
if (in_array(strtolower($value), array('inherit'))) {
return true;
} else if (preg_match($hex, $value)) {
return true;
} else if (in_array(strtolower($value), array_keys(css_optimiser::$htmlcolours))) {
return true;
} else if (preg_match($rgb, $value, $m) && $m[1] < 256 && $m[2] < 256 && $m[3] < 256) {
// It is an RGB colour.
return true;
} else if (preg_match($rgba, $value, $m) && $m[1] < 256 && $m[2] < 256 && $m[3] < 256) {
// It is an RGBA colour.
return true;
} else if (preg_match($hsl, $value, $m) && $m[1] <= 360 && $m[2] <= 100 && $m[3] <= 100) {
// It is an HSL colour.
return true;
} else if (preg_match($hsla, $value, $m) && $m[1] <= 360 && $m[2] <= 100 && $m[3] <= 100) {
// It is an HSLA colour.
return true;
}
// Doesn't look like a colour.
return false;
}
/**
* Returns true is the passed value looks like a CSS width.
* In order to pass this test the value must be purely numerical or end with a
* valid CSS unit term.
*
* @param string|int $value
* @return boolean
* @deprecated since Moodle 3.2
* @todo MDL-56173 for final deprecation in Moodle 3.6
*/
function css_is_width($value) {
debugging('css_is_width() is deprecated without a replacement. Please copy the implementation '.
'into your plugin if you need this functionality.', DEBUG_DEVELOPER);
$value = trim($value);
if (in_array(strtolower($value), array('auto', 'inherit'))) {
return true;
}
if ((string)$value === '0' || preg_match('#^(\-\s*)?(\d*\.)?(\d+)\s*(em|px|pt|\%|in|cm|mm|ex|pc)$#i', $value)) {
return true;
}
return false;
}
/**
* A simple sorting function to sort two array values on the number of items they contain
*
* @param array $a
* @param array $b
* @return int
* @deprecated since Moodle 3.2
* @todo MDL-56173 for final deprecation in Moodle 3.6
*/
function css_sort_by_count(array $a, array $b) {
debugging('css_sort_by_count() is deprecated without a replacement. Please copy the implementation '.
'into your plugin if you need this functionality.', DEBUG_DEVELOPER);
$a = count($a);
$b = count($b);
if ($a == $b) {
return 0;
}
return ($a > $b) ? -1 : 1;
}
/**
* A basic CSS optimiser that strips out unwanted things and then processes CSS organising and cleaning styles.
* @deprecated since Moodle 3.2
* @todo MDL-56173 for final deprecation in Moodle 3.6
*/
class css_optimiser {
/**
* An array of the common HTML colours that are supported by most browsers.
*
* This reference table is used to allow us to unify colours, and will aid
* us in identifying buggy CSS using unsupported colours.
*
* @var string[]
* @deprecated since Moodle 3.2
* @todo MDL-56173 for final deprecation in Moodle 3.6
*/
public static $htmlcolours = array(
'aliceblue' => '#F0F8FF',
'antiquewhite' => '#FAEBD7',
'aqua' => '#00FFFF',
'aquamarine' => '#7FFFD4',
'azure' => '#F0FFFF',
'beige' => '#F5F5DC',
'bisque' => '#FFE4C4',
'black' => '#000000',
'blanchedalmond' => '#FFEBCD',
'blue' => '#0000FF',
'blueviolet' => '#8A2BE2',
'brown' => '#A52A2A',
'burlywood' => '#DEB887',
'cadetblue' => '#5F9EA0',
'chartreuse' => '#7FFF00',
'chocolate' => '#D2691E',
'coral' => '#FF7F50',
'cornflowerblue' => '#6495ED',
'cornsilk' => '#FFF8DC',
'crimson' => '#DC143C',
'cyan' => '#00FFFF',
'darkblue' => '#00008B',
'darkcyan' => '#008B8B',
'darkgoldenrod' => '#B8860B',
'darkgray' => '#A9A9A9',
'darkgrey' => '#A9A9A9',
'darkgreen' => '#006400',
'darkKhaki' => '#BDB76B',
'darkmagenta' => '#8B008B',
'darkolivegreen' => '#556B2F',
'arkorange' => '#FF8C00',
'darkorchid' => '#9932CC',
'darkred' => '#8B0000',
'darksalmon' => '#E9967A',
'darkseagreen' => '#8FBC8F',
'darkslateblue' => '#483D8B',
'darkslategray' => '#2F4F4F',
'darkslategrey' => '#2F4F4F',
'darkturquoise' => '#00CED1',
'darkviolet' => '#9400D3',
'deeppink' => '#FF1493',
'deepskyblue' => '#00BFFF',
'dimgray' => '#696969',
'dimgrey' => '#696969',
'dodgerblue' => '#1E90FF',
'firebrick' => '#B22222',
'floralwhite' => '#FFFAF0',
'forestgreen' => '#228B22',
'fuchsia' => '#FF00FF',
'gainsboro' => '#DCDCDC',
'ghostwhite' => '#F8F8FF',
'gold' => '#FFD700',
'goldenrod' => '#DAA520',
'gray' => '#808080',
'grey' => '#808080',
'green' => '#008000',
'greenyellow' => '#ADFF2F',
'honeydew' => '#F0FFF0',
'hotpink' => '#FF69B4',
'indianred ' => '#CD5C5C',
'indigo ' => '#4B0082',
'ivory' => '#FFFFF0',
'khaki' => '#F0E68C',
'lavender' => '#E6E6FA',
'lavenderblush' => '#FFF0F5',
'lawngreen' => '#7CFC00',
'lemonchiffon' => '#FFFACD',
'lightblue' => '#ADD8E6',
'lightcoral' => '#F08080',
'lightcyan' => '#E0FFFF',
'lightgoldenrodyellow' => '#FAFAD2',
'lightgray' => '#D3D3D3',
'lightgrey' => '#D3D3D3',
'lightgreen' => '#90EE90',
'lightpink' => '#FFB6C1',
'lightsalmon' => '#FFA07A',
'lightseagreen' => '#20B2AA',
'lightskyblue' => '#87CEFA',
'lightslategray' => '#778899',
'lightslategrey' => '#778899',
'lightsteelblue' => '#B0C4DE',
'lightyellow' => '#FFFFE0',
'lime' => '#00FF00',
'limegreen' => '#32CD32',
'linen' => '#FAF0E6',
'magenta' => '#FF00FF',
'maroon' => '#800000',
'mediumaquamarine' => '#66CDAA',
'mediumblue' => '#0000CD',
'mediumorchid' => '#BA55D3',
'mediumpurple' => '#9370D8',
'mediumseagreen' => '#3CB371',
'mediumslateblue' => '#7B68EE',
'mediumspringgreen' => '#00FA9A',
'mediumturquoise' => '#48D1CC',
'mediumvioletred' => '#C71585',
'midnightblue' => '#191970',
'mintcream' => '#F5FFFA',
'mistyrose' => '#FFE4E1',
'moccasin' => '#FFE4B5',
'navajowhite' => '#FFDEAD',
'navy' => '#000080',
'oldlace' => '#FDF5E6',
'olive' => '#808000',
'olivedrab' => '#6B8E23',
'orange' => '#FFA500',
'orangered' => '#FF4500',
'orchid' => '#DA70D6',
'palegoldenrod' => '#EEE8AA',
'palegreen' => '#98FB98',
'paleturquoise' => '#AFEEEE',
'palevioletred' => '#D87093',
'papayawhip' => '#FFEFD5',
'peachpuff' => '#FFDAB9',
'peru' => '#CD853F',
'pink' => '#FFC0CB',
'plum' => '#DDA0DD',
'powderblue' => '#B0E0E6',
'purple' => '#800080',
'red' => '#FF0000',
'rosybrown' => '#BC8F8F',
'royalblue' => '#4169E1',
'saddlebrown' => '#8B4513',
'salmon' => '#FA8072',
'sandybrown' => '#F4A460',
'seagreen' => '#2E8B57',
'seashell' => '#FFF5EE',
'sienna' => '#A0522D',
'silver' => '#C0C0C0',
'skyblue' => '#87CEEB',
'slateblue' => '#6A5ACD',
'slategray' => '#708090',
'slategrey' => '#708090',
'snow' => '#FFFAFA',
'springgreen' => '#00FF7F',
'steelblue' => '#4682B4',
'tan' => '#D2B48C',
'teal' => '#008080',
'thistle' => '#D8BFD8',
'tomato' => '#FF6347',
'transparent' => 'transparent',
'turquoise' => '#40E0D0',
'violet' => '#EE82EE',
'wheat' => '#F5DEB3',
'white' => '#FFFFFF',
'whitesmoke' => '#F5F5F5',
'yellow' => '#FFFF00',
'yellowgreen' => '#9ACD32'
);
/**
* Used to orocesses incoming CSS optimising it and then returning it. Now just returns
* what is sent to it. Do not use.
*
* @param string $css The raw CSS to optimise
* @return string The optimised CSS
* @deprecated since Moodle 3.2
* @todo MDL-56173 for final deprecation in Moodle 3.6
*/
public function process($css) {
debugging('class css_optimiser is deprecated and no longer does anything, '.
'please consider using stylelint to optimise your css.', DEBUG_DEVELOPER);
return $css;
}
}
/**
* Load the course contexts for all of the users courses
*
* @deprecated since Moodle 3.2
* @param array $courses array of course objects. The courses the user is enrolled in.
* @return array of course contexts
*/
function message_get_course_contexts($courses) {
debugging('message_get_course_contexts() is deprecated and is no longer used.', DEBUG_DEVELOPER);
$coursecontexts = array();
foreach($courses as $course) {
$coursecontexts[$course->id] = context_course::instance($course->id);
}
return $coursecontexts;
}
/**
* strip off action parameters like 'removecontact'
*
* @deprecated since Moodle 3.2
* @param moodle_url/string $moodleurl a URL. Typically the current page URL.
* @return string the URL minus parameters that perform actions (like adding/removing/blocking a contact).
*/
function message_remove_url_params($moodleurl) {
debugging('message_remove_url_params() is deprecated and is no longer used.', DEBUG_DEVELOPER);
$newurl = new moodle_url($moodleurl);
$newurl->remove_params('addcontact','removecontact','blockcontact','unblockcontact');
return $newurl->out();
}
/**
* Count the number of messages with a field having a specified value.
* if $field is empty then return count of the whole array
* if $field is non-existent then return 0
*
* @deprecated since Moodle 3.2
* @param array $messagearray array of message objects
* @param string $field the field to inspect on the message objects
* @param string $value the value to test the field against
*/
function message_count_messages($messagearray, $field='', $value='') {
debugging('message_count_messages() is deprecated and is no longer used.', DEBUG_DEVELOPER);
if (!is_array($messagearray)) return 0;
if ($field == '' or empty($messagearray)) return count($messagearray);
$count = 0;
foreach ($messagearray as $message) {
$count += ($message->$field == $value) ? 1 : 0;
}
return $count;
}
/**
* Count the number of users blocked by $user1
*
* @deprecated since Moodle 3.2
* @param object $user1 user object
* @return int the number of blocked users
*/
function message_count_blocked_users($user1=null) {
debugging('message_count_blocked_users() is deprecated, please use \core_message\api::count_blocked_users() instead.',
DEBUG_DEVELOPER);
return \core_message\api::count_blocked_users($user1);
}
/**
* Print a message contact link
*
* @deprecated since Moodle 3.2
* @param int $userid the ID of the user to apply to action to
* @param string $linktype can be add, remove, block or unblock
* @param bool $return if true return the link as a string. If false echo the link.
* @param string $script the URL to send the user to when the link is clicked. If null, the current page.
* @param bool $text include text next to the icons?
* @param bool $icon include a graphical icon?
* @return string if $return is true otherwise bool
*/
function message_contact_link($userid, $linktype='add', $return=false, $script=null, $text=false, $icon=true) {
debugging('message_contact_link() is deprecated and is no longer used.', DEBUG_DEVELOPER);
global $OUTPUT, $PAGE;
//hold onto the strings as we're probably creating a bunch of links
static $str;
if (empty($script)) {
//strip off previous action params like 'removecontact'
$script = message_remove_url_params($PAGE->url);
}
if (empty($str->blockcontact)) {
$str = new stdClass();
$str->blockcontact = get_string('blockcontact', 'message');
$str->unblockcontact = get_string('unblockcontact', 'message');
$str->removecontact = get_string('removecontact', 'message');
$str->addcontact = get_string('addcontact', 'message');
}
$command = $linktype.'contact';
$string = $str->{$command};
$safealttext = s($string);
$safestring = '';
if (!empty($text)) {
$safestring = $safealttext;
}
$img = '';
if ($icon) {
$iconpath = null;
switch ($linktype) {
case 'block':
$iconpath = 't/block';
break;
case 'unblock':
$iconpath = 't/unblock';
break;
case 'remove':
$iconpath = 't/removecontact';
break;
case 'add':
default:
$iconpath = 't/addcontact';
}
$img = $OUTPUT->pix_icon($iconpath, $safealttext);
}
$output = '<span class="'.$linktype.'contact">'.
'<a href="'.$script.'&amp;'.$command.'='.$userid.
'&amp;sesskey='.sesskey().'" title="'.$safealttext.'">'.
$img.
$safestring.'</a></span>';
if ($return) {
return $output;
} else {
echo $output;
return true;
}
}
/**
* @deprecated since Moodle 3.2
*/
function message_get_recent_notifications($user, $limitfrom=0, $limitto=100) {
throw new coding_exception('message_get_recent_notifications() can not be used any more.', DEBUG_DEVELOPER);
}
/**
* echo or return a link to take the user to the full message history between themselves and another user
*
* @deprecated since Moodle 3.2
* @param int $userid1 the ID of the user displayed on the left (usually the current user)
* @param int $userid2 the ID of the other user
* @param bool $return true to return the link as a string. False to echo the link.
* @param string $keywords any keywords to highlight in the message history
* @param string $position anchor name to jump to within the message history
* @param string $linktext optionally specify the link text
* @return string|bool. Returns a string if $return is true. Otherwise returns a boolean.
*/
function message_history_link($userid1, $userid2, $return=false, $keywords='', $position='', $linktext='') {
debugging('message_history_link() is deprecated and is no longer used.', DEBUG_DEVELOPER);
global $OUTPUT, $PAGE;
static $strmessagehistory;
if (empty($strmessagehistory)) {
$strmessagehistory = get_string('messagehistory', 'message');
}
if ($position) {
$position = "#$position";
}
if ($keywords) {
$keywords = "&search=".urlencode($keywords);
}
if ($linktext == 'icon') { // Icon only
$fulllink = $OUTPUT->pix_icon('t/messages', $strmessagehistory);
} else if ($linktext == 'both') { // Icon and standard name
$fulllink = $OUTPUT->pix_icon('t/messages', '');
$fulllink .= '&nbsp;'.$strmessagehistory;
} else if ($linktext) { // Custom name
$fulllink = $linktext;
} else { // Standard name only
$fulllink = $strmessagehistory;
}
$popupoptions = array(
'height' => 500,
'width' => 500,
'menubar' => false,
'location' => false,
'status' => true,
'scrollbars' => true,
'resizable' => true);
$link = new moodle_url('/message/index.php?history='.MESSAGE_HISTORY_ALL."&user1=$userid1&user2=$userid2$keywords$position");
if ($PAGE->url && $PAGE->url->get_param('viewing')) {
$link->param('viewing', $PAGE->url->get_param('viewing'));
}
$action = null;
$str = $OUTPUT->action_link($link, $fulllink, $action, array('title' => $strmessagehistory));
$str = '<span class="history">'.$str.'</span>';
if ($return) {
return $str;
} else {
echo $str;
return true;
}
}
/**
* @deprecated since Moodle 3.2
*/
function message_search($searchterms, $fromme=true, $tome=true, $courseid='none', $userid=0) {
throw new coding_exception('message_search() can not be used any more.', DEBUG_DEVELOPER);
}
/**
* Given a message object that we already know has a long message
* this function truncates the message nicely to the first
* sane place between $CFG->forum_longpost and $CFG->forum_shortpost
*
* @deprecated since Moodle 3.2
* @param string $message the message
* @param int $minlength the minimum length to trim the message to
* @return string the shortened message
*/
function message_shorten_message($message, $minlength = 0) {
debugging('message_shorten_message() is deprecated and is no longer used.', DEBUG_DEVELOPER);
$i = 0;
$tag = false;
$length = strlen($message);
$count = 0;
$stopzone = false;
$truncate = 0;
if ($minlength == 0) $minlength = MESSAGE_SHORTLENGTH;
for ($i=0; $i<$length; $i++) {
$char = $message[$i];
switch ($char) {
case "<":
$tag = true;
break;
case ">":
$tag = false;
break;
default:
if (!$tag) {
if ($stopzone) {
if ($char == '.' or $char == ' ') {
$truncate = $i+1;
break 2;
}
}
$count++;
}
break;
}
if (!$stopzone) {
if ($count > $minlength) {
$stopzone = true;
}
}
}
if (!$truncate) {
$truncate = $i;
}
return substr($message, 0, $truncate);
}
/**
* Given a string and an array of keywords, this function looks
* for the first keyword in the string, and then chops out a
* small section from the text that shows that word in context.
*
* @deprecated since Moodle 3.2
* @param string $message the text to search
* @param array $keywords array of keywords to find
*/
function message_get_fragment($message, $keywords) {
debugging('message_get_fragment() is deprecated and is no longer used.', DEBUG_DEVELOPER);
$fullsize = 160;
$halfsize = (int)($fullsize/2);
$message = strip_tags($message);
foreach ($keywords as $keyword) { // Just get the first one
if ($keyword !== '') {
break;
}
}
if (empty($keyword)) { // None found, so just return start of message
return message_shorten_message($message, 30);
}
$leadin = $leadout = '';
/// Find the start of the fragment
$start = 0;
$length = strlen($message);
$pos = strpos($message, $keyword);
if ($pos > $halfsize) {
$start = $pos - $halfsize;
$leadin = '...';
}
/// Find the end of the fragment
$end = $start + $fullsize;
if ($end > $length) {
$end = $length;
} else {
$leadout = '...';
}
/// Pull out the fragment and format it
$fragment = substr($message, $start, $end - $start);
$fragment = $leadin.highlight(implode(' ',$keywords), $fragment).$leadout;
return $fragment;
}
/**
* @deprecated since Moodle 3.2
*/
function message_get_history($user1, $user2, $limitnum=0, $viewingnewmessages=false) {
throw new coding_exception('message_get_history() can not be used any more.', DEBUG_DEVELOPER);
}
/**
* Constructs the add/remove contact link to display next to other users
*
* @deprecated since Moodle 3.2
* @param bool $incontactlist is the user a contact
* @param bool $isblocked is the user blocked
* @param stdClass $contact contact object
* @param string $script the URL to send the user to when the link is clicked. If null, the current page.
* @param bool $text include text next to the icons?
* @param bool $icon include a graphical icon?
* @return string
*/
function message_get_contact_add_remove_link($incontactlist, $isblocked, $contact, $script=null, $text=false, $icon=true) {
debugging('message_get_contact_add_remove_link() is deprecated and is no longer used.', DEBUG_DEVELOPER);
$strcontact = '';
if($incontactlist){
$strcontact = message_contact_link($contact->id, 'remove', true, $script, $text, $icon);
} else if ($isblocked) {
$strcontact = message_contact_link($contact->id, 'add', true, $script, $text, $icon);
} else{
$strcontact = message_contact_link($contact->id, 'add', true, $script, $text, $icon);
}
return $strcontact;
}
/**
* Constructs the block contact link to display next to other users
*
* @deprecated since Moodle 3.2
* @param bool $incontactlist is the user a contact?
* @param bool $isblocked is the user blocked?
* @param stdClass $contact contact object
* @param string $script the URL to send the user to when the link is clicked. If null, the current page.
* @param bool $text include text next to the icons?
* @param bool $icon include a graphical icon?
* @return string
*/
function message_get_contact_block_link($incontactlist, $isblocked, $contact, $script=null, $text=false, $icon=true) {
debugging('message_get_contact_block_link() is deprecated and is no longer used.', DEBUG_DEVELOPER);
$strblock = '';
//commented out to allow the user to block a contact without having to remove them first
/*if ($incontactlist) {
//$strblock = '';
} else*/
if ($isblocked) {
$strblock = message_contact_link($contact->id, 'unblock', true, $script, $text, $icon);
} else{
$strblock = message_contact_link($contact->id, 'block', true, $script, $text, $icon);
}
return $strblock;
}
/**
* marks ALL messages being sent from $fromuserid to $touserid as read
*
* @deprecated since Moodle 3.2
* @param int $touserid the id of the message recipient
* @param int $fromuserid the id of the message sender
* @return void
*/
function message_mark_messages_read($touserid, $fromuserid) {
debugging('message_mark_messages_read() is deprecated and is no longer used, please use
\core_message\api::mark_all_messages_as_read() instead.', DEBUG_DEVELOPER);
\core_message\api::mark_all_messages_as_read($touserid, $fromuserid);
}
/**
* Return a list of page types
*
* @deprecated since Moodle 3.2
* @param string $pagetype current page type
* @param stdClass $parentcontext Block's parent context
* @param stdClass $currentcontext Current context of block
*/
function message_page_type_list($pagetype, $parentcontext, $currentcontext) {
debugging('message_page_type_list() is deprecated and is no longer used.', DEBUG_DEVELOPER);
return array('messages-*'=>get_string('page-message-x', 'message'));
}
/**
* Determines if a user is permitted to send another user a private message.
* If no sender is provided then it defaults to the logged in user.
*
* @deprecated since Moodle 3.2
* @param object $recipient User object.
* @param object $sender User object.
* @return bool true if user is permitted, false otherwise.
*/
function message_can_post_message($recipient, $sender = null) {
debugging('message_can_post_message() is deprecated and is no longer used, please use
\core_message\api::can_post_message() instead.', DEBUG_DEVELOPER);
return \core_message\api::can_post_message($recipient, $sender);
}
/**
* Checks if the recipient is allowing messages from users that aren't a
* contact. If not then it checks to make sure the sender is in the
* recipient's contacts.
*
* @deprecated since Moodle 3.2
* @param object $recipient User object.
* @param object $sender User object.
* @return bool true if $sender is blocked, false otherwise.
*/
function message_is_user_non_contact_blocked($recipient, $sender = null) {
debugging('message_is_user_non_contact_blocked() is deprecated and is no longer used, please use
\core_message\api::is_user_non_contact_blocked() instead.', DEBUG_DEVELOPER);
return \core_message\api::is_user_non_contact_blocked($recipient, $sender);
}
/**
* Checks if the recipient has specifically blocked the sending user.
*
* Note: This function will always return false if the sender has the
* readallmessages capability at the system context level.
*
* @deprecated since Moodle 3.2
* @param object $recipient User object.
* @param object $sender User object.
* @return bool true if $sender is blocked, false otherwise.
*/
function message_is_user_blocked($recipient, $sender = null) {
debugging('message_is_user_blocked() is deprecated and is no longer used, please use
\core_message\api::is_user_blocked() instead.', DEBUG_DEVELOPER);
$senderid = null;
if ($sender !== null && isset($sender->id)) {
$senderid = $sender->id;
}
return \core_message\api::is_user_blocked($recipient->id, $senderid);
}
/**
* Display logs.
*
* @deprecated since 3.2
*/
function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100,
$url="", $modname="", $modid=0, $modaction="", $groupid=0) {
debugging(__FUNCTION__ . '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER);
global $CFG, $DB, $OUTPUT;
if (!$logs = build_logs_array($course, $user, $date, $order, $page*$perpage, $perpage,
$modname, $modid, $modaction, $groupid)) {
echo $OUTPUT->notification("No logs found!");
echo $OUTPUT->footer();
exit;
}
$courses = array();
if ($course->id == SITEID) {
$courses[0] = '';
if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
foreach ($ccc as $cc) {
$courses[$cc->id] = $cc->shortname;
}
}
} else {
$courses[$course->id] = $course->shortname;
}
$totalcount = $logs['totalcount'];
$ldcache = array();
$strftimedatetime = get_string("strftimedatetime");
echo "<div class=\"info\">\n";
print_string("displayingrecords", "", $totalcount);
echo "</div>\n";
echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage");
$table = new html_table();
$table->classes = array('logtable','generaltable');
$table->align = array('right', 'left', 'left');
$table->head = array(
get_string('time'),
get_string('ip_address'),
get_string('fullnameuser'),
get_string('action'),
get_string('info')
);
$table->data = array();
if ($course->id == SITEID) {
array_unshift($table->align, 'left');
array_unshift($table->head, get_string('course'));
}
// Make sure that the logs array is an array, even it is empty, to avoid warnings from the foreach.
if (empty($logs['logs'])) {
$logs['logs'] = array();
}
foreach ($logs['logs'] as $log) {
if (isset($ldcache[$log->module][$log->action])) {
$ld = $ldcache[$log->module][$log->action];
} else {
$ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
$ldcache[$log->module][$log->action] = $ld;
}
if ($ld && is_numeric($log->info)) {
// ugly hack to make sure fullname is shown correctly
if ($ld->mtable == 'user' && $ld->field == $DB->sql_concat('firstname', "' '" , 'lastname')) {
$log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
} else {
$log->info = $DB->get_field($ld->mtable, $ld->field, array('id'=>$log->info));
}
}
//Filter log->info
$log->info = format_string($log->info);
// If $log->url has been trimmed short by the db size restriction
// code in add_to_log, keep a note so we don't add a link to a broken url
$brokenurl=(core_text::strlen($log->url)==100 && core_text::substr($log->url,97)=='...');
$row = array();
if ($course->id == SITEID) {
if (empty($log->course)) {
$row[] = get_string('site');
} else {
$row[] = "<a href=\"{$CFG->wwwroot}/course/view.php?id={$log->course}\">". format_string($courses[$log->course])."</a>";
}
}
$row[] = userdate($log->time, '%a').' '.userdate($log->time, $strftimedatetime);
$link = new moodle_url("/iplookup/index.php?ip=$log->ip&user=$log->userid");
$row[] = $OUTPUT->action_link($link, $log->ip, new popup_action('click', $link, 'iplookup', array('height' => 440, 'width' => 700)));
$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))));
$displayaction="$log->module $log->action";
if ($brokenurl) {
$row[] = $displayaction;
} else {
$link = make_log_url($log->module,$log->url);
$row[] = $OUTPUT->action_link($link, $displayaction, new popup_action('click', $link, 'fromloglive'), array('height' => 440, 'width' => 700));
}
$row[] = $log->info;
$table->data[] = $row;
}
echo html_writer::table($table);
echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage");
}
/**
* Display MNET logs.
*
* @deprecated since 3.2
*/
function print_mnet_log($hostid, $course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100,
$url="", $modname="", $modid=0, $modaction="", $groupid=0) {
debugging(__FUNCTION__ . '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER);
global $CFG, $DB, $OUTPUT;
if (!$logs = build_mnet_logs_array($hostid, $course, $user, $date, $order, $page*$perpage, $perpage,
$modname, $modid, $modaction, $groupid)) {
echo $OUTPUT->notification("No logs found!");
echo $OUTPUT->footer();
exit;
}
if ($course->id == SITEID) {
$courses[0] = '';
if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname,c.visible')) {
foreach ($ccc as $cc) {
$courses[$cc->id] = $cc->shortname;
}
}
}
$totalcount = $logs['totalcount'];
$ldcache = array();
$strftimedatetime = get_string("strftimedatetime");
echo "<div class=\"info\">\n";
print_string("displayingrecords", "", $totalcount);
echo "</div>\n";
echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage");
echo "<table class=\"logtable\" cellpadding=\"3\" cellspacing=\"0\">\n";
echo "<tr>";
if ($course->id == SITEID) {
echo "<th class=\"c0 header\">".get_string('course')."</th>\n";
}
echo "<th class=\"c1 header\">".get_string('time')."</th>\n";
echo "<th class=\"c2 header\">".get_string('ip_address')."</th>\n";
echo "<th class=\"c3 header\">".get_string('fullnameuser')."</th>\n";
echo "<th class=\"c4 header\">".get_string('action')."</th>\n";
echo "<th class=\"c5 header\">".get_string('info')."</th>\n";
echo "</tr>\n";
if (empty($logs['logs'])) {
echo "</table>\n";
return;
}
$row = 1;
foreach ($logs['logs'] as $log) {
$log->info = $log->coursename;
$row = ($row + 1) % 2;
if (isset($ldcache[$log->module][$log->action])) {
$ld = $ldcache[$log->module][$log->action];
} else {
$ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
$ldcache[$log->module][$log->action] = $ld;
}
if (0 && $ld && !empty($log->info)) {
// ugly hack to make sure fullname is shown correctly
if (($ld->mtable == 'user') and ($ld->field == $DB->sql_concat('firstname', "' '" , 'lastname'))) {
$log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
} else {
$log->info = $DB->get_field($ld->mtable, $ld->field, array('id'=>$log->info));
}
}
//Filter log->info
$log->info = format_string($log->info);
echo '<tr class="r'.$row.'">';
if ($course->id == SITEID) {
$courseshortname = format_string($courses[$log->course], true, array('context' => context_course::instance(SITEID)));
echo "<td class=\"r$row c0\" >\n";
echo " <a href=\"{$CFG->wwwroot}/course/view.php?id={$log->course}\">".$courseshortname."</a>\n";
echo "</td>\n";
}
echo "<td class=\"r$row c1\" align=\"right\">".userdate($log->time, '%a').
' '.userdate($log->time, $strftimedatetime)."</td>\n";
echo "<td class=\"r$row c2\" >\n";
$link = new moodle_url("/iplookup/index.php?ip=$log->ip&user=$log->userid");
echo $OUTPUT->action_link($link, $log->ip, new popup_action('click', $link, 'iplookup', array('height' => 400, 'width' => 700)));
echo "</td>\n";
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', context_course::instance($course->id)));
echo "<td class=\"r$row c3\" >\n";
echo " <a href=\"$CFG->wwwroot/user/view.php?id={$log->userid}\">$fullname</a>\n";
echo "</td>\n";
echo "<td class=\"r$row c4\">\n";
echo $log->action .': '.$log->module;
echo "</td>\n";
echo "<td class=\"r$row c5\">{$log->info}</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage");
}
/**
* Display logs in CSV format.
*
* @deprecated since 3.2
*/
function print_log_csv($course, $user, $date, $order='l.time DESC', $modname,
$modid, $modaction, $groupid) {
debugging(__FUNCTION__ . '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER);
global $DB, $CFG;
require_once($CFG->libdir . '/csvlib.class.php');
$csvexporter = new csv_export_writer('tab');
$header = array();
$header[] = get_string('course');
$header[] = get_string('time');
$header[] = get_string('ip_address');
$header[] = get_string('fullnameuser');
$header[] = get_string('action');
$header[] = get_string('info');
if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
$modname, $modid, $modaction, $groupid)) {
return false;
}
$courses = array();
if ($course->id == SITEID) {
$courses[0] = '';
if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
foreach ($ccc as $cc) {
$courses[$cc->id] = $cc->shortname;
}
}
} else {
$courses[$course->id] = $course->shortname;
}
$count=0;
$ldcache = array();
$tt = getdate(time());
$today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
$strftimedatetime = get_string("strftimedatetime");
$csvexporter->set_filename('logs', '.txt');
$title = array(get_string('savedat').userdate(time(), $strftimedatetime));
$csvexporter->add_data($title);
$csvexporter->add_data($header);
if (empty($logs['logs'])) {
return true;
}
foreach ($logs['logs'] as $log) {
if (isset($ldcache[$log->module][$log->action])) {
$ld = $ldcache[$log->module][$log->action];
} else {
$ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
$ldcache[$log->module][$log->action] = $ld;
}
if ($ld && is_numeric($log->info)) {
// ugly hack to make sure fullname is shown correctly
if (($ld->mtable == 'user') and ($ld->field == $DB->sql_concat('firstname', "' '" , 'lastname'))) {
$log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
} else {
$log->info = $DB->get_field($ld->mtable, $ld->field, array('id'=>$log->info));
}
}
//Filter log->info
$log->info = format_string($log->info);
$log->info = strip_tags(urldecode($log->info)); // Some XSS protection
$coursecontext = context_course::instance($course->id);
$firstField = format_string($courses[$log->course], true, array('context' => $coursecontext));
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
$actionurl = $CFG->wwwroot. make_log_url($log->module,$log->url);
$row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module.' '.$log->action.' ('.$actionurl.')', $log->info);
$csvexporter->add_data($row);
}
$csvexporter->download_file();
return true;
}
/**
* Display logs in XLS format.
*
* @deprecated since 3.2
*/
function print_log_xls($course, $user, $date, $order='l.time DESC', $modname,
$modid, $modaction, $groupid) {
debugging(__FUNCTION__ . '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER);
global $CFG, $DB;
require_once("$CFG->libdir/excellib.class.php");
if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
$modname, $modid, $modaction, $groupid)) {
return false;
}
$courses = array();
if ($course->id == SITEID) {
$courses[0] = '';
if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
foreach ($ccc as $cc) {
$courses[$cc->id] = $cc->shortname;
}
}
} else {
$courses[$course->id] = $course->shortname;
}
$count=0;
$ldcache = array();
$tt = getdate(time());
$today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
$strftimedatetime = get_string("strftimedatetime");
$nroPages = ceil(count($logs)/(EXCELROWS-FIRSTUSEDEXCELROW+1));
$filename = 'logs_'.userdate(time(),get_string('backupnameformat', 'langconfig'),99,false);
$filename .= '.xls';
$workbook = new MoodleExcelWorkbook('-');
$workbook->send($filename);
$worksheet = array();
$headers = array(get_string('course'), get_string('time'), get_string('ip_address'),
get_string('fullnameuser'), get_string('action'), get_string('info'));
// Creating worksheets
for ($wsnumber = 1; $wsnumber <= $nroPages; $wsnumber++) {
$sheettitle = get_string('logs').' '.$wsnumber.'-'.$nroPages;
$worksheet[$wsnumber] = $workbook->add_worksheet($sheettitle);
$worksheet[$wsnumber]->set_column(1, 1, 30);
$worksheet[$wsnumber]->write_string(0, 0, get_string('savedat').
userdate(time(), $strftimedatetime));
$col = 0;
foreach ($headers as $item) {
$worksheet[$wsnumber]->write(FIRSTUSEDEXCELROW-1,$col,$item,'');
$col++;
}
}
if (empty($logs['logs'])) {
$workbook->close();
return true;
}
$formatDate =& $workbook->add_format();
$formatDate->set_num_format(get_string('log_excel_date_format'));
$row = FIRSTUSEDEXCELROW;
$wsnumber = 1;
$myxls =& $worksheet[$wsnumber];
foreach ($logs['logs'] as $log) {
if (isset($ldcache[$log->module][$log->action])) {
$ld = $ldcache[$log->module][$log->action];
} else {
$ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
$ldcache[$log->module][$log->action] = $ld;
}
if ($ld && is_numeric($log->info)) {
// ugly hack to make sure fullname is shown correctly
if (($ld->mtable == 'user') and ($ld->field == $DB->sql_concat('firstname', "' '" , 'lastname'))) {
$log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
} else {
$log->info = $DB->get_field($ld->mtable, $ld->field, array('id'=>$log->info));
}
}
// Filter log->info
$log->info = format_string($log->info);
$log->info = strip_tags(urldecode($log->info)); // Some XSS protection
if ($nroPages>1) {
if ($row > EXCELROWS) {
$wsnumber++;
$myxls =& $worksheet[$wsnumber];
$row = FIRSTUSEDEXCELROW;
}
}
$coursecontext = context_course::instance($course->id);
$myxls->write($row, 0, format_string($courses[$log->course], true, array('context' => $coursecontext)), '');
$myxls->write_date($row, 1, $log->time, $formatDate); // write_date() does conversion/timezone support. MDL-14934
$myxls->write($row, 2, $log->ip, '');
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
$myxls->write($row, 3, $fullname, '');
$actionurl = $CFG->wwwroot. make_log_url($log->module,$log->url);
$myxls->write($row, 4, $log->module.' '.$log->action.' ('.$actionurl.')', '');
$myxls->write($row, 5, $log->info, '');
$row++;
}
$workbook->close();
return true;
}
/**
* Display logs in ODS format.
*
* @deprecated since 3.2
*/
function print_log_ods($course, $user, $date, $order='l.time DESC', $modname,
$modid, $modaction, $groupid) {
debugging(__FUNCTION__ . '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER);
global $CFG, $DB;
require_once("$CFG->libdir/odslib.class.php");
if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
$modname, $modid, $modaction, $groupid)) {
return false;
}
$courses = array();
if ($course->id == SITEID) {
$courses[0] = '';
if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
foreach ($ccc as $cc) {
$courses[$cc->id] = $cc->shortname;
}
}
} else {
$courses[$course->id] = $course->shortname;
}
$ldcache = array();
$strftimedatetime = get_string("strftimedatetime");
$nroPages = ceil(count($logs)/(EXCELROWS-FIRSTUSEDEXCELROW+1));
$filename = 'logs_'.userdate(time(),get_string('backupnameformat', 'langconfig'),99,false);
$filename .= '.ods';
$workbook = new MoodleODSWorkbook('-');
$workbook->send($filename);
$worksheet = array();
$headers = array(get_string('course'), get_string('time'), get_string('ip_address'),
get_string('fullnameuser'), get_string('action'), get_string('info'));
// Creating worksheets
for ($wsnumber = 1; $wsnumber <= $nroPages; $wsnumber++) {
$sheettitle = get_string('logs').' '.$wsnumber.'-'.$nroPages;
$worksheet[$wsnumber] = $workbook->add_worksheet($sheettitle);
$worksheet[$wsnumber]->set_column(1, 1, 30);
$worksheet[$wsnumber]->write_string(0, 0, get_string('savedat').
userdate(time(), $strftimedatetime));
$col = 0;
foreach ($headers as $item) {
$worksheet[$wsnumber]->write(FIRSTUSEDEXCELROW-1,$col,$item,'');
$col++;
}
}
if (empty($logs['logs'])) {
$workbook->close();
return true;
}
$formatDate =& $workbook->add_format();
$formatDate->set_num_format(get_string('log_excel_date_format'));
$row = FIRSTUSEDEXCELROW;
$wsnumber = 1;
$myxls =& $worksheet[$wsnumber];
foreach ($logs['logs'] as $log) {
if (isset($ldcache[$log->module][$log->action])) {
$ld = $ldcache[$log->module][$log->action];
} else {
$ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
$ldcache[$log->module][$log->action] = $ld;
}
if ($ld && is_numeric($log->info)) {
// ugly hack to make sure fullname is shown correctly
if (($ld->mtable == 'user') and ($ld->field == $DB->sql_concat('firstname', "' '" , 'lastname'))) {
$log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
} else {
$log->info = $DB->get_field($ld->mtable, $ld->field, array('id'=>$log->info));
}
}
// Filter log->info
$log->info = format_string($log->info);
$log->info = strip_tags(urldecode($log->info)); // Some XSS protection
if ($nroPages>1) {
if ($row > EXCELROWS) {
$wsnumber++;
$myxls =& $worksheet[$wsnumber];
$row = FIRSTUSEDEXCELROW;
}
}
$coursecontext = context_course::instance($course->id);
$myxls->write_string($row, 0, format_string($courses[$log->course], true, array('context' => $coursecontext)));
$myxls->write_date($row, 1, $log->time);
$myxls->write_string($row, 2, $log->ip);
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
$myxls->write_string($row, 3, $fullname);
$actionurl = $CFG->wwwroot. make_log_url($log->module,$log->url);
$myxls->write_string($row, 4, $log->module.' '.$log->action.' ('.$actionurl.')');
$myxls->write_string($row, 5, $log->info);
$row++;
}
$workbook->close();
return true;
}
/**
* Build an array of logs.
*
* @deprecated since 3.2
*/
function build_logs_array($course, $user=0, $date=0, $order="l.time ASC", $limitfrom='', $limitnum='',
$modname="", $modid=0, $modaction="", $groupid=0) {
global $DB, $SESSION, $USER;
debugging(__FUNCTION__ . '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER);
// It is assumed that $date is the GMT time of midnight for that day,
// and so the next 86400 seconds worth of logs are printed.
// Setup for group handling.
// If the group mode is separate, and this user does not have editing privileges,
// then only the user's group can be viewed.
if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', context_course::instance($course->id))) {
if (isset($SESSION->currentgroup[$course->id])) {
$groupid = $SESSION->currentgroup[$course->id];
} else {
$groupid = groups_get_all_groups($course->id, $USER->id);
if (is_array($groupid)) {
$groupid = array_shift(array_keys($groupid));
$SESSION->currentgroup[$course->id] = $groupid;
} else {
$groupid = 0;
}
}
}
// If this course doesn't have groups, no groupid can be specified.
else if (!$course->groupmode) {
$groupid = 0;
}
$joins = array();
$params = array();
if ($course->id != SITEID || $modid != 0) {
$joins[] = "l.course = :courseid";
$params['courseid'] = $course->id;
}
if ($modname) {
$joins[] = "l.module = :modname";
$params['modname'] = $modname;
}
if ('site_errors' === $modid) {
$joins[] = "( l.action='error' OR l.action='infected' )";
} else if ($modid) {
$joins[] = "l.cmid = :modid";
$params['modid'] = $modid;
}
if ($modaction) {
$firstletter = substr($modaction, 0, 1);
if ($firstletter == '-') {
$joins[] = $DB->sql_like('l.action', ':modaction', false, true, true);
$params['modaction'] = '%'.substr($modaction, 1).'%';
} else {
$joins[] = $DB->sql_like('l.action', ':modaction', false);
$params['modaction'] = '%'.$modaction.'%';
}
}
/// Getting all members of a group.
if ($groupid and !$user) {
if ($gusers = groups_get_members($groupid)) {
$gusers = array_keys($gusers);
$joins[] = 'l.userid IN (' . implode(',', $gusers) . ')';
} else {
$joins[] = 'l.userid = 0'; // No users in groups, so we want something that will always be false.
}
}
else if ($user) {
$joins[] = "l.userid = :userid";
$params['userid'] = $user;
}
if ($date) {
$enddate = $date + 86400;
$joins[] = "l.time > :date AND l.time < :enddate";
$params['date'] = $date;
$params['enddate'] = $enddate;
}
$selector = implode(' AND ', $joins);
$totalcount = 0; // Initialise
$result = array();
$result['logs'] = get_logs($selector, $params, $order, $limitfrom, $limitnum, $totalcount);
$result['totalcount'] = $totalcount;
return $result;
}
/**
* Select all log records for a given course and user.
*
* @deprecated since 3.2
* @param int $userid The id of the user as found in the 'user' table.
* @param int $courseid The id of the course as found in the 'course' table.
* @param string $coursestart unix timestamp representing course start date and time.
* @return array
*/
function get_logs_usercourse($userid, $courseid, $coursestart) {
global $DB;
debugging(__FUNCTION__ . '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER);
$params = array();
$courseselect = '';
if ($courseid) {
$courseselect = "AND course = :courseid";
$params['courseid'] = $courseid;
}
$params['userid'] = $userid;
// We have to sanitize this param ourselves here instead of relying on DB.
// Postgres complains if you use name parameter or column alias in GROUP BY.
// See MDL-27696 and 51c3e85 for details.
$coursestart = (int)$coursestart;
return $DB->get_records_sql("SELECT FLOOR((time - $coursestart)/". DAYSECS .") AS day, COUNT(*) AS num
FROM {log}
WHERE userid = :userid
AND time > $coursestart $courseselect
GROUP BY FLOOR((time - $coursestart)/". DAYSECS .")", $params);
}
/**
* Select all log records for a given course, user, and day.
*
* @deprecated since 3.2
* @param int $userid The id of the user as found in the 'user' table.
* @param int $courseid The id of the course as found in the 'course' table.
* @param string $daystart unix timestamp of the start of the day for which the logs needs to be retrived
* @return array
*/
function get_logs_userday($userid, $courseid, $daystart) {
global $DB;
debugging(__FUNCTION__ . '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER);
$params = array('userid'=>$userid);
$courseselect = '';
if ($courseid) {
$courseselect = "AND course = :courseid";
$params['courseid'] = $courseid;
}
// Note: unfortunately pg complains if you use name parameter or column alias in GROUP BY.
$daystart = (int) $daystart;
return $DB->get_records_sql("SELECT FLOOR((time - $daystart)/". HOURSECS .") AS hour, COUNT(*) AS num
FROM {log}
WHERE userid = :userid
AND time > $daystart $courseselect
GROUP BY FLOOR((time - $daystart)/". HOURSECS .") ", $params);
}
/**
* Select all log records based on SQL criteria.
*
* @deprecated since 3.2
* @param string $select SQL select criteria
* @param array $params named sql type params
* @param string $order SQL order by clause to sort the records returned
* @param string $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set)
* @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set)
* @param int $totalcount Passed in by reference.
* @return array
*/
function get_logs($select, array $params=null, $order='l.time DESC', $limitfrom='', $limitnum='', &$totalcount) {
global $DB;
debugging(__FUNCTION__ . '() is deprecated. Please use the report_log framework instead.', DEBUG_DEVELOPER);
if ($order) {
$order = "ORDER BY $order";
}
if ($select) {
$select = "WHERE $select";
}
$sql = "SELECT COUNT(*)
FROM {log} l
$select";
$totalcount = $DB->count_records_sql($sql, $params);
$allnames = get_all_user_name_fields(true, 'u');
$sql = "SELECT l.*, $allnames, u.picture
FROM {log} l
LEFT JOIN {user} u ON l.userid = u.id
$select
$order";
return $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
}
/**
* Renders a hidden password field so that browsers won't incorrectly autofill password fields with the user's password.
*
* @deprecated since Moodle 3.2 MDL-53048
*/
function prevent_form_autofill_password() {
debugging('prevent_form_autofill_password has been deprecated and is no longer in use.', DEBUG_DEVELOPER);
return '';
}
/**
* @deprecated since Moodle 3.3 MDL-57370
*/
function message_get_recent_conversations($userorid, $limitfrom = 0, $limitto = 100) {
throw new coding_exception('message_get_recent_conversations() can not be used any more. ' .
'Please use \core_message\api::get_conversations() instead.', DEBUG_DEVELOPER);
}
/**
* Display calendar preference button.
*
* @param stdClass $course course object
* @deprecated since Moodle 3.2
* @return string return preference button in html
*/
function calendar_preferences_button(stdClass $course) {
debugging('This should no longer be used, the calendar preferences are now linked to the user preferences page.');
global $OUTPUT;
// Guests have no preferences.
if (!isloggedin() || isguestuser()) {
return '';
}
return $OUTPUT->single_button(new moodle_url('/user/calendar.php'), get_string("preferences", "calendar"));
}
/**
* Return the name of the weekday
*
* @deprecated since 3.3
* @todo The final deprecation of this function will take place in Moodle 3.7 - see MDL-57617.
* @param string $englishname
* @return string of the weekeday
*/
function calendar_wday_name($englishname) {
debugging(__FUNCTION__ . '() is deprecated and no longer used in core.', DEBUG_DEVELOPER);
return get_string(strtolower($englishname), 'calendar');
}
/**
* Get the upcoming event block.
*
* @deprecated since 3.3
* @todo The final deprecation of this function will take place in Moodle 3.7 - see MDL-57617.
* @param array $events list of events
* @param moodle_url|string $linkhref link to event referer
* @param boolean $showcourselink whether links to courses should be shown
* @return string|null $content html block content
*/
function calendar_get_block_upcoming($events, $linkhref = null, $showcourselink = false) {
global $CFG;
debugging(
__FUNCTION__ . '() has been deprecated. ' .
'Please see block_calendar_upcoming::get_content() for the correct API usage.',
DEBUG_DEVELOPER
);
require_once($CFG->dirroot . '/blocks/moodleblock.class.php');
require_once($CFG->dirroot . '/blocks/calendar_upcoming/block_calendar_upcoming.php');
return block_calendar_upcoming::get_upcoming_content($events, $linkhref, $showcourselink);
}
/**
* Display month selector options.
*
* @deprecated since 3.3
* @todo The final deprecation of this function will take place in Moodle 3.7 - see MDL-57617.
* @param string $name for the select element
* @param string|array $selected options for select elements
*/
function calendar_print_month_selector($name, $selected) {
debugging(__FUNCTION__ . '() is deprecated and no longer used in core.', DEBUG_DEVELOPER);
$months = array();
for ($i = 1; $i <= 12; $i++) {
$months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), '%B');
}
echo html_writer::label(get_string('months'), 'menu'. $name, false, array('class' => 'accesshide'));
echo html_writer::select($months, $name, $selected, false);
}
/**
* Update calendar subscriptions.
*
* @deprecated since 3.3
* @todo The final deprecation of this function will take place in Moodle 3.7 - see MDL-57617.
* @return bool
*/
function calendar_cron() {
debugging(__FUNCTION__ . '() is deprecated and should not be used. Please use the core\task\calendar_cron_task instead.',
DEBUG_DEVELOPER);
global $CFG, $DB;
require_once($CFG->dirroot . '/calendar/lib.php');
// In order to execute this we need bennu.
require_once($CFG->libdir.'/bennu/bennu.inc.php');
mtrace('Updating calendar subscriptions:');
cron_trace_time_and_memory();
$time = time();
$subscriptions = $DB->get_records_sql('SELECT * FROM {event_subscriptions} WHERE pollinterval > 0
AND lastupdated + pollinterval < ?', array($time));
foreach ($subscriptions as $sub) {
mtrace("Updating calendar subscription {$sub->name} in course {$sub->courseid}");
try {
$log = calendar_update_subscription_events($sub->id);
mtrace(trim(strip_tags($log)));
} catch (moodle_exception $ex) {
mtrace('Error updating calendar subscription: ' . $ex->getMessage());
}
}
mtrace('Finished updating calendar subscriptions.');
return true;
}
/**
* @deprecated since Moodle 3.4 and removed immediately. MDL-49398.
*/
function load_course_context() {
throw new coding_exception('load_course_context() is removed. Do not use private functions or data structures.');
}
/**
* @deprecated since Moodle 3.4 and removed immediately. MDL-49398.
*/
function load_role_access_by_context() {
throw new coding_exception('load_role_access_by_context() is removed. Do not use private functions or data structures.');
}
/**
* @deprecated since Moodle 3.4 and removed immediately. MDL-49398.
*/
function dedupe_user_access() {
throw new coding_exception('dedupe_user_access() is removed. Do not use private functions or data structures.');
}
/**
* Previous internal API, it was not supposed to be used anywhere.
* Return a nested array showing role assignments
* and all relevant role capabilities for the user.
*
* [ra] => [/path][roleid]=roleid
* [rdef] => ["$contextpath:$roleid"][capability]=permission
*
* @access private
* @deprecated since Moodle 3.4. MDL-49398.
* @param int $userid - the id of the user
* @return array access info array
*/
function get_user_access_sitewide($userid) {
debugging('get_user_access_sitewide() is deprecated. Do not use private functions or data structures.', DEBUG_DEVELOPER);
$accessdata = get_user_accessdata($userid);
$accessdata['rdef'] = array();
$roles = array();
foreach ($accessdata['ra'] as $path => $pathroles) {
$roles = array_merge($pathroles, $roles);
}
$rdefs = get_role_definitions($roles);
foreach ($rdefs as $roleid => $rdef) {
foreach ($rdef as $path => $caps) {
$accessdata['rdef']["$path:$roleid"] = $caps;
}
}
return $accessdata;
}
/**
* Generates the HTML for a miniature calendar.
*
* @param array $courses list of course to list events from
* @param array $groups list of group
* @param array $users user's info
* @param int|bool $calmonth calendar month in numeric, default is set to false
* @param int|bool $calyear calendar month in numeric, default is set to false
* @param string|bool $placement the place/page the calendar is set to appear - passed on the the controls function
* @param int|bool $courseid id of the course the calendar is displayed on - passed on the the controls function
* @param int $time the unixtimestamp representing the date we want to view, this is used instead of $calmonth
* and $calyear to support multiple calendars
* @return string $content return html table for mini calendar
* @deprecated since Moodle 3.4. MDL-59333
*/
function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyear = false, $placement = false,
$courseid = false, $time = 0) {
global $PAGE;
debugging('calendar_get_mini() has been deprecated. Please update your code to use calendar_get_view.',
DEBUG_DEVELOPER);
if (!empty($calmonth) && !empty($calyear)) {
// Do this check for backwards compatibility.
// The core should be passing a timestamp rather than month and year.
// If a month and year are passed they will be in Gregorian.
// Ensure it is a valid date, else we will just set it to the current timestamp.
if (checkdate($calmonth, 1, $calyear)) {
$time = make_timestamp($calyear, $calmonth, 1);
} else {
$time = time();
}
} else if (empty($time)) {
// Get the current date in the calendar type being used.
$time = time();
}
if ($courseid == SITEID) {
$course = get_site();
} else {
$course = get_course($courseid);
}
$calendar = new calendar_information(0, 0, 0, $time);
$calendar->prepare_for_view($course, $courses);
$renderer = $PAGE->get_renderer('core_calendar');
list($data, $template) = calendar_get_view($calendar, 'mini');
return $renderer->render_from_template($template, $data);
}
/**
* Gets the calendar upcoming event.
*
* @param array $courses array of courses
* @param array|int|bool $groups array of groups, group id or boolean for all/no group events
* @param array|int|bool $users array of users, user id or boolean for all/no user events
* @param int $daysinfuture number of days in the future we 'll look
* @param int $maxevents maximum number of events
* @param int $fromtime start time
* @return array $output array of upcoming events
* @deprecated since Moodle 3.4. MDL-59333
*/
function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime=0) {
debugging(
'calendar_get_upcoming() has been deprecated. ' .
'Please see block_calendar_upcoming::get_content() for the correct API usage.',
DEBUG_DEVELOPER
);
global $COURSE;
$display = new \stdClass;
$display->range = $daysinfuture; // How many days in the future we 'll look.
$display->maxevents = $maxevents;
$output = array();
$processed = 0;
$now = time(); // We 'll need this later.
$usermidnighttoday = usergetmidnight($now);
if ($fromtime) {
$display->tstart = $fromtime;
} else {
$display->tstart = $usermidnighttoday;
}
// This works correctly with respect to the user's DST, but it is accurate
// only because $fromtime is always the exact midnight of some day!
$display->tend = usergetmidnight($display->tstart + DAYSECS * $display->range + 3 * HOURSECS) - 1;
// Get the events matching our criteria.
$events = calendar_get_legacy_events($display->tstart, $display->tend, $users, $groups, $courses);
// This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after
// possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month
// will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra
// arguments to this function.
$hrefparams = array();
if (!empty($courses)) {
$courses = array_diff($courses, array(SITEID));
if (count($courses) == 1) {
$hrefparams['course'] = reset($courses);
}
}
if ($events !== false) {
foreach ($events as $event) {
if (!empty($event->modulename)) {
$instances = get_fast_modinfo($event->courseid)->get_instances_of($event->modulename);
if (empty($instances[$event->instance]->uservisible)) {
continue;
}
}
if ($processed >= $display->maxevents) {
break;
}
$event->time = calendar_format_event_time($event, $now, $hrefparams);
$output[] = $event;
$processed++;
}
}
return $output;
}
/**
* Creates a record in the role_allow_override table
*
* @param int $sroleid source roleid
* @param int $troleid target roleid
* @return void
* @deprecated since Moodle 3.4. MDL-50666
*/
function allow_override($sroleid, $troleid) {
debugging('allow_override() has been deprecated. Please update your code to use core_role_set_override_allowed.',
DEBUG_DEVELOPER);
core_role_set_override_allowed($sroleid, $troleid);
}
/**
* Creates a record in the role_allow_assign table
*
* @param int $fromroleid source roleid
* @param int $targetroleid target roleid
* @return void
* @deprecated since Moodle 3.4. MDL-50666
*/
function allow_assign($fromroleid, $targetroleid) {
debugging('allow_assign() has been deprecated. Please update your code to use core_role_set_assign_allowed.',
DEBUG_DEVELOPER);
core_role_set_assign_allowed($fromroleid, $targetroleid);
}
/**
* Creates a record in the role_allow_switch table
*
* @param int $fromroleid source roleid
* @param int $targetroleid target roleid
* @return void
* @deprecated since Moodle 3.4. MDL-50666
*/
function allow_switch($fromroleid, $targetroleid) {
debugging('allow_switch() has been deprecated. Please update your code to use core_role_set_switch_allowed.',
DEBUG_DEVELOPER);
core_role_set_switch_allowed($fromroleid, $targetroleid);
}
/**
* Organise categories into a single parent category (called the 'Top' category) per context.
*
* @param array $categories List of question categories in the format of ["$categoryid,$contextid" => $category].
* @param array $pcontexts List of context ids.
* @return array
* @deprecated since Moodle 3.5. MDL-61132
*/
function question_add_tops($categories, $pcontexts) {
debugging('question_add_tops() has been deprecated. You may want to pass $top = true to get_categories_for_contexts().',
DEBUG_DEVELOPER);
$topcats = array();
foreach ($pcontexts as $contextid) {
$topcat = question_get_top_category($contextid, true);
$context = context::instance_by_id($contextid);
$newcat = new stdClass();
$newcat->id = "{$topcat->id},$contextid";
$newcat->name = get_string('topfor', 'question', $context->get_context_name(false));
$newcat->parent = 0;
$newcat->contextid = $contextid;
$topcats["{$topcat->id},$contextid"] = $newcat;
}
// Put topcats in at beginning of array - they'll be sorted into different contexts later.
return array_merge($topcats, $categories);
}
/**
* Checks if the question category is the highest-level category in the context that can be edited, and has no siblings.
*
* @param int $categoryid a category id.
* @return bool
* @deprecated since Moodle 3.5. MDL-61132
*/
function question_is_only_toplevel_category_in_context($categoryid) {
debugging('question_is_only_toplevel_category_in_context() has been deprecated. '
. 'Please update your code to use question_is_only_child_of_top_category_in_context() instead.',
DEBUG_DEVELOPER);
return question_is_only_child_of_top_category_in_context($categoryid);
}
/**
* Moves messages from a particular user from the message table (unread messages) to message_read
* This is typically only used when a user is deleted
*
* @param object $userid User id
* @return boolean success
* @deprecated since Moodle 3.5
*/
function message_move_userfrom_unread2read($userid) {
debugging('message_move_userfrom_unread2read() is deprecated and is no longer used.', DEBUG_DEVELOPER);
global $DB;
// Move all unread messages from message table to message_read.
if ($messages = $DB->get_records_select('message', 'useridfrom = ?', array($userid), 'timecreated')) {
foreach ($messages as $message) {
message_mark_message_read($message, 0); // Set timeread to 0 as the message was never read.
}
}
return true;
}
/**
* Retrieve users blocked by $user1
*
* @param object $user1 the user whose messages are being viewed
* @param object $user2 the user $user1 is talking to. If they are being blocked
* they will have a variable called 'isblocked' added to their user object
* @return array the users blocked by $user1
* @deprecated since Moodle 3.5
*/
function message_get_blocked_users($user1=null, $user2=null) {
debugging('message_get_blocked_users() is deprecated, please use \core_message\api::get_blocked_users() instead.',
DEBUG_DEVELOPER);
global $USER;
if (empty($user1)) {
$user1 = new stdClass();
$user1->id = $USER->id;
}
return \core_message\api::get_blocked_users($user1->id);
}
/**
* Retrieve $user1's contacts (online, offline and strangers)
*
* @param object $user1 the user whose messages are being viewed
* @param object $user2 the user $user1 is talking to. If they are a contact
* they will have a variable called 'iscontact' added to their user object
* @return array containing 3 arrays. array($onlinecontacts, $offlinecontacts, $strangers)
* @deprecated since Moodle 3.5
*/
function message_get_contacts($user1=null, $user2=null) {
debugging('message_get_contacts() is deprecated and is no longer used.', DEBUG_DEVELOPER);
global $DB, $CFG, $USER;
if (empty($user1)) {
$user1 = $USER;
}
if (!empty($user2)) {
$user2->iscontact = false;
}
$timetoshowusers = 300; // Seconds default.
if (isset($CFG->block_online_users_timetosee)) {
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
}
// Rime which a user is counting as being active since.
$timefrom = time() - $timetoshowusers;
// People in our contactlist who are online.
$onlinecontacts = array();
// People in our contactlist who are offline.
$offlinecontacts = array();
// People who are not in our contactlist but have sent us a message.
$strangers = array();
// Get all in our contact list who are not blocked in our and count messages we have waiting from each of them.
$rs = \core_message\api::get_contacts_with_unread_message_count($user1->id);
foreach ($rs as $rd) {
if ($rd->lastaccess >= $timefrom) {
// They have been active recently, so are counted online.
$onlinecontacts[] = $rd;
} else {
$offlinecontacts[] = $rd;
}
if (!empty($user2) && $user2->id == $rd->id) {
$user2->iscontact = true;
}
}
// Get messages from anyone who isn't in our contact list and count the number of messages we have from each of them.
$rs = \core_message\api::get_non_contacts_with_unread_message_count($user1->id);
// Add user id as array index, so supportuser and noreply user don't get duplicated (if they are real users).
foreach ($rs as $rd) {
$strangers[$rd->id] = $rd;
}
// Add noreply user and support user to the list, if they don't exist.
$supportuser = core_user::get_support_user();
if (!isset($strangers[$supportuser->id]) && !$supportuser->deleted) {
$supportuser->messagecount = message_count_unread_messages($USER, $supportuser);
if ($supportuser->messagecount > 0) {
$strangers[$supportuser->id] = $supportuser;
}
}
$noreplyuser = core_user::get_noreply_user();
if (!isset($strangers[$noreplyuser->id]) && !$noreplyuser->deleted) {
$noreplyuser->messagecount = message_count_unread_messages($USER, $noreplyuser);
if ($noreplyuser->messagecount > 0) {
$strangers[$noreplyuser->id] = $noreplyuser;
}
}
return array($onlinecontacts, $offlinecontacts, $strangers);
}
/**
* Mark a single message as read
*
* @param stdClass $message An object with an object property ie $message->id which is an id in the message table
* @param int $timeread the timestamp for when the message should be marked read. Usually time().
* @param bool $messageworkingempty Is the message_working table already confirmed empty for this message?
* @return int the ID of the message in the messags table
* @deprecated since Moodle 3.5
*/
function message_mark_message_read($message, $timeread, $messageworkingempty=false) {
debugging('message_mark_message_read() is deprecated, please use \core_message\api::mark_message_as_read()
or \core_message\api::mark_notification_as_read().', DEBUG_DEVELOPER);
if (!empty($message->notification)) {
\core_message\api::mark_notification_as_read($message, $timeread);
} else {
\core_message\api::mark_message_as_read($message->useridto, $message, $timeread);
}
return $message->id;
}
/**
* Checks if a user can delete a message.
*
* @param stdClass $message the message to delete
* @param string $userid the user id of who we want to delete the message for (this may be done by the admin
* but will still seem as if it was by the user)
* @return bool Returns true if a user can delete the message, false otherwise.
* @deprecated since Moodle 3.5
*/
function message_can_delete_message($message, $userid) {
debugging('message_can_delete_message() is deprecated, please use \core_message\api::can_delete_message() instead.',
DEBUG_DEVELOPER);
return \core_message\api::can_delete_message($userid, $message->id);
}
/**
* Deletes a message.
*
* This function does not verify any permissions.
*
* @param stdClass $message the message to delete
* @param string $userid the user id of who we want to delete the message for (this may be done by the admin
* but will still seem as if it was by the user)
* @return bool
* @deprecated since Moodle 3.5
*/
function message_delete_message($message, $userid) {
debugging('message_delete_message() is deprecated, please use \core_message\api::delete_message() instead.',
DEBUG_DEVELOPER);
return \core_message\api::delete_message($userid, $message->id);
}
/**
* Get all of the allowed types for all of the courses and groups
* the logged in user belongs to.
*
* The returned array will optionally have 5 keys:
* 'user' : true if the logged in user can create user events
* 'site' : true if the logged in user can create site events
* 'category' : array of course categories that the user can create events for
* 'course' : array of courses that the user can create events for
* 'group': array of groups that the user can create events for
* 'groupcourses' : array of courses that the groups belong to (can
* be different from the list in 'course'.
* @deprecated since 3.6
* @return array The array of allowed types.
*/
function calendar_get_all_allowed_types() {
debugging('calendar_get_all_allowed_types() is deprecated. Please use calendar_get_allowed_types() instead.',
DEBUG_DEVELOPER);
global $CFG, $USER, $DB;
require_once($CFG->libdir . '/enrollib.php');
$types = [];
$allowed = new stdClass();
calendar_get_allowed_types($allowed);
if ($allowed->user) {
$types['user'] = true;
}
if ($allowed->site) {
$types['site'] = true;
}
if (coursecat::has_manage_capability_on_any()) {
$types['category'] = coursecat::make_categories_list('moodle/category:manage');
}
// This function warms the context cache for the course so the calls
// to load the course context in calendar_get_allowed_types don't result
// in additional DB queries.
$courses = calendar_get_default_courses(null, 'id, groupmode, groupmodeforce', true);
// We want to pre-fetch all of the groups for each course in a single
// query to avoid calendar_get_allowed_types from hitting the DB for
// each separate course.
$groups = groups_get_all_groups_for_courses($courses);
foreach ($courses as $course) {
$coursegroups = isset($groups[$course->id]) ? $groups[$course->id] : null;
calendar_get_allowed_types($allowed, $course, $coursegroups);
if (!empty($allowed->courses)) {
$types['course'][$course->id] = $course;
}
if (!empty($allowed->groups)) {
$types['groupcourses'][$course->id] = $course;
if (!isset($types['group'])) {
$types['group'] = array_values($allowed->groups);
} else {
$types['group'] = array_merge($types['group'], array_values($allowed->groups));
}
}
}
return $types;
}
/**
* Gets array of all groups in a set of course.
*
* @category group
* @param array $courses Array of course objects or course ids.
* @return array Array of groups indexed by course id.
*/
function groups_get_all_groups_for_courses($courses) {
global $DB;
if (empty($courses)) {
return [];
}
$groups = [];
$courseids = [];
foreach ($courses as $course) {
$courseid = is_object($course) ? $course->id : $course;
$groups[$courseid] = [];
$courseids[] = $courseid;
}
$groupfields = [
'g.id as gid',
'g.courseid',
'g.idnumber',
'g.name',
'g.description',
'g.descriptionformat',
'g.enrolmentkey',
'g.picture',
'g.hidepicture',
'g.timecreated',
'g.timemodified'
];
$groupsmembersfields = [
'gm.id as gmid',
'gm.groupid',
'gm.userid',
'gm.timeadded',
'gm.component',
'gm.itemid'
];
$concatidsql = $DB->sql_concat_join("'-'", ['g.id', 'COALESCE(gm.id, 0)']) . ' AS uniqid';
list($courseidsql, $params) = $DB->get_in_or_equal($courseids);
$groupfieldssql = implode(',', $groupfields);
$groupmembersfieldssql = implode(',', $groupsmembersfields);
$sql = "SELECT {$concatidsql}, {$groupfieldssql}, {$groupmembersfieldssql}
FROM {groups} g
LEFT JOIN {groups_members} gm
ON gm.groupid = g.id
WHERE g.courseid {$courseidsql}";
$results = $DB->get_records_sql($sql, $params);
// The results will come back as a flat dataset thanks to the left
// join so we will need to do some post processing to blow it out
// into a more usable data structure.
//
// This loop will extract the distinct groups from the result set
// and add it's list of members to the object as a property called
// 'members'. Then each group will be added to the result set indexed
// by it's course id.
//
// The resulting data structure for $groups should be:
// $groups = [
// '1' = [
// '1' => (object) [
// 'id' => 1,
// <rest of group properties>
// 'members' => [
// '1' => (object) [
// <group member properties>
// ],
// '2' => (object) [
// <group member properties>
// ]
// ]
// ],
// '2' => (object) [
// 'id' => 2,
// <rest of group properties>
// 'members' => [
// '1' => (object) [
// <group member properties>
// ],
// '3' => (object) [
// <group member properties>
// ]
// ]
// ]
// ]
// ]
//
foreach ($results as $key => $result) {
$groupid = $result->gid;
$courseid = $result->courseid;
$coursegroups = $groups[$courseid];
$groupsmembersid = $result->gmid;
$reducefunc = function($carry, $field) use ($result) {
// Iterate over the groups properties and pull
// them out into a separate object.
list($prefix, $field) = explode('.', $field);
if (property_exists($result, $field)) {
$carry[$field] = $result->{$field};
}
return $carry;
};
if (isset($coursegroups[$groupid])) {
$group = $coursegroups[$groupid];
} else {
$initial = [
'id' => $groupid,
'members' => []
];
$group = (object) array_reduce(
$groupfields,
$reducefunc,
$initial
);
}
if (!empty($groupsmembersid)) {
$initial = ['id' => $groupsmembersid];
$groupsmembers = (object) array_reduce(
$groupsmembersfields,
$reducefunc,
$initial
);
$group->members[$groupsmembers->userid] = $groupsmembers;
}
$coursegroups[$groupid] = $group;
$groups[$courseid] = $coursegroups;
}
return $groups;
}