Bugfixes to allow to write to a person or to a prestudent from different GUIs

This commit is contained in:
Paolo
2020-02-12 14:43:11 +01:00
parent 98b2abeb51
commit 6882199d0e
8 changed files with 62 additions and 54 deletions
@@ -56,18 +56,18 @@ class Messages extends Auth_Controller
{
$subject = $this->input->post('subject');
$body = $this->input->post('body');
$persons = $this->input->post('persons');
$prestudenten = $this->input->post('prestudenten');
$recipients_ids = $this->input->post('recipients_ids');
$relationmessage_id = $this->input->post('relationmessage_id');
$type = $this->input->post('type');
$sendImplicitTemplate = $this->CLMessagesModel->sendImplicitTemplate($prestudenten, $subject, $body, $relationmessage_id);
$sendImplicitTemplate = $this->CLMessagesModel->sendImplicitTemplate($type, $recipients_ids, $subject, $body, $relationmessage_id);
if (isSuccess($sendImplicitTemplate))
{
$this->load->view('system/messages/htmlSuccess');
$this->load->view('system/messages/htmlMessageSentSuccess');
}
else
{
$this->load->view('system/messages/htmlError');
$this->load->view('system/messages/htmlMessageSentError');
}
}
@@ -92,17 +92,21 @@ class Messages extends Auth_Controller
*/
public function parseMessageText()
{
$person_id = $this->input->get('person_id');
$prestudent_id = $this->input->get('prestudent_id');
$receiver_id = $this->input->get('receiver_id');
$text = $this->input->get('text');
$type = $this->input->get('type');
if (!isEmptyString($person_id))
if ($type == Messages_model::TYPE_PERSONS)
{
$this->outputJson($this->CLMessagesModel->parseMessageText($person_id, $text));
$this->outputJson($this->CLMessagesModel->parseMessageTextPerson($receiver_id, $text));
}
elseif ($type == Messages_model::TYPE_PRESTUDENTS)
{
$this->outputJson($this->CLMessagesModel->parseMessageTextPrestudent($receiver_id, $text));
}
else
{
$this->outputJson($this->CLMessagesModel->parseMessageTextPrestudent($prestudent_id, $text));
$this->outputJsonError('Not a person nor a prestudent was provided');
}
}
@@ -73,11 +73,11 @@ class ViewMessage extends FHC_Controller
$sendReply = $this->CLMessagesModel->sendReply($receiver_id, $subject, $body, $relationmessage_id, $token);
if (isSuccess($sendReply))
{
$this->load->view('system/messages/htmlSuccess');
$this->load->view('system/messages/htmlMessageSentSuccess');
}
else
{
$this->load->view('system/messages/htmlError');
$this->load->view('system/messages/htmlMessageSentError');
}
}
+34 -23
View File
@@ -23,6 +23,10 @@ class Messages_model extends CI_Model
const NO_AUTH_UID = 'online'; // hard coded uid if no authentication is performed
const ALT_OE = 'infocenter'; // alternative organisation unit when no one is found for a presetudent
// Recipients types
const TYPE_PERSONS = 'persons';
const TYPE_PRESTUDENTS = 'prestudents';
/**
* Constructor
*/
@@ -330,14 +334,22 @@ class Messages_model extends CI_Model
* Sends a new message or a reply to a message (if $relationmessage_id is given)
* using the template stored in the subject and body
*/
public function sendImplicitTemplate($persons, $subject, $body, $relationmessage_id = null)
public function sendImplicitTemplate($type, $recipients_ids, $subject, $body, $relationmessage_id = null)
{
// Retrieves the sender id
$sender_id = getAuthPersonId();
if (!is_numeric($sender_id)) show_error('The current logged user person_id is not defined');
$msgVarsData = error('No persons nor prestudents were provided');
// Retrieves message vars data for the given user/s
$msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($persons);
if ($type == self::TYPE_PERSONS) // if persons were given
{
$msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($recipients_ids);
}
elseif ($type == self::TYPE_PRESTUDENTS) // otherwise prestudents were given
{
$msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($recipients_ids);
}
if (isError($msgVarsData)) show_error(getError($msgVarsData));
if (!hasData($msgVarsData)) show_error('No recipients were given');
@@ -361,9 +373,12 @@ class Messages_model extends CI_Model
if (isError($message)) return $message;
if (!hasData($message)) return error('No messages were saved in database');
// Write log entry
$personLog = $this->_personLog($sender_id, $msgVarsDataArray['person_id'], getData($message)[0]);
if (isError($personLog)) return $personLog;
// Write log entry only if persons were given
if ($type == self::TYPE_PERSONS)
{
$personLog = $this->_personLog($sender_id, $msgVarsDataArray['person_id'], getData($message)[0]);
if (isError($personLog)) return $personLog;
}
}
return success('Messages sent successfully');
@@ -515,14 +530,11 @@ class Messages_model extends CI_Model
* Parse the given given text using data from the given user
* Use the CI parser which performs simple text substitution for pseudo-variable
*/
public function parseMessageText($person_id, $text)
public function parseMessageTextPerson($person_id, $text)
{
$parseMessageText = error('The given person_id is not a valid number');
if (is_numeric($person_id))
{
$parseMessageText = $this->MessageModel->getMsgVarsDataByPersonId($person_id);
}
if (is_numeric($person_id)) $parseMessageText = $this->MessageModel->getMsgVarsDataByPersonId($person_id);
if (hasData($parseMessageText))
{
@@ -545,10 +557,7 @@ class Messages_model extends CI_Model
{
$parseMessageText = error('The given prestudent_id is not a valid number');
if (is_numeric($prestudent_id))
{
$parseMessageText = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id);
}
if (is_numeric($prestudent_id)) $parseMessageText = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id);
if (hasData($parseMessageText))
{
@@ -683,27 +692,30 @@ class Messages_model extends CI_Model
// - persons: a string that contains HTML input hidden with alla the receivers id (person_id)
$recipientsArray = array();
$recipientsList = '';
$persons = '';
$prestudenten = '';
$recipients_ids = '';
foreach (getData($info) as $receiver)
{
$id = 0;
$recipient = new stdClass();
$recipient->description = $receiver->Vorname.' '.$receiver->Nachname;
$recipientsList .= $receiver->Vorname.' '.$receiver->Nachname.'; ';
// If it is a prestudent then
if (isset($receiver->prestudent_id) && is_numeric($receiver->prestudent_id))
{
$recipient->id = $receiver->prestudent_id;
$id = $receiver->prestudent_id;
}
else // otherwise it is a person
{
$recipient->id = $receiver->person_id;
$id = $receiver->person_id;
}
$recipients_ids .= '<input type="hidden" name="recipients_ids[]" value="'.$id.'">'."\n";
$recipientsArray[] = $recipient;
$recipientsList .= $receiver->Vorname.' '.$receiver->Nachname.'; ';
$persons .= '<input type="hidden" name="persons[]" value="'.$receiver->person_id.'">'."\n";
$prestudenten .= '<input type="hidden" name="prestudenten[]" value="'.$receiver->prestudent_id.'">'."\n";
}
// ---------------------------------------------------------------------------------------
@@ -738,12 +750,12 @@ class Messages_model extends CI_Model
if (isset(getData($info)[0]->prestudent_id) && is_numeric(getData($info)[0]->prestudent_id))
{
$variablesResult = $this->messagelib->getMessageVarsPrestudent();
$type = '<input type="hidden" id="type" value="prestudents">';
$type = '<input type="hidden" id="type" name="type" value="'.self::TYPE_PRESTUDENTS.'">';
}
else
{
$variablesResult = $this->messagelib->getMessageVarsPerson();
$type = '<input type="hidden" id="type" value="persons">';
$type = '<input type="hidden" id="type" name="type" value="'.self::TYPE_PERSONS.'">';
}
if (isError($variablesResult)) show_error(getError($variablesResult));
@@ -780,8 +792,7 @@ class Messages_model extends CI_Model
'organisationUnits' => getData($organisationUnits),
'senderIsAdmin' => getData($senderIsAdmin),
'recipientsArray' => $recipientsArray,
'persons' => $persons,
'prestudenten' => $prestudenten,
'recipients_ids' => $recipients_ids,
'relationmessage_id' => $relationmessage,
'type' => $type
);
@@ -2,7 +2,7 @@
$this->load->view(
'templates/FHC-Header',
array(
'title' => 'Message sent failure',
'title' => 'Message sent failure - Fehler beim Senden der Nachricht',
'jquery' => true,
'bootstrap' => true,
'fontawesome' => true,
@@ -2,7 +2,7 @@
$this->load->view(
'templates/FHC-Header',
array(
'title' => 'Message sent successfully',
'title' => 'Message sent successfully - Nachricht erfolgreich versandt!',
'jquery' => true,
'bootstrap' => true,
'fontawesome' => true,
@@ -2,7 +2,7 @@
$this->load->view(
'templates/FHC-Header',
array(
'title' => 'Read a message',
'title' => 'Read message - Lies die Nachricht',
'jquery' => true,
'bootstrap' => true,
'fontawesome' => true,
@@ -162,8 +162,12 @@
<textarea id="tinymcePreview"></textarea>
</div>
<<<<<<< Updated upstream
<?php echo $persons; ?>
<?php echo $prestudenten; ?>
=======
<?php echo $recipients_ids; ?>
>>>>>>> Stashed changes
<?php echo $relationmessage_id; ?>
<?php echo $type; ?>
+5 -16
View File
@@ -19,24 +19,13 @@ function tinymcePreviewSetContent()
function parseMessageText(receiver_id, text)
{
var data = {text: text};
if ($("#type").val() == 'persons')
{
data.person_id = receiver_id;
}
else if ($("#type").val() == 'prestudents')
{
data.prestudent_id = receiver_id;
}
else
{
return;
}
FHC_AjaxClient.ajaxCallGet(
"system/messages/Messages/parseMessageText",
data,
{
receiver_id: receiver_id,
text: text,
type: $("#type").val()
},
{
successCallback: function(data, textStatus, jqXHR) {