diff --git a/RestControllers/notificationsController.php b/RestControllers/notificationsController.php index d41c102..63497b4 100644 --- a/RestControllers/notificationsController.php +++ b/RestControllers/notificationsController.php @@ -50,6 +50,12 @@ class notificationsController { if(postBool("friends_request")) $data["friends_request"] = components()->friends->count_requests(userID); + + //Include pending calls if required + if(isset($_POST["include_calls"])) + if(postBool("include_calls")) + $data["calls"] = components()->calls->countPendingResponsesForUser(userID); + return $data; } diff --git a/classes/components/CallsComponent.php b/classes/components/CallsComponent.php index 4a7f093..87fb0a8 100644 --- a/classes/components/CallsComponent.php +++ b/classes/components/CallsComponent.php @@ -147,6 +147,22 @@ class CallsComponents { return count($entries) > 0; } + /** + * Count and return the number of pending calls for a user + * + * @param $userID The ID of the target user + * @return int The number of pending calls for the user + */ + public function countPendingResponsesForUser(int $userID) : int { + + return db()->count( + self::CALLS_MEMBERS_TABLE, + "WHERE user_id = ? AND user_accepted = ?", + array($userID, CallMemberInformation::USER_UNKNOWN) + ); + + } + /** * Set the response of a member to a call *