mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'MDL-63966' of https://github.com/Chocolate-lightning/moodle
This commit is contained in:
commit
3d7a8a09ba
@ -748,57 +748,12 @@ function print_side_block() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a basic textarea field.
|
||||
*
|
||||
* This was 'deprecated' in 2.0, but not properly (there was no alternative) so the
|
||||
* debugging message was commented out.
|
||||
*
|
||||
* @deprecated since Moodle 3.6
|
||||
*
|
||||
* 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() is deprecated. Please use $OUTPUT->print_textarea() instead.', DEBUG_DEVELOPER);
|
||||
|
||||
global $OUTPUT;
|
||||
|
||||
$mincols = 65;
|
||||
$minrows = 10;
|
||||
|
||||
if ($id === '') {
|
||||
$id = 'edit-'.$name;
|
||||
}
|
||||
|
||||
if ($height && ($rows < $minrows)) {
|
||||
$rows = $minrows;
|
||||
}
|
||||
if ($width && ($cols < $mincols)) {
|
||||
$cols = $mincols;
|
||||
}
|
||||
|
||||
$textarea = $OUTPUT->print_textarea($name, $id, $value, $rows, $cols);
|
||||
if ($return) {
|
||||
return $textarea;
|
||||
}
|
||||
|
||||
echo $textarea;
|
||||
function print_textarea() {
|
||||
throw new coding_exception(
|
||||
'print_textarea() has been removed. Please use $OUTPUT->print_textarea() instead.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2668,542 +2623,133 @@ function message_delete_message() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
throw new coding_exception(
|
||||
'calendar_get_all_allowed_types() has been removed. Please use calendar_get_allowed_types() instead.'
|
||||
);
|
||||
|
||||
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 (core_course_category::has_manage_capability_on_any()) {
|
||||
$types['category'] = core_course_category::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.
|
||||
* @deprecated since Moodle 3.6.
|
||||
*/
|
||||
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;
|
||||
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.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the capabilities that have been cached in the database for this
|
||||
* component.
|
||||
* @deprecated since Moodle 3.6. Please use the Events 2 API.
|
||||
* @todo final deprecation. To be removed in Moodle 4.0
|
||||
*
|
||||
* @access protected To be used from eventslib only
|
||||
*
|
||||
* @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
|
||||
* @return array of events
|
||||
*/
|
||||
function events_get_cached($component) {
|
||||
global $DB;
|
||||
|
||||
debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
$cachedhandlers = array();
|
||||
|
||||
if ($storedhandlers = $DB->get_records('events_handlers', array('component'=>$component))) {
|
||||
foreach ($storedhandlers as $handler) {
|
||||
$cachedhandlers[$handler->eventname] = array (
|
||||
'id' => $handler->id,
|
||||
'handlerfile' => $handler->handlerfile,
|
||||
'handlerfunction' => $handler->handlerfunction,
|
||||
'schedule' => $handler->schedule,
|
||||
'internal' => $handler->internal);
|
||||
}
|
||||
}
|
||||
|
||||
return $cachedhandlers;
|
||||
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.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all event handlers and queued events
|
||||
* @deprecated since Moodle 3.6. Please use the Events 2 API.
|
||||
* @todo final deprecation. To be removed in Moodle 4.0
|
||||
*
|
||||
* @category event
|
||||
* @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
|
||||
*/
|
||||
function events_uninstall($component) {
|
||||
debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
$cachedhandlers = events_get_cached($component);
|
||||
events_cleanup($component, $cachedhandlers);
|
||||
|
||||
events_get_handlers('reset');
|
||||
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.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes cached events that are no longer needed by the component.
|
||||
* @deprecated since Moodle 3.6. Please use the Events 2 API.
|
||||
* @todo final deprecation. To be removed in Moodle 4.0
|
||||
*
|
||||
* @access protected To be used from eventslib only
|
||||
*
|
||||
* @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
|
||||
* @param array $cachedhandlers array of the cached events definitions that will be
|
||||
* @return int number of unused handlers that have been removed
|
||||
*/
|
||||
function events_cleanup($component, $cachedhandlers) {
|
||||
global $DB;
|
||||
debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
$deletecount = 0;
|
||||
foreach ($cachedhandlers as $eventname => $cachedhandler) {
|
||||
if ($qhandlers = $DB->get_records('events_queue_handlers', array('handlerid'=>$cachedhandler['id']))) {
|
||||
//debugging("Removing pending events from queue before deleting of event handler: $component - $eventname");
|
||||
foreach ($qhandlers as $qhandler) {
|
||||
events_dequeue($qhandler);
|
||||
}
|
||||
}
|
||||
$DB->delete_records('events_handlers', array('eventname'=>$eventname, 'component'=>$component));
|
||||
$deletecount++;
|
||||
}
|
||||
|
||||
return $deletecount;
|
||||
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.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes this queued handler from the events_queued_handler table
|
||||
*
|
||||
* Removes events_queue record from events_queue if no more references to this event object exists
|
||||
* @deprecated since Moodle 3.6. Please use the Events 2 API.
|
||||
* @todo final deprecation. To be removed in Moodle 4.0
|
||||
*
|
||||
* @access protected To be used from eventslib only
|
||||
*
|
||||
* @param stdClass $qhandler A row from the events_queued_handler table
|
||||
*/
|
||||
function events_dequeue($qhandler) {
|
||||
global $DB;
|
||||
debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
// first delete the queue handler
|
||||
$DB->delete_records('events_queue_handlers', array('id'=>$qhandler->id));
|
||||
|
||||
// if no more queued handler is pointing to the same event - delete the event too
|
||||
if (!$DB->record_exists('events_queue_handlers', array('queuedeventid'=>$qhandler->queuedeventid))) {
|
||||
$DB->delete_records('events_queue', array('id'=>$qhandler->queuedeventid));
|
||||
}
|
||||
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.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns handlers for given event. Uses caching for better perf.
|
||||
* @deprecated since Moodle 3.6. Please use the Events 2 API.
|
||||
* @todo final deprecation. To be removed in Moodle 4.0
|
||||
*
|
||||
* @access protected To be used from eventslib only
|
||||
*
|
||||
* @staticvar array $handlers
|
||||
* @param string $eventname name of event or 'reset'
|
||||
* @return array|false array of handlers or false otherwise
|
||||
*/
|
||||
function events_get_handlers($eventname) {
|
||||
global $DB;
|
||||
static $handlers = array();
|
||||
debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
if ($eventname === 'reset') {
|
||||
$handlers = array();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!array_key_exists($eventname, $handlers)) {
|
||||
$handlers[$eventname] = $DB->get_records('events_handlers', array('eventname'=>$eventname));
|
||||
}
|
||||
|
||||
return $handlers[$eventname];
|
||||
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.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function finds the roles assigned directly to this context only
|
||||
* i.e. no roles in parent contexts
|
||||
*
|
||||
* @deprecated since Moodle 3.6. Please use the get_roles_used_in_context().
|
||||
* @todo final deprecation. To be removed in Moodle 4.0
|
||||
* @param context $context
|
||||
* @return array
|
||||
*/
|
||||
function get_roles_on_exact_context(context $context) {
|
||||
debugging('get_roles_on_exact_context() is deprecated, please use get_roles_used_in_context() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
return get_roles_used_in_context($context, false);
|
||||
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.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out which roles has assignment on this context
|
||||
*
|
||||
* @deprecated since Moodle 3.6. Please use the get_roles_used_in_context().
|
||||
* @todo final deprecation. To be removed in Moodle 4.0
|
||||
* @param context $context
|
||||
* @return array
|
||||
*/
|
||||
function get_roles_with_assignment_on_context(context $context) {
|
||||
debugging('get_roles_with_assignment_on_context() is deprecated, please use get_roles_used_in_context() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
return get_roles_used_in_context($context, false);
|
||||
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.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the selected user as a contact for the current user
|
||||
*
|
||||
* @deprecated since Moodle 3.6
|
||||
* @param int $contactid the ID of the user to add as a contact
|
||||
* @param int $blocked 1 if you wish to block the contact
|
||||
* @param int $userid the user ID of the user we want to add the contact for, defaults to current user if not specified.
|
||||
* @return bool/int false if the $contactid isnt a valid user id. True if no changes made.
|
||||
* Otherwise returns the result of update_record() or insert_record()
|
||||
*/
|
||||
function message_add_contact($contactid, $blocked = 0, $userid = 0) {
|
||||
debugging('message_add_contact() is deprecated. Please use \core_message\api::create_contact_request() instead. ' .
|
||||
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.', DEBUG_DEVELOPER);
|
||||
|
||||
global $USER, $DB;
|
||||
|
||||
if (!$DB->record_exists('user', array('id' => $contactid))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($userid)) {
|
||||
$userid = $USER->id;
|
||||
}
|
||||
|
||||
// Check if a record already exists as we may be changing blocking status.
|
||||
if (\core_message\api::is_contact($userid, $contactid)) {
|
||||
$isblocked = \core_message\api::is_blocked($userid, $contactid);
|
||||
// Check if blocking status has been changed.
|
||||
if ($isblocked != $blocked) {
|
||||
if ($blocked == 1) {
|
||||
if (!$isblocked) {
|
||||
\core_message\api::block_user($userid, $contactid);
|
||||
}
|
||||
} else {
|
||||
\core_message\api::unblock_user($userid, $contactid);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
// No change to blocking status.
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if ($blocked == 1) {
|
||||
if (!\core_message\api::is_blocked($userid, $contactid)) {
|
||||
\core_message\api::block_user($userid, $contactid);
|
||||
}
|
||||
} else {
|
||||
\core_message\api::unblock_user($userid, $contactid);
|
||||
if (!\core_message\api::does_contact_request_exist($userid, $contactid)) {
|
||||
\core_message\api::create_contact_request($userid, $contactid);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
'\core_message\api::block_user() or \core_message\api::unblock_user() respectively.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a contact.
|
||||
*
|
||||
* @deprecated since Moodle 3.6
|
||||
* @param int $contactid the user ID of the contact to remove
|
||||
* @param int $userid the user ID of the user we want to remove the contacts for, defaults to current user if not specified.
|
||||
* @return bool returns the result of delete_records()
|
||||
*/
|
||||
function message_remove_contact($contactid, $userid = 0) {
|
||||
debugging('message_remove_contact() is deprecated. Please use \core_message\api::remove_contact() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
global $USER;
|
||||
|
||||
if (empty($userid)) {
|
||||
$userid = $USER->id;
|
||||
}
|
||||
|
||||
\core_message\api::remove_contact($userid, $contactid);
|
||||
|
||||
return true;
|
||||
function message_remove_contact() {
|
||||
throw new coding_exception(
|
||||
'message_remove_contact() has been removed. Please use \core_message\api::remove_contact() instead.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unblock a contact.
|
||||
*
|
||||
* @deprecated since Moodle 3.6
|
||||
* @param int $contactid the user ID of the contact to unblock
|
||||
* @param int $userid the user ID of the user we want to unblock the contact for, defaults to current user
|
||||
* if not specified.
|
||||
* @return bool returns the result of delete_records()
|
||||
*/
|
||||
function message_unblock_contact($contactid, $userid = 0) {
|
||||
debugging('message_unblock_contact() is deprecated. Please use \core_message\api::unblock_user() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
global $DB, $USER;
|
||||
|
||||
if (!$DB->record_exists('user', array('id' => $contactid))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($userid)) {
|
||||
$userid = $USER->id;
|
||||
}
|
||||
|
||||
\core_message\api::unblock_user($userid, $contactid);
|
||||
|
||||
return true;
|
||||
function message_unblock_contact() {
|
||||
throw new coding_exception(
|
||||
'message_unblock_contact() has been removed. Please use \core_message\api::unblock_user() instead.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Block a user.
|
||||
*
|
||||
* @deprecated since Moodle 3.6
|
||||
* @param int $contactid the user ID of the user to block
|
||||
* @param int $userid the user ID of the user we want to unblock the contact for, defaults to current user
|
||||
* if not specified.
|
||||
* @return bool
|
||||
*/
|
||||
function message_block_contact($contactid, $userid = 0) {
|
||||
debugging('message_block_contact() is deprecated. Please use \core_message\api::is_blocked() and ' .
|
||||
'\core_message\api::block_user() instead.', DEBUG_DEVELOPER);
|
||||
|
||||
global $DB, $USER;
|
||||
|
||||
if (!$DB->record_exists('user', array('id' => $contactid))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($userid)) {
|
||||
$userid = $USER->id;
|
||||
}
|
||||
|
||||
if (!\core_message\api::is_blocked($userid, $contactid)) {
|
||||
\core_message\api::block_user($userid, $contactid);
|
||||
}
|
||||
|
||||
return true;
|
||||
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.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a user's contact record
|
||||
*
|
||||
* @deprecated since Moodle 3.6
|
||||
* @param int $contactid the user ID of the user whose contact record you want
|
||||
* @return array message contacts
|
||||
*/
|
||||
function message_get_contact($contactid) {
|
||||
debugging('message_get_contact() is deprecated. Please use \core_message\api::get_contact() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
global $USER;
|
||||
|
||||
return \core_message\api::get_contact($USER->id, $contactid);
|
||||
function message_get_contact() {
|
||||
throw new coding_exception(
|
||||
'message_get_contact() has been removed. Please use \core_message\api::get_contact() instead.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -596,7 +596,7 @@ class core_event_testcase extends advanced_testcase {
|
||||
events_update_definition('unittest');
|
||||
|
||||
$DB->delete_records_select('events_handlers', "component <> 'unittest'");
|
||||
events_get_handlers('reset');
|
||||
|
||||
$this->assertDebuggingCalled(self::DEBUGGING_MSG, DEBUG_DEVELOPER);
|
||||
$this->assertEquals(3, $DB->count_records('events_handlers'));
|
||||
set_config('loglifetime', 60*60*24*5);
|
||||
|
@ -9,6 +9,22 @@ information provided here is intended especially for developers.
|
||||
* The `$CFG->behat_retart_browser_after` configuration setting has been removed.
|
||||
The browser session is now restarted between all tests.
|
||||
* add_to_log() has been through final deprecation, please rewrite your code to the new events API.
|
||||
* The following functions have been finally deprecated and can not be used anymore:
|
||||
- print_textarea
|
||||
- calendar_get_all_allowed_types
|
||||
- groups_get_all_groups_for_courses
|
||||
- events_get_cached
|
||||
- events_uninstall
|
||||
- events_cleanup
|
||||
- events_dequeue
|
||||
- events_get_handlers
|
||||
- get_roles_on_exact_context
|
||||
- get_roles_with_assignment_on_context
|
||||
- message_add_contact
|
||||
- message_remove_contact
|
||||
- message_unblock_contact
|
||||
- message_block_contact
|
||||
- message_get_contact
|
||||
|
||||
=== 3.9 ===
|
||||
* Following function has been deprecated, please use \core\task\manager::run_from_cli().
|
||||
|
@ -292,6 +292,7 @@ class core_message_external extends external_api {
|
||||
* Create contacts.
|
||||
*
|
||||
* @deprecated since Moodle 3.6
|
||||
* TODO: MDL-63261
|
||||
* @param array $userids array of user IDs.
|
||||
* @param int $userid The id of the user we are creating the contacts for
|
||||
* @return external_description
|
||||
@ -323,7 +324,7 @@ class core_message_external extends external_api {
|
||||
|
||||
$warnings = array();
|
||||
foreach ($params['userids'] as $id) {
|
||||
if (!message_add_contact($id, 0, $params['userid'])) {
|
||||
if (!\core_message\api::create_contact_request($params['userid'], $id)) {
|
||||
$warnings[] = array(
|
||||
'item' => 'user',
|
||||
'itemid' => $id,
|
||||
@ -682,6 +683,7 @@ class core_message_external extends external_api {
|
||||
* Block contacts.
|
||||
*
|
||||
* @deprecated since Moodle 3.6
|
||||
* TODO: MDL-63261
|
||||
* @param array $userids array of user IDs.
|
||||
* @param int $userid The id of the user we are blocking the contacts for
|
||||
* @return external_description
|
||||
@ -713,7 +715,7 @@ class core_message_external extends external_api {
|
||||
|
||||
$warnings = array();
|
||||
foreach ($params['userids'] as $id) {
|
||||
if (!message_block_contact($id, $params['userid'])) {
|
||||
if (!\core_message\api::block_user($params['userid'], $id)) {
|
||||
$warnings[] = array(
|
||||
'item' => 'user',
|
||||
'itemid' => $id,
|
||||
@ -798,7 +800,7 @@ class core_message_external extends external_api {
|
||||
}
|
||||
|
||||
foreach ($params['userids'] as $id) {
|
||||
message_unblock_contact($id, $params['userid']);
|
||||
core_message\api::unblock_user($params['userid'], $id);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -340,6 +340,8 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test create_contacts.
|
||||
*
|
||||
* TODO: MDL-63261
|
||||
*/
|
||||
public function test_create_contacts() {
|
||||
$this->resetAfterTest(true);
|
||||
@ -351,41 +353,17 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
|
||||
$user5 = self::getDataGenerator()->create_user();
|
||||
$this->setUser($user1);
|
||||
|
||||
// Adding a contact.
|
||||
$return = core_message_external::create_contacts(array($user2->id));
|
||||
$this->assertDebuggingCalled();
|
||||
$return = external_api::clean_returnvalue(core_message_external::create_contacts_returns(), $return);
|
||||
$this->assertEquals(array(), $return);
|
||||
|
||||
// Adding a contact who is already a contact.
|
||||
$return = core_message_external::create_contacts(array($user2->id));
|
||||
$this->assertDebuggingCalled();
|
||||
$return = external_api::clean_returnvalue(core_message_external::create_contacts_returns(), $return);
|
||||
$this->assertEquals(array(), $return);
|
||||
|
||||
// Adding multiple contacts.
|
||||
$return = core_message_external::create_contacts(array($user3->id, $user4->id));
|
||||
$this->assertDebuggingCalledCount(2);
|
||||
$return = external_api::clean_returnvalue(core_message_external::create_contacts_returns(), $return);
|
||||
$this->assertEquals(array(), $return);
|
||||
|
||||
// Adding a non-existing user.
|
||||
$return = core_message_external::create_contacts(array(99999));
|
||||
$this->assertDebuggingCalled();
|
||||
$return = external_api::clean_returnvalue(core_message_external::create_contacts_returns(), $return);
|
||||
$this->assertCount(1, $return);
|
||||
$return = array_pop($return);
|
||||
$this->assertEquals($return['warningcode'], 'contactnotcreated');
|
||||
$this->assertEquals($return['itemid'], 99999);
|
||||
|
||||
// Adding contacts with valid and invalid parameters.
|
||||
$return = core_message_external::create_contacts(array($user5->id, 99999));
|
||||
$this->assertDebuggingCalledCount(2);
|
||||
$return = external_api::clean_returnvalue(core_message_external::create_contacts_returns(), $return);
|
||||
$this->assertCount(1, $return);
|
||||
$return = array_pop($return);
|
||||
$this->assertEquals($return['warningcode'], 'contactnotcreated');
|
||||
$this->assertEquals($return['itemid'], 99999);
|
||||
// Note: We should add real user checks in api L:2656.
|
||||
|
||||
// Try to add a contact to another user, should throw an exception.
|
||||
// All assertions must be added before this point.
|
||||
@ -455,36 +433,36 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
|
||||
\core_message\api::add_contact($user1->id, $user4->id);
|
||||
\core_message\api::add_contact($user1->id, $user5->id);
|
||||
|
||||
// Blocking a contact.
|
||||
$return = core_message_external::block_contacts(array($user2->id));
|
||||
$this->assertDebuggingCalled();
|
||||
$return = external_api::clean_returnvalue(core_message_external::block_contacts_returns(), $return);
|
||||
$this->assertEquals(array(), $return);
|
||||
|
||||
// Blocking a contact who is already a contact.
|
||||
$return = core_message_external::block_contacts(array($user2->id));
|
||||
$this->assertDebuggingCalled();
|
||||
$return = external_api::clean_returnvalue(core_message_external::block_contacts_returns(), $return);
|
||||
$this->assertEquals(array(), $return);
|
||||
$this->assertEquals(array(array(
|
||||
'item' => 'user',
|
||||
'itemid' => $user2->id,
|
||||
'warningcode' => 'contactnotblocked',
|
||||
'message' => 'The contact could not be blocked'
|
||||
)), $return);
|
||||
|
||||
// Blocking multiple contacts.
|
||||
$return = core_message_external::block_contacts(array($user3->id, $user4->id));
|
||||
$this->assertDebuggingCalledCount(2);
|
||||
$return = external_api::clean_returnvalue(core_message_external::block_contacts_returns(), $return);
|
||||
$this->assertEquals(array(), $return);
|
||||
$this->assertEquals(array(
|
||||
array(
|
||||
'item' => 'user',
|
||||
'itemid' => $user3->id,
|
||||
'warningcode' => 'contactnotblocked',
|
||||
'message' => 'The contact could not be blocked'
|
||||
),
|
||||
array(
|
||||
'item' => 'user',
|
||||
'itemid' => $user4->id,
|
||||
'warningcode' => 'contactnotblocked',
|
||||
'message' => 'The contact could not be blocked'
|
||||
)
|
||||
), $return);
|
||||
|
||||
// Blocking a non-existing user.
|
||||
$return = core_message_external::block_contacts(array(99999));
|
||||
$this->assertDebuggingCalled();
|
||||
$return = external_api::clean_returnvalue(core_message_external::block_contacts_returns(), $return);
|
||||
$this->assertCount(1, $return);
|
||||
$return = array_pop($return);
|
||||
$this->assertEquals($return['warningcode'], 'contactnotblocked');
|
||||
$this->assertEquals($return['itemid'], 99999);
|
||||
|
||||
// Blocking contacts with valid and invalid parameters.
|
||||
$return = core_message_external::block_contacts(array($user5->id, 99999));
|
||||
$this->assertDebuggingCalledCount(2);
|
||||
$return = external_api::clean_returnvalue(core_message_external::block_contacts_returns(), $return);
|
||||
$this->assertCount(1, $return);
|
||||
$return = array_pop($return);
|
||||
@ -518,34 +496,28 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// Removing a non-contact.
|
||||
$return = core_message_external::unblock_contacts(array($user2->id));
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertNull($return);
|
||||
|
||||
// Removing one contact.
|
||||
$return = core_message_external::unblock_contacts(array($user3->id));
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertNull($return);
|
||||
|
||||
// Removing multiple contacts.
|
||||
$return = core_message_external::unblock_contacts(array($user4->id, $user5->id));
|
||||
$this->assertDebuggingCalledCount(2);
|
||||
$this->assertNull($return);
|
||||
|
||||
// Removing contact from unexisting user.
|
||||
$return = core_message_external::unblock_contacts(array(99999));
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertNull($return);
|
||||
|
||||
// Removing mixed valid and invalid data.
|
||||
$return = core_message_external::unblock_contacts(array($user6->id, 99999));
|
||||
$this->assertDebuggingCalledCount(2);
|
||||
$this->assertNull($return);
|
||||
|
||||
// Try to unblock a contact of another user contact list, should throw an exception.
|
||||
// All assertions must be added before this point.
|
||||
$this->expectException('required_capability_exception');
|
||||
core_message_external::unblock_contacts(array($user2->id), $user3->id);
|
||||
$this->assertDebuggingCalled();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1392,7 +1364,6 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
|
||||
$this->assertCount(1, $contacts['online']);
|
||||
$this->assertCount(3, $contacts['strangers']);
|
||||
core_message_external::block_contacts(array($user_blocked->id));
|
||||
$this->assertDebuggingCalled();
|
||||
$contacts = core_message_external::get_contacts();
|
||||
$contacts = external_api::clean_returnvalue(core_message_external::get_contacts_returns(), $contacts);
|
||||
$this->assertCount(3, $contacts['offline']);
|
||||
@ -1822,7 +1793,6 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
|
||||
|
||||
// Block the $userblocked and retrieve again the list.
|
||||
core_message_external::block_contacts(array($userblocked->id));
|
||||
$this->assertDebuggingCalled();
|
||||
$blockedusers = core_message_external::get_blocked_users($user1->id);
|
||||
$blockedusers = external_api::clean_returnvalue(core_message_external::get_blocked_users_returns(), $blockedusers);
|
||||
$this->assertCount(1, $blockedusers['users']);
|
||||
|
@ -223,102 +223,6 @@ class core_message_messagelib_testcase extends advanced_testcase {
|
||||
$this->assertEquals(0, message_count_unread_messages($userfrom));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test message_add_contact.
|
||||
*/
|
||||
public function test_message_add_contact() {
|
||||
global $DB, $USER;
|
||||
|
||||
// Set this user as the admin.
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create a user to add to the admin's contact list.
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
|
||||
message_add_contact($user1->id);
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertEquals(1, $DB->count_records('message_contact_requests'));
|
||||
|
||||
message_add_contact($user2->id, 1);
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertEquals(1, $DB->count_records('message_users_blocked'));
|
||||
|
||||
message_add_contact($user2->id, 0);
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertEquals(0, $DB->count_records('message_users_blocked'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test message_remove_contact.
|
||||
*/
|
||||
public function test_message_remove_contact() {
|
||||
global $USER;
|
||||
|
||||
// Set this user as the admin.
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create a user to add to the admin's contact list.
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
|
||||
// Add the user to the admin's contact list.
|
||||
\core_message\api::add_contact($USER->id, $user->id);
|
||||
|
||||
// Remove user from admin's contact list.
|
||||
message_remove_contact($user->id);
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertEquals(false, message_get_contact($user->id));
|
||||
$this->assertDebuggingCalled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test message_block_contact.
|
||||
*/
|
||||
public function test_message_block_contact() {
|
||||
global $USER;
|
||||
|
||||
// Set this user as the admin.
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create a user to add to the admin's contact list.
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
|
||||
// Add users to the admin's contact list.
|
||||
\core_message\api::add_contact($USER->id, $user1->id);
|
||||
\core_message\api::add_contact($USER->id, $user2->id);
|
||||
|
||||
$this->assertEquals(0, \core_message\api::count_blocked_users());
|
||||
|
||||
// Block 1 user.
|
||||
message_block_contact($user2->id);
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertEquals(1, \core_message\api::count_blocked_users());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test message_unblock_contact.
|
||||
*/
|
||||
public function test_message_unblock_contact() {
|
||||
global $USER;
|
||||
|
||||
// Set this user as the admin.
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create a user to add to the admin's contact list.
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
|
||||
// Add users to the admin's blocked list.
|
||||
\core_message\api::block_user($USER->id, $user1->id);
|
||||
$this->assertEquals(1, \core_message\api::count_blocked_users());
|
||||
|
||||
// Unblock user.
|
||||
message_unblock_contact($user1->id);
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertEquals(0, \core_message\api::count_blocked_users());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test message_search_users.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user