mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-25 00:24:35 +00:00
- Added permission system/vorlagestudiengang to dump.sql
- Added method getMessagesByToken to controller Message - Library MessageLib now load the helper fhc_helper - Added new method getMessagesByToken to library MessageLib - Added field relationmessage_id to methods sendMessage and sendMessageVorlage - Method sendMessageVorlage now checks if the text and the subject for the template are not empty - Method sendMessageVorlage now saves the token automatically generated - Method sendMessageVorlage now return a more comprehensive error message - Method getMessagesByPerson of Message_model now checks for the right permissions - Added fields relationmessage_id and person_id in getMessagesByPerson query - Added method getMessagesByToken to model Message_model
This commit is contained in:
@@ -66,6 +66,25 @@ class Message extends APIv1_Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function getMessagesByToken()
|
||||
{
|
||||
$token = $this->get('token');
|
||||
|
||||
if (isset($token))
|
||||
{
|
||||
$result = $this->messagelib->getMessagesByToken($token);
|
||||
|
||||
$this->response($result, REST_Controller::HTTP_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->response();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
@@ -80,7 +99,7 @@ class Message extends APIv1_Controller
|
||||
$this->post()['subject'],
|
||||
$this->post()['body'],
|
||||
PRIORITY_NORMAL,
|
||||
NULL,
|
||||
$this->post()['relationmessage_id'],
|
||||
$this->post()['oe_kurzbz']
|
||||
);
|
||||
|
||||
@@ -107,6 +126,7 @@ class Message extends APIv1_Controller
|
||||
$this->post()['vorlage_kurzbz'],
|
||||
$this->post()['oe_kurzbz'],
|
||||
$this->post()['data'],
|
||||
$this->post()['relationmessage_id'],
|
||||
$this->post()['orgform_kurzbz']
|
||||
);
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ class MessageLib
|
||||
|
||||
$this->ci->load->library('VorlageLib');
|
||||
|
||||
$this->ci->load->helper('fhc');
|
||||
|
||||
//$this->ci->load->helper('language');
|
||||
$this->ci->lang->load('message');
|
||||
}
|
||||
@@ -104,6 +106,42 @@ class MessageLib
|
||||
|
||||
return $this->getMessage($msg_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* getMessagesByToken
|
||||
*
|
||||
* @param token string
|
||||
* @return array
|
||||
*/
|
||||
function getMessagesByToken($token)
|
||||
{
|
||||
if (empty($token))
|
||||
return $this->_error(MSG_ERR_INVALID_MSG_ID);
|
||||
|
||||
$result = $this->ci->MessageModel->getMessagesByToken($token);
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS && is_array($result->retval) && count($result->retval) > 0)
|
||||
{
|
||||
if ($result->retval[0]->status == MSG_STATUS_UNREAD)
|
||||
{
|
||||
$statusKey = array(
|
||||
'message_id' => $result->retval[0]->message_id,
|
||||
'person_id' => $result->retval[0]->receiver_id,
|
||||
'status' => MSG_STATUS_UNREAD
|
||||
);
|
||||
$resTmp = $this->ci->MsgStatusModel->update($statusKey, array('status' => MSG_STATUS_READ));
|
||||
if (!is_object($resTmp) || (is_object($resTmp) && $resTmp->error != EXIT_SUCCESS))
|
||||
{
|
||||
$result = $resTmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result->retval[0]->status = MSG_STATUS_READ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@@ -190,7 +228,7 @@ class MessageLib
|
||||
'subject' => $subject,
|
||||
'body' => $body,
|
||||
'priority' => $priority,
|
||||
//'relationmessage_id' => $relationmessage_id,
|
||||
'relationmessage_id' => $relationmessage_id,
|
||||
'oe_kurzbz' => $oe_kurzbz
|
||||
);
|
||||
|
||||
@@ -230,7 +268,7 @@ class MessageLib
|
||||
* @param integer $priority
|
||||
* @return array
|
||||
*/
|
||||
function sendMessageVorlage($sender_id, $receiver_id, $vorlage_kurzbz, $oe_kurzbz, $data, $orgform_kurzbz = null)
|
||||
function sendMessageVorlage($sender_id, $receiver_id, $vorlage_kurzbz, $oe_kurzbz, $data, $relationmessage_id = null, $orgform_kurzbz = null)
|
||||
{
|
||||
if (!is_numeric($sender_id) || !is_numeric($receiver_id))
|
||||
return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID);
|
||||
@@ -238,7 +276,8 @@ class MessageLib
|
||||
$result = $this->ci->vorlagelib->loadVorlagetext($vorlage_kurzbz, $oe_kurzbz, $orgform_kurzbz);
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
{
|
||||
if (is_array($result->retval) && count($result->retval) > 0)
|
||||
if (is_array($result->retval) && count($result->retval) > 0 &&
|
||||
!empty($result->retval[0]->text) && !empty($result->retval[0]->subject))
|
||||
{
|
||||
$parsedText = $this->ci->vorlagelib->parseVorlagetext($result->retval[0]->text, $data);
|
||||
|
||||
@@ -249,7 +288,7 @@ class MessageLib
|
||||
'subject' => $result->retval[0]->subject,
|
||||
'body' => $parsedText,
|
||||
'priority' => PRIORITY_NORMAL,
|
||||
//'relationmessage_id' => $relationmessage_id,
|
||||
'relationmessage_id' => $relationmessage_id,
|
||||
'oe_kurzbz' => $oe_kurzbz
|
||||
);
|
||||
|
||||
@@ -259,7 +298,8 @@ class MessageLib
|
||||
$msg_id = $result->retval;
|
||||
$recipientData = array(
|
||||
'person_id' => $receiver_id,
|
||||
'message_id' => $msg_id
|
||||
'message_id' => $msg_id,
|
||||
'token' => generateToken()
|
||||
);
|
||||
$result = $this->ci->RecipientModel->insert($recipientData);
|
||||
if (is_object($result) && $result->error == EXIT_SUCCESS)
|
||||
@@ -293,7 +333,7 @@ class MessageLib
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->_error($result->msg, EXIT_ERROR);
|
||||
$result = $this->_error($result->retval, EXIT_ERROR);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
@@ -10,7 +10,6 @@ class Message_model extends DB_Model
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
//require_once APPPATH.'config/message.php';
|
||||
$this->dbTable = 'public.tbl_msg_message';
|
||||
$this->pk = 'message_id';
|
||||
}
|
||||
@@ -73,48 +72,24 @@ class Message_model extends DB_Model
|
||||
return $this->_error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
|
||||
public function getMessagesByPerson($person_id, $all)
|
||||
public function getMessagesByPerson($person_id, $all)
|
||||
{
|
||||
// Check wrights
|
||||
if (! $this->fhc_db_acl->isBerechtigt('basis/message', 's'))
|
||||
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> basis/message', FHC_MODEL_ERROR);
|
||||
|
||||
// prepare parameters
|
||||
$person_id = (int)$person_id;
|
||||
// get Data
|
||||
/*$sql = 'SELECT person_id,
|
||||
message_id,
|
||||
subject,
|
||||
body,
|
||||
priority,
|
||||
relationmessage_id,
|
||||
oe_kurzbz,
|
||||
m.insertamum,
|
||||
anrede,
|
||||
titelpost,
|
||||
titelpre,
|
||||
nachname,
|
||||
vorname,
|
||||
vornamen,
|
||||
status,
|
||||
statusinfo,
|
||||
s.insertamum AS statusamum
|
||||
FROM public.tbl_msg_message m JOIN public.tbl_person USING (person_id)
|
||||
LEFT OUTER JOIN (
|
||||
SELECT message_id, person_id, status, statusinfo, tbl_msg_status.insertamum
|
||||
FROM public.tbl_msg_status INNER JOIN (
|
||||
SELECT message_id, person_id, max(insertamum) AS insertamum
|
||||
FROM public.tbl_msg_status
|
||||
GROUP BY message_id, person_id
|
||||
) status USING (message_id, person_id)
|
||||
WHERE tbl_msg_status.insertamum=status.insertamum
|
||||
) s USING (message_id, person_id)
|
||||
WHERE person_id = ?';*/
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->acl['public.tbl_msg_recipient'], 's'))
|
||||
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl['public.tbl_msg_recipient'], FHC_MODEL_ERROR);
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->acl['public.tbl_msg_message'], 's'))
|
||||
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl['public.tbl_msg_message'], FHC_MODEL_ERROR);
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->acl['public.tbl_person'], 's'))
|
||||
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl['public.tbl_person'], FHC_MODEL_ERROR);
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->acl['public.tbl_msg_status'], 's'))
|
||||
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl['public.tbl_msg_status'], FHC_MODEL_ERROR);
|
||||
|
||||
$sql = 'SELECT r.message_id,
|
||||
m.person_id,
|
||||
m.subject,
|
||||
m.body,
|
||||
m.insertamum,
|
||||
m.relationmessage_id,
|
||||
m.oe_kurzbz,
|
||||
s.status,
|
||||
s.statusinfo,
|
||||
@@ -124,13 +99,43 @@ public function getMessagesByPerson($person_id, $all)
|
||||
JOIN public.tbl_msg_status s USING (message_id)
|
||||
WHERE r.person_id = ?';
|
||||
|
||||
/*if (! $all)
|
||||
$sql .= ' AND (status < 3 OR status IS NULL)';*/
|
||||
$result = $this->db->query($sql, array($person_id));
|
||||
//var_dump($result);
|
||||
if (is_object($result))
|
||||
return $this->_success($result->result());
|
||||
else
|
||||
return $this->_error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
public function getMessagesByToken($token)
|
||||
{
|
||||
// Check wrights
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->acl['public.tbl_msg_recipient'], 's'))
|
||||
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl['public.tbl_msg_recipient'], FHC_MODEL_ERROR);
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->acl['public.tbl_msg_message'], 's'))
|
||||
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl['public.tbl_msg_message'], FHC_MODEL_ERROR);
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->acl['public.tbl_msg_status'], 's'))
|
||||
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl['public.tbl_msg_status'], FHC_MODEL_ERROR);
|
||||
|
||||
$sql = 'SELECT r.message_id,
|
||||
r.person_id as receiver_id,
|
||||
m.person_id as sender_id,
|
||||
m.subject,
|
||||
m.body,
|
||||
m.insertamum,
|
||||
m.relationmessage_id,
|
||||
m.oe_kurzbz,
|
||||
s.status,
|
||||
s.statusinfo,
|
||||
s.updateamum
|
||||
FROM public.tbl_msg_recipient r JOIN public.tbl_msg_message m USING (message_id)
|
||||
JOIN public.tbl_msg_status s USING (message_id)
|
||||
WHERE r.token = ?
|
||||
AND status < ?';
|
||||
|
||||
$result = $this->db->query($sql, array($token, MSG_STATUS_DELETED));
|
||||
if (is_object($result))
|
||||
return $this->_success($result->result());
|
||||
else
|
||||
return $this->_error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user