mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-17 20:19:28 +00:00
8135c6275e
- Better code in controller api/v1/system/Message.php - Adapted controller api/v1/system/Message.php to use sendMessageUser and sendMessageUserTemplate methods from MessageLib - Adapted model models/CL/Messages_model.php to use sendMessageUser and sendMessageUserTemplate methods from MessageLib - Adapted model models/CL/Messages_model.php to use function parseText - Removed constant MSG_INDX_PREFIX from MessageLib - Added constants to MessageLib: CFG_SYSTEM_PERSON_ID, CFG_SEND_IMMEDIATELY, CFG_MESSAGE_SERVER, CFG_MESSAGE_HTML_VIEW_URL, CFG_OU_RECEIVERS, NOTICE_TEMPLATE_HTML, NOTICE_TEMPLATE_TXT, NOTICE_TEMPLATE_FALLBACK_HTML, NOTICE_TEMPLATE_FALLBACK_TXT, EMAIL_KONTAKT_TYPE and SENT_INFO_NEWLINE - MessageLib does not load anymore library parser - Improved MessageLib code - Added private methodis _sendMessage, _getSender, _getNoticeBody, _getNoticeHTMLBody, _getNoticeTXTBody and _ouExists to MessageLib - Added public methods sendMessageUser, sendMessageUserTemplate and sendMessageOU to MessageLib - Renamed method sendAll to sendAllNotices in MessageLib - Renamed method sendOne to _sendNotice and changed it from public to private - Renamed method _checkReceiverId to _getReceiversByPersonId
223 lines
5.3 KiB
PHP
223 lines
5.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* This model extends CI_Model because here is just implemented logic
|
|
* It does not represent a resource (ex. like models that extend DB_Model)
|
|
*/
|
|
class Messages_model extends CI_Model
|
|
{
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
// Loads the message library
|
|
$this->load->library('MessageLib');
|
|
|
|
// Loads the person log library
|
|
$this->load->library('PersonLogLib');
|
|
|
|
$this->load->model('system/MessageToken_model', 'MessageTokenModel');
|
|
}
|
|
|
|
/**
|
|
* Executes message sending
|
|
* @param $sender_id
|
|
* @return array wether execution was successfull - error or success
|
|
*/
|
|
public function send($msgVarsData, $relationmessage_id = null, $oe_kurzbz = null, $vorlage_kurzbz = null, $msgVars = null)
|
|
{
|
|
$subject = $this->input->post('subject');
|
|
$body = $this->input->post('body');
|
|
|
|
$authUser = $this->getAuthUser();
|
|
|
|
if (isError($authUser)) return $authUser;
|
|
|
|
$sender_id = getData($authUser)[0]->person_id;
|
|
|
|
|
|
// Send message(s)
|
|
if (hasData($msgVarsData))
|
|
{
|
|
for ($i = 0; $i < count(getData($msgVarsData)); $i++)
|
|
{
|
|
$parsedText = '';
|
|
$msgVarsDataArray = $this->replaceKeys((array)getData($msgVarsData)[$i]); // replaces array keys
|
|
|
|
// Send without vorlage
|
|
if (isEmptyString($vorlage_kurzbz))
|
|
{
|
|
$parsedText = parseText($body, $msgVarsDataArray);
|
|
|
|
$msg = $this->messagelib->sendMessageUser(
|
|
$msgVarsDataArray['person_id'], // receiverPersonId
|
|
$subject, // subject
|
|
$parsedText, // body
|
|
$sender_id, // sender_id
|
|
$oe_kurzbz, // senderOU
|
|
$relationmessage_id, // relationmessage_id
|
|
MSG_PRIORITY_NORMAL // priority
|
|
);
|
|
}
|
|
// Send with vorlage
|
|
else
|
|
{
|
|
if (is_array($msgVars))
|
|
{
|
|
// Additional message variables
|
|
foreach ($msgVars as $key => $msgvar)
|
|
{
|
|
$msgVarsDataArray[$key] = $msgvar;
|
|
}
|
|
}
|
|
|
|
$msg = $this->messagelib->sendMessageUserTemplate(
|
|
$msgVarsDataArray['person_id'], // receiversPersonId
|
|
$vorlage_kurzbz, // vorlage
|
|
$msgVarsDataArray, // parseData
|
|
null, // orgform
|
|
$sender_id, // sender_id
|
|
$oe_kurzbz // senderOU
|
|
);
|
|
}
|
|
|
|
if (isError($msg)) return $msg;
|
|
|
|
// Write log entry
|
|
$personLog = $this->personloglib->log(
|
|
$msgVarsDataArray['person_id'],
|
|
'Action',
|
|
array(
|
|
'name' => 'Message sent',
|
|
'message' => 'Message sent from person '.$sender_id.' to '.$msgVarsDataArray['person_id'].', messageid '.getData($msg),
|
|
'success' => 'true'
|
|
),
|
|
'kommunikation',
|
|
'core',
|
|
null,
|
|
getAuthUID()
|
|
);
|
|
|
|
if (isError($personLog)) return $personLog;
|
|
}
|
|
|
|
return success('Messages sent successfully');
|
|
}
|
|
else
|
|
{
|
|
return $msgVarsData;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Send a reply to a message accessed using a token
|
|
*/
|
|
public function sendReply($subject, $body, $persons, $relationmessage_id, $token)
|
|
{
|
|
$relationmsg = $this->MessageTokenModel->getMessageByToken($token);
|
|
if (!hasData($relationmsg) || $relationmessage_id !== getData($relationmsg)[0]->message_id)
|
|
{
|
|
show_error('Error while sending reply');
|
|
}
|
|
|
|
// Get sender (receiver of previous msg)
|
|
$sender_id = getData($relationmsg)[0]->receiver_id;
|
|
|
|
// Get message data of persons
|
|
$data = $this->MessageTokenModel->getPersonData($persons);
|
|
if (hasData($data))
|
|
{
|
|
for ($i = 0; $i < count(getData($data)); $i++)
|
|
{
|
|
$dataArray = (array)getData($data)[$i];
|
|
|
|
$msg = $this->messagelib->sendMessageUser(
|
|
$dataArray['person_id'], // receiverPersonId
|
|
$subject, // subject
|
|
$body, // body
|
|
$sender_id, // sender_id
|
|
null, // senderOU
|
|
$relationmessage_id, // relationmessage_id
|
|
MSG_PRIORITY_NORMAL // priority
|
|
);
|
|
|
|
if (isError($msg)) return $msg;
|
|
|
|
// Logs person data
|
|
$personLog = $this->personloglib->log(
|
|
$sender_id,
|
|
'Action',
|
|
array(
|
|
'name' => 'Message sent',
|
|
'message' => 'Message sent from person '.$sender_id.' to '.$dataArray['person_id'].', messageid '.getData($msg),
|
|
'success' => 'true'
|
|
),
|
|
'kommunikation',
|
|
'core',
|
|
null,
|
|
'online'
|
|
);
|
|
|
|
// Unpark bewerber after he sends message
|
|
$personLog = $this->personloglib->unPark($sender_id);
|
|
|
|
if (isError($personLog)) return $personLog;
|
|
}
|
|
}
|
|
|
|
return success('Reply sent');
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function getAuthUser()
|
|
{
|
|
$sender_id = null;
|
|
|
|
$this->load->model('person/Person_model', 'PersonModel');
|
|
$authUser = $this->PersonModel->getByUid(getAuthUID());
|
|
|
|
if (!hasData($authUser)) $authUser = error('The current logged user person_id is not defined');
|
|
|
|
return $authUser;
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function replaceKeys($data)
|
|
{
|
|
$tmpData = array();
|
|
|
|
// Replaces data array keys to a lowercase without spaces string
|
|
foreach ($data as $key => $val)
|
|
{
|
|
$tmpData[str_replace(' ', '_', strtolower($key))] = $val;
|
|
}
|
|
|
|
return $tmpData;
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function addOeToPrestudents(&$msgVarsData, $prestudentsData)
|
|
{
|
|
for ($i = 0; $i < count(getData($msgVarsData)); $i++)
|
|
{
|
|
for ($p = 0; $p < count(getData($prestudentsData)); $p++)
|
|
{
|
|
if (getData($prestudentsData)[$p]->prestudent_id == getData($msgVarsData)[$i]->prestudent_id)
|
|
{
|
|
$msgVarsData->retval[$i]->oe_kurzbz = getData($prestudentsData)[$p]->oe_kurzbz;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|