From a68dfa7ba288386bb78b2270b06e3f88aec27359 Mon Sep 17 00:00:00 2001 From: paolo Date: Tue, 28 Jun 2016 18:13:20 +0200 Subject: [PATCH] Added method postChangeStatus to controller Message --- .../controllers/api/v1/system/Message.php | 22 ++++++++++++++++ application/libraries/MessageLib.php | 25 +++++++++---------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/application/controllers/api/v1/system/Message.php b/application/controllers/api/v1/system/Message.php index 2451eb044..6b9fdf9ef 100644 --- a/application/controllers/api/v1/system/Message.php +++ b/application/controllers/api/v1/system/Message.php @@ -119,6 +119,28 @@ class Message extends APIv1_Controller } } + /** + * @return void + */ + public function postChangeStatus() + { + $person_id = $this->post()['person_id']; + $message_id = $this->post()['message_id']; + $status = $this->post()['status']; + + if (isset($person_id) && isset($message_id) && isset($status) && + in_array($status, array(MSG_STATUS_UNREAD, MSG_STATUS_READ, MSG_STATUS_ARCHIVED, MSG_STATUS_DELETED))) + { + $result = $this->messagelib->updateMessageStatus($message_id, $person_id, $status); + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } + private function _validatePostMessage($message = null) { if (!isset($message)) diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 2fe4735d5..440d75357 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -118,31 +118,30 @@ class MessageLib * @param integer $status_id REQUIRED - should come from config/message.php list of constants * @return array */ - function updateMessageStatus($msg_id, $user_id, $status_id ) + function updateMessageStatus($message_id, $person_id, $status) { - if (empty($msg_id)) + if (empty($message_id)) { return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID); } - if (empty($user_id)) + if (empty($person_id)) { return $this->_invalid_id(MSG_ERR_INVALID_USER_ID); } - if (empty($status_id)) + // Not use empty otherwise if status is 0 it returns an error + if (!isset($status)) { return $this->_invalid_id(MSG_ERR_INVALID_STATUS_ID); } - if ($this->ci->message_model->update_message_status($msg_id, $user_id, $status_id)) - { - return $this->_success(NULL, MSG_STATUS_UPDATE); - } - - // General Error Occurred - return $this->_general_error(); - + $result = $this->ci->MsgStatusModel->update( + array('message_id' => $message_id, 'person_id' => $person_id), + array('status' => $status) + ); + + return $result; } // ------------------------------------------------------------------------ @@ -343,4 +342,4 @@ class MessageLib 'msg' => lang('message_'.$error) ); } -} +} \ No newline at end of file