mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 17:06:53 +02:00
MDL-63303 message: add count_contacts api function
This commit is contained in:
parent
b3bbd4a0e1
commit
ecb4755c91
2 changed files with 44 additions and 0 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue