Added method getCountUnreadMessages

This commit is contained in:
bison-paolo
2016-12-20 11:28:51 +01:00
parent b3476f93c1
commit b99123efc6
3 changed files with 57 additions and 0 deletions
@@ -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
*/
+16
View File
@@ -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);
}
}