59 $this->db = $DIC->database();
60 $this->tree = $DIC->repositoryTree();
61 $this->
access = $DIC->access();
65 $this->ass_id = $a_ass_id;
68 $this->exc_id = $a_exc_id;
71 $this->rmd_type = $a_type;
73 if ($a_exc_id and $a_ass_id and $a_type) {
89 $this->rmd_status = $a_status;
100 $this->rmd_start = $a_num_days;
110 $this->rmd_end = $a_date;
121 $this->rmd_frequency = $a_num_days;
131 $this->rmd_last_send = $a_timestamp;
141 $this->rmd_tpl_id = $a_tpl_id;
151 $this->db->insert(
"exc_ass_reminders", array(
152 "type" => array(
"text", $this->rmd_type),
153 "ass_id" => array(
"integer", $this->ass_id),
154 "exc_id" => array(
"integer", $this->exc_id),
177 "type" => array(
"text", $this->rmd_type),
178 "exc_id" => array(
"integer", $this->exc_id),
179 "ass_id" => array(
"integer", $this->ass_id)
187 $set = $this->db->queryF(
188 "SELECT status, start, freq, end, last_send, template_id" .
189 " FROM exc_ass_reminders" .
190 " WHERE type = %s AND ass_id = %s AND exc_id = %s",
191 [
"text",
"integer",
"integer"],
192 [$this->rmd_type, $this->ass_id, $this->exc_id]
195 $rec = $this->db->fetchAssoc($set);
196 if (is_array($rec)) {
221 $today = date(
"Y-m-d");
223 $this->log->debug(
"Get reminders $a_type.");
228 if ($a_type == self::SUBMIT_REMINDER || $a_type == self::GRADE_REMINDER || $a_type == self::FEEDBACK_REMINDER) {
229 $and_type =
" AND type = '" . $a_type .
"'";
232 $query =
"SELECT last_send_day, ass_id, exc_id, status, start, freq, end, type, last_send, template_id" .
233 " FROM exc_ass_reminders" .
234 " WHERE status = 1" .
235 " AND start <= " . $now .
236 " AND end > " . ($now - 86400) .
240 $result = $this->db->query(
$query);
242 $array_data = array();
243 while ($rec = $this->db->fetchAssoc($result)) {
245 "ass_id" => $rec[
"ass_id"],
246 "exc_id" => $rec[
"exc_id"],
247 "start" => $rec[
"start"],
248 "end" => $rec[
"end"],
249 "freq" => $rec[
"freq"],
250 "type" => $rec[
"type"],
251 "last_send" => $rec[
"last_send"],
252 "last_send_day" => $rec[
"last_send_day"],
253 "template_id" => $rec[
"template_id"]
256 $end_day = date(
"Y-m-d", $rec[
"end"]);
260 if ($rec[
"last_send_day"] !=
"") {
261 $date =
new DateTime($rec[
"last_send_day"]);
262 $date->add(
new DateInterval(
'P' . $rec[
"freq"] .
'D'));
263 $next_send = $date->format(
'Y-m-d');
265 $this->log->debug(
"ass: " . $rec[
"ass_id"] .
", last send: " . $rec[
"last_send_day"] .
266 ", freq: " . $rec[
"freq"] .
", end_day: $end_day, today: " . $today .
", next send: $next_send");
267 if ($rec[
"last_send_day"] ==
"" || $next_send <= $today) {
268 if ($end_day >= $today) {
269 $this->log->debug(
"included");
270 $array_data[] = $rem;
283 public function parseSubmissionReminders(array $a_reminders): array
285 $reminders = $a_reminders;
286 $users_to_remind = array();
288 foreach ($reminders as $rem) {
289 $ass_id = $rem[
"ass_id"];
292 $exc_id = $rem[
"exc_id"];
295 foreach ($exc_refs as $exc_ref) {
298 if ($course_ref_id = $this->tree->checkForParentType($exc_ref,
'crs')) {
300 $participants_class = ilCourseParticipants::class;
301 $parent_ref_id = $course_ref_id;
302 $parent_obj_type =
'crs';
305 } elseif ($group_ref_id = $this->tree->checkForParentType($exc_ref,
'grp')) {
307 $participants_class = ilGroupParticipants::class;
308 $parent_ref_id = $group_ref_id;
309 $parent_obj_type =
'grp';
315 $parent_obj_id = $obj->getId();
317 $participants_ids = $participants_class::getInstance($parent_ref_id)->getMembers();
319 foreach ($participants_ids as $member_id) {
320 $this->log->debug(
"submission reminder: ass: $ass_id, member: $member_id.");
323 if ($this->
access->checkAccessOfUser($member_id,
"read",
"", $exc_ref)) {
326 $deadline_day = date(
"Y-m-d", $state->getOfficialDeadline());
327 $today = date(
"Y-m-d");
328 $date =
new DateTime($deadline_day);
329 $date->sub(
new DateInterval(
'P' . $rem[
"start"] .
'D'));
330 $send_from = $date->format(
'Y-m-d');
331 $this->log->debug(
"today: $today, send from: $send_from, start: " . $rem[
"start"] .
", submission allowed: " . $state->isSubmissionAllowed());
334 if ($state->isSubmissionAllowed() && $send_from <= $today) {
338 if (!$submission->getLastSubmission()) {
339 $member_data = array(
340 "parent_type" => $parent_obj_type,
341 "parent_id" => $parent_obj_id,
343 "exc_ref" => $exc_ref,
345 "member_id" => $member_id,
346 "reminder_type" => $rem[
"type"],
347 "template_id" => $rem[
"template_id"]
349 $users_to_remind[] = $member_data;
356 return $users_to_remind;
364 $reminders = $a_reminders;
365 $users_to_remind = array();
367 $has_pending_to_grade =
false;
369 foreach ($reminders as $rem) {
372 $members_data = $ass_obj->getMemberListData();
375 foreach ($members_data as $assignment_data) {
378 $has_pending_to_grade =
true;
382 if ($has_pending_to_grade) {
386 foreach ($users as $user_id) {
388 $unike_usr_id = array();
389 foreach ($exc_refs as $exc_ref) {
390 if ($this->
access->checkAccessOfUser($user_id,
"write",
"", $exc_ref)) {
391 if (!in_array($user_id, $unike_usr_id)) {
392 $member_data = array(
393 "exc_id" => $rem[
"exc_id"],
394 "exc_ref" => $exc_ref,
395 "ass_id" => $rem[
"ass_id"],
396 "member_id" => $user_id,
397 "reminder_type" => $rem[
"type"],
398 "template_id" => $rem[
"template_id"]
400 $users_to_remind[] = $member_data;
401 $unike_usr_id[] = $user_id;
409 return $users_to_remind;
417 $reminders = $a_reminders;
418 $users_to_remind = array();
420 $this->log->debug(
"Peer Reminders: " . count($a_reminders));
422 foreach ($reminders as $reminder) {
423 $this->log->debug(
"Init peer review: " . $reminder[
"ass_id"]);
425 $pr->initPeerReviews();
427 foreach ($giver_ids as $giver_id) {
429 $days_diff = (($state->getPeerReviewDeadline() - time()) / (60 * 60 * 24));
431 if ($state->isPeerReviewAllowed() && $days_diff < $reminder[
"start"]) {
433 foreach ($exc_refs as $exc_ref) {
434 if ($this->
access->checkAccessOfUser($giver_id,
"read",
"", $exc_ref)) {
435 $member_data = array(
436 "exc_id" => $reminder[
"exc_id"],
437 "exc_ref" => $exc_ref,
438 "ass_id" => $reminder[
"ass_id"],
439 "member_id" => $giver_id,
440 "reminder_type" => $reminder[
"type"],
441 "template_id" => $reminder[
"template_id"]
443 $users_to_remind[] = $member_data;
450 return $users_to_remind;
460 $submit_reminders = $this->
getReminders(self::SUBMIT_REMINDER);
461 $parsed_submit_reminders = $this->parseSubmissionReminders($submit_reminders);
463 $grade_reminders = $this->
getReminders(self::GRADE_REMINDER);
466 $peer_reminders = $this->
getReminders(self::FEEDBACK_REMINDER);
484 $reminders = array_merge($parsed_submit_reminders, $parsed_grade_reminders, $parsed_peer_reminders);
486 return $this->sendReminders($reminders);
489 protected function sendReminders(array $reminders):
int 495 foreach ($reminders as $reminder) {
496 $template_id = $reminder[
'template_id'];
498 $rmd_type = $reminder[
"reminder_type"];
499 $this->log->debug(
"Sending reminder type = " . $rmd_type);
504 $templateService = $DIC[
'mail.texttemplates.service'];
505 $tpl = $templateService->loadTemplateForId((
int) $template_id);
509 $this->log->debug(
"** send reminder WITH template.");
510 $subject =
$tpl->getSubject();
512 $placeholder_params = array(
513 "exc_id" => $reminder[
"exc_id"],
514 "exc_ref" => $reminder[
"exc_ref"],
515 "ass_id" => $reminder[
"ass_id"],
516 "member_id" => $reminder[
"member_id"]
520 $this->log->debug(
"** send reminder WITHOUT template.");
527 $ulng->loadLanguageModule(
'exc');
529 $link =
ilLink::_getLink($reminder[
"exc_ref"],
"exc", array(),
"_" . $reminder[
"ass_id"]);
533 $this->log->debug(
"send: MAIL TYPE = " . $rmd_type .
", user: " . $reminder[
"member_id"] .
", ass: " . $reminder[
"ass_id"]);
537 $subject = sprintf($ulng->txt(
'exc_reminder_submit_subject'), $ass_title);
538 $message .= $ulng->txt(
'exc_reminder_submit_body') .
":\n\n";
542 $subject = sprintf($ulng->txt(
'exc_reminder_grade_subject'), $ass_title);
543 $message .= $ulng->txt(
'exc_reminder_grade_body') .
":\n\n";
547 $subject = sprintf($ulng->txt(
'exc_reminder_peer_subject'), $ass_title);
548 $message .= $ulng->txt(
'exc_reminder_peer_body') .
":\n\n";
552 $message .= $ulng->txt(
'obj_exc') .
": " . $exc_title .
"\n";
553 $message .= $ulng->txt(
'obj_ass') .
": " . $ass_title .
"\n";
554 $message .=
"\n" . $ulng->txt(
'exc_reminder_link') .
": " . $link;
557 $mail_obj->appendInstallationSignature(
true);
569 return count($reminders);
575 array $a_reminder_data,
576 string $a_reminder_type
580 switch ($a_reminder_type) {
594 $user =
new ilObjUser($a_reminder_data[
"member_id"]);
597 $a_message = $processor->resolve($user, $a_reminder_data);
608 $today = date(
"Y-m-d");
609 foreach ($a_reminders as $reminder) {
610 $sql =
"UPDATE exc_ass_reminders" .
611 " SET last_send = " . $this->db->quote(time(),
'integer') .
612 " , last_send_day = " . $this->db->quote($today,
'date') .
613 " WHERE type = " . $this->db->quote($reminder[
"reminder_type"],
'text') .
614 " AND ass_id = " . $this->db->quote($reminder[
"ass_id"],
'integer') .
615 " AND exc_id = " . $this->db->quote($reminder[
"exc_id"],
'integer');
617 $this->db->manipulate($sql);
624 $sql =
"DELETE FROM exc_ass_reminders" .
625 " WHERE ass_id = " . $a_ass_id;
627 $this->db->manipulate($sql);
sentReminderPlaceholders(string $a_message, array $a_reminder_data, string $a_reminder_type)
updateRemindersLastDate(array $a_reminders)
getReminderMailTemplate()
setReminderMailTemplate(int $a_tpl_id)
static getLogger(string $a_component_id)
Get component logger.
static _lookupFullname(int $a_user_id)
static _getAllReferences(int $id)
get all reference ids for object ID
static lookupTitle(int $a_id)
static lookupGiversWithPendingFeedback(int $a_ass_id)
deleteReminders(int $a_ass_id)
getReminders(string $a_type="")
Get reminders available by date/frequence.
setReminderLastSend(int $a_timestamp)
setReminderFrequency(int $a_num_days)
static getNotificationsForObject(int $type, int $id, ?int $page_id=null, bool $ignore_threshold=false)
Get all users/recipients for given object.
static getTemplateContextById(string $a_id)
static _lookupTitle(int $obj_id)
static _getLanguageOfUser(int $a_usr_id)
Get language object of user.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByIds(int $a_ass_id, int $a_user_id=0)
static _getLink(?int $a_ref_id, string $a_type='', array $a_params=array(), string $append="")
setReminderEnd(int $a_date)
Class ilMailTemplatePlaceholderResolver.
parsePeerReminders(array $a_reminders)
const TYPE_EXERCISE_SUBMISSION
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setReminderStart(int $a_num_days)
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
setReminderStatus(?bool $a_status)
Set reminder for users without submission.
parseGradeReminders(array $a_reminders)
__construct(int $a_exc_id=0, int $a_ass_id=0, string $a_type="")
static _lookupLogin(int $a_user_id)