Skip to content

Commit

Permalink
prg - mantis_27750 - fix reminder mails (ILIAS-eLearning#2641)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniwe4 authored Apr 14, 2020
1 parent a3a6f82 commit 79abd38
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 68 deletions.
73 changes: 49 additions & 24 deletions Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,21 @@ public function setAutoMailSettings(\ilStudyProgrammeAutoMailSettings $automail_
$this->settings = $this->settings->withAutoMailSettings($automail_settings);
}

public function shouldSendReAssignedMail() : bool
{
return $this->getAutoMailSettings()->getSendReAssignedMail();
}

public function shouldSendInfoToReAssignMail() : bool
{
return $this->getAutoMailSettings()->getReminderNotRestartedByUserDays() > 0;
}

public function shouldSendRiskyToFailMail() : bool
{
return $this->getAutoMailSettings()->getProcessingEndsNotSuccessfulDays() > 0;
}

////////////////////////////////////
// TREE NAVIGATION
////////////////////////////////////
Expand Down Expand Up @@ -1962,7 +1977,7 @@ public static function sendReAssignedMail(int $ref_id, int $usr_id) : bool
$lng = $DIC['lng'];
$log = $DIC['ilLog'];
$lng->loadLanguageModule("prg");
$senderFactory = $DIC["mail.mime.sender.factory"];
$lng->loadLanguageModule("mail");

/** @var ilObjStudyProgramme $prg */
$prg = ilObjStudyProgramme::getInstanceByRefId($ref_id);
Expand All @@ -1972,58 +1987,68 @@ public static function sendReAssignedMail(int $ref_id, int $usr_id) : bool
return false;
}

$mail = new ilMimeMail();
$mail->From($senderFactory->system());

$mailOptions = new \ilMailOptions($usr_id);
$mail->To($mailOptions->getExternalEmailAddresses());

$subject = $lng->txt("re_assigned_mail_subject");
$mail->Subject($subject);

$gender = ilObjUser::_lookupGender($usr_id);
$name = ilObjUser::_lookupFullname($usr_id);

$body = sprintf(
$lng->txt("re_assigned_mail_body"),
$lng->txt("mail_salutation_" . $gender),
$name,
$prg->getTitle()
);
$mail->Body($body);

return $mail->Send();
$send = true;
$mail = new ilMail(ANONYMOUS_USER_ID);
try {
$mail->enqueue(
ilObjUser::_lookupLogin($usr_id),
'',
'',
$subject,
$body,
null
);
} catch (Exception $e) {
$send = false;
}

return $send;
}

public static function sendInvalidateMail(int $ref_id, int $usr_id) : bool
{
global $DIC;
$lng = $DIC['lng'];
$lng->loadLanguageModule("prg");
$senderFactory = $DIC["mail.mime.sender.factory"];
$lng->loadLanguageModule("mail");

$prg = ilObjStudyProgramme::getInstanceByRefId($ref_id);

$mail = new ilMimeMail();
$mail->From($senderFactory->system());

$mailOptions = new \ilMailOptions($usr_id);
$mail->To($mailOptions->getExternalEmailAddresses());

$subject = $lng->txt("invalidate_mail_subject");
$mail->Subject($subject);

$gender = ilObjUser::_lookupGender($usr_id);
$name = ilObjUser::_lookupFullname($usr_id);

$body = sprintf(
$lng->txt("invalidate_mail_body"),
$lng->txt("mail_salutation_" . $gender),
$name,
$prg->getTitle()
);
$mail->Body($body);

return $mail->Send();
$send = true;
$mail = new ilMail(ANONYMOUS_USER_ID);
try {
$mail->enqueue(
ilObjUser::_lookupLogin($usr_id),
'',
'',
$subject,
$body,
null
);
} catch (Exception $e) {
$send = false;
}

return $send;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,24 @@ public function run()
{
$result = new ilCronJobResult();
$result->setStatus(ilCronJobResult::STATUS_OK);
$now = date('Y-m-d');
foreach ($this->user_assignments_db->getDueToRestartAndMail() as $assignment) {
try {
$prg_settings = $assignment->getStudyProgramme()->getRawSettings();
$auto_re_assign = $prg_settings->getRestartPeriod();
$prg = $assignment->getStudyProgramme();
$validity_of_qualification = $prg->getValidityOfQualificationSettings();
$auto_re_assign = $validity_of_qualification->getRestartPeriod();
if ($auto_re_assign == -1) {
continue;
}

$inform_by_days = $prg_settings->getReminderNotRestartedByUserDays();
$auto_mail_settings = $prg->getAutoMailSettings();
$inform_by_days = $auto_mail_settings->getReminderNotRestartedByUserDays();
if (is_null($inform_by_days)) {
continue;
}

$restart_date = $assignment->getRestartDate();
$restart_date->sub(new DateInterval(('P' . $inform_by_days . 'D')));

if ($restart_date->format("Y-m-d") > $now) {
$assignment->informUserByMailToRestart();
}
$assignment->informUserByMailToRestart();
} catch (ilException $e) {
$this->log->write('an error occured: ' . $e->getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public function run()
$result = new ilCronJobResult();
foreach ($this->user_progress_db->getRiskyToFailInstances() as $progress) {
try {
$prg_settings = $progress->getStudyProgramme()->getRawSettings();
$remind_days = $prg_settings->getProcessingEndsNotSuccessfulDays();
$auto_mail_settings = $progress->getStudyProgramme()->getAutoMailSettings();
$remind_days = $auto_mail_settings->getProcessingEndsNotSuccessfulDays();

if (is_null($remind_days)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private static function removeMemberFromProgrammes(string $src_type, array $para
private static function sendReAssignedMail(array $params) : void
{
$usr_id = $params['usr_id'];
$ref_id = $params['ref_id'];
$ref_id = $params['root_prg_ref_id'];

ilObjStudyProgramme::sendReAssignedMail($ref_id, $usr_id);
}
Expand All @@ -309,7 +309,7 @@ private static function sendReAssignedMail(array $params) : void
private static function sendInformToReAssignMail(array $params) : void
{
$usr_id = $params['usr_id'];
$assignment_id = $params['ref_id'];
$assignment_id = $params['ass_id'];

ilStudyProgrammeUserAssignment::sendInformToReAssignMail($assignment_id, $usr_id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public static function sendInformToReAssignMail(int $assignment_id, int $usr_id)
$lng = $DIC['lng'];
$log = $DIC['ilLog'];
$lng->loadLanguageModule("prg");
$senderFactory = $DIC["mail.mime.sender.factory"];
$lng->loadLanguageModule("mail");

/** @var ilStudyProgrammeUserAssignmentDB $assignment_db */
$assignment_db = ilStudyProgrammeDIC::dic()['ilStudyProgrammeUserAssignmentDB'];
Expand All @@ -243,27 +243,32 @@ public static function sendInformToReAssignMail(int $assignment_id, int $usr_id)
return;
}

$mail = new ilMimeMail();
$mail->From($senderFactory->system());

$mailOptions = new \ilMailOptions($usr_id);
$mail->To($mailOptions->getExternalEmailAddresses());

$subject = $lng->txt("info_to_re_assign_mail_subject");
$mail->Subject($subject);

$gender = ilObjUser::_lookupGender($usr_id);
$name = ilObjUser::_lookupFullname($usr_id);

$body = sprintf(
$lng->txt("info_to_re_assign_mail_body"),
$lng->txt("mail_salutation_" . $gender),
$name,
$prg->getTitle()
);
$mail->Body($body);

if ($mail->Send()) {
$send = true;
$mail = new ilMail(ANONYMOUS_USER_ID);
try {
$mail->enqueue(
ilObjUser::_lookupLogin($usr_id),
'',
'',
$subject,
$body,
null
);
} catch (Exception $e) {
$send = false;
}

if ($send) {
$assignment_db->reminderSendFor($assignment->getId());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ public static function sendRiskyToFailMail(int $progress_id, int $usr_id) : void
$lng = $DIC['lng'];
$log = $DIC['ilLog'];
$lng->loadLanguageModule("prg");
$senderFactory = $DIC["mail.mime.sender.factory"];
$lng->loadLanguageModule("mail");

/** @var ilStudyProgrammeUserProgressDB $usr_progress_db */
$usr_progress_db = ilStudyProgrammeDIC::dic()['ilStudyProgrammeUserProgressDB'];
Expand All @@ -970,27 +970,32 @@ public static function sendRiskyToFailMail(int $progress_id, int $usr_id) : void
return;
}

$mail = new ilMimeMail();
$mail->From($senderFactory->system());

$mailOptions = new \ilMailOptions($usr_id);
$mail->To($mailOptions->getExternalEmailAddresses());

$subject = $lng->txt("risky_to_fail_mail_subject");
$mail->Subject($subject);

$gender = ilObjUser::_lookupGender($usr_id);
$name = ilObjUser::_lookupFullname($usr_id);

$body = sprintf(
$lng->txt("risky_to_fail_mail_body"),
$lng->txt("mail_salutation_" . $gender),
$name,
$prg->getTitle()
);
$mail->Body($body);

if ($mail->Send()) {
$send = true;
$mail = new ilMail(ANONYMOUS_USER_ID);
try {
$mail->enqueue(
ilObjUser::_lookupLogin($usr_id),
'',
'',
$subject,
$body,
null
);
} catch (Exception $e) {
$send = false;
}

if ($send) {
$usr_progress_db->reminderSendFor($usr_progress->getId());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function readDueToRestartAndMail() : array

protected function loadDueToRestart()
{
$q = $this->getDuoToRestartBaseSQL();
$q = $this->getDueToRestartBaseSQL();
$res = $this->db->query($q);
while ($rec = $this->db->fetchAssoc($res)) {
yield $rec;
Expand All @@ -139,7 +139,7 @@ protected function loadDueToRestart()

protected function loadDueToRestartAndMail()
{
$q = $this->getDuoToRestartBaseSQL();
$q = $this->getDueToRestartBaseSQL();
$q .= ' AND ' . self::FIELD_RESTART_MAIL . ' IS NULL';

$res = $this->db->query($q);
Expand All @@ -160,7 +160,7 @@ protected function getSQLHeader() : string
. ' FROM ' . self::TABLE . PHP_EOL;
}

protected function getDuoToRestartBaseSQL() : string
protected function getDueToRestartBaseSQL() : string
{
return $this->getSQLHeader()
. ' WHERE ' . self::FIELD_RESTARTED_ASSIGNMENT_ID
Expand Down
10 changes: 7 additions & 3 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -13425,7 +13425,7 @@ prg#:#prg_mark_relevant_multi_success#:#Ausgewählte Benutzer als relevant marki
prg#:#prg_mark_not_relevant_multi_success#:#Ausgewählte Benutzer als nicht relevant markiert.
prg#:#prg_remove_users_success#:#Ausgewählte Benutzer wurden entfernt.
prg#:#prg_remove_users_partitial_success#:#Ausgewählte Benutzer wurden teilweise entfernt.
prg#:#prg_remove_users_not_possible#:#Ausgewählte Benutzerkönnen nicht entfernt werden.
prg#:#prg_remove_users_not_possible#:#Ausgewählte Benutzer können nicht entfernt werden.
prg#:#prg_update_from_current_plan_not_possible#:#Aus dem aktuellen Plan aktualisieren ist nicht möglich.
prg#:#prg_update_from_current_plan_partitial_success#:#Aus dem aktuellen Plan aktualisieren teilweise abgeschlossen.
prg#:#prg_update_from_current_plan_success#:#Aus dem aktuellen Plan aktualisieren ist erfolgreich.
Expand Down Expand Up @@ -15969,9 +15969,9 @@ prg#:#not_a_valid_cat_id#:#%s entspricht keiner Kategorie.
prg#:#prg_mail_permanent_link#:#Wählen Sie den folgenden Link, um auf den Inhalt des Studienprogramms zuzugreifen:
prg#:#prg_title#:#Titel
prg#:#re_assigned_mail_subject#:#Erneute Teilnahme am Studienprogramm
prg#:#re_assigned_mail_body#:#%s %s,<br \><br \>Sie wurden erneut dem Studienprogramm '%s' als Teilnehmer zugeordnet.
prg#:#re_assigned_mail_body#:#%s %s,<br/><br/>Sie wurden erneut dem Studienprogramm '%s' als Teilnehmer zugeordnet.
prg#:#info_to_re_assign_mail_subject#:#Erinnerung zur erneuten Teilnahme am Studienprogramm
prg#:#info_to_re_assign_mail_body#:#%s %s,<br \><br \>Die Gültigkeit ihrer Teilnahme am Studienprogramm '%s' läuft bald ab. Bitte melden Sie sich erneut an.
prg#:#info_to_re_assign_mail_body#:#%s %s,<br/><br/>die Gültigkeit ihrer Teilnahme am Studienprogramm '%s' läuft bald ab. Bitte melden Sie sich erneut an.
prg#:#prg_user_not_restarted_time_input#:#Erinnerungsmail Neustart
prg#:#prg_user_not_restarted_time_input_info#:#Erinnert den Benutzer x Tage vor der invalidierung, dass er das Programm neu starten muss.
prg#:#prg_processing_ends_no_success#:#Erinnerungsmail Fehlschlag
Expand Down Expand Up @@ -16113,3 +16113,7 @@ mail#:#mail_enable_lso_member_notification#:#Mitglieder benachrichtigen
mail#:#mail_enable_lso_member_notification_info#:#Mitglieder erhalten automatisch eine E-Mail, wenn sich ihr Mitgliedsstatus ändert. Diese Einstellung betrifft alle Lernsequenzen der Plattform.
mail#:#mail_enable_lso_admin_notification#:#Administratoren der Lernsequenz benachrichtigen
mail#:#mail_enable_lso_admin_notification_info#:#In neuen Lernsequenzen ist im Reiter "Mitglieder" für Administratoren die Einstellungen "Benachrichtigungen" standardmäßig aktiviert. Sie erhalten E-Mails, wenn ein Mitglied beitritt oder die Sequenz verlässt.
prg#:#risky_to_fail_mail_subject#:#Erinnerung, das der Stichtag am Studienprogramm bald ereicht ist
prg#:#risky_to_fail_mail_body#:#%s %s,<br/><br/>der Stichtag für das Abschließen des Studienprogramm '%s' ist bald ereicht.
prg#:#prg_update_progress_title#:#Setzt Status nach Stichtag auf 'nicht bestanden'
prg#:#prg_update_progress_description#:#Setzt den Status von 'In Bearbeitung' auf 'nicht bestanden' wenn der Stichtag überschritten ist.
8 changes: 6 additions & 2 deletions lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -15981,9 +15981,9 @@ prg#:#not_a_valid_cat_id#:#%s is not a valid ref-id of a category.
prg#:#prg_mail_permanent_link#:#Click on the following link to find all of the information you need regarding the study programm:
prg#:#prg_title#:#Title
prg#:#re_assigned_mail_subject#:#Renewed participation in the study programm
prg#:#re_assigned_mail_body#:#%s %s,<br \><br \>you were reassigned to study program '%s' as participants.
prg#:#re_assigned_mail_body#:#%s %s,<br/><br/>you were reassigned to study program '%s' as participants.
prg#:#info_to_re_assign_mail_subject#:#Reminder of renewed participation in the study programm
prg#:#info_to_re_assign_mail_body#:#%s %s,<br \><br \>The validity of their participation in the study programm '% s' expires soon. Please sign in again.
prg#:#info_to_re_assign_mail_body#:#%s %s,<br/><br/>The validity of their participation in the study programm '% s' expires soon. Please sign in again.
prg#:#prg_user_not_restarted_time_input#:#Reminder mail restart
prg#:#prg_user_not_restarted_time_input_info#:#Reminder Mail Reminds the user x days before the invalidation that he must restart the programm.
prg#:#prg_processing_ends_no_success#:#Reminder mail failing
Expand Down Expand Up @@ -16113,3 +16113,7 @@ mail#:#mail_enable_lso_member_notification#:#Notify Learning Sequence Members
mail#:#mail_enable_lso_member_notification_info#:#ILIAS will automatically send an e-mail to every member if his or her membership status is changed. This setting applies to all Learning Sequences on the platform.
mail#:#mail_enable_lso_admin_notification#:#Notify Learning Sequence Administrators
mail#:#mail_enable_lso_admin_notification_info#:#In new Learning Sequences the setting 'Notification About New Members' will be activated by default. It is set in the 'Member'-tab of Learning Sequences. Administrators will receive an e-mail when a member joins the Learning Sequence or leaves it.
prg#:#risky_to_fail_mail_subject#:#Reminder, that the deadline for the study program will soon be reached
prg#:#risky_to_fail_mail_body#:#%s %s,<br/><br/>the deadline for completing the study program '%s' will soon be reached.
prg#:#prg_update_progress_title#:#Set Progress to Failed after Deadline
prg#:#prg_update_progress_description#:#Set Progress from 'In Progress' to 'failed' after crossing Deadline.

0 comments on commit 79abd38

Please sign in to comment.