_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.');
}
/**
* @deprecated since Moodle 3.2
* @see csv_import_reader::load_csv_content()
*/
function get_records_csv() {
throw new coding_exception('get_records_csv() can not be used anymore. Please use ' .
'lib/csvlib.class.php csv_import_reader() instead.');
}
/**
* @deprecated since Moodle 3.2
* @see download_as_dataformat (lib/dataformatlib.php)
*/
function put_records_csv() {
throw new coding_exception('put_records_csv() can not be used anymore. Please use ' .
'lib/dataformatlib.php download_as_dataformat() instead.');
}
/**
* @deprecated since Moodle 3.2
*/
function css_is_colour() {
throw new coding_exception('css_is_colour() can not be used anymore.');
}
/**
* @deprecated since Moodle 3.2
*/
function css_is_width() {
throw new coding_exception('css_is_width() can not be used anymore.');
}
/**
* @deprecated since Moodle 3.2
*/
function css_sort_by_count() {
throw new coding_exception('css_sort_by_count() can not be used anymore.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_get_course_contexts() {
throw new coding_exception('message_get_course_contexts() can not be used anymore.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_remove_url_params() {
throw new coding_exception('message_remove_url_params() can not be used anymore.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_count_messages() {
throw new coding_exception('message_count_messages() can not be used anymore.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_count_blocked_users() {
throw new coding_exception('message_count_blocked_users() can not be used anymore. Please use ' .
'\core_message\api::count_blocked_users() instead.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_contact_link() {
throw new coding_exception('message_contact_link() can not be used anymore.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_get_recent_notifications() {
throw new coding_exception('message_get_recent_notifications() can not be used anymore.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_history_link() {
throw new coding_exception('message_history_link() can not be used anymore.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_search() {
throw new coding_exception('message_search() can not be used anymore.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_shorten_message() {
throw new coding_exception('message_shorten_message() can not be used anymore.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_get_fragment() {
throw new coding_exception('message_get_fragment() can not be used anymore.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_get_history() {
throw new coding_exception('message_get_history() can not be used anymore.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_get_contact_add_remove_link() {
throw new coding_exception('message_get_contact_add_remove_link() can not be used anymore.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_get_contact_block_link() {
throw new coding_exception('message_get_contact_block_link() can not be used anymore.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_mark_messages_read() {
throw new coding_exception('message_mark_messages_read() can not be used anymore. Please use ' .
'\core_message\api::mark_all_messages_as_read() instead.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_can_post_message() {
throw new coding_exception('message_can_post_message() can not be used anymore. Please use ' .
'\core_message\api::can_send_message() instead.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_is_user_non_contact_blocked() {
throw new coding_exception('message_is_user_non_contact_blocked() can not be used anymore. Please use ' .
'\core_message\api::is_user_non_contact_blocked() instead.');
}
/**
* @deprecated since Moodle 3.2
*/
function message_is_user_blocked() {
throw new coding_exception('message_is_user_blocked() can not be used anymore. Please use ' .
'\core_message\api::is_user_blocked() instead.');
}
/**
* @deprecated since Moodle 3.2
*/
function print_log() {
throw new coding_exception('print_log() can not be used anymore. Please use the ' .
'report_log framework instead.');
}
/**
* @deprecated since Moodle 3.2
*/
function print_mnet_log() {
throw new coding_exception('print_mnet_log() can not be used anymore. Please use the ' .
'report_log framework instead.');
}
/**
* @deprecated since Moodle 3.2
*/
function print_log_csv() {
throw new coding_exception('print_log_csv() can not be used anymore. Please use the ' .
'report_log framework instead.');
}
/**
* @deprecated since Moodle 3.2
*/
function print_log_xls() {
throw new coding_exception('print_log_xls() can not be used anymore. Please use the ' .
'report_log framework instead.');
}
/**
* @deprecated since Moodle 3.2
*/
function print_log_ods() {
throw new coding_exception('print_log_ods() can not be used anymore. Please use the ' .
'report_log framework instead.');
}
/**
* @deprecated since Moodle 3.2
*/
function build_logs_array() {
throw new coding_exception('build_logs_array() can not be used anymore. Please use the ' .
'report_log framework instead.');
}
/**
* @deprecated since Moodle 3.2
*/
function get_logs_usercourse() {
throw new coding_exception('get_logs_usercourse() can not be used anymore. Please use the ' .
'report_log framework instead.');
}
/**
* @deprecated since Moodle 3.2
*/
function get_logs_userday() {
throw new coding_exception('get_logs_userday() can not be used anymore. Please use the ' .
'report_log framework instead.');
}
/**
* @deprecated since Moodle 3.2
*/
function get_logs() {
throw new coding_exception('get_logs() can not be used anymore. Please use the ' .
'report_log framework instead.');
}
/**
* @deprecated since Moodle 3.2
*/
function prevent_form_autofill_password() {
throw new coding_exception('prevent_form_autofill_password() can not be used anymore.');
}
/**
* @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);
}
/**
* @deprecated since Moodle 3.2
*/
function calendar_preferences_button() {
throw new coding_exception('calendar_preferences_button() can not be used anymore. The calendar ' .
'preferences are now linked to the user preferences page.');
}
/**
* @deprecated since 3.3
*/
function calendar_wday_name() {
throw new coding_exception('Function calendar_wday_name() is removed and no longer used in core.');
}
/**
* @deprecated since 3.3
*/
function calendar_get_block_upcoming() {
throw new coding_exception('Function calendar_get_block_upcoming() is removed,' .
'Please see block_calendar_upcoming::get_content() for the correct API usage.');
}
/**
* @deprecated since 3.3
*/
function calendar_print_month_selector() {
throw new coding_exception('Function calendar_print_month_selector() is removed and can no longer used in core.');
}
/**
* @deprecated since 3.3
*/
function calendar_cron() {
throw new coding_exception('Function calendar_cron() is removed. Please use the core\task\calendar_cron_task instead.');
}
/**
* @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.');
}
/**
* @deprecated since Moodle 3.4. MDL-49398.
*/
function get_user_access_sitewide() {
throw new coding_exception('get_user_access_sitewide() is removed. Do not use private functions or data structures.');
}
/**
* @deprecated since Moodle 3.4. MDL-59333
*/
function calendar_get_mini() {
throw new coding_exception('calendar_get_mini() has been removed. Please update your code to use calendar_get_view.');
}
/**
* @deprecated since Moodle 3.4. MDL-59333
*/
function calendar_get_upcoming() {
throw new coding_exception('calendar_get_upcoming() has been removed. ' .
'Please see block_calendar_upcoming::get_content() for the correct API usage.');
}
/**
* @deprecated since Moodle 3.4. MDL-50666
*/
function allow_override() {
throw new coding_exception('allow_override() has been removed. Please update your code to use core_role_set_override_allowed.');
}
/**
* @deprecated since Moodle 3.4. MDL-50666
*/
function allow_assign() {
throw new coding_exception('allow_assign() has been removed. Please update your code to use core_role_set_assign_allowed.');
}
/**
* @deprecated since Moodle 3.4. MDL-50666
*/
function allow_switch() {
throw new coding_exception('allow_switch() has been removed. Please update your code to use core_role_set_switch_allowed.');
}
/**
* @deprecated since Moodle 3.5. MDL-61132
*/
function question_add_tops() {
throw new coding_exception(
'question_add_tops() has been removed. You may want to pass $top = true to get_categories_for_contexts().'
);
}
/**
* @deprecated since Moodle 3.5. MDL-61132
*/
function question_is_only_toplevel_category_in_context() {
throw new coding_exception('question_is_only_toplevel_category_in_context() has been removed. '
. 'Please update your code to use question_is_only_child_of_top_category_in_context() instead.');
}
/**
* @deprecated since Moodle 3.5
*/
function message_move_userfrom_unread2read() {
throw new coding_exception('message_move_userfrom_unread2read() has been removed.');
}
/**
* @deprecated since Moodle 3.5
*/
function message_get_blocked_users() {
throw new coding_exception(
'message_get_blocked_users() has been removed, please use \core_message\api::get_blocked_users() instead.'
);
}
/**
* @deprecated since Moodle 3.5
*/
function message_get_contacts() {
throw new coding_exception('message_get_contacts() has been removed.');
}
/**
* @deprecated since Moodle 3.5
*/
function message_mark_message_read() {
throw new coding_exception('message_mark_message_read() has been removed, please use \core_message\api::mark_message_as_read()
or \core_message\api::mark_notification_as_read().');
}
/**
* @deprecated since Moodle 3.5
*/
function message_can_delete_message() {
throw new coding_exception(
'message_can_delete_message() has been removed, please use \core_message\api::can_delete_message() instead.'
);
}
/**
* @deprecated since Moodle 3.5
*/
function message_delete_message() {
throw new coding_exception(
'message_delete_message() has been removed, please use \core_message\api::delete_message() instead.'
);
}
/**
* @deprecated since 3.6
*/
function calendar_get_all_allowed_types() {
throw new coding_exception(
'calendar_get_all_allowed_types() has been removed. Please use calendar_get_allowed_types() instead.'
);
}
/**
* @deprecated since Moodle 3.6.
*/
function groups_get_all_groups_for_courses() {
throw new coding_exception(
'groups_get_all_groups_for_courses() has been removed and can not be used anymore.'
);
}
/**
* @deprecated since Moodle 3.6. Please use the Events 2 API.
*/
function events_get_cached() {
throw new coding_exception(
'Events API using $handlers array has been removed in favour of Events 2 API, please use it instead.'
);
}
/**
* @deprecated since Moodle 3.6. Please use the Events 2 API.
*/
function events_uninstall() {
throw new coding_exception(
'Events API using $handlers array has been removed in favour of Events 2 API, please use it instead.'
);
}
/**
* @deprecated since Moodle 3.6. Please use the Events 2 API.
*/
function events_cleanup() {
throw new coding_exception(
'Events API using $handlers array has been removed in favour of Events 2 API, please use it instead.'
);
}
/**
* @deprecated since Moodle 3.6. Please use the Events 2 API.
*/
function events_dequeue() {
throw new coding_exception(
'Events API using $handlers array has been removed in favour of Events 2 API, please use it instead.'
);
}
/**
* @deprecated since Moodle 3.6. Please use the Events 2 API.
*/
function events_get_handlers() {
throw new coding_exception(
'Events API using $handlers array has been removed in favour of Events 2 API, please use it instead.'
);
}
/**
* @deprecated since Moodle 3.6. Please use the get_roles_used_in_context().
*/
function get_roles_on_exact_context() {
throw new coding_exception(
'get_roles_on_exact_context() has been removed, please use get_roles_used_in_context() instead.'
);
}
/**
* @deprecated since Moodle 3.6. Please use the get_roles_used_in_context().
*/
function get_roles_with_assignment_on_context() {
throw new coding_exception(
'get_roles_with_assignment_on_context() has been removed, please use get_roles_used_in_context() instead.'
);
}
/**
* @deprecated since Moodle 3.6
*/
function message_add_contact() {
throw new coding_exception(
'message_add_contact() has been removed. Please use \core_message\api::create_contact_request() instead. ' .
'If you wish to block or unblock a user please use \core_message\api::is_blocked() and ' .
'\core_message\api::block_user() or \core_message\api::unblock_user() respectively.'
);
}
/**
* @deprecated since Moodle 3.6
*/
function message_remove_contact() {
throw new coding_exception(
'message_remove_contact() has been removed. Please use \core_message\api::remove_contact() instead.'
);
}
/**
* @deprecated since Moodle 3.6
*/
function message_unblock_contact() {
throw new coding_exception(
'message_unblock_contact() has been removed. Please use \core_message\api::unblock_user() instead.'
);
}
/**
* @deprecated since Moodle 3.6
*/
function message_block_contact() {
throw new coding_exception(
'message_block_contact() has been removed. Please use \core_message\api::is_blocked() and ' .
'\core_message\api::block_user() instead.'
);
}
/**
* @deprecated since Moodle 3.6
*/
function message_get_contact() {
throw new coding_exception(
'message_get_contact() has been removed. Please use \core_message\api::get_contact() instead.'
);
}
/**
* @deprecated since Moodle 3.7
*/
function get_courses_page() {
throw new coding_exception(
'Function get_courses_page() has been removed. Please use core_course_category::get_courses() ' .
'or core_course_category::search_courses()'
);
}
/**
* @deprecated since Moodle 3.8
*/
function report_insights_context_insights(\context $context) {
throw new coding_exception(
'Function report_insights_context_insights() ' .
'has been removed. Please use \core_analytics\manager::cached_models_with_insights instead'
);
}
/**
* @deprecated since 3.9
*/
function get_module_metadata() {
throw new coding_exception(
'get_module_metadata() has been removed. Please use \core_course\local\service\content_item_service instead.');
}
/**
* @deprecated since Moodle 3.9 MDL-63580. Please use the \core\task\manager::run_from_cli($task).
*/
function cron_run_single_task() {
throw new coding_exception(
'cron_run_single_task() has been removed. Please use \\core\task\manager::run_from_cli() instead.'
);
}
/**
* Executes cron functions for a specific type of plugin.
*
* @param string $plugintype Plugin type (e.g. 'report')
* @param string $description If specified, will display 'Starting (whatever)'
* and 'Finished (whatever)' lines, otherwise does not display
*
* @deprecated since Moodle 3.9 MDL-52846. Please use new task API.
* @todo MDL-61165 This will be deleted in Moodle 4.1.
*/
function cron_execute_plugin_type($plugintype, $description = null) {
global $DB;
// Get list from plugin => function for all plugins.
$plugins = get_plugin_list_with_function($plugintype, 'cron');
// Modify list for backward compatibility (different files/names).
$plugins = cron_bc_hack_plugin_functions($plugintype, $plugins);
// Return if no plugins with cron function to process.
if (!$plugins) {
return;
}
if ($description) {
mtrace('Starting '.$description);
}
foreach ($plugins as $component => $cronfunction) {
$dir = core_component::get_component_directory($component);
// Get cron period if specified in version.php, otherwise assume every cron.
$cronperiod = 0;
if (file_exists("$dir/version.php")) {
$plugin = new stdClass();
include("$dir/version.php");
if (isset($plugin->cron)) {
$cronperiod = $plugin->cron;
}
}
// Using last cron and cron period, don't run if it already ran recently.
$lastcron = get_config($component, 'lastcron');
if ($cronperiod && $lastcron) {
if ($lastcron + $cronperiod > time()) {
// Do not execute cron yet.
continue;
}
}
mtrace('Processing cron function for ' . $component . '...');
debugging("Use of legacy cron is deprecated ($cronfunction). Please use scheduled tasks.", DEBUG_DEVELOPER);
cron_trace_time_and_memory();
$pre_dbqueries = $DB->perf_get_queries();
$pre_time = microtime(true);
$cronfunction();
mtrace("done. (" . ($DB->perf_get_queries() - $pre_dbqueries) . " dbqueries, " .
round(microtime(true) - $pre_time, 2) . " seconds)");
set_config('lastcron', time(), $component);
core_php_time_limit::raise();
}
if ($description) {
mtrace('Finished ' . $description);
}
}
/**
* Used to add in old-style cron functions within plugins that have not been converted to the
* new standard API. (The standard API is frankenstyle_name_cron() in lib.php; some types used
* cron.php and some used a different name.)
*
* @param string $plugintype Plugin type e.g. 'report'
* @param array $plugins Array from plugin name (e.g. 'report_frog') to function name (e.g.
* 'report_frog_cron') for plugin cron functions that were already found using the new API
* @return array Revised version of $plugins that adds in any extra plugin functions found by
* looking in the older location
*
* @deprecated since Moodle 3.9 MDL-52846. Please use new task API.
* @todo MDL-61165 This will be deleted in Moodle 4.1.
*/
function cron_bc_hack_plugin_functions($plugintype, $plugins) {
global $CFG; // Mandatory in case it is referenced by include()d PHP script.
if ($plugintype === 'report') {
// Admin reports only - not course report because course report was
// never implemented before, so doesn't need BC.
foreach (core_component::get_plugin_list($plugintype) as $pluginname => $dir) {
$component = $plugintype . '_' . $pluginname;
if (isset($plugins[$component])) {
// We already have detected the function using the new API.
continue;
}
if (!file_exists("$dir/cron.php")) {
// No old style cron file present.
continue;
}
include_once("$dir/cron.php");
$cronfunction = $component . '_cron';
if (function_exists($cronfunction)) {
$plugins[$component] = $cronfunction;
} else {
debugging("Invalid legacy cron.php detected in $component, " .
"please use lib.php instead");
}
}
} else if (strpos($plugintype, 'grade') === 0) {
// Detect old style cron function names.
// Plugin gradeexport_frog used to use grade_export_frog_cron() instead of
// new standard API gradeexport_frog_cron(). Also applies to gradeimport, gradereport.
foreach (core_component::get_plugin_list($plugintype) as $pluginname => $dir) {
$component = $plugintype.'_'.$pluginname;
if (isset($plugins[$component])) {
// We already have detected the function using the new API.
continue;
}
if (!file_exists("$dir/lib.php")) {
continue;
}
include_once("$dir/lib.php");
$cronfunction = str_replace('grade', 'grade_', $plugintype) . '_' .
$pluginname . '_cron';
if (function_exists($cronfunction)) {
$plugins[$component] = $cronfunction;
}
}
}
return $plugins;
}
/**
* Returns the SQL used by the participants table.
*
* @deprecated since Moodle 3.9 MDL-68612 - See \core_user\table\participants_search for an improved way to fetch participants.
* @param int $courseid The course id
* @param int $groupid The groupid, 0 means all groups and USERSWITHOUTGROUP no group
* @param int $accesssince The time since last access, 0 means any time
* @param int $roleid The role id, 0 means all roles and -1 no roles
* @param int $enrolid The enrolment id, 0 means all enrolment methods will be returned.
* @param int $statusid The user enrolment status, -1 means all enrolments regardless of the status will be returned, if allowed.
* @param string|array $search The search that was performed, empty means perform no search
* @param string $additionalwhere Any additional SQL to add to where
* @param array $additionalparams The additional params
* @return array
*/
function user_get_participants_sql($courseid, $groupid = 0, $accesssince = 0, $roleid = 0, $enrolid = 0, $statusid = -1,
$search = '', $additionalwhere = '', $additionalparams = array()) {
global $DB, $USER, $CFG;
$deprecatedtext = __FUNCTION__ . '() is deprecated. ' .
'Please use \core\table\participants_search::class with table filtersets instead.';
debugging($deprecatedtext, DEBUG_DEVELOPER);
// Get the context.
$context = \context_course::instance($courseid, MUST_EXIST);
$isfrontpage = ($courseid == SITEID);
// Default filter settings. We only show active by default, especially if the user has no capability to review enrolments.
$onlyactive = true;
$onlysuspended = false;
if (has_capability('moodle/course:enrolreview', $context) && (has_capability('moodle/course:viewsuspendedusers', $context))) {
switch ($statusid) {
case ENROL_USER_ACTIVE:
// Nothing to do here.
break;
case ENROL_USER_SUSPENDED:
$onlyactive = false;
$onlysuspended = true;
break;
default:
// If the user has capability to review user enrolments, but statusid is set to -1, set $onlyactive to false.
$onlyactive = false;
break;
}
}
list($esql, $params) = get_enrolled_sql($context, null, $groupid, $onlyactive, $onlysuspended, $enrolid);
$joins = array('FROM {user} u');
$wheres = array();
// TODO Does not support custom user profile fields (MDL-70456).
$userfields = \core_user\fields::get_identity_fields($context, false);
$userfieldsapi = \core_user\fields::for_userpic()->including(...$userfields);
$userfieldssql = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
if ($isfrontpage) {
$select = "SELECT $userfieldssql, u.lastaccess";
$joins[] = "JOIN ($esql) e ON e.id = u.id"; // Everybody on the frontpage usually.
if ($accesssince) {
$wheres[] = user_get_user_lastaccess_sql($accesssince);
}
} else {
$select = "SELECT $userfieldssql, COALESCE(ul.timeaccess, 0) AS lastaccess";
$joins[] = "JOIN ($esql) e ON e.id = u.id"; // Course enrolled users only.
// Not everybody has accessed the course yet.
$joins[] = 'LEFT JOIN {user_lastaccess} ul ON (ul.userid = u.id AND ul.courseid = :courseid)';
$params['courseid'] = $courseid;
if ($accesssince) {
$wheres[] = user_get_course_lastaccess_sql($accesssince);
}
}
// Performance hacks - we preload user contexts together with accounts.
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
$ccjoin = 'LEFT JOIN {context} ctx ON (ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel)';
$params['contextlevel'] = CONTEXT_USER;
$select .= $ccselect;
$joins[] = $ccjoin;
// Limit list to users with some role only.
if ($roleid) {
// We want to query both the current context and parent contexts.
list($relatedctxsql, $relatedctxparams) = $DB->get_in_or_equal($context->get_parent_context_ids(true),
SQL_PARAMS_NAMED, 'relatedctx');
// Get users without any role.
if ($roleid == -1) {
$wheres[] = "u.id NOT IN (SELECT userid FROM {role_assignments} WHERE contextid $relatedctxsql)";
$params = array_merge($params, $relatedctxparams);
} else {
$wheres[] = "u.id IN (SELECT userid FROM {role_assignments} WHERE roleid = :roleid AND contextid $relatedctxsql)";
$params = array_merge($params, array('roleid' => $roleid), $relatedctxparams);
}
}
if (!empty($search)) {
if (!is_array($search)) {
$search = [$search];
}
foreach ($search as $index => $keyword) {
$searchkey1 = 'search' . $index . '1';
$searchkey2 = 'search' . $index . '2';
$searchkey3 = 'search' . $index . '3';
$searchkey4 = 'search' . $index . '4';
$searchkey5 = 'search' . $index . '5';
$searchkey6 = 'search' . $index . '6';
$searchkey7 = 'search' . $index . '7';
$conditions = array();
// Search by fullname.
$fullname = $DB->sql_fullname('u.firstname', 'u.lastname');
$conditions[] = $DB->sql_like($fullname, ':' . $searchkey1, false, false);
// Search by email.
$email = $DB->sql_like('email', ':' . $searchkey2, false, false);
if (!in_array('email', $userfields)) {
$maildisplay = 'maildisplay' . $index;
$userid1 = 'userid' . $index . '1';
// Prevent users who hide their email address from being found by others
// who aren't allowed to see hidden email addresses.
$email = "(". $email ." AND (" .
"u.maildisplay <> :$maildisplay " .
"OR u.id = :$userid1". // User can always find himself.
"))";
$params[$maildisplay] = core_user::MAILDISPLAY_HIDE;
$params[$userid1] = $USER->id;
}
$conditions[] = $email;
// Search by idnumber.
$idnumber = $DB->sql_like('idnumber', ':' . $searchkey3, false, false);
if (!in_array('idnumber', $userfields)) {
$userid2 = 'userid' . $index . '2';
// Users who aren't allowed to see idnumbers should at most find themselves
// when searching for an idnumber.
$idnumber = "(". $idnumber . " AND u.id = :$userid2)";
$params[$userid2] = $USER->id;
}
$conditions[] = $idnumber;
// TODO Does not support custom user profile fields (MDL-70456).
$extrasearchfields = \core_user\fields::get_identity_fields($context, false);
if (!empty($extrasearchfields)) {
// Search all user identify fields.
foreach ($extrasearchfields as $extrasearchfield) {
if (in_array($extrasearchfield, ['email', 'idnumber', 'country'])) {
// Already covered above. Search by country not supported.
continue;
}
$param = $searchkey3 . $extrasearchfield;
$condition = $DB->sql_like($extrasearchfield, ':' . $param, false, false);
$params[$param] = "%$keyword%";
if (!in_array($extrasearchfield, $userfields)) {
// User cannot see this field, but allow match if their own account.
$userid3 = 'userid' . $index . '3' . $extrasearchfield;
$condition = "(". $condition . " AND u.id = :$userid3)";
$params[$userid3] = $USER->id;
}
$conditions[] = $condition;
}
}
// Search by middlename.
$middlename = $DB->sql_like('middlename', ':' . $searchkey4, false, false);
$conditions[] = $middlename;
// Search by alternatename.
$alternatename = $DB->sql_like('alternatename', ':' . $searchkey5, false, false);
$conditions[] = $alternatename;
// Search by firstnamephonetic.
$firstnamephonetic = $DB->sql_like('firstnamephonetic', ':' . $searchkey6, false, false);
$conditions[] = $firstnamephonetic;
// Search by lastnamephonetic.
$lastnamephonetic = $DB->sql_like('lastnamephonetic', ':' . $searchkey7, false, false);
$conditions[] = $lastnamephonetic;
$wheres[] = "(". implode(" OR ", $conditions) .") ";
$params[$searchkey1] = "%$keyword%";
$params[$searchkey2] = "%$keyword%";
$params[$searchkey3] = "%$keyword%";
$params[$searchkey4] = "%$keyword%";
$params[$searchkey5] = "%$keyword%";
$params[$searchkey6] = "%$keyword%";
$params[$searchkey7] = "%$keyword%";
}
}
if (!empty($additionalwhere)) {
$wheres[] = $additionalwhere;
$params = array_merge($params, $additionalparams);
}
$from = implode("\n", $joins);
if ($wheres) {
$where = 'WHERE ' . implode(' AND ', $wheres);
} else {
$where = '';
}
return array($select, $from, $where, $params);
}
/**
* Returns the total number of participants for a given course.
*
* @deprecated since Moodle 3.9 MDL-68612 - See \core_user\table\participants_search for an improved way to fetch participants.
* @param int $courseid The course id
* @param int $groupid The groupid, 0 means all groups and USERSWITHOUTGROUP no group
* @param int $accesssince The time since last access, 0 means any time
* @param int $roleid The role id, 0 means all roles
* @param int $enrolid The applied filter for the user enrolment ID.
* @param int $status The applied filter for the user's enrolment status.
* @param string|array $search The search that was performed, empty means perform no search
* @param string $additionalwhere Any additional SQL to add to where
* @param array $additionalparams The additional params
* @return int
*/
function user_get_total_participants($courseid, $groupid = 0, $accesssince = 0, $roleid = 0, $enrolid = 0, $statusid = -1,
$search = '', $additionalwhere = '', $additionalparams = array()) {
global $DB;
$deprecatedtext = __FUNCTION__ . '() is deprecated. ' .
'Please use \core\table\participants_search::class with table filtersets instead.';
debugging($deprecatedtext, DEBUG_DEVELOPER);
list($select, $from, $where, $params) = user_get_participants_sql($courseid, $groupid, $accesssince, $roleid, $enrolid,
$statusid, $search, $additionalwhere, $additionalparams);
return $DB->count_records_sql("SELECT COUNT(u.id) $from $where", $params);
}
/**
* Returns the participants for a given course.
*
* @deprecated since Moodle 3.9 MDL-68612 - See \core_user\table\participants_search for an improved way to fetch participants.
* @param int $courseid The course id
* @param int $groupid The groupid, 0 means all groups and USERSWITHOUTGROUP no group
* @param int $accesssince The time since last access
* @param int $roleid The role id
* @param int $enrolid The applied filter for the user enrolment ID.
* @param int $status The applied filter for the user's enrolment status.
* @param string $search The search that was performed
* @param string $additionalwhere Any additional SQL to add to where
* @param array $additionalparams The additional params
* @param string $sort The SQL sort
* @param int $limitfrom return a subset of records, starting at this point (optional).
* @param int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
* @return moodle_recordset
*/
function user_get_participants($courseid, $groupid, $accesssince, $roleid, $enrolid, $statusid, $search,
$additionalwhere = '', $additionalparams = array(), $sort = '', $limitfrom = 0, $limitnum = 0) {
global $DB;
$deprecatedtext = __FUNCTION__ . '() is deprecated. ' .
'Please use \core\table\participants_search::class with table filtersets instead.';
debugging($deprecatedtext, DEBUG_DEVELOPER);
list($select, $from, $where, $params) = user_get_participants_sql($courseid, $groupid, $accesssince, $roleid, $enrolid,
$statusid, $search, $additionalwhere, $additionalparams);
return $DB->get_recordset_sql("$select $from $where $sort", $params, $limitfrom, $limitnum);
}
/**
* Returns the list of full course categories to be used in html_writer::select()
*
* Calls {@see core_course_category::make_categories_list()} to build the list.
*
* @deprecated since Moodle 3.10
* @todo This will be finally removed for Moodle 4.2 as part of MDL-69124.
* @return array array mapping course category id to the display name
*/
function make_categories_options() {
$deprecatedtext = __FUNCTION__ . '() is deprecated. Please use \core_course_category::make_categories_list() instead.';
debugging($deprecatedtext, DEBUG_DEVELOPER);
return core_course_category::make_categories_list('', 0, ' / ');
}
/**
* Checks if current user is shown any extra fields when listing users.
*
* Does not include any custom profile fields.
*
* @param object $context Context
* @param array $already Array of fields that we're going to show anyway
* so don't bother listing them
* @return array Array of field names from user table, not including anything
* listed in $already
* @deprecated since Moodle 3.11 MDL-45242
* @see \core_user\fields
*/
function get_extra_user_fields($context, $already = array()) {
debugging('get_extra_user_fields() is deprecated. Please use the \core_user\fields API instead.', DEBUG_DEVELOPER);
$fields = \core_user\fields::for_identity($context, false)->excluding(...$already);
return $fields->get_required_fields();
}
/**
* If the current user is to be shown extra user fields when listing or
* selecting users, returns a string suitable for including in an SQL select
* clause to retrieve those fields.
*
* Does not include any custom profile fields.
*
* @param context $context Context
* @param string $alias Alias of user table, e.g. 'u' (default none)
* @param string $prefix Prefix for field names using AS, e.g. 'u_' (default none)
* @param array $already Array of fields that we're going to include anyway so don't list them (default none)
* @return string Partial SQL select clause, beginning with comma, for example ',u.idnumber,u.department' unless it is blank
* @deprecated since Moodle 3.11 MDL-45242
* @see \core_user\fields
*/
function get_extra_user_fields_sql($context, $alias='', $prefix='', $already = array()) {
debugging('get_extra_user_fields_sql() is deprecated. Please use the \core_user\fields API instead.', DEBUG_DEVELOPER);
$fields = \core_user\fields::for_identity($context, false)->excluding(...$already);
// Note: There will never be any joins or join params because we turned off profile fields.
$selects = $fields->get_sql($alias, false, $prefix)->selects;
return $selects;
}
/**
* Returns the display name of a field in the user table. Works for most fields that are commonly displayed to users.
*
* Also works for custom fields.
*
* @param string $field Field name, e.g. 'phone1'
* @return string Text description taken from language file, e.g. 'Phone number'
* @deprecated since Moodle 3.11 MDL-45242
* @see \core_user\fields
*/
function get_user_field_name($field) {
debugging('get_user_field_name() is deprecated. Please use \core_user\fields::get_display_name() instead', DEBUG_DEVELOPER);
return \core_user\fields::get_display_name($field);
}
/**
* A centralised location for the all name fields. Returns an array / sql string snippet.
*
* @param bool $returnsql True for an sql select field snippet.
* @param string $tableprefix table query prefix to use in front of each field.
* @param string $prefix prefix added to the name fields e.g. authorfirstname.
* @param string $fieldprefix sql field prefix e.g. id AS userid.
* @param bool $order moves firstname and lastname to the top of the array / start of the string.
* @return array|string All name fields.
* @deprecated since Moodle 3.11 MDL-45242
* @see \core_user\fields
*/
function get_all_user_name_fields($returnsql = false, $tableprefix = null, $prefix = null, $fieldprefix = null, $order = false) {
debugging('get_all_user_name_fields() is deprecated. Please use the \core_user\fields API instead', DEBUG_DEVELOPER);
// This array is provided in this order because when called by fullname() (above) if firstname is before
// firstnamephonetic str_replace() will change the wrong placeholder.
$alternatenames = [];
foreach (\core_user\fields::get_name_fields() as $field) {
$alternatenames[$field] = $field;
}
// Let's add a prefix to the array of user name fields if provided.
if ($prefix) {
foreach ($alternatenames as $key => $altname) {
$alternatenames[$key] = $prefix . $altname;
}
}
// If we want the end result to have firstname and lastname at the front / top of the result.
if ($order) {
// Move the last two elements (firstname, lastname) off the array and put them at the top.
for ($i = 0; $i < 2; $i++) {
// Get the last element.
$lastelement = end($alternatenames);
// Remove it from the array.
unset($alternatenames[$lastelement]);
// Put the element back on the top of the array.
$alternatenames = array_merge(array($lastelement => $lastelement), $alternatenames);
}
}
// Create an sql field snippet if requested.
if ($returnsql) {
if ($tableprefix) {
if ($fieldprefix) {
foreach ($alternatenames as $key => $altname) {
$alternatenames[$key] = $tableprefix . '.' . $altname . ' AS ' . $fieldprefix . $altname;
}
} else {
foreach ($alternatenames as $key => $altname) {
$alternatenames[$key] = $tableprefix . '.' . $altname;
}
}
}
$alternatenames = implode(',', $alternatenames);
}
return $alternatenames;
}
/**
* Update a subscription from the form data in one of the rows in the existing subscriptions table.
*
* @param int $subscriptionid The ID of the subscription we are acting upon.
* @param int $pollinterval The poll interval to use.
* @param int $action The action to be performed. One of update or remove.
* @throws dml_exception if invalid subscriptionid is provided
* @return string A log of the import progress, including errors
* @deprecated since Moodle 4.0 MDL-71953
*/
function calendar_process_subscription_row($subscriptionid, $pollinterval, $action) {
debugging('calendar_process_subscription_row() is deprecated.', DEBUG_DEVELOPER);
// Fetch the subscription from the database making sure it exists.
$sub = calendar_get_subscription($subscriptionid);
// Update or remove the subscription, based on action.
switch ($action) {
case CALENDAR_SUBSCRIPTION_UPDATE:
// Skip updating file subscriptions.
if (empty($sub->url)) {
break;
}
$sub->pollinterval = $pollinterval;
calendar_update_subscription($sub);
// Update the events.
return "" . get_string('subscriptionupdated', 'calendar', $sub->name) . "
" .
calendar_update_subscription_events($subscriptionid);
case CALENDAR_SUBSCRIPTION_REMOVE:
calendar_delete_subscription($subscriptionid);
return get_string('subscriptionremoved', 'calendar', $sub->name);
break;
default:
break;
}
return '';
}
/**
* Import events from an iCalendar object into a course calendar.
*
* @param iCalendar $ical The iCalendar object.
* @param int $unused Deprecated
* @param int $subscriptionid The subscription ID.
* @return string A log of the import progress, including errors.
*/
function calendar_import_icalendar_events($ical, $unused = null, $subscriptionid = null) {
debugging('calendar_import_icalendar_events() is deprecated. Please use calendar_import_events_from_ical() instead.',
DEBUG_DEVELOPER);
global $DB;
$return = '';
$eventcount = 0;
$updatecount = 0;
$skippedcount = 0;
// Large calendars take a while...
if (!CLI_SCRIPT) {
\core_php_time_limit::raise(300);
}
// Grab the timezone from the iCalendar file to be used later.
if (isset($ical->properties['X-WR-TIMEZONE'][0]->value)) {
$timezone = $ical->properties['X-WR-TIMEZONE'][0]->value;
} else {
$timezone = 'UTC';
}
$icaluuids = [];
foreach ($ical->components['VEVENT'] as $event) {
$icaluuids[] = $event->properties['UID'][0]->value;
$res = calendar_add_icalendar_event($event, null, $subscriptionid, $timezone);
switch ($res) {
case CALENDAR_IMPORT_EVENT_UPDATED:
$updatecount++;
break;
case CALENDAR_IMPORT_EVENT_INSERTED:
$eventcount++;
break;
case CALENDAR_IMPORT_EVENT_SKIPPED:
$skippedcount++;
break;
case 0:
$return .= '' . get_string('erroraddingevent', 'calendar') . ': ';
if (empty($event->properties['SUMMARY'])) {
$return .= '(' . get_string('notitle', 'calendar') . ')';
} else {
$return .= $event->properties['SUMMARY'][0]->value;
}
$return .= "
\n";
break;
}
}
$return .= html_writer::start_tag('ul');
$existing = $DB->get_field('event_subscriptions', 'lastupdated', ['id' => $subscriptionid]);
if (!empty($existing)) {
$eventsuuids = $DB->get_records_menu('event', ['subscriptionid' => $subscriptionid], '', 'id, uuid');
$icaleventscount = count($icaluuids);
$tobedeleted = [];
if (count($eventsuuids) > $icaleventscount) {
foreach ($eventsuuids as $eventid => $eventuuid) {
if (!in_array($eventuuid, $icaluuids)) {
$tobedeleted[] = $eventid;
}
}
if (!empty($tobedeleted)) {
$DB->delete_records_list('event', 'id', $tobedeleted);
$return .= html_writer::tag('li', get_string('eventsdeleted', 'calendar', count($tobedeleted)));
}
}
}
$return .= html_writer::tag('li', get_string('eventsimported', 'calendar', $eventcount));
$return .= html_writer::tag('li', get_string('eventsskipped', 'calendar', $skippedcount));
$return .= html_writer::tag('li', get_string('eventsupdated', 'calendar', $updatecount));
$return .= html_writer::end_tag('ul');
return $return;
}
/**
* Print grading plugin selection tab-based navigation.
*
* @deprecated since Moodle 4.0. Tabs navigation has been replaced with tertiary navigation.
* @param string $active_type type of plugin on current page - import, export, report or edit
* @param string $active_plugin active plugin type - grader, user, cvs, ...
* @param array $plugin_info Array of plugins
* @param boolean $return return as string
*
* @return nothing or string if $return true
*/
function grade_print_tabs($active_type, $active_plugin, $plugin_info, $return=false) {
global $CFG, $COURSE;
debugging('grade_print_tabs() has been deprecated. Tabs navigation has been replaced with tertiary navigation.',
DEBUG_DEVELOPER);
if (!isset($currenttab)) { //TODO: this is weird
$currenttab = '';
}
$tabs = array();
$top_row = array();
$bottom_row = array();
$inactive = array($active_plugin);
$activated = array($active_type);
$count = 0;
$active = '';
foreach ($plugin_info as $plugin_type => $plugins) {
if ($plugin_type == 'strings') {
continue;
}
// If $plugins is actually the definition of a child-less parent link:
if (!empty($plugins->id)) {
$string = $plugins->string;
if (!empty($plugin_info[$active_type]->parent)) {
$string = $plugin_info[$active_type]->parent->string;
}
$top_row[] = new tabobject($plugin_type, $plugins->link, $string);
continue;
}
$first_plugin = reset($plugins);
$url = $first_plugin->link;
if ($plugin_type == 'report') {
$url = $CFG->wwwroot.'/grade/report/index.php?id='.$COURSE->id;
}
$top_row[] = new tabobject($plugin_type, $url, $plugin_info['strings'][$plugin_type]);
if ($active_type == $plugin_type) {
foreach ($plugins as $plugin) {
$bottom_row[] = new tabobject($plugin->id, $plugin->link, $plugin->string);
if ($plugin->id == $active_plugin) {
$inactive = array($plugin->id);
}
}
}
}
// Do not display rows that contain only one item, they are not helpful.
if (count($top_row) > 1) {
$tabs[] = $top_row;
}
if (count($bottom_row) > 1) {
$tabs[] = $bottom_row;
}
if (empty($tabs)) {
return;
}
$rv = html_writer::div(print_tabs($tabs, $active_plugin, $inactive, $activated, true), 'grade-navigation');
if ($return) {
return $rv;
} else {
echo $rv;
}
}
/**
* Print grading plugin selection popup form.
*
* @deprecated since Moodle 4.0. Dropdown box navigation has been replaced with tertiary navigation.
* @param array $plugin_info An array of plugins containing information for the selector
* @param boolean $return return as string
*
* @return nothing or string if $return true
*/
function print_grade_plugin_selector($plugin_info, $active_type, $active_plugin, $return=false) {
global $CFG, $OUTPUT, $PAGE;
debugging('print_grade_plugin_selector() has been deprecated. Dropdown box navigation has been replaced ' .
'with tertiary navigation.', DEBUG_DEVELOPER);
$menu = array();
$count = 0;
$active = '';
foreach ($plugin_info as $plugin_type => $plugins) {
if ($plugin_type == 'strings') {
continue;
}
$first_plugin = reset($plugins);
$sectionname = $plugin_info['strings'][$plugin_type];
$section = array();
foreach ($plugins as $plugin) {
$link = $plugin->link->out(false);
$section[$link] = $plugin->string;
$count++;
if ($plugin_type === $active_type and $plugin->id === $active_plugin) {
$active = $link;
}
}
if ($section) {
$menu[] = array($sectionname=>$section);
}
}
// finally print/return the popup form
if ($count > 1) {
$select = new url_select($menu, $active, null, 'choosepluginreport');
$select->set_label(get_string('gradereport', 'grades'), array('class' => 'accesshide'));
if ($return) {
return $OUTPUT->render($select);
} else {
echo $OUTPUT->render($select);
}
} else {
// only one option - no plugin selector needed
return '';
}
/**
* Purge the cache of a course section.
*
* $sectioninfo must have following attributes:
* - course: course id
* - section: section number
*
* @param object $sectioninfo section info
* @return void
* @deprecated since Moodle 4.0. Please use {@link course_modinfo::purge_course_section_cache_by_id()}
* or {@link course_modinfo::purge_course_section_cache_by_number()} instead.
*/
function course_purge_section_cache(object $sectioninfo): void {
debugging(__FUNCTION__ . '() is deprecated. ' .
'Please use course_modinfo::purge_course_section_cache_by_id() ' .
'or course_modinfo::purge_course_section_cache_by_number() instead.',
DEBUG_DEVELOPER);
$sectionid = $sectioninfo->section;
$courseid = $sectioninfo->course;
course_modinfo::purge_course_section_cache_by_id($courseid, $sectionid);
}
/**
* Purge the cache of a course module.
*
* $cm must have following attributes:
* - id: cmid
* - course: course id
*
* @param cm_info|stdClass $cm course module
* @return void
* @deprecated since Moodle 4.0. Please use {@link course_modinfo::purge_course_module_cache()} instead.
*/
function course_purge_module_cache($cm): void {
debugging(__FUNCTION__ . '() is deprecated. ' . 'Please use course_modinfo::purge_course_module_cache() instead.',
DEBUG_DEVELOPER);
$cmid = $cm->id;
$courseid = $cm->course;
course_modinfo::purge_course_module_cache($courseid, $cmid);
}
}
/**
* For a given course, returns an array of course activity objects
* Each item in the array contains he following properties:
*
* @param int $courseid course id
* @param bool $usecache get activities from cache if modinfo exists when $usecache is true
* @return array list of activities
* @deprecated since Moodle 4.0. Please use {@link course_modinfo::get_array_of_activities()} instead.
*/
function get_array_of_activities(int $courseid, bool $usecache = false): array {
debugging(__FUNCTION__ . '() is deprecated. ' . 'Please use course_modinfo::get_array_of_activities() instead.',
DEBUG_DEVELOPER);
return course_modinfo::get_array_of_activities(get_course($courseid), $usecache);
}
/**
* Abort execution by throwing of a general exception,
* default exception handler displays the error message in most cases.
*
* @deprecated since Moodle 4.1
* @todo MDL-74484 Final deprecation in Moodle 4.5.
* @param string $errorcode The name of the language string containing the error message.
* Normally this should be in the error.php lang file.
* @param string $module The language file to get the error message from.
* @param string $link The url where the user will be prompted to continue.
* If no url is provided the user will be directed to the site index page.
* @param object $a Extra words and phrases that might be required in the error string
* @param string $debuginfo optional debugging information
* @return void, always throws exception!
*/
function print_error($errorcode, $module = 'error', $link = '', $a = null, $debuginfo = null) {
debugging("The function print_error() is deprecated. " .
"Please throw a new moodle_exception instance instead.", DEBUG_DEVELOPER);
throw new \moodle_exception($errorcode, $module, $link, $a, $debuginfo);
}