- Modified MessageLib constructor to allow to give the parameter UID from a Controller

- Controller Message now works with MessageLib
- Added getMessagesByPersonID method to controller Message
- Added permissions basis/message and fs/system to dump.sql
This commit is contained in:
paolo
2016-06-21 15:07:51 +02:00
parent 6e62fbdcd4
commit 5a5472257a
4 changed files with 53 additions and 37 deletions
@@ -23,45 +23,20 @@ class Message extends APIv1_Controller
{
parent::__construct();
// Load model MessageModel
$this->load->model('system/message_model', 'MessageModel');
// Load set the uid of the model to let to check the permissions
$this->MessageModel->setUID($this->_getUID());
$this->load->library('MessageLib', array('uid' => $this->_getUID()));
}
/**
* @return void
*/
public function getMessage()
public function getMessagesByPersonID()
{
$messageID = $this->get('message_id');
$person_id = $this->get('person_id');
$all = $this->get('all');
if (isset($messageID))
if (isset($person_id))
{
$result = $this->MessageModel->load($messageID);
$this->response($result, REST_Controller::HTTP_OK);
}
else
{
$this->response();
}
}
/**
* @return void
*/
public function postMessage()
{
if ($this->_validate($this->post()))
{
if (isset($this->post()['message_id']))
{
$result = $this->MessageModel->update($this->post()['message_id'], $this->post());
}
else
{
$result = $this->MessageModel->insert($this->post());
}
$result = $this->messagelib->getMessagesByPerson($person_id, $all);
$this->response($result, REST_Controller::HTTP_OK);
}
@@ -71,8 +46,38 @@ class Message extends APIv1_Controller
}
}
private function _validate($message = NULL)
/**
* @return void
*/
public function postMessage()
{
if ($this->_validate($this->post()))
{
$this->messagelib->addRecipient($this->post()['person_id']);
$result = $this->messagelib->sendMessage(
$this->post()['person_id'],
$this->post()['subject'],
$this->post()['body'],
$this->post()['priority'],
$this->post()['relationmessage_id'],
$this->post()['oe_kurzbz']
);
$this->response($result, REST_Controller::HTTP_OK);
}
else
{
$this->response();
}
}
private function _validate($message = null)
{
if (!isset($message['person_id']) || !isset($message['subject']) || !isset($message['body']))
{
return false;
}
return true;
}
}