- 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;
}
}
+6 -1
View File
@@ -11,13 +11,18 @@ class MessageLib
{
private $recipients = array();
public function __construct()
public function __construct($params)
{
require_once APPPATH.'config/message.php';
$this->ci =& get_instance();
//$this->ci->load->model('person/Person_model', 'PersonModel');
$this->ci->load->model('system/Message_model', 'MessageModel');
if (is_array($params) && isset($params['uid']))
{
$this->ci->MessageModel->setUID($params['uid']);
}
$this->ci->load->model('system/MsgStatus_model', 'MsgStatusModel');
$this->ci->load->model('system/Recipient_model', 'RecipientModel');
$this->ci->load->model('system/Attachment_model', 'AttachmentModel');
+1 -1
View File
@@ -92,7 +92,7 @@ WHERE person_id = ?';
if (! $all)
$sql .= ' AND status<2';
$result = $this->db->query($sql, array($person_id));
var_dump($result);
//var_dump($result);
if (is_object($result))
return $this->_success($result->result());
else