mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 00:12:15 +00:00
AbgabetoolJob notifyStudentMail function to send Emails to students about their changed abgabetermine inside the configurable threshold;
This commit is contained in:
@@ -7,3 +7,5 @@ $config['turnitin_link'] = 'https://technikum-wien.turnitin.com/sso/sp/redwood/s
|
||||
|
||||
$config['old_abgabe_beurteilung_link'] = 'https://moodle.technikum-wien.at/mod/page/view.php?id=1005052';
|
||||
|
||||
//$config['PAABGABE_EMAIL_THRESHOLD_MS'] = 86400000; // 1 day
|
||||
$config['PAABGABE_EMAIL_THRESHOLD_MS'] = 864000000; // 10 day
|
||||
@@ -42,7 +42,8 @@ class Abgabe extends FHCAPI_Controller
|
||||
'getProjektarbeitenForStudiengang' =>array('basis/abgabe_assistenz:rw'),
|
||||
'getStudiengaenge' => array('basis/abgabe_assistenz:rw'),
|
||||
'getStudentProjektarbeitAbgabeFile' => array('basis/abgabe_student:rw', 'basis/abgabe_lektor:rw', 'basis/abgabe_assistenz:rw'),
|
||||
]);
|
||||
'notifyStudentMail' => self::PERM_LOGGED
|
||||
]);
|
||||
|
||||
$this->load->library('PhrasesLib');
|
||||
$this->load->library('SignatureLib');
|
||||
@@ -68,7 +69,7 @@ class Abgabe extends FHCAPI_Controller
|
||||
'abgabetool'
|
||||
)
|
||||
);
|
||||
|
||||
$this->load->config('abgabe');
|
||||
$this->load->helper('hlp_sancho_helper');
|
||||
}
|
||||
|
||||
@@ -997,6 +998,95 @@ class Abgabe extends FHCAPI_Controller
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// test method for abgabe nightly email job
|
||||
public function notifyStudentMail()
|
||||
{
|
||||
// send all new projektarbeit abgabe since the last job run to the related student
|
||||
|
||||
// $this->logInfo('Start job queue scheduler FHC-Core->notifyBetreuerMail');
|
||||
$this->load->model('education/Projektarbeit_model', 'ProjektarbeitModel');
|
||||
$this->load->model('education/Paabgabe_model', 'PaabgabeModel');
|
||||
$this->load->model('crm/Student_model', 'StudentModel');
|
||||
|
||||
$milliseconds = $this->config->item('PAABGABE_EMAIL_THRESHOLD_MS');
|
||||
|
||||
$result = $this->PaabgabeModel->findAbgabenNewOrUpdatedSince($milliseconds);
|
||||
$retval = getData($result);
|
||||
|
||||
// group results per projektarbeit/student_uid
|
||||
$student_uids = [];
|
||||
forEach($retval as $paabgabe) {
|
||||
if(!isset($student_uids[$paabgabe->student_uid])) {
|
||||
$student_uids[$paabgabe->student_uid] = [];
|
||||
}
|
||||
|
||||
$student_uids[$paabgabe->student_uid][] = $paabgabe;
|
||||
}
|
||||
|
||||
foreach ($student_uids as $uid => $abgaben) {
|
||||
// $uid is the student's UID
|
||||
$result = $this->StudentModel->getEmailAnredeForStudentUID($uid);
|
||||
$data = getData($result)[0];
|
||||
|
||||
// $abgabe is the array of paabgabe objects
|
||||
$anredeFillString = $data->anrede=="Herr"?"r":"";
|
||||
$fullFormattedNameString = trim($data->titelpre." ".$data->vorname." ".$data->vornamen." ".$data->nachname." ".$data->titelpost);
|
||||
|
||||
// https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.spaceship-op
|
||||
// php has spaceships 🚀🚀🚀🚀🚀
|
||||
usort($abgaben, function($a, $b) {
|
||||
return strtotime($a->datum) <=> strtotime($b->datum);
|
||||
});
|
||||
|
||||
$projektarbeit_titel = $abgaben[0]->titel;
|
||||
$abgabenString = '<br /><br />';
|
||||
forEach($abgaben as $abgabe) {
|
||||
$datetime = new DateTime($abgabe->datum);
|
||||
$dateEmailFormatted = $datetime->format('d.m.Y');
|
||||
|
||||
$abgabenString .= $dateEmailFormatted.' '.$abgabe->bezeichnung.' '.$abgabe->kurzbz.'<br />';
|
||||
}
|
||||
|
||||
// Link to Entschuldigungsmanagement
|
||||
if(defined('CIS4') && CIS4) {
|
||||
$ci3BootstrapFilePath = "cis.php";
|
||||
} else {
|
||||
$ci3BootstrapFilePath = "index.ci.php";
|
||||
}
|
||||
$url = APP_ROOT.$ci3BootstrapFilePath.'/Cis/Abgabetool/Student';
|
||||
|
||||
// $linkAbgabetool = '';
|
||||
$body_fields = array(
|
||||
'anrede' => $data->anrede,
|
||||
'anredeFillString' => $anredeFillString,
|
||||
'fullFormattedNameString' => $fullFormattedNameString,
|
||||
'paTitel' => $projektarbeit_titel,
|
||||
'abgabenString' => $abgabenString,
|
||||
'linkAbgabetool' => $url
|
||||
);
|
||||
|
||||
// send email with bundled info
|
||||
sendSanchoMail(
|
||||
'paabgabeUpdatesSammelmail',
|
||||
$body_fields,
|
||||
$uid.'@'.DOMAIN,
|
||||
$this->p->t('abgabetool', 'changedAbgabeterminev2')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$this->terminateWithSuccess(
|
||||
array(
|
||||
'student_uids' => $student_uids,
|
||||
'result' => $result,
|
||||
'body_fields' => $body_fields
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private function checkAbgabeSignatur($abgabe, $projektarbeit) {
|
||||
if($abgabe->paabgabetyp_kurzbz != 'end') {
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class AbgabetoolJob extends JOB_Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->_ci =& get_instance();
|
||||
|
||||
$this->_ci->load->helper('hlp_sancho_helper');
|
||||
|
||||
$this->_ci->load->model('education/Projektarbeit_model', 'ProjektarbeitModel');
|
||||
$this->_ci->load->model('education/Paabgabe_model', 'PaabgabeModel');
|
||||
|
||||
// signatur fehlt mail
|
||||
$this->_ci->load->model('crm/Student_model', 'StudentModel');
|
||||
$this->_ci->load->model('organisation/Studiengang_model', 'StudiengangModel');
|
||||
|
||||
|
||||
// 2. begutachter mail
|
||||
$this->_ci->load->model('education/Projektbetreuer_model', 'ProjektbetreuerModel');
|
||||
|
||||
$this->loadPhrases([
|
||||
'abgabetool'
|
||||
]);
|
||||
|
||||
// $this->_ci->load->model('extensions/FHC-Core-Anwesenheiten/QR_model', 'QRModel');
|
||||
// $this->_ci->load->config('extensions/FHC-Core-Anwesenheiten/qrsettings');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function notifyBetreuerMail()
|
||||
{
|
||||
// send all new projektarbeit abgabe since the lat job run to the related betreuer
|
||||
|
||||
// $this->logInfo('Start job queue scheduler FHC-Core->notifyBetreuerMail');
|
||||
|
||||
$milliseconds = $this->_ci->config->item('PAABGABE_UPDATEAMUM_EMAIL_THRESHOLD_MILLISECONDS');
|
||||
|
||||
$result = $this->PaabgabeModel->findAbgabenNewOrUpdatedSince($milliseconds);
|
||||
$retval = getData($result);
|
||||
|
||||
// group results per projektarbeit/student_uid
|
||||
$student_uids = [];
|
||||
forEach($retval as $paabgabe) {
|
||||
if(!in_array($paabgabe->student_uid, $student_uids, true)) {
|
||||
$student_uids[$paabgabe->student_uid] = [$paabgabe];
|
||||
} else {
|
||||
$student_uids[$paabgabe->student_uid][] = $paabgabe;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// send emails with bundled info
|
||||
|
||||
// $rows_affected = $this->QRModel->db->affected_rows();
|
||||
//
|
||||
// if (isError($result))
|
||||
// {
|
||||
// $this->logError(getError($result), $milliseconds);
|
||||
// } else {
|
||||
// $this->logInfo($rows_affected." QR Codes deleted.");
|
||||
// }
|
||||
//
|
||||
// $this->logInfo('End job queue scheduler FHC-Core->notifyBetreuerMail');
|
||||
}
|
||||
|
||||
public function notifyStudentMail()
|
||||
{
|
||||
// send all new projektarbeit abgabe since the last job run to the related student
|
||||
|
||||
$this->logInfo('Start job queue scheduler FHC-Core->notifyStudentMail');
|
||||
|
||||
$milliseconds = $this->_ci->config->item('PAABGABE_EMAIL_THRESHOLD_MS');
|
||||
|
||||
$result = $this->_ci->PaabgabeModel->findAbgabenNewOrUpdatedSince($milliseconds);
|
||||
$retval = getData($result);
|
||||
|
||||
// group results per projektarbeit/student_uid
|
||||
$student_uids = [];
|
||||
forEach($retval as $paabgabe) {
|
||||
if(!isset($student_uids[$paabgabe->student_uid])) {
|
||||
$student_uids[$paabgabe->student_uid] = [];
|
||||
}
|
||||
|
||||
$student_uids[$paabgabe->student_uid][] = $paabgabe;
|
||||
}
|
||||
|
||||
foreach ($student_uids as $uid => $abgaben) {
|
||||
// $uid is the student's UID
|
||||
$result = $this->_ci->StudentModel->getEmailAnredeForStudentUID($uid);
|
||||
$data = getData($result)[0];
|
||||
|
||||
// $abgabe is the array of paabgabe objects
|
||||
$anredeFillString = $data->anrede=="Herr"?"r":"";
|
||||
$fullFormattedNameString = trim($data->titelpre." ".$data->vorname." ".$data->vornamen." ".$data->nachname." ".$data->titelpost);
|
||||
|
||||
// https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.spaceship-op
|
||||
// php has spaceships 🚀🚀🚀🚀🚀
|
||||
usort($abgaben, function($a, $b) {
|
||||
return strtotime($a->datum) <=> strtotime($b->datum);
|
||||
});
|
||||
|
||||
$projektarbeit_titel = $abgaben[0]->titel;
|
||||
$abgabenString = '<br /><br />';
|
||||
forEach($abgaben as $abgabe) {
|
||||
$datetime = new DateTime($abgabe->datum);
|
||||
$dateEmailFormatted = $datetime->format('d.m.Y');
|
||||
|
||||
$abgabenString .= $dateEmailFormatted.' '.$abgabe->bezeichnung.' '.$abgabe->kurzbz.'<br />';
|
||||
}
|
||||
|
||||
// TODO: check this config flag in job context
|
||||
// Link to Entschuldigungsmanagement
|
||||
if(defined('CIS4') && CIS4) {
|
||||
$ci3BootstrapFilePath = "cis.php";
|
||||
} else {
|
||||
$ci3BootstrapFilePath = "index.ci.php";
|
||||
}
|
||||
$url = APP_ROOT.$ci3BootstrapFilePath.'/Cis/Abgabetool/Student';
|
||||
|
||||
$body_fields = array(
|
||||
'anrede' => $data->anrede,
|
||||
'anredeFillString' => $anredeFillString,
|
||||
'fullFormattedNameString' => $fullFormattedNameString,
|
||||
'paTitel' => $projektarbeit_titel,
|
||||
'abgabenString' => $abgabenString,
|
||||
'linkAbgabetool' => $url
|
||||
);
|
||||
|
||||
// send email with bundled info
|
||||
sendSanchoMail(
|
||||
'paabgabeUpdatesSammelmail',
|
||||
$body_fields,
|
||||
$uid.'@'.DOMAIN,
|
||||
$this->p->t('abgabetool', 'changedAbgabeterminev2')
|
||||
);
|
||||
}
|
||||
|
||||
$this->logInfo('End job queue scheduler FHC-Core->notifyStudentMail');
|
||||
}
|
||||
}
|
||||
@@ -279,4 +279,12 @@ class Student_model extends DB_Model
|
||||
{
|
||||
return $student_uid . '@' . DOMAIN;
|
||||
}
|
||||
|
||||
public function getEmailAnredeForStudentUID($student_uid) {
|
||||
$qry = "SELECT anrede, titelpre, vorname, vornamen, nachname, titelpost
|
||||
FROM campus.vw_student
|
||||
WHERE uid = ?";
|
||||
|
||||
return $this->execReadOnlyQuery($qry, array($student_uid));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,5 +60,21 @@ class Paabgabe_model extends DB_Model
|
||||
|
||||
return $this->execReadOnlyQuery($qry, array($person_id));
|
||||
}
|
||||
|
||||
|
||||
public function findAbgabenNewOrUpdatedSince($milliseconds)
|
||||
{
|
||||
$interval = $milliseconds . ' milliseconds';
|
||||
$query = "SELECT projektarbeit_id, paabgabe_id, paabgabetyp_kurzbz, fixtermin, datum, kurzbz, campus.tbl_paabgabetyp.bezeichnung, campus.tbl_paabgabe.abgabedatum,
|
||||
campus.tbl_paabgabe.insertvon, campus.tbl_paabgabe.insertamum, campus.tbl_paabgabe.updatevon, campus.tbl_paabgabe.updateamum,
|
||||
campus.tbl_paabgabe.note, upload_allowed, beurteilungsnotiz, student_uid, tbl_projektarbeit.note, lehre.tbl_projektarbeit.titel
|
||||
FROM campus.tbl_paabgabe
|
||||
JOIN campus.tbl_paabgabetyp USING (paabgabetyp_kurzbz)
|
||||
JOIN lehre.tbl_projektarbeit USING (projektarbeit_id)
|
||||
|
||||
WHERE campus.tbl_paabgabe.insertamum >= NOW() - INTERVAL ?
|
||||
OR campus.tbl_paabgabe.updateamum >= NOW() - INTERVAL ?
|
||||
";
|
||||
|
||||
return $this->execQuery($query, [$interval, $interval]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44048,6 +44048,26 @@ array(
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'app' => 'core',
|
||||
'category' => 'abgabetool',
|
||||
'phrase' => 'changedAbgabeterminev2',
|
||||
'insertvon' => 'system',
|
||||
'phrases' => array(
|
||||
array(
|
||||
'sprache' => 'German',
|
||||
'text' => 'Updates: Abgabetermine Bachelor-/Masterarbeiten',
|
||||
'description' => '',
|
||||
'insertvon' => 'system'
|
||||
),
|
||||
array(
|
||||
'sprache' => 'English',
|
||||
'text' => "Updates: Deadlines Bachelor's-/Master's Thesis",
|
||||
'description' => '',
|
||||
'insertvon' => 'system'
|
||||
)
|
||||
)
|
||||
),
|
||||
// ABGABETOOL PHRASEN END
|
||||
array(
|
||||
'app' => 'core',
|
||||
|
||||
Reference in New Issue
Block a user