mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 20:29:29 +00:00
Merge branch 'feature-7082/Cronjob_message_für_wartende'
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
if (!defined("BASEPATH")) exit("No direct script access allowed");
|
||||
|
||||
/**
|
||||
* This job takes care of sending messages to a pool of users,
|
||||
* should not be a scheduled job, or maybe just for a short time,
|
||||
* but it is called manually every time it is needed.
|
||||
* Each method takes care to send a different message to a different pool of users,
|
||||
* so they are very specialize, diffucult to be reused.
|
||||
*/
|
||||
class OneTimeMessages extends JOB_Controller
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Loads CLMessagesModel
|
||||
$this->load->model('CL/Messages_model', 'CLMessagesModel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the same message to all the applicants whith:
|
||||
* - Status set as "Wartender"
|
||||
* - The given study course type (b = bachelor, m = master)
|
||||
* - 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($senderId, $studyCourseType, $semester, $months, $messageTemplate)
|
||||
{
|
||||
$this->logInfo('Send message to applicants still waiting start');
|
||||
|
||||
$queryParams = array(
|
||||
$semester,
|
||||
$studyCourseType,
|
||||
$semester,
|
||||
$studyCourseType,
|
||||
$semester,
|
||||
$studyCourseType
|
||||
);
|
||||
|
||||
$dbModel = new DB_Model();
|
||||
|
||||
$dbPrestudents = $dbModel->execReadOnlyQuery(
|
||||
'SELECT p.prestudent_id
|
||||
FROM public.tbl_prestudent p
|
||||
JOIN public.tbl_prestudentstatus ps USING (prestudent_id)
|
||||
JOIN public.tbl_studiengang s USING (studiengang_kz)
|
||||
WHERE ps.status_kurzbz = \'Wartender\'
|
||||
AND ps.studiensemester_kurzbz = ?
|
||||
AND ps.datum <= NOW() - \''.$months.' months\'::interval
|
||||
AND s.typ = ?
|
||||
AND NOT EXISTS (
|
||||
SELECT pp.person_id
|
||||
FROM public.tbl_prestudent pp
|
||||
JOIN public.tbl_prestudentstatus pss USING (prestudent_id)
|
||||
JOIN public.tbl_studiengang ss USING (studiengang_kz)
|
||||
WHERE pss.status_kurzbz = \'Aufgenommener\'
|
||||
AND pss.studiensemester_kurzbz = ?
|
||||
AND ss.typ = ?
|
||||
AND pp.person_id = p.person_id
|
||||
)
|
||||
AND NOT EXISTS (
|
||||
SELECT pp.person_id
|
||||
FROM public.tbl_prestudent pp
|
||||
JOIN public.tbl_prestudentstatus pss USING (prestudent_id)
|
||||
JOIN public.tbl_studiengang ss USING (studiengang_kz)
|
||||
WHERE pss.status_kurzbz = \'Student\'
|
||||
AND pss.studiensemester_kurzbz = ?
|
||||
AND ss.typ = ?
|
||||
AND pp.person_id = p.person_id
|
||||
)',
|
||||
$queryParams
|
||||
);
|
||||
|
||||
if (isError($dbPrestudents))
|
||||
{
|
||||
$this->logError(getError($dbPrestudents), $queryParams);
|
||||
}
|
||||
elseif (!hasData($dbPrestudents))
|
||||
{
|
||||
$this->logInfo('There were no users to send message');
|
||||
}
|
||||
else
|
||||
{
|
||||
$prestudentIdsArray = array();
|
||||
|
||||
foreach (getData($dbPrestudents) as $dbPrestudent)
|
||||
{
|
||||
$prestudentIdsArray[] = $dbPrestudent->prestudent_id;
|
||||
}
|
||||
|
||||
$sendMessage = $this->CLMessagesModel->sendExplicitTemplateSenderId(
|
||||
$senderId, // sender person id
|
||||
$prestudentIdsArray, // prestudents id
|
||||
null, // organization unit
|
||||
$messageTemplate, // template id
|
||||
null // extra variables
|
||||
);
|
||||
|
||||
if (isError($sendMessage))
|
||||
{
|
||||
$this->logError(
|
||||
getError($sendMessage),
|
||||
array(
|
||||
'prestudents' => $prestudentIdsArray,
|
||||
'template' => $messageTemplate
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->logInfo('Total amount of prestudents: '.count($prestudentIdsArray));
|
||||
}
|
||||
|
||||
$this->logInfo('Send message to applicants still waiting end');
|
||||
}
|
||||
}
|
||||
@@ -422,10 +422,10 @@ 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)
|
||||
{
|
||||
@@ -433,6 +433,15 @@ class Messages_model extends CI_Model
|
||||
$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));
|
||||
@@ -454,12 +463,12 @@ class Messages_model extends CI_Model
|
||||
if (is_array($msgVars)) $msgVarsDataArray = array_merge($msgVarsDataArray, $msgVars);
|
||||
|
||||
$message = $this->messagelib->sendMessageUserTemplate(
|
||||
$msgVarsDataArray['person_id'], // receiversPersonId
|
||||
$vorlage_kurzbz, // vorlage
|
||||
$msgVarsDataArray, // parseData
|
||||
null, // orgform
|
||||
$sender_id, // sender_id
|
||||
$oe_kurzbz // senderOU
|
||||
$msgVarsDataArray['person_id'], // receiversPersonId
|
||||
$vorlage_kurzbz, // vorlage
|
||||
$msgVarsDataArray, // parseData
|
||||
null, // orgform
|
||||
$sender_id, // sender_id
|
||||
$oe_kurzbz // senderOU
|
||||
);
|
||||
|
||||
if (isError($message)) return $message;
|
||||
|
||||
Reference in New Issue
Block a user