mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-18 23:42:17 +00:00
- Added new method writeReply to FASMessages
- Moved logic from Messages and MessageLib to MessageLib\ - Better code in views/system/messageWrite.php - Adapted content/messages.js.php to use writeReply
This commit is contained in:
@@ -9,34 +9,36 @@ class MessageLib
|
||||
{
|
||||
const MSG_INDX_PREFIX = 'message_';
|
||||
|
||||
private $_ci;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Get code igniter instance
|
||||
$this->ci =& get_instance();
|
||||
$this->_ci =& get_instance();
|
||||
|
||||
// Loads message configuration
|
||||
$this->ci->config->load('message');
|
||||
$this->_ci->config->load('message');
|
||||
|
||||
// CI Parser library
|
||||
$this->ci->load->library('parser');
|
||||
$this->_ci->load->library('parser');
|
||||
// Loads LogLib
|
||||
$this->ci->load->library('LogLib');
|
||||
$this->_ci->load->library('LogLib');
|
||||
// Loads VorlageLib
|
||||
$this->ci->load->library('VorlageLib');
|
||||
$this->_ci->load->library('VorlageLib');
|
||||
// Loads Mail library
|
||||
$this->ci->load->library('MailLib');
|
||||
$this->_ci->load->library('MailLib');
|
||||
|
||||
// Loading models
|
||||
$this->ci->load->model('system/Message_model', 'MessageModel');
|
||||
$this->ci->load->model('system/MsgStatus_model', 'MsgStatusModel');
|
||||
$this->ci->load->model('system/Recipient_model', 'RecipientModel');
|
||||
$this->ci->load->model('system/Attachment_model', 'AttachmentModel');
|
||||
$this->_ci->load->model('system/Message_model', 'MessageModel');
|
||||
$this->_ci->load->model('system/MsgStatus_model', 'MsgStatusModel');
|
||||
$this->_ci->load->model('system/Recipient_model', 'RecipientModel');
|
||||
$this->_ci->load->model('system/Attachment_model', 'AttachmentModel');
|
||||
|
||||
// Loads phrases
|
||||
$this->ci->lang->load('message');
|
||||
$this->_ci->lang->load('message');
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
@@ -52,7 +54,7 @@ class MessageLib
|
||||
if (!is_numeric($person_id))
|
||||
return $this->_error('', MSG_ERR_INVALID_RECIPIENTS);
|
||||
|
||||
$msg = $this->ci->RecipientModel->getMessage($msg_id, $person_id);
|
||||
$msg = $this->_ci->RecipientModel->getMessage($msg_id, $person_id);
|
||||
|
||||
return $msg;
|
||||
}
|
||||
@@ -65,7 +67,7 @@ class MessageLib
|
||||
if (isEmptyString($uid))
|
||||
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
|
||||
|
||||
$msg = $this->ci->RecipientModel->getMessagesByUID($uid, $oe_kurzbz, $all);
|
||||
$msg = $this->_ci->RecipientModel->getMessagesByUID($uid, $oe_kurzbz, $all);
|
||||
|
||||
return $msg;
|
||||
}
|
||||
@@ -78,7 +80,7 @@ class MessageLib
|
||||
if (!is_numeric($person_id))
|
||||
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
|
||||
|
||||
$msg = $this->ci->RecipientModel->getMessagesByPerson($person_id, $oe_kurzbz, $all);
|
||||
$msg = $this->_ci->RecipientModel->getMessagesByPerson($person_id, $oe_kurzbz, $all);
|
||||
|
||||
return $msg;
|
||||
}
|
||||
@@ -91,7 +93,7 @@ class MessageLib
|
||||
if (!is_numeric($person_id))
|
||||
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
|
||||
|
||||
$msg = $this->ci->MessageModel->getMessagesByPerson($person_id, $oe_kurzbz, $all);
|
||||
$msg = $this->_ci->MessageModel->getMessagesByPerson($person_id, $oe_kurzbz, $all);
|
||||
|
||||
return $msg;
|
||||
}
|
||||
@@ -104,7 +106,7 @@ class MessageLib
|
||||
if (isEmptyString($token))
|
||||
return $this->_error('', MSG_ERR_INVALID_TOKEN);
|
||||
|
||||
$result = $this->ci->RecipientModel->getMessageByToken($token);
|
||||
$result = $this->_ci->RecipientModel->getMessageByToken($token);
|
||||
if (hasData($result))
|
||||
{
|
||||
// Searches for a status that is different from unread
|
||||
@@ -127,7 +129,7 @@ class MessageLib
|
||||
'status' => MSG_STATUS_READ
|
||||
);
|
||||
|
||||
$resultIns = $this->ci->MsgStatusModel->insert($statusKey);
|
||||
$resultIns = $this->_ci->MsgStatusModel->insert($statusKey);
|
||||
// If an error occured while writing on data base, then return it
|
||||
if (isError($resultIns))
|
||||
{
|
||||
@@ -147,7 +149,7 @@ class MessageLib
|
||||
if (!is_numeric($person_id))
|
||||
return $this->_error('', MSG_ERR_INVALID_RECIPIENTS);
|
||||
|
||||
$msg = $this->ci->RecipientModel->getCountUnreadMessages($person_id, $oe_kurzbz);
|
||||
$msg = $this->_ci->RecipientModel->getCountUnreadMessages($person_id, $oe_kurzbz);
|
||||
|
||||
return $msg;
|
||||
}
|
||||
@@ -175,7 +177,7 @@ class MessageLib
|
||||
}
|
||||
|
||||
// Searches if the status is already present
|
||||
$result = $this->ci->MsgStatusModel->load(array($message_id, $person_id, $status));
|
||||
$result = $this->_ci->MsgStatusModel->load(array($message_id, $person_id, $status));
|
||||
if (hasData($result))
|
||||
{
|
||||
// status already present
|
||||
@@ -189,7 +191,7 @@ class MessageLib
|
||||
'status' => $status
|
||||
);
|
||||
|
||||
$result = $this->ci->MsgStatusModel->insert($statusKey);
|
||||
$result = $this->_ci->MsgStatusModel->insert($statusKey);
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -202,7 +204,7 @@ class MessageLib
|
||||
{
|
||||
if (!is_numeric($sender_id))
|
||||
{
|
||||
$sender_id = $this->ci->config->item('system_person_id');
|
||||
$sender_id = $this->_ci->config->item('system_person_id');
|
||||
}
|
||||
|
||||
$receivers = $this->_getReceivers($receiver_id, $oe_kurzbz);
|
||||
@@ -233,7 +235,7 @@ class MessageLib
|
||||
if (isSuccess($result))
|
||||
{
|
||||
// If the system is configured to send messages immediately
|
||||
if ($this->ci->config->item('send_immediately') === true)
|
||||
if ($this->_ci->config->item('send_immediately') === true)
|
||||
{
|
||||
// Send message by email!
|
||||
$resultSendEmail = $this->sendOne($result->retval, $subject, $body, $multiPartMime);
|
||||
@@ -277,7 +279,7 @@ class MessageLib
|
||||
{
|
||||
if (!is_numeric($sender_id))
|
||||
{
|
||||
$sender_id = $this->ci->config->item('system_person_id');
|
||||
$sender_id = $this->_ci->config->item('system_person_id');
|
||||
}
|
||||
|
||||
$receivers = $this->_getReceivers($receiver_id, $oe_kurzbz);
|
||||
@@ -293,7 +295,7 @@ class MessageLib
|
||||
else
|
||||
{
|
||||
// Load reveiver data to get its relative language
|
||||
$this->ci->load->model('person/Person_model', 'PersonModel');
|
||||
$this->_ci->load->model('person/Person_model', 'PersonModel');
|
||||
}
|
||||
|
||||
// Looping on receivers
|
||||
@@ -302,14 +304,14 @@ class MessageLib
|
||||
$receiver_id = $receivers->retval[$i]->person_id;
|
||||
|
||||
// Checks if the receiver exists
|
||||
$result = $this->ci->PersonModel->load($receiver_id);
|
||||
$result = $this->_ci->PersonModel->load($receiver_id);
|
||||
if (hasData($result))
|
||||
{
|
||||
// Retrives the language of the logged user
|
||||
$sprache = getUserLanguage();
|
||||
|
||||
// Loads template data
|
||||
$result = $this->ci->vorlagelib->loadVorlagetext($vorlage_kurzbz, $oe_kurzbz, $orgform_kurzbz, $sprache);
|
||||
$result = $this->_ci->vorlagelib->loadVorlagetext($vorlage_kurzbz, $oe_kurzbz, $orgform_kurzbz, $sprache);
|
||||
if (isSuccess($result))
|
||||
{
|
||||
// If the text and the subject of the template are not empty
|
||||
@@ -317,9 +319,9 @@ class MessageLib
|
||||
!isEmptyString($result->retval[0]->text) && !isEmptyString($result->retval[0]->subject))
|
||||
{
|
||||
// Parses template text
|
||||
$parsedText = $this->ci->vorlagelib->parseVorlagetext($result->retval[0]->text, $data);
|
||||
$parsedText = $this->_ci->vorlagelib->parseVorlagetext($result->retval[0]->text, $data);
|
||||
// Parses subject
|
||||
$subject = $this->ci->vorlagelib->parseVorlagetext($result->retval[0]->subject, $data);
|
||||
$subject = $this->_ci->vorlagelib->parseVorlagetext($result->retval[0]->subject, $data);
|
||||
|
||||
// Save message
|
||||
$result = $this->_saveMessage($sender_id, $receiver_id, $subject, $parsedText, $relationmessage_id, $oe_kurzbz);
|
||||
@@ -327,7 +329,7 @@ class MessageLib
|
||||
if (isSuccess($result))
|
||||
{
|
||||
// If the system is configured to send messages immediately
|
||||
if ($this->ci->config->item('send_immediately') === true)
|
||||
if ($this->_ci->config->item('send_immediately') === true)
|
||||
{
|
||||
// Send message by email!
|
||||
$resultSendEmail = $this->sendOne($result->retval, $subject, $parsedText, $multiPartMime);
|
||||
@@ -392,21 +394,21 @@ class MessageLib
|
||||
$sent = true; // optimistic expectation
|
||||
|
||||
// Gets standard configs
|
||||
$cfg = $this->ci->maillib->getConfigs();
|
||||
$cfg = $this->_ci->maillib->getConfigs();
|
||||
$cfg->email_number_to_sent = $numberToSent;
|
||||
$cfg->email_number_per_time_range = $numberPerTimeRange;
|
||||
$cfg->email_time_range = $email_time_range;
|
||||
$cfg->email_from_system = $email_from_system;
|
||||
|
||||
// Overrides configs with the parameters
|
||||
$this->ci->maillib->overrideConfigs($cfg);
|
||||
$this->_ci->maillib->overrideConfigs($cfg);
|
||||
|
||||
// Gets a number ($this->ci->maillib->getMaxEmailToSent()) of unsent messages from DB
|
||||
// Gets a number ($this->_ci->maillib->getMaxEmailToSent()) of unsent messages from DB
|
||||
// having EMAIL_KONTAKT_TYPE as relative contact type
|
||||
$result = $this->ci->RecipientModel->getMessages(
|
||||
$result = $this->_ci->RecipientModel->getMessages(
|
||||
EMAIL_KONTAKT_TYPE,
|
||||
null,
|
||||
$this->ci->maillib->getConfigs()->email_number_to_sent
|
||||
$this->_ci->maillib->getConfigs()->email_number_to_sent
|
||||
);
|
||||
// Checks if errors were occurred
|
||||
if (isSuccess($result))
|
||||
@@ -421,14 +423,14 @@ class MessageLib
|
||||
if ((!is_null($result->retval[$i]->receiver) && $result->retval[$i]->receiver != '')
|
||||
|| (!is_null($result->retval[$i]->employeecontact) && $result->retval[$i]->employeecontact != ''))
|
||||
{
|
||||
$href = $this->ci->config->item('message_server').$this->ci->config->item('message_html_view_url').$result->retval[$i]->token;
|
||||
$href = $this->_ci->config->item('message_server').$this->_ci->config->item('message_html_view_url').$result->retval[$i]->token;
|
||||
|
||||
$vorlage = $this->ci->vorlagelib->loadVorlagetext('MessageMailHTML');
|
||||
$vorlage = $this->_ci->vorlagelib->loadVorlagetext('MessageMailHTML');
|
||||
|
||||
if(hasData($vorlage))
|
||||
{
|
||||
// Using a template for the html email body
|
||||
$body = $this->ci->parser->parse_string(
|
||||
$body = $this->_ci->parser->parse_string(
|
||||
$vorlage->retval[0]->text,
|
||||
array(
|
||||
'href' => $href,
|
||||
@@ -441,7 +443,7 @@ class MessageLib
|
||||
else
|
||||
{
|
||||
// Using a template for the html email body
|
||||
$body = $this->ci->parser->parse(
|
||||
$body = $this->_ci->parser->parse(
|
||||
'templates/mailHTML',
|
||||
array(
|
||||
'href' => $href,
|
||||
@@ -453,14 +455,14 @@ class MessageLib
|
||||
}
|
||||
if (is_null($body) || $body == '')
|
||||
{
|
||||
$this->ci->loglib->logError('Error while parsing the mail template');
|
||||
$this->_ci->loglib->logError('Error while parsing the mail template');
|
||||
}
|
||||
|
||||
$vorlage = $this->ci->vorlagelib->loadVorlagetext('MessageMailTXT');
|
||||
$vorlage = $this->_ci->vorlagelib->loadVorlagetext('MessageMailTXT');
|
||||
if(hasData($vorlage))
|
||||
{
|
||||
// Using a template for the plain text email body
|
||||
$altBody = $this->ci->parser->parse_string(
|
||||
$altBody = $this->_ci->parser->parse_string(
|
||||
$vorlage->retval[0]->text,
|
||||
array(
|
||||
'href' => $href,
|
||||
@@ -473,7 +475,7 @@ class MessageLib
|
||||
else
|
||||
{
|
||||
// Using a template for the plain text email body
|
||||
$altBody = $this->ci->parser->parse(
|
||||
$altBody = $this->_ci->parser->parse(
|
||||
'templates/mailTXT',
|
||||
array(
|
||||
'href' => $href,
|
||||
@@ -485,7 +487,7 @@ class MessageLib
|
||||
}
|
||||
if (is_null($altBody) || $altBody == '')
|
||||
{
|
||||
$this->ci->loglib->logError('Error while parsing the mail template');
|
||||
$this->_ci->loglib->logError('Error while parsing the mail template');
|
||||
}
|
||||
|
||||
// If the sender is not an employee, then system-sender is used if empty
|
||||
@@ -502,7 +504,7 @@ class MessageLib
|
||||
}
|
||||
|
||||
// Sending email
|
||||
$sent = $this->ci->maillib->send(
|
||||
$sent = $this->_ci->maillib->send(
|
||||
$sender,
|
||||
$receiverContact,
|
||||
$result->retval[$i]->subject,
|
||||
@@ -515,7 +517,7 @@ class MessageLib
|
||||
// If errors were occurred while sending the email
|
||||
if (!$sent)
|
||||
{
|
||||
$this->ci->loglib->logError('Error while sending an email');
|
||||
$this->_ci->loglib->logError('Error while sending an email');
|
||||
// Writing errors in tbl_msg_recipient
|
||||
$sme = $this->setMessageError(
|
||||
$result->retval[$i]->message_id,
|
||||
@@ -525,7 +527,7 @@ class MessageLib
|
||||
);
|
||||
if (!$sme)
|
||||
{
|
||||
$this->ci->loglib->logError('Error while updating DB');
|
||||
$this->_ci->loglib->logError('Error while updating DB');
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -535,13 +537,13 @@ class MessageLib
|
||||
// If some errors occurred
|
||||
if (!$sent)
|
||||
{
|
||||
$this->ci->loglib->logError('Error while updating DB');
|
||||
$this->_ci->loglib->logError('Error while updating DB');
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->ci->loglib->logError('This person does not have an email account');
|
||||
$this->_ci->loglib->logError('This person does not have an email account');
|
||||
// Writing errors in tbl_msg_recipient
|
||||
$sme = $this->setMessageError(
|
||||
$result->retval[$i]->message_id,
|
||||
@@ -551,7 +553,7 @@ class MessageLib
|
||||
);
|
||||
if (!$sme)
|
||||
{
|
||||
$this->ci->loglib->logError('Error while updating DB');
|
||||
$this->_ci->loglib->logError('Error while updating DB');
|
||||
}
|
||||
$sent = true; // Non blocking error
|
||||
}
|
||||
@@ -559,13 +561,13 @@ class MessageLib
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->ci->loglib->logInfo('There are no email to be sent');
|
||||
$this->_ci->loglib->logInfo('There are no email to be sent');
|
||||
$sent = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->ci->loglib->logError('Something went wrong while getting data from DB');
|
||||
$this->_ci->loglib->logError('Something went wrong while getting data from DB');
|
||||
$sent = false;
|
||||
}
|
||||
|
||||
@@ -580,7 +582,7 @@ class MessageLib
|
||||
$sent = true; // optimistic expectation
|
||||
|
||||
// Get a specific message from DB having EMAIL_KONTAKT_TYPE as relative contact type
|
||||
$result = $this->ci->RecipientModel->getMessages(
|
||||
$result = $this->_ci->RecipientModel->getMessages(
|
||||
EMAIL_KONTAKT_TYPE,
|
||||
null,
|
||||
null,
|
||||
@@ -601,12 +603,12 @@ class MessageLib
|
||||
if ($multiPartMime === true)
|
||||
{
|
||||
// Using a template for the html email body
|
||||
$href = $this->ci->config->item('message_server').$this->ci->config->item('message_html_view_url').$result->retval[0]->token;
|
||||
$href = $this->_ci->config->item('message_server').$this->_ci->config->item('message_html_view_url').$result->retval[0]->token;
|
||||
|
||||
$vorlage = $this->ci->vorlagelib->loadVorlagetext('MessageMailHTML');
|
||||
$vorlage = $this->_ci->vorlagelib->loadVorlagetext('MessageMailHTML');
|
||||
if(hasData($vorlage))
|
||||
{
|
||||
$bodyMsg = $this->ci->parser->parse_string(
|
||||
$bodyMsg = $this->_ci->parser->parse_string(
|
||||
$vorlage->retval[0]->text,
|
||||
array(
|
||||
'href' => $href,
|
||||
@@ -618,7 +620,7 @@ class MessageLib
|
||||
}
|
||||
else
|
||||
{
|
||||
$bodyMsg = $this->ci->parser->parse(
|
||||
$bodyMsg = $this->_ci->parser->parse(
|
||||
'templates/mailHTML',
|
||||
array(
|
||||
'href' => $href,
|
||||
@@ -631,14 +633,14 @@ class MessageLib
|
||||
if (is_null($bodyMsg) || $bodyMsg == '')
|
||||
{
|
||||
// $body = $result->retval[0]->body;
|
||||
$this->ci->loglib->logError('Error while parsing the html mail template');
|
||||
$this->_ci->loglib->logError('Error while parsing the html mail template');
|
||||
}
|
||||
|
||||
// Using a template for the plain text email body
|
||||
$vorlage = $this->ci->vorlagelib->loadVorlagetext('MessageMailTXT');
|
||||
$vorlage = $this->_ci->vorlagelib->loadVorlagetext('MessageMailTXT');
|
||||
if(hasData($vorlage))
|
||||
{
|
||||
$altBody = $this->ci->parser->parse_string(
|
||||
$altBody = $this->_ci->parser->parse_string(
|
||||
$vorlage->retval[0]->text,
|
||||
array(
|
||||
'href' => $href,
|
||||
@@ -650,7 +652,7 @@ class MessageLib
|
||||
}
|
||||
else
|
||||
{
|
||||
$altBody = $this->ci->parser->parse(
|
||||
$altBody = $this->_ci->parser->parse(
|
||||
'templates/mailTXT',
|
||||
array(
|
||||
'href' => $href,
|
||||
@@ -662,7 +664,7 @@ class MessageLib
|
||||
}
|
||||
if (is_null($altBody) || $altBody == '')
|
||||
{
|
||||
$this->ci->loglib->logError('Error while parsing the plain text mail template');
|
||||
$this->_ci->loglib->logError('Error while parsing the plain text mail template');
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -684,7 +686,7 @@ class MessageLib
|
||||
}
|
||||
|
||||
// Sending email
|
||||
$sent = $this->ci->maillib->send(
|
||||
$sent = $this->_ci->maillib->send(
|
||||
null,
|
||||
$receiverContact,
|
||||
is_null($subject) ? $result->retval[0]->subject : $subject, // if parameter subject is not null, use it!
|
||||
@@ -697,7 +699,7 @@ class MessageLib
|
||||
// If errors were occurred while sending the email
|
||||
if (!$sent)
|
||||
{
|
||||
$this->ci->loglib->logError('Error while sending an email');
|
||||
$this->_ci->loglib->logError('Error while sending an email');
|
||||
// Writing errors in tbl_msg_recipient
|
||||
$sme = $this->setMessageError(
|
||||
$result->retval[0]->message_id,
|
||||
@@ -707,7 +709,7 @@ class MessageLib
|
||||
);
|
||||
if (!$sme)
|
||||
{
|
||||
$this->ci->loglib->logError('Error while updating DB');
|
||||
$this->_ci->loglib->logError('Error while updating DB');
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -717,13 +719,13 @@ class MessageLib
|
||||
// If the email has been sent and the DB updated
|
||||
if (!$sent)
|
||||
{
|
||||
$this->ci->loglib->logError('Error while updating DB');
|
||||
$this->_ci->loglib->logError('Error while updating DB');
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->ci->loglib->logError('This person does not have an email account');
|
||||
$this->_ci->loglib->logError('This person does not have an email account');
|
||||
// Writing errors in tbl_msg_recipient
|
||||
$sme = $this->setMessageError(
|
||||
$result->retval[0]->message_id,
|
||||
@@ -733,20 +735,20 @@ class MessageLib
|
||||
);
|
||||
if (!$sme)
|
||||
{
|
||||
$this->ci->loglib->logError('Error while updating DB');
|
||||
$this->_ci->loglib->logError('Error while updating DB');
|
||||
}
|
||||
$sent = true; // Non blocking error
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->ci->loglib->logInfo('There are no email to be sent');
|
||||
$this->_ci->loglib->logInfo('There are no email to be sent');
|
||||
$sent = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->ci->loglib->logError('Something went wrong while getting data from DB');
|
||||
$this->_ci->loglib->logError('Something went wrong while getting data from DB');
|
||||
$sent = false;
|
||||
}
|
||||
|
||||
@@ -758,7 +760,7 @@ class MessageLib
|
||||
*/
|
||||
public function parseMessageText($text, $data = array())
|
||||
{
|
||||
return $this->ci->parser->parse_string($text, $data, true);
|
||||
return $this->_ci->parser->parse_string($text, $data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -768,7 +770,7 @@ class MessageLib
|
||||
public function getMessageVarsPerson()
|
||||
{
|
||||
$variablesArray = array();
|
||||
$variables = $this->ci->MessageModel->getMessageVarsPerson();
|
||||
$variables = $this->_ci->MessageModel->getMessageVarsPerson();
|
||||
|
||||
if (hasData($variables))
|
||||
{
|
||||
@@ -783,6 +785,46 @@ class MessageLib
|
||||
return $variablesArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* A person may belongs to more organisation units
|
||||
*/
|
||||
public function getOeKurzbz($sender_id)
|
||||
{
|
||||
$oe_kurzbz = array();
|
||||
|
||||
$this->_ci->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel');
|
||||
$benutzerResult = $this->_ci->BenutzerfunktionModel->getByPersonId($sender_id);
|
||||
if (isError($benutzerResult))
|
||||
{
|
||||
show_error($benutzerResult->retval);
|
||||
}
|
||||
elseif (hasData($benutzerResult))
|
||||
{
|
||||
foreach ($benutzerResult->retval as $val)
|
||||
{
|
||||
$oe_kurzbz[] = $val->oe_kurzbz;
|
||||
}
|
||||
}
|
||||
|
||||
return $oe_kurzbz;
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin or commoner?
|
||||
*/
|
||||
public function getIsAdmin($sender_id)
|
||||
{
|
||||
$this->_ci->load->model('system/Benutzerrolle_model', 'BenutzerrolleModel');
|
||||
$isAdmin = $this->_ci->BenutzerrolleModel->isAdminByPersonId($sender_id);
|
||||
|
||||
if (isError($isAdmin))
|
||||
{
|
||||
show_error($isAdmin->retval);
|
||||
}
|
||||
|
||||
return $isAdmin->retval;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Private methods
|
||||
|
||||
@@ -794,7 +836,7 @@ class MessageLib
|
||||
$updated = false;
|
||||
|
||||
// Updates table tbl_msg_recipient
|
||||
$resultUpdate = $this->ci->RecipientModel->update(array($receiver_id, $message_id), $parameters);
|
||||
$resultUpdate = $this->_ci->RecipientModel->update(array($receiver_id, $message_id), $parameters);
|
||||
// Checks if errors were occurred
|
||||
if (isSuccess($resultUpdate) && is_array($resultUpdate->retval))
|
||||
{
|
||||
@@ -835,13 +877,13 @@ class MessageLib
|
||||
private function _getReceiversByOekurzbz($oe_kurzbz)
|
||||
{
|
||||
// Load Benutzerfunktion_model
|
||||
$this->ci->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel');
|
||||
$this->_ci->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel');
|
||||
// Join with table public.tbl_benutzer on field uid
|
||||
$this->ci->BenutzerfunktionModel->addJoin('public.tbl_benutzer', 'uid');
|
||||
$this->_ci->BenutzerfunktionModel->addJoin('public.tbl_benutzer', 'uid');
|
||||
// Get all the valid receivers id using the oe_kurzbz
|
||||
$receivers = $this->ci->BenutzerfunktionModel->loadWhere(
|
||||
'oe_kurzbz = '.$this->ci->db->escape($oe_kurzbz).
|
||||
' AND funktion_kurzbz = '.$this->ci->db->escape($this->ci->config->item('assistent_function')).
|
||||
$receivers = $this->_ci->BenutzerfunktionModel->loadWhere(
|
||||
'oe_kurzbz = '.$this->_ci->db->escape($oe_kurzbz).
|
||||
' AND funktion_kurzbz = '.$this->_ci->db->escape($this->_ci->config->item('assistent_function')).
|
||||
' AND (NOW() BETWEEN COALESCE(datum_von, NOW()) AND COALESCE(datum_bis, NOW()))'
|
||||
);
|
||||
|
||||
@@ -884,8 +926,8 @@ class MessageLib
|
||||
private function _checkReceiverId($receiver_id)
|
||||
{
|
||||
// Load Person_model
|
||||
$this->ci->load->model('person/Person_model', 'PersonModel');
|
||||
$result = $this->ci->PersonModel->load($receiver_id);
|
||||
$this->_ci->load->model('person/Person_model', 'PersonModel');
|
||||
$result = $this->_ci->PersonModel->load($receiver_id);
|
||||
if (hasData($result))
|
||||
{
|
||||
return true;
|
||||
@@ -900,7 +942,7 @@ class MessageLib
|
||||
private function _saveMessage($sender_id, $receiver_id, $subject, $body, $relationmessage_id, $oe_kurzbz)
|
||||
{
|
||||
// Starts db transaction
|
||||
$this->ci->db->trans_start(false);
|
||||
$this->_ci->db->trans_start(false);
|
||||
|
||||
// Save Message
|
||||
$msgData = array(
|
||||
@@ -911,7 +953,7 @@ class MessageLib
|
||||
'relationmessage_id' => $relationmessage_id,
|
||||
'oe_kurzbz' => $oe_kurzbz
|
||||
);
|
||||
$result = $this->ci->MessageModel->insert($msgData);
|
||||
$result = $this->_ci->MessageModel->insert($msgData);
|
||||
if (isSuccess($result))
|
||||
{
|
||||
// Link the message with the receiver
|
||||
@@ -921,7 +963,7 @@ class MessageLib
|
||||
'message_id' => $msg_id,
|
||||
'token' => generateToken()
|
||||
);
|
||||
$result = $this->ci->RecipientModel->insert($recipientData);
|
||||
$result = $this->_ci->RecipientModel->insert($recipientData);
|
||||
if (isSuccess($result))
|
||||
{
|
||||
// Save message status
|
||||
@@ -930,20 +972,20 @@ class MessageLib
|
||||
'person_id' => $receiver_id,
|
||||
'status' => MSG_STATUS_UNREAD
|
||||
);
|
||||
$result = $this->ci->MsgStatusModel->insert($statusData);
|
||||
$result = $this->_ci->MsgStatusModel->insert($statusData);
|
||||
}
|
||||
}
|
||||
|
||||
$this->ci->db->trans_complete();
|
||||
$this->_ci->db->trans_complete();
|
||||
|
||||
if ($this->ci->db->trans_status() === false || isError($result))
|
||||
if ($this->_ci->db->trans_status() === false || isError($result))
|
||||
{
|
||||
$this->ci->db->trans_rollback();
|
||||
$this->_ci->db->trans_rollback();
|
||||
$result = $this->_error($result->msg, EXIT_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->ci->db->trans_commit();
|
||||
$this->_ci->db->trans_commit();
|
||||
$result = $this->_success($msg_id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user