diff --git a/lib/db/services.php b/lib/db/services.php index c9318ffc6cc..913bbeb887f 100644 --- a/lib/db/services.php +++ b/lib/db/services.php @@ -772,6 +772,15 @@ $functions = array( 'capabilities' => '', ), + 'core_message_get_blocked_users' => array( + 'classname' => 'core_message_external', + 'methodname' => 'get_blocked_users', + 'classpath' => 'message/externallib.php', + 'description' => 'Retrieve a list of users blocked', + 'type' => 'read', + 'capabilities' => '', + ), + // === notes related functions === 'moodle_notes_create_notes' => array( @@ -975,7 +984,9 @@ $services = array( 'core_message_block_contacts', 'core_message_unblock_contacts', 'core_message_get_contacts', - 'core_message_search_contacts'), + 'core_message_search_contacts', + 'core_message_get_blocked_users' + ), 'enabled' => 0, 'restrictedusers' => 0, 'shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE, diff --git a/message/externallib.php b/message/externallib.php index b1468ad9d8d..f1eb25c7029 100644 --- a/message/externallib.php +++ b/message/externallib.php @@ -829,6 +829,105 @@ class core_message_external extends external_api { ); } + /** + * Get blocked users parameters description. + * + * @return external_function_parameters + * @since 2.9 + */ + public static function get_blocked_users_parameters() { + return new external_function_parameters( + array( + 'userid' => new external_value(PARAM_INT, + 'the user whose blocked users we want to retrieve', + VALUE_REQUIRED), + ) + ); + } + + /** + * Retrieve a list of users blocked + * + * @param int $userid the user whose blocked users we want to retrieve + * @return external_description + * @since 2.9 + */ + public static function get_blocked_users($userid) { + global $CFG, $USER; + require_once($CFG->dirroot . "/message/lib.php"); + + // Warnings array, it can be empty at the end but is mandatory. + $warnings = array(); + + // Validate params. + $params = array( + 'userid' => $userid + ); + $params = self::validate_parameters(self::get_blocked_users_parameters(), $params); + $userid = $params['userid']; + + // Validate context. + $context = context_system::instance(); + self::validate_context($context); + + // Check if private messaging between users is allowed. + if (empty($CFG->messaging)) { + throw new moodle_exception('disabled', 'message'); + } + + $user = core_user::get_user($userid, 'id', MUST_EXIST); + + // Check if we have permissions for retrieve the information. + if ($userid != $USER->id and !has_capability('moodle/site:readallmessages', $context)) { + throw new moodle_exception('accessdenied', 'admin'); + } + + // Now, we can get safely all the blocked users. + $users = message_get_blocked_users($user); + + $blockedusers = array(); + foreach ($users as $user) { + $newuser = array( + 'id' => $user->id, + 'fullname' => fullname($user), + ); + $newuser['profileimageurl'] = moodle_url::make_webservice_pluginfile_url( + context_user::instance($user->id)->id, 'user', 'icon', null, '/', 'f1')->out(false); + + $blockedusers[] = $newuser; + } + + $results = array( + 'users' => $blockedusers, + 'warnings' => $warnings + ); + return $results; + } + + /** + * Get blocked users return description. + * + * @return external_single_structure + * @since 2.9 + */ + public static function get_blocked_users_returns() { + return new external_single_structure( + array( + 'users' => new external_multiple_structure( + new external_single_structure( + array( + 'id' => new external_value(PARAM_INT, 'User ID'), + 'fullname' => new external_value(PARAM_NOTAGS, 'User full name'), + 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL) + ) + ), + 'List of blocked users' + ), + 'warnings' => new external_warnings() + ) + ); + } + } /** diff --git a/version.php b/version.php index c60ff4de674..08c187e5ef6 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2015012900.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2015012900.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes.