Files
FHC-Core/application/controllers/api/v1/system/Message.php
T
paolo 5a5472257a - 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
2016-06-21 15:07:51 +02:00

83 lines
1.6 KiB
PHP

<?php
/**
* FH-Complete
*
* @package FHC-API
* @author FHC-Team
* @copyright Copyright (c) 2016, fhcomplete.org
* @license GPLv3
* @link http://fhcomplete.org
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Message extends APIv1_Controller
{
/**
* Message API constructor.
*/
public function __construct()
{
parent::__construct();
// Load model MessageModel
$this->load->library('MessageLib', array('uid' => $this->_getUID()));
}
/**
* @return void
*/
public function getMessagesByPersonID()
{
$person_id = $this->get('person_id');
$all = $this->get('all');
if (isset($person_id))
{
$result = $this->messagelib->getMessagesByPerson($person_id, $all);
$this->response($result, REST_Controller::HTTP_OK);
}
else
{
$this->response();
}
}
/**
* @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;
}
}