MDL-63303 message: add count_contacts api function

This commit is contained in:
Ryan Wyllie 2018-11-09 13:20:04 +08:00
parent b3bbd4a0e1
commit ecb4755c91
2 changed files with 44 additions and 0 deletions

View file

@ -1001,6 +1001,21 @@ class api {
return [];
}
/**
* Returns the contacts count.
*
* @param int $userid The user id
* @return array
*/
public static function count_contacts(int $userid) : int {
global $DB;
$sql = "SELECT COUNT(id)
FROM {message_contacts}
WHERE userid = ? OR contactid = ?";
return $DB->count_records_sql($sql, [$userid, $userid]);
}
/**
* Returns the an array of the users the given user is in a conversation
* with who are a contact and the number of unread messages.