mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 00:12:15 +00:00
Merge
This commit is contained in:
@@ -22,7 +22,7 @@ class Message extends APIv1_Controller
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// Load model MessageModel
|
||||
// Load library MessageLib
|
||||
$this->load->library('MessageLib', array('uid' => $this->_getUID()));
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ class Message extends APIv1_Controller
|
||||
*/
|
||||
public function postMessage()
|
||||
{
|
||||
$validation = $this->_validate($this->post());
|
||||
$validation = $this->_validatePostMessage($this->post());
|
||||
|
||||
if (is_object($validation) && $validation->error == EXIT_SUCCESS)
|
||||
{
|
||||
@@ -93,7 +93,33 @@ class Message extends APIv1_Controller
|
||||
}
|
||||
}
|
||||
|
||||
private function _validate($message = null)
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function postMessageVorlage()
|
||||
{
|
||||
$validation = $this->_validatePostMessageVorlage($this->post());
|
||||
|
||||
if (is_object($validation) && $validation->error == EXIT_SUCCESS)
|
||||
{
|
||||
$result = $this->messagelib->sendMessageVorlage(
|
||||
$this->post()['sender_id'],
|
||||
$this->post()['receiver_id'],
|
||||
$this->post()['vorlage_kurzbz'],
|
||||
$this->post()['oe_kurzbz'],
|
||||
$this->post()['data'],
|
||||
$this->post()['orgform_kurzbz']
|
||||
);
|
||||
|
||||
$this->response($result, REST_Controller::HTTP_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->response($validation, REST_Controller::HTTP_OK);
|
||||
}
|
||||
}
|
||||
|
||||
private function _validatePostMessage($message = null)
|
||||
{
|
||||
if (!isset($message))
|
||||
{
|
||||
@@ -118,4 +144,34 @@ class Message extends APIv1_Controller
|
||||
|
||||
return $this->_success('Input data are valid');
|
||||
}
|
||||
|
||||
private function _validatePostMessageVorlage($message = null)
|
||||
{
|
||||
if (!isset($message))
|
||||
{
|
||||
return $this->_error('Parameter is null');
|
||||
}
|
||||
if (!isset($message['sender_id']))
|
||||
{
|
||||
return $this->_error('person_id of sender is not set');
|
||||
}
|
||||
if (!isset($message['receiver_id']))
|
||||
{
|
||||
return $this->_error('person_id of receiver is not set');
|
||||
}
|
||||
if (!isset($message['vorlage_kurzbz']))
|
||||
{
|
||||
return $this->_error('vorlage_kurzbz is not set');
|
||||
}
|
||||
if( !isset($message['oe_kurzbz']))
|
||||
{
|
||||
return $this->_error('oe_kurzbz is not set');
|
||||
}
|
||||
if (!isset($message['data']))
|
||||
{
|
||||
return $this->_error('data is not set');
|
||||
}
|
||||
|
||||
return $this->_success('Input data are valid');
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function success($retval, $message = FHC_SUCCESS)
|
||||
function success($retval, $message = EXIT_SUCCESS)
|
||||
{
|
||||
$return = new stdClass();
|
||||
$return->error = EXIT_SUCCESS;
|
||||
@@ -20,10 +20,10 @@ function success($retval, $message = FHC_SUCCESS)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function error($retval = '', $message = FHC_MODEL_ERROR)
|
||||
function error($retval = '', $message = EXIT_ERROR)
|
||||
{
|
||||
$return = new stdClass();
|
||||
$return->error = EXIT_MODEL;
|
||||
$return->error = EXIT_ERROR;
|
||||
$return->fhcCode = $message;
|
||||
$return->msg = lang('fhc_' . $message);
|
||||
$return->retval = $retval;
|
||||
|
||||
@@ -17,16 +17,26 @@ class MessageLib
|
||||
$this->ci->config->load('message');
|
||||
|
||||
$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');
|
||||
|
||||
if (is_array($params) && isset($params['uid']))
|
||||
{
|
||||
$this->ci->load->library('VorlageLib', array('uid' => $params['uid']));
|
||||
$this->ci->MessageModel->setUID($params['uid']);
|
||||
$this->ci->MsgStatusModel->setUID($params['uid']);
|
||||
$this->ci->RecipientModel->setUID($params['uid']);
|
||||
$this->ci->AttachmentModel->setUID($params['uid']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->ci->load->library('VorlageLib');
|
||||
}
|
||||
|
||||
//$this->ci->load->helper('language');
|
||||
$this->ci->lang->load('message');
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -212,6 +222,86 @@ class MessageLib
|
||||
else
|
||||
return $this->_success($msg_id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* sendMessage() - sends new internal message. This function will create a new thread
|
||||
*
|
||||
* @param integer $sender_id REQUIRED
|
||||
* @param mixed $recipients REQUIRED - a single integer or an array of integers, representing user_ids
|
||||
* @param string $subject
|
||||
* @param string $body
|
||||
* @param integer $priority
|
||||
* @return array
|
||||
*/
|
||||
function sendMessageVorlage($sender_id, $receiver_id, $vorlage_kurzbz, $oe_kurzbz, $data, $orgform_kurzbz = null)
|
||||
{
|
||||
var_dump($data);
|
||||
|
||||
exit;
|
||||
|
||||
if (!is_numeric($sender_id) || !is_numeric($receiver_id))
|
||||
return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID);
|
||||
|
||||
$result = $this->ci->vorlagelib->getVorlage($vorlage_kurzbz);
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
{
|
||||
if (is_array($result->retval) && count($result->retval) > 0)
|
||||
{
|
||||
$parsedText = $this->ci->vorlagelib->parseVorlagetext($result->retval[0]->text, $data);
|
||||
|
||||
error_log($parsedText);
|
||||
|
||||
$this->ci->db->trans_start(false);
|
||||
//save Message
|
||||
$msgData = array(
|
||||
'person_id' => $sender_id,
|
||||
//'subject' => $subject,
|
||||
'body' => $parsedText,
|
||||
'priority' => PRIORITY_NORMAL,
|
||||
//'relationmessage_id' => $relationmessage_id,
|
||||
'oe_kurzbz' => $oe_kurzbz
|
||||
);
|
||||
|
||||
$result = $this->ci->MessageModel->insert($msgData);
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
{
|
||||
$msg_id = $result->retval;
|
||||
$recipientData = array(
|
||||
'person_id' => $receiver_id,
|
||||
'message_id' => $msg_id
|
||||
);
|
||||
$result = $this->ci->RecipientModel->insert($recipientData);
|
||||
/*if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
{
|
||||
|
||||
}*/
|
||||
}
|
||||
|
||||
$this->ci->db->trans_complete();
|
||||
|
||||
if ($this->ci->db->trans_status() === FALSE)
|
||||
{
|
||||
$this->db->trans_rollback();
|
||||
return $this->_error($result->msg, EXIT_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->trans_commit();
|
||||
return $this->_success($msg_id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->_error('Vorlage not found', EXIT_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->_error($result->msg, EXIT_ERROR);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -345,4 +435,4 @@ class MessageLib
|
||||
'msg' => lang('message_'.$error)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ class VorlageLib
|
||||
{
|
||||
private $recipients = array();
|
||||
|
||||
public function __construct()
|
||||
public function __construct($params = null)
|
||||
{
|
||||
require_once APPPATH.'config/message.php';
|
||||
|
||||
@@ -19,6 +19,13 @@ class VorlageLib
|
||||
$this->ci->load->library('parser');
|
||||
$this->ci->load->model('system/Vorlage_model', 'VorlageModel');
|
||||
$this->ci->load->model('system/Vorlagestudiengang_model', 'VorlageStudiengangModel');
|
||||
|
||||
if (is_array($params) && isset($params['uid']))
|
||||
{
|
||||
$this->ci->VorlageModel->setUID($params['uid']);
|
||||
$this->ci->VorlageStudiengangModel->setUID($params['uid']);
|
||||
}
|
||||
|
||||
$this->ci->load->helper('language');
|
||||
//$this->ci->lang->load('fhcomplete');
|
||||
}
|
||||
@@ -149,4 +156,35 @@ class VorlageLib
|
||||
$text = $this->ci->parser->parse_string($text, $data, TRUE);
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* Success
|
||||
*
|
||||
* @param mixed $retval
|
||||
* @return array
|
||||
*/
|
||||
protected function _success($retval, $message = EXIT_SUCCESS)
|
||||
{
|
||||
$return = new stdClass();
|
||||
$return->error = EXIT_SUCCESS;
|
||||
$return->Code = $message;
|
||||
$return->msg = lang('message_' . $message);
|
||||
$return->retval = $retval;
|
||||
return $return;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* General Error
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _error($retval = '', $message = EXIT_ERROR)
|
||||
{
|
||||
$return = new stdClass();
|
||||
$return->error = EXIT_ERROR;
|
||||
$return->Code = $message;
|
||||
$return->msg = lang('message_' . $message);
|
||||
$return->retval = $retval;
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user