mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-24 10:22:18 +00:00
- Renamed view system/messages/messageSent.php to system/messages/htmlSuccess.php
- Added new view system/messages/htmlError.php - Renamed view system/messages/messageWrite.php to system/messages/htmlWriteTemplate.php - Added new widget views: widgets/Dropdown_widget.php and widgets/MultipleDropdown_widget.php - Added new CSS public/css/Widgets.css - Controller system/FASMessages: - Renamed method write to writeTemplate and method writeReply to writeReplyTemplate - Removed all the private methods and moved all the logic to model CL/Messages_model - Methods writeTemplate and writeReplyTemplate do not need anymore the sender id as parameter - Controller system/Messages: - Renamed method write to writeTemplate - Renamed method send to sendImplicitTemplate - Renamed method sendJson to sendExplicitTemplateJson - Moved all the logic to model CL/Messages_model - Adapted php and JS code to use these new methods names and interfaces - Removed public method getIsAdmin from MessageLib - Method _sendMessage of MessageLib now returns the saved message ids - Added new package olifolkerd/tabulator to composer - Added new parameter widgets to view templates/FHC-Header.php - Added new HTML widget widgets/Dropdown_widget and widgets/MultipleDropdown_widget - Added constants REPLY_SUBJECT_PREFIX and REPLY_BODY_PREFIX to model CL/Messages_model - Added new public methods prepareHtmlWriteTemplatePersons, prepareHtmlWriteTemplatePrestudents, sendImplicitTemplate, sendExplicitTemplate, getVorlage, parseMessageText and getMessageFromIds to model CL/Messages_model - Added new private methods _getAuthUser, _lowerReplaceSpaceArrayKeys, _addOeToPrestudents, _personLog and _prepareHtmlWriteTemplate to model CL/Messages_model
This commit is contained in:
@@ -11,17 +11,15 @@ class FASMessages extends Auth_Controller
|
||||
{
|
||||
parent::__construct(
|
||||
array(
|
||||
'write' => 'basis/message:rw',
|
||||
'writeReply' => 'basis/message:rw'
|
||||
'writeTemplate' => 'basis/message:rw',
|
||||
'writeReplyTemplate' => 'basis/message:rw'
|
||||
)
|
||||
);
|
||||
|
||||
// Loads the message library
|
||||
$this->load->library('MessageLib');
|
||||
|
||||
// Loads the widget library
|
||||
$this->load->library('WidgetLib');
|
||||
// Loads model CLMessagesModel which contains the GUI logic
|
||||
$this->load->model('CL/Messages_model', 'CLMessagesModel');
|
||||
|
||||
// Phrases used in loaded views
|
||||
$this->loadPhrases(
|
||||
array(
|
||||
'global',
|
||||
@@ -30,162 +28,33 @@ class FASMessages extends Auth_Controller
|
||||
);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Public methods
|
||||
|
||||
/**
|
||||
* Write a new message
|
||||
* Writes a new message to a prestudent using templates
|
||||
*/
|
||||
public function write($sender_id)
|
||||
public function writeTemplate()
|
||||
{
|
||||
$prestudent_id = $this->input->post('prestudent_id'); // recipients prestudend_id(s)
|
||||
$prestudents = $this->input->post('prestudent_id'); // recipients prestudend_id(s)
|
||||
|
||||
if (!is_numeric($sender_id))
|
||||
{
|
||||
show_error('The current logged user person_id is not defined');
|
||||
}
|
||||
|
||||
$msgVarsData = $this->_getMsgVarsData($prestudent_id);
|
||||
|
||||
// Retrieves message vars for a person from view view vw_msg_vars_person
|
||||
$variablesArray = $this->_getMessageVarsPerson();
|
||||
|
||||
// Organisation units used to get the templates
|
||||
$oe_kurzbz = $this->_getOeKurzbz($sender_id);
|
||||
|
||||
// Admin or commoner?
|
||||
$isAdmin = $this->_getIsAdmin($sender_id);
|
||||
|
||||
$data = array(
|
||||
'recipients' => getData($msgVarsData),
|
||||
'variables' => $variablesArray,
|
||||
'oe_kurzbz' => $oe_kurzbz, // used to get the templates
|
||||
'isAdmin' => $isAdmin
|
||||
);
|
||||
|
||||
$this->load->view('system/messages/messageWrite', $data);
|
||||
// Loads the view to write a new message with a template
|
||||
$this->load->view(
|
||||
'system/messages/htmlWriteTemplate',
|
||||
$this->CLMessagesModel->prepareHtmlWriteTemplatePrestudents($prestudents)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a reply
|
||||
* Writes a reply to a message identified by parameters $message_id and $recipient_id
|
||||
* The recipient is a prestudent
|
||||
* Uses templates
|
||||
*/
|
||||
public function writeReply($sender_id, $msg_id, $receiver_id)
|
||||
public function writeReplyTemplate($message_id, $recipient_id)
|
||||
{
|
||||
$prestudent_id = $this->input->post('prestudent_id'); // recipients prestudend_id(s)
|
||||
$prestudents = $this->input->post('prestudent_id'); // recipients prestudend_id(s)
|
||||
|
||||
if (!is_numeric($sender_id))
|
||||
{
|
||||
show_error('The current logged user person_id is not defined');
|
||||
}
|
||||
|
||||
if (!is_numeric($msg_id))
|
||||
{
|
||||
show_error('The msg_id must be a number');
|
||||
}
|
||||
|
||||
if (!is_numeric($receiver_id))
|
||||
{
|
||||
show_error('The receiver_id must be a number');
|
||||
}
|
||||
|
||||
$msg = $this->_getMessage($msg_id, $receiver_id);
|
||||
|
||||
$msgVarsData = $this->_getMsgVarsData($prestudent_id);
|
||||
|
||||
// Retrieves message vars for a person from view view vw_msg_vars_person
|
||||
$variablesArray = $this->_getMessageVarsPerson();
|
||||
|
||||
// Organisation units used to get the templates
|
||||
$oe_kurzbz = $this->_getOeKurzbz($sender_id);
|
||||
|
||||
// Admin or commoner?
|
||||
$isAdmin = $this->_getIsAdmin($sender_id);
|
||||
|
||||
$data = array(
|
||||
'recipients' => getData($msgVarsData),
|
||||
'message' => $msg,
|
||||
'variables' => $variablesArray,
|
||||
'oe_kurzbz' => $oe_kurzbz, // used to get the templates
|
||||
'isAdmin' => $isAdmin
|
||||
);
|
||||
|
||||
$this->load->view('system/messages/messageWrite', $data);
|
||||
// Loads the view to write a new message with a template
|
||||
$this->load->view(
|
||||
'system/messages/htmlWriteTemplate',
|
||||
$this->CLMessagesModel->prepareHtmlWriteTemplatePrestudents($prestudents, $message_id, $recipient_id)
|
||||
);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Private methods
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _getMessage($msg_id, $receiver_id)
|
||||
{
|
||||
$msg = $this->messagelib->getMessage($msg_id, $receiver_id);
|
||||
if (isError($msg))
|
||||
{
|
||||
show_error(getData($msg));
|
||||
}
|
||||
elseif (!hasData($msg))
|
||||
{
|
||||
show_error('The selected message does not exist');
|
||||
}
|
||||
else
|
||||
{
|
||||
$msg = getData($msg)[0];
|
||||
}
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves message vars from view vw_msg_vars
|
||||
*/
|
||||
private function _getMsgVarsData($prestudent_id)
|
||||
{
|
||||
$this->load->model('system/Message_model', 'MessageModel');
|
||||
$msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id);
|
||||
|
||||
if (isError($msgVarsData))
|
||||
{
|
||||
show_error(getData($msgVarsData));
|
||||
}
|
||||
|
||||
return $msgVarsData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method to call messagelib->getMessageVarsPerson
|
||||
*/
|
||||
private function _getMessageVarsPerson()
|
||||
{
|
||||
$variables = $this->messagelib->getMessageVarsPerson();
|
||||
|
||||
if (isError($variables)) show_error(getData($variables));
|
||||
|
||||
return getData($variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method to call messagelib->getOeKurzbz
|
||||
*/
|
||||
private function _getOeKurzbz($sender_id)
|
||||
{
|
||||
$oe_kurzbz = $this->messagelib->getOeKurzbz($sender_id);
|
||||
|
||||
if (isError($oe_kurzbz)) show_error(getData($oe_kurzbz));
|
||||
|
||||
return getData($oe_kurzbz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method to call messagelib->getIsAdmin
|
||||
*/
|
||||
private function _getIsAdmin($sender_id)
|
||||
{
|
||||
$isAdmin = $this->messagelib->getIsAdmin($sender_id);
|
||||
|
||||
if (isError($isAdmin)) show_error(getData($isAdmin));
|
||||
|
||||
return getData($isAdmin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,28 +4,23 @@ if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Messages extends Auth_Controller
|
||||
{
|
||||
/**
|
||||
* MessageLib is loaded by CLMessagesModel
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
array(
|
||||
'write' => array('basis/message:rw', 'infocenter:rw'),
|
||||
'send' => array('basis/message:rw', 'infocenter:rw'),
|
||||
'sendJson' => array('basis/message:rw', 'infocenter:rw'),
|
||||
'writeTemplate' => array('basis/message:rw', 'infocenter:rw'),
|
||||
'sendImplicitTemplate' => array('basis/message:rw', 'infocenter:rw'),
|
||||
'sendExplicitTemplateJson' => array('basis/message:rw', 'infocenter:rw'),
|
||||
'getVorlage' => array('basis/message:r', 'infocenter:r'),
|
||||
'parseMessageText' => array('basis/message:r', 'infocenter:r'),
|
||||
'getMessageFromIds' => array('basis/message:r', 'infocenter:r')
|
||||
)
|
||||
);
|
||||
|
||||
// Loads the widget library
|
||||
$this->load->library('WidgetLib');
|
||||
|
||||
$this->load->model('system/Message_model', 'MessageModel');
|
||||
// Loads model CLMessagesModel which contains the GUI logic
|
||||
$this->load->model('CL/Messages_model', 'CLMessagesModel');
|
||||
|
||||
// Phrases used in loaded views
|
||||
$this->loadPhrases(
|
||||
array(
|
||||
'global',
|
||||
@@ -38,65 +33,45 @@ class Messages extends Auth_Controller
|
||||
// Public methods - HTML output
|
||||
|
||||
/**
|
||||
* Initialize all the parameters used by view system/messages/messageWrite
|
||||
* to build a GUI used to write a messate to user/s
|
||||
* Initialize all the parameters used by view system/messages/htmlWriteTemplate
|
||||
* to build a GUI used to write a messate to user/s using a template
|
||||
*/
|
||||
public function write()
|
||||
public function writeTemplate()
|
||||
{
|
||||
$persons = $this->input->post('person_id');
|
||||
|
||||
$authUser = $this->CLMessagesModel->getAuthUser();
|
||||
if (isError($authUser)) show_error(getData($authUser));
|
||||
|
||||
$sender_id = getData($authUser)[0]->person_id;
|
||||
|
||||
// Retrieves person information
|
||||
$msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($persons);
|
||||
if (isError($msgVarsData)) show_error(getData($msgVarsData));
|
||||
|
||||
// Retrieves message vars from view vw_msg_vars_person
|
||||
$variables = $this->messagelib->getMessageVarsPerson();
|
||||
if (isError($variables)) show_error(getData($variables));
|
||||
|
||||
// Organisation units used to get the templates
|
||||
$oe_kurzbz = $this->messagelib->getOeKurzbz($sender_id);
|
||||
if (isError($oe_kurzbz)) show_error(getData($oe_kurzbz));
|
||||
|
||||
// Admin or commoner?
|
||||
$isAdmin = $this->messagelib->getIsAdmin($sender_id);
|
||||
if (isError($isAdmin)) show_error(getData($isAdmin));
|
||||
|
||||
// Loads the view to write a new message with a template
|
||||
$this->load->view(
|
||||
'system/messages/messageWrite',
|
||||
array (
|
||||
'recipients' => getData($msgVarsData), // recipients data
|
||||
'variables' => getData($variables), // message vars
|
||||
'oe_kurzbz' => getData($oe_kurzbz), // used to get the templates
|
||||
'isAdmin' => getData($isAdmin) // is admin?
|
||||
)
|
||||
'system/messages/htmlWriteTemplate',
|
||||
$this->CLMessagesModel->prepareHtmlWriteTemplatePersons($persons)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a new message or reply to user/s
|
||||
* If a relationmessage_id this message is a reply to another one
|
||||
* Body is a template and will be parsed using information present in persons parameter
|
||||
*/
|
||||
public function send()
|
||||
public function sendImplicitTemplate()
|
||||
{
|
||||
$subject = $this->input->post('subject');
|
||||
$body = $this->input->post('body');
|
||||
$persons = $this->input->post('persons');
|
||||
$relationmessage_id = $this->input->post('relationmessage_id');
|
||||
|
||||
// Retrieves message vars data for the fiven user/s
|
||||
$msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($persons);
|
||||
|
||||
// Send the message
|
||||
$send = $this->CLMessagesModel->send($msgVarsData, $relationmessage_id);
|
||||
|
||||
$this->load->view('system/messages/messageSent', array('success' => isSuccess($send)));
|
||||
$sendImplicitTemplate = $this->CLMessagesModel->sendImplicitTemplate($persons, $subject, $body, $relationmessage_id);
|
||||
if (isSuccess($sendImplicitTemplate))
|
||||
{
|
||||
$this->load->view('system/messages/htmlSuccess');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->load->view('system/messages/htmlError');
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Public methods - JSON output - called by this controller and FASMessages (view system/messages/messageWrite)
|
||||
// Public methods - JSON output - called by this controller and FASMessages (view system/messages/htmlWriteTemplate)
|
||||
|
||||
/**
|
||||
* Returns an object that represent a template store in database
|
||||
@@ -106,24 +81,8 @@ class Messages extends Auth_Controller
|
||||
public function getVorlage()
|
||||
{
|
||||
$vorlage_kurzbz = $this->input->get('vorlage_kurzbz');
|
||||
$result = error('The given vorlage_kurzbz is not valid');
|
||||
|
||||
if (!isEmptyString($vorlage_kurzbz))
|
||||
{
|
||||
$this->load->model('system/Vorlagestudiengang_model', 'VorlagestudiengangModel');
|
||||
$this->VorlagestudiengangModel->addOrder('version','DESC');
|
||||
|
||||
$result = $this->VorlagestudiengangModel->loadWhere(array('vorlage_kurzbz' => $vorlage_kurzbz));
|
||||
}
|
||||
|
||||
if (isError($result) || !hasData($result))
|
||||
{
|
||||
$this->outputJsonError(getData($result));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->outputJsonSuccess(getData($result));
|
||||
}
|
||||
$this->outputJson($this->CLMessagesModel->getVorlage($vorlage_kurzbz));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,26 +93,8 @@ class Messages extends Auth_Controller
|
||||
{
|
||||
$person_id = $this->input->get('person_id');
|
||||
$text = $this->input->get('text');
|
||||
$msgVarsData = error('The given person_id is not a valid number');
|
||||
|
||||
if (is_numeric($person_id))
|
||||
{
|
||||
$msgVarsData = $this->MessageModel->getMsgVarsDataByPersonId($person_id);
|
||||
}
|
||||
|
||||
if (isError($msgVarsData) || !hasData($msgVarsData))
|
||||
{
|
||||
$this->outputJsonError(getData($msgVarsData));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->outputJsonSuccess(
|
||||
parseText(
|
||||
$text,
|
||||
$this->CLMessagesModel->replaceKeys((array)getData($msgVarsData)[0])
|
||||
)
|
||||
);
|
||||
}
|
||||
$this->outputJson($this->CLMessagesModel->parseMessageText($person_id, $text));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
@@ -164,19 +105,10 @@ class Messages extends Auth_Controller
|
||||
*/
|
||||
public function getMessageFromIds()
|
||||
{
|
||||
$msg_id = $this->input->get('msg_id');
|
||||
$message_id = $this->input->get('msg_id');
|
||||
$receiver_id = $this->input->get('receiver_id');
|
||||
|
||||
$msg = $this->messagelib->getMessage($msg_id, $receiver_id);
|
||||
|
||||
if (isError($msg) || !hasData($msg))
|
||||
{
|
||||
$this->outputJson(array());
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->outputJson(array(getData($msg)[0]));
|
||||
}
|
||||
$this->outputJson($this->CLMessagesModel->getMessageFromIds($message_id, $receiver_id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,27 +116,16 @@ class Messages extends Auth_Controller
|
||||
* - The recipients are prestudents
|
||||
* - An email template with message var may be provided
|
||||
* - A global organisation unit may be provided, otherwise is used the prestudent one
|
||||
* - A template is explicitly specified
|
||||
*/
|
||||
public function sendJson()
|
||||
public function sendExplicitTemplateJson()
|
||||
{
|
||||
$prestudents = $this->input->post('prestudents');
|
||||
$vorlage_kurzbz = $this->input->post('vorlage_kurzbz');
|
||||
$oe_kurzbz = $this->input->post('oe_kurzbz');
|
||||
$vorlage_kurzbz = $this->input->post('vorlage_kurzbz');
|
||||
$msgVars = $this->input->post('msgvars');
|
||||
|
||||
$msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudents);
|
||||
|
||||
$this->load->model('crm/Prestudent_model', 'PrestudentModel');
|
||||
$prestudentsData = $this->PrestudentModel->getOrganisationunits($prestudents);
|
||||
|
||||
// Adds the organisation unit to each prestudent
|
||||
if (isEmptyString($oe_kurzbz) && hasData($msgVarsData) && hasData($prestudentsData))
|
||||
{
|
||||
$this->CLMessagesModel->addOeToPrestudents($msgVarsData, $prestudentsData);
|
||||
}
|
||||
|
||||
$send = $this->CLMessagesModel->send($msgVarsData, null, $oe_kurzbz, $vorlage_kurzbz, $msgVars);
|
||||
|
||||
$this->outputJson(getData($send));
|
||||
$sendExplicitTemplate = $this->CLMessagesModel->sendExplicitTemplate($prestudents, $oe_kurzbz, $vorlage_kurzbz, $msgVars);
|
||||
$this->outputJson(getData($sendExplicitTemplate));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user