From a5e0c9ca5a89020cf0796f00bba657400a147a34 Mon Sep 17 00:00:00 2001 From: Cris Date: Wed, 27 May 2020 11:52:12 +0200 Subject: [PATCH] Added logic to provide fields of logged in user in Messaging system Signed-off-by: Cris --- application/libraries/MessageLib.php | 25 ++++++++++++++++++++++++ application/models/CL/Messages_model.php | 21 ++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index fd2051f48..31d33eda4 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -215,6 +215,31 @@ class MessageLib return $messageVars; // otherwise returns the error } + + /** + * Retrieves message vars of the logged in user from view vw_msg_vars_user + */ + public function getMessageVarsLoggedInUser() + { + // Retrieves message vars from view vw_msg_vars + $messageVars = $this->_ci->MessageModel->getMsgVarsDataLoggedInUser(); + if (isSuccess($messageVars)) // if everything is ok + { + $variablesArray = array(); + $tmpVariablesArray = getData($messageVars); + + // Starts from 1 to skip the first element which is uid + for ($i = 1; $i < count($tmpVariablesArray); $i++) + { + $variablesArray['{my_'.str_replace(' ', '_', strtolower($tmpVariablesArray[$i])).'}'] + = 'my_'. strtoupper($tmpVariablesArray[$i]); + } + + return success($variablesArray); + } + + return $messageVars; // otherwise returns the error + } /** * Retrieves organisation units for each role that a user plays inside that organisation unit diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index 67e7ff969..2bec3dd9c 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -833,6 +833,26 @@ class Messages_model extends CI_Model $variables[] = $tmpVar; } + + // --------------------------------------------------------------------------------------- + // Retrieves message vars of logged in user from database view vw_msg_vars_person + $result = null; + + // If data contains a prestudent id + $result = $this->messagelib->getMessageVarsLoggedInUser(); + + if (isError($result)) show_error(getError($result)); + + // Then builds an array that contains objects with field name and field description of logged in user data + $user_fields = array(); + foreach (getData($result) as $id => $description) + { + $obj = new stdClass(); + $obj->id = $id; + $obj->description = $description; + + $user_fields[] = $obj; + } // --------------------------------------------------------------------------------------- // Retrieves the sender id @@ -853,6 +873,7 @@ class Messages_model extends CI_Model 'subject' => $replySubject, 'body' => $replyBody, 'variables' => $variables, + 'user_fields' => $user_fields, 'organisationUnits' => getData($organisationUnits), 'senderIsAdmin' => getData($senderIsAdmin), 'recipientsArray' => $recipientsArray,