Can get the number of friendship request with the notifications.

This commit is contained in:
Pierre HUBERT 2018-08-24 08:25:38 +02:00
parent 85582a44cc
commit e1760dd772
2 changed files with 20 additions and 1 deletions

View File

@ -40,11 +40,17 @@ class notificationsController {
user_login_required();
//Get and return the data
return array(
$data = array(
"notifications" => components()->notifications->count_unread(userID),
"conversations" => components()->conversations->number_user_unread(userID)
);
//Include friendship requests if required
if(isset($_POST["friends_request"]))
if(postBool("friends_request"))
$data["friends_request"] = components()->friends->count_requests(userID);
return $data;
}

View File

@ -409,6 +409,19 @@ class friends {
}
/**
* Count the number of friendship requests a user has received
*
* @param int $userID Target user ID
* @return int The number of friendship request the user received
*/
public function count_requests(int $userID) : int {
return db()->count(
$this->friendsTable,
"WHERE ID_personne = ? AND actif = 0",
array($userID));
}
/**
* Parse friend informations from the database
*