ILIAS  release_8 Revision v8.24
class.ilPRGMail.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
25{
27 protected ilLanguage $lng;
28
29 public function __construct(
32 ) {
33 $this->log = $log;
34 $this->lng = $lng;
35 $this->lng->loadLanguageModule("prg");
36 $this->lng->loadLanguageModule("mail");
37 }
38
42 protected function getAssignmentAndProgramme(int $assignment_id, int $root_prg_id): array
43 {
44 $prg = ilObjStudyProgramme::getInstanceByObjId($root_prg_id);
45 $ass = $prg->getSpecificAssignment($assignment_id);
46 return [$ass, $prg];
47 }
48
49 protected function sendMail(
51 ilPRGAssignment $assignment,
52 string $subject,
53 string $body_template
54 ): bool {
55 $user_info = $assignment->getUserInformation();
56 $gender = $user_info->getGender() ?: 'anonymous';
57 $name = $user_info->getFullname();
58 $login = $user_info->getLogin();
59
60 $body = sprintf(
61 $body_template,
62 $this->lng->txt("mail_salutation_" . $gender),
63 $name,
64 $prg->getTitle()
65 );
66
67 $mail = new ilMail(ANONYMOUS_USER_ID);
68 try {
69 $mail->enqueue($login, '', '', $subject, $body, []);
70 return true;
71 } catch (Exception $e) {
72 $this->log->write($e->getMessage());
73 return false;
74 }
75 }
76
77 public function sendInformToReAssignMail(int $assignment_id, int $root_prg_id): void
78 {
79 list($ass, $prg) = $this->getAssignmentAndProgramme($assignment_id, $root_prg_id);
80
81 if (! $prg->getSettings()->getAutoMailSettings()->getReminderNotRestartedByUserDays() > 0) {
82 $this->log->write("Send info to re-assign mail is deactivated in study programme settings");
83 return;
84 }
85
86 $subject = $this->lng->txt("info_to_re_assign_mail_subject");
87 $body_template = $this->lng->txt("info_to_re_assign_mail_body");
88 $sent = $this->sendMail($prg, $ass, $subject, $body_template);
89
90 if ($sent) {
91 $prg->storeExpiryInfoSentFor($ass);
92 }
93 }
94
95 public function resetExpiryInfoSentFor(int $assignment_id, int $root_prg_id): void
96 {
97 list($ass, $prg) = $this->getAssignmentAndProgramme($assignment_id, $root_prg_id);
98 $now = new \DateTimeImmutable();
99 $vq = $ass->getProgressTree()->getValidityOfQualification();
100
101 if ($vq && $vq > $now) {
102 $prg->resetExpiryInfoSentFor($ass);
103 }
104 }
105
106 public function sendRiskyToFailMail(int $assignment_id, int $root_prg_id): void
107 {
108 list($ass, $prg) = $this->getAssignmentAndProgramme($assignment_id, $root_prg_id);
109
110 if (! $prg->getSettings()->getAutoMailSettings()->getProcessingEndsNotSuccessfulDays() > 0) {
111 $this->log->write("Send risky to fail mail is deactivated in study programme settings");
112 return;
113 }
114
115 $subject = $this->lng->txt("risky_to_fail_mail_subject");
116 $body_template = $this->lng->txt("risky_to_fail_mail_body");
117 $sent = $this->sendMail($prg, $ass, $subject, $body_template);
118
119 if ($sent) {
120 $prg->storeRiskyToFailSentFor($ass);
121 }
122 }
123
124 public function resetRiskyToFailSentFor(int $assignment_id, int $root_prg_id): void
125 {
126 list($ass, $prg) = $this->getAssignmentAndProgramme($assignment_id, $root_prg_id);
127 $now = new \DateTimeImmutable();
128 $deadline = $ass->getProgressTree()->getDeadline();
129 if ($deadline && $deadline > $now) {
130 $prg->resetRiskyToFailSentFor($ass);
131 }
132 }
133
134 public function sendReAssignedMail(int $assignment_id, int $root_prg_id): bool
135 {
136 list($ass, $prg) = $this->getAssignmentAndProgramme($assignment_id, $root_prg_id);
137
138 if (! $prg->getSettings()->getAutoMailSettings()->getSendReAssignedMail()) {
139 $this->log->write("Send re assign mail is deactivated in study programme settings");
140 return false;
141 }
142
143 $subject = $this->lng->txt("re_assigned_mail_subject");
144 $body_template = $this->lng->txt("re_assigned_mail_body");
145 $sent = $this->sendMail($prg, $ass, $subject, $body_template);
146
147 return $sent;
148 }
149}
Component logger with individual log levels by component id.
language handling
resetRiskyToFailSentFor(ilPRGAssignment $ass)
resetExpiryInfoSentFor(ilPRGAssignment $ass)
static getInstanceByObjId(int $obj_id)
storeRiskyToFailSentFor(ilPRGAssignment $ass)
storeExpiryInfoSentFor(ilPRGAssignment $ass)
Assignments are relations of users to a PRG; They hold progress-information for (sub-)nodes of the PR...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
resetRiskyToFailSentFor(int $assignment_id, int $root_prg_id)
sendRiskyToFailMail(int $assignment_id, int $root_prg_id)
ilLanguage $lng
ilComponentLogger $log
getAssignmentAndProgramme(int $assignment_id, int $root_prg_id)
resetExpiryInfoSentFor(int $assignment_id, int $root_prg_id)
sendInformToReAssignMail(int $assignment_id, int $root_prg_id)
sendMail(ilObjStudyProgramme $prg, ilPRGAssignment $assignment, string $subject, string $body_template)
sendReAssignedMail(int $assignment_id, int $root_prg_id)
__construct(ilComponentLogger $log, ilLanguage $lng)
const ANONYMOUS_USER_ID
Definition: constants.php:27
if($format !==null) $name
Definition: metadata.php:247