mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-02 03:19:27 +00:00
- CL/Messages_model->sendExplicitTemplate now gets the sender id from
the configuration if the user is not logged (ex. job) - Added new job application/controllers/jobs/OneTimeMessages.php
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
<?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)
|
||||
*/
|
||||
public function sendMessageToApplicantsStillWaiting($studyCourseType, $semester, $months, $messageTemplate)
|
||||
{
|
||||
$this->logInfo('Send message to applicants still waiting start');
|
||||
|
||||
$queryParams = array(
|
||||
$semester,
|
||||
$studyCourseType,
|
||||
$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 = \'Interessent\'
|
||||
AND ps.studiensemester_kurzbz = ?
|
||||
AND ps.datum >= NOW() - \''.$months.' months\'::interval
|
||||
AND s.typ = ?
|
||||
AND p.prestudent_id NOT IN (
|
||||
SELECT pp.prestudent_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 ss.typ = ?
|
||||
AND pp.prestudent_id = p.prestudent_id
|
||||
)
|
||||
AND p.prestudent_id NOT IN (
|
||||
SELECT pp.prestudent_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 = \'Bewerber\'
|
||||
AND pss.studiensemester_kurzbz = ?
|
||||
AND ss.typ = ?
|
||||
AND pp.prestudent_id = p.prestudent_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->sendExplicitTemplate(
|
||||
$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('Send message to applicants still waiting end');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -430,8 +430,8 @@ class Messages_model extends CI_Model
|
||||
public function sendExplicitTemplate($prestudents, $oe_kurzbz, $vorlage_kurzbz, $msgVars)
|
||||
{
|
||||
// Retrieves the sender id
|
||||
$sender_id = getAuthPersonId();
|
||||
if (!is_numeric($sender_id)) show_error('The current logged user person_id is not defined');
|
||||
$sender_id = isLogged() ? getAuthPersonId() : null;
|
||||
if (!is_numeric($sender_id)) $sender_id = $this->config->item(MessageLib::CFG_SYSTEM_PERSON_ID);
|
||||
|
||||
// Retrieves message vars data for the given user/s
|
||||
$msgVarsData = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudents);
|
||||
@@ -454,12 +454,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