Permalink
Browse files

Merge branch 'MDL-64140-master' of https://github.com/snake/moodle

  • Loading branch information...
dmonllao committed Nov 26, 2018
2 parents 9f61908 + 36fabf7 commit 65c6723681deccfc952a784fa9128d1b20b36af1
Showing with 483 additions and 157 deletions.
  1. +9 −0 lib/db/services.php
  2. +75 −0 message/externallib.php
  3. +192 −115 message/tests/api_test.php
  4. +206 −41 message/tests/externallib_test.php
  5. +1 −1 version.php
@@ -1143,6 +1143,15 @@
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
'ajax' => true,
),
'core_message_get_unread_conversation_counts' => array(
'classname' => 'core_message_external',
'methodname' => 'get_unread_conversation_counts',
'classpath' => 'message/externallib.php',
'description' => 'Retrieve a list of unread conversation counts, indexed by type.',
'type' => 'read',
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
'ajax' => true,
),
'core_message_get_conversation_members' => array(
'classname' => 'core_message_external',
'methodname' => 'get_conversation_members',
@@ -4480,4 +4480,79 @@ public static function get_conversation_counts_returns() {
]
);
}
/**
* Returns description of method parameters for get_unread_conversation_counts() method.
*
* @return external_function_parameters
*/
public static function get_unread_conversation_counts_parameters() {
return new external_function_parameters(
[
'userid' => new external_value(PARAM_INT, 'id of the user, 0 for current user', VALUE_DEFAULT, 0)
]
);
}
/**
* Returns an array of unread conversation counts for the various types of conversations, including favourites.
*
* Return format:
* [
* 'favourites' => 0,
* 'types' => [
* \core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL => 0,
* \core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP => 0
* ]
* ]
*
* @param int $userid the id of the user whose counts we are fetching.
* @return array the array of unread conversation counts, indexed by type.
* @throws moodle_exception if the current user cannot perform this action.
*/
public static function get_unread_conversation_counts(int $userid) {
global $CFG, $USER;
// All the business logic checks that really shouldn't be in here.
if (empty($CFG->messaging)) {
throw new moodle_exception('disabled', 'message');
}
if (empty($userid)) {
$userid = $USER->id;
}
$params = ['userid' => $userid];
$params = self::validate_parameters(self::get_unread_conversation_counts_parameters(), $params);
$systemcontext = context_system::instance();
self::validate_context($systemcontext);
if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
throw new moodle_exception('You do not have permission to perform this action.');
}
return \core_message\api::get_unread_conversation_counts($params['userid']);
}
/**
* Get unread conversation counts return description.
*
* @return external_description
*/
public static function get_unread_conversation_counts_returns() {
return new external_single_structure(
[
'favourites' => new external_value(PARAM_INT, 'Total number of unread favourite conversations'),
'types' => new external_single_structure(
[
\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL => new external_value(PARAM_INT,
'Total number of unread individual conversations'),
\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP => new external_value(PARAM_INT,
'Total number of unread group conversations'),
]
),
]
);
}
}
Oops, something went wrong.

0 comments on commit 65c6723

Please sign in to comment.