mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-21 08:52:21 +00:00
Added method getCountUnreadMessages
This commit is contained in:
@@ -105,6 +105,25 @@ class Message extends APIv1_Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function getCountUnreadMessages()
|
||||
{
|
||||
$person_id = $this->get('person_id');
|
||||
|
||||
if (isset($person_id))
|
||||
{
|
||||
$result = $this->messagelib->getCountUnreadMessages($person_id);
|
||||
|
||||
$this->response($result, REST_Controller::HTTP_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->response();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
||||
@@ -153,6 +153,22 @@ class MessageLib
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCountUnreadMessages
|
||||
*
|
||||
* @param bigint $person_id REQUIRED
|
||||
* @return array
|
||||
*/
|
||||
public function getCountUnreadMessages($person_id)
|
||||
{
|
||||
if (!is_numeric($person_id))
|
||||
return $this->_error('', MSG_ERR_INVALID_RECIPIENTS);
|
||||
|
||||
$msg = $this->ci->RecipientModel->getCountUnreadMessages($person_id);
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* updateMessageStatus() - will change status on message for particular user
|
||||
|
||||
@@ -259,4 +259,26 @@ class Recipient_model extends DB_Model
|
||||
|
||||
return $this->execQuery($query, $parametersArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all unread messages for a person identified by person_id
|
||||
*/
|
||||
public function getCountUnreadMessages($person_id)
|
||||
{
|
||||
// Checks if the operation is permitted by the API caller
|
||||
if (($isEntitled = $this->isEntitled('public.tbl_msg_recipient', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $isEntitled;
|
||||
if (($isEntitled = $this->isEntitled('public.tbl_msg_status', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $isEntitled;
|
||||
|
||||
$sql = 'SELECT COUNT(r.message_id) AS unreadMessages
|
||||
FROM public.tbl_msg_recipient r JOIN public.tbl_msg_status s
|
||||
ON (r.message_id = s.message_id AND r.person_id = s.person_id)
|
||||
WHERE r.person_id = ?
|
||||
AND s.status = ?';
|
||||
|
||||
$parametersArray = array($person_id, MSG_STATUS_UNREAD);
|
||||
|
||||
return $this->execQuery($sql, $parametersArray);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user