mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-12-25 04:58:59 +00:00
Can get the number of unread notifications
This commit is contained in:
parent
abecb78111
commit
b9406731a4
30
RestControllers/notificationsController.php
Normal file
30
RestControllers/notificationsController.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Notifications REST controller
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
class notificationsController {
|
||||
|
||||
|
||||
/**
|
||||
* Get the number of unread notifications of a user
|
||||
*
|
||||
* @url POST notifications/count_unread
|
||||
*/
|
||||
public function count_unread(){
|
||||
|
||||
user_login_required();
|
||||
|
||||
//Get the number of unread notifications
|
||||
$number = components()->notifications->count_unread(userID);
|
||||
|
||||
//Return it
|
||||
return array(
|
||||
"number" => $number
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -13,6 +13,24 @@ class notificationComponent {
|
||||
*/
|
||||
const NOTIFICATIONS_TABLE = "comunic_notifications";
|
||||
|
||||
/**
|
||||
* Count the number of unread notifications of a user
|
||||
*
|
||||
* @param int $userID Target user ID
|
||||
* @return int The number of unread notifications
|
||||
*/
|
||||
public function count_unread(int $userID) : int {
|
||||
|
||||
//Set the conditions of the request
|
||||
$conditions = "WHERE dest_user_id = ? AND seen = 0";
|
||||
$values = array($userID);
|
||||
|
||||
//Compute and return result
|
||||
return CS::get()->db->count(self::NOTIFICATIONS_TABLE, $conditions, $values);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Push a new notification
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user