diff --git a/application/controllers/jobs/OneTimeMessages.php b/application/controllers/jobs/OneTimeMessages.php index 66efe3da5..39e0a946c 100644 --- a/application/controllers/jobs/OneTimeMessages.php +++ b/application/controllers/jobs/OneTimeMessages.php @@ -29,8 +29,9 @@ class OneTimeMessages extends JOB_Controller * - The given semester (ex WS2020) * - How long since applicant (months) * - The given template id to be used as message subject and body (vorlage_kurzbz) + * The sender of all the messages is specified by the parameter senderId (sender person_id) */ - public function sendMessageToApplicantsStillWaiting($studyCourseType, $semester, $months, $messageTemplate) + public function sendMessageToApplicantsStillWaiting($senderId, $studyCourseType, $semester, $months, $messageTemplate) { $this->logInfo('Send message to applicants still waiting start'); @@ -94,11 +95,12 @@ class OneTimeMessages extends JOB_Controller $prestudentIdsArray[] = $dbPrestudent->prestudent_id; } - $sendMessage = $this->CLMessagesModel->sendExplicitTemplate( - $prestudentIdsArray, // prestudents id - null, // organization unit - $messageTemplate, // template id - null // extra variables + $sendMessage = $this->CLMessagesModel->sendExplicitTemplateSenderId( + $senderId, // sender person id + $prestudentIdsArray, // prestudents id + null, // organization unit + $messageTemplate, // template id + null // extra variables ); if (isError($sendMessage)) @@ -111,6 +113,8 @@ class OneTimeMessages extends JOB_Controller ) ); } + + $this->logInfo('Total amount of prestudents: '.count($prestudentIdsArray)); } $this->logInfo('Send message to applicants still waiting end'); diff --git a/application/models/CL/Messages_model.php b/application/models/CL/Messages_model.php index a162d6639..119f9b37c 100644 --- a/application/models/CL/Messages_model.php +++ b/application/models/CL/Messages_model.php @@ -422,17 +422,26 @@ class Messages_model extends CI_Model return success('Messages sent successfully'); } - + /** - * Sends a new message using the given template and information present in parameter prestudents - * Extra variables can be added using parameter $msgVars + * Wrapper method for sendExplicitTemplateSenderId + * The sender id is retrieved from the authentication session, if not present an error would be raised */ public function sendExplicitTemplate($prestudents, $oe_kurzbz, $vorlage_kurzbz, $msgVars) { // Retrieves the sender id - $sender_id = isLogged() ? getAuthPersonId() : null; - if (!is_numeric($sender_id)) $sender_id = $this->config->item(MessageLib::CFG_SYSTEM_PERSON_ID); + $sender_id = getAuthPersonId(); + if (!is_numeric($sender_id)) show_error('The current logged user person_id is not defined'); + return $this->sendExplicitTemplateSenderId($sender_id, $prestudents, $oe_kurzbz, $vorlage_kurzbz, $msgVars); + } + + /** + * Sends a new message using the given template and information present in parameter prestudents + * Extra variables can be added using parameter $msgVars + */ + public function sendExplicitTemplateSenderId($sender_id, $prestudents, $oe_kurzbz, $vorlage_kurzbz, $msgVars) + { // Retrieves message vars data for the given user/s $msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudents); if (isError($msgVarsData)) show_error(getError($msgVarsData));