60 $this->db =
$DIC->database();
61 $this->tree =
$DIC->repositoryTree();
62 $this->
access = $DIC->access();
64 $this->placeholder_resolver =
$DIC->mail()->placeholderResolver();
67 $this->ass_id = $a_ass_id;
70 $this->exc_id = $a_exc_id;
73 $this->rmd_type = $a_type;
75 if ($a_exc_id and $a_ass_id and $a_type) {
91 $this->rmd_status = $a_status;
102 $this->rmd_start = $a_num_days;
112 $this->rmd_end = $a_date;
123 $this->rmd_frequency = $a_num_days;
133 $this->rmd_last_send = $a_timestamp;
143 $this->rmd_tpl_id = $a_tpl_id;
153 $this->db->insert(
"exc_ass_reminders", array(
154 "type" => array(
"text", $this->rmd_type),
155 "ass_id" => array(
"integer", $this->ass_id),
156 "exc_id" => array(
"integer", $this->exc_id),
179 "type" => array(
"text", $this->rmd_type),
180 "exc_id" => array(
"integer", $this->exc_id),
181 "ass_id" => array(
"integer", $this->ass_id)
189 $set = $this->db->queryF(
190 "SELECT status, start, freq, end, last_send, template_id" .
191 " FROM exc_ass_reminders" .
192 " WHERE type = %s AND ass_id = %s AND exc_id = %s",
193 [
"text",
"integer",
"integer"],
194 [$this->rmd_type, $this->ass_id, $this->exc_id]
197 $rec = $this->db->fetchAssoc($set);
198 if (is_array($rec)) {
223 $today = date(
"Y-m-d");
225 $this->log->debug(
"Get reminders $a_type.");
230 if ($a_type == self::SUBMIT_REMINDER || $a_type == self::GRADE_REMINDER || $a_type == self::FEEDBACK_REMINDER) {
231 $and_type =
" AND type = '" . $a_type .
"'";
234 $query =
"SELECT last_send_day, ass_id, exc_id, status, start, freq, end, type, last_send, template_id" .
235 " FROM exc_ass_reminders" .
236 " WHERE status = 1" .
237 " AND start <= " . $now .
238 " AND end > " . ($now - 86400) .
242 $result = $this->db->query($query);
244 $array_data = array();
245 while ($rec = $this->db->fetchAssoc($result)) {
247 "ass_id" => $rec[
"ass_id"],
248 "exc_id" => $rec[
"exc_id"],
249 "start" => $rec[
"start"],
250 "end" => $rec[
"end"],
251 "freq" => $rec[
"freq"],
252 "type" => $rec[
"type"],
253 "last_send" => $rec[
"last_send"],
254 "last_send_day" => $rec[
"last_send_day"],
255 "template_id" => $rec[
"template_id"]
258 $end_day = date(
"Y-m-d", $rec[
"end"]);
262 if ($rec[
"last_send_day"] !=
"") {
263 $date =
new DateTime($rec[
"last_send_day"]);
264 $date->add(
new DateInterval(
'P' . $rec[
"freq"] .
'D'));
265 $next_send = $date->format(
'Y-m-d');
267 $this->log->debug(
"ass: " . $rec[
"ass_id"] .
", last send: " . $rec[
"last_send_day"] .
268 ", freq: " . $rec[
"freq"] .
", end_day: $end_day, today: " . $today .
", next send: $next_send");
269 if ($rec[
"last_send_day"] ==
"" || $next_send <= $today) {
270 if ($end_day >= $today) {
271 $this->log->debug(
"included");
272 $array_data[] = $rem;
285 public function parseSubmissionReminders(array $a_reminders): array
287 $reminders = $a_reminders;
288 $users_to_remind = array();
290 foreach ($reminders as $rem) {
297 foreach ($exc_refs as $exc_ref) {
299 if ($course_ref_id = $this->tree->checkForParentType($exc_ref,
'crs')) {
301 $participants_class = ilCourseParticipants::class;
302 $parent_ref_id = $course_ref_id;
303 $parent_obj_type =
'crs';
306 } elseif ($group_ref_id = $this->tree->checkForParentType($exc_ref,
'grp')) {
308 $participants_class = ilGroupParticipants::class;
309 $parent_ref_id = $group_ref_id;
310 $parent_obj_type =
'grp';
316 $parent_obj_id = $obj->getId();
318 $participants_ids = $participants_class::getInstance($parent_ref_id)->getMembers();
320 foreach ($participants_ids as $member_id) {
321 $this->log->debug(
"submission reminder: ass: $ass_id, member: $member_id.");
324 if ($this->
access->checkAccessOfUser($member_id,
"read",
"", $exc_ref)) {
327 $deadline_day = date(
"Y-m-d", $state->getOfficialDeadline());
328 $today = date(
"Y-m-d");
329 $date =
new DateTime($deadline_day);
330 $date->sub(
new DateInterval(
'P' . $rem[
"start"] .
'D'));
331 $send_from = $date->format(
'Y-m-d');
332 $this->log->debug(
"today: $today, send from: $send_from, start: " . $rem[
"start"] .
", submission allowed: " . $state->isSubmissionAllowed());
335 if ($state->isSubmissionAllowed() && $send_from <= $today) {
339 if (!$submission->getLastSubmission()) {
340 $member_data = array(
341 "parent_type" => $parent_obj_type,
342 "parent_id" => $parent_obj_id,
344 "exc_ref" => $exc_ref,
346 "member_id" => $member_id,
347 "reminder_type" => $rem[
"type"],
348 "template_id" => $rem[
"template_id"]
350 $users_to_remind[] = $member_data;
357 return $users_to_remind;
365 $reminders = $a_reminders;
366 $users_to_remind = array();
368 $has_pending_to_grade =
false;
370 foreach ($reminders as $rem) {
373 $members_data = $ass_obj->getMemberListData();
376 foreach ($members_data as $assignment_data) {
379 $has_pending_to_grade =
true;
383 if ($has_pending_to_grade) {
389 $unike_usr_id = array();
390 foreach ($exc_refs as $exc_ref) {
391 if ($this->
access->checkAccessOfUser($user_id,
"write",
"", $exc_ref)) {
392 if (!in_array(
$user_id, $unike_usr_id)) {
393 $member_data = array(
394 "exc_id" => $rem[
"exc_id"],
395 "exc_ref" => $exc_ref,
396 "ass_id" => $rem[
"ass_id"],
398 "reminder_type" => $rem[
"type"],
399 "template_id" => $rem[
"template_id"]
401 $users_to_remind[] = $member_data;
410 return $users_to_remind;
418 $reminders = $a_reminders;
419 $users_to_remind = array();
421 $this->log->debug(
"Peer Reminders: " . count($a_reminders));
423 foreach ($reminders as $reminder) {
424 $this->log->debug(
"Init peer review: " . $reminder[
"ass_id"]);
426 $pr->initPeerReviews();
428 foreach ($giver_ids as $giver_id) {
430 $days_diff = (($state->getPeerReviewDeadline() - time()) / (60 * 60 * 24));
432 if ($state->isPeerReviewAllowed() && $days_diff < $reminder[
"start"]) {
434 foreach ($exc_refs as $exc_ref) {
435 if ($this->
access->checkAccessOfUser($giver_id,
"read",
"", $exc_ref)) {
436 $member_data = array(
437 "exc_id" => $reminder[
"exc_id"],
438 "exc_ref" => $exc_ref,
439 "ass_id" => $reminder[
"ass_id"],
440 "member_id" => $giver_id,
441 "reminder_type" => $reminder[
"type"],
442 "template_id" => $reminder[
"template_id"]
444 $users_to_remind[] = $member_data;
451 return $users_to_remind;
461 $submit_reminders = $this->
getReminders(self::SUBMIT_REMINDER);
462 $parsed_submit_reminders = $this->parseSubmissionReminders($submit_reminders);
464 $grade_reminders = $this->
getReminders(self::GRADE_REMINDER);
467 $peer_reminders = $this->
getReminders(self::FEEDBACK_REMINDER);
485 $reminders = array_merge($parsed_submit_reminders, $parsed_grade_reminders, $parsed_peer_reminders);
496 foreach ($reminders as $reminder) {
497 $template_id = $reminder[
'template_id'];
500 $this->log->debug(
"Sending reminder type = " .
$rmd_type);
504 $templateService =
$DIC->mail()->textTemplates();
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"]);
596 $a_message = $this->placeholder_resolver->resolve(
$context, $a_message, $user, $a_reminder_data);
597 }
catch (Exception
$e) {
607 $today = date(
"Y-m-d");
608 foreach ($a_reminders as $reminder) {
609 $sql =
"UPDATE exc_ass_reminders" .
610 " SET last_send = " . $this->db->quote(time(),
'integer') .
611 " , last_send_day = " . $this->db->quote($today,
'date') .
612 " WHERE type = " . $this->db->quote($reminder[
"reminder_type"],
'text') .
613 " AND ass_id = " . $this->db->quote($reminder[
"ass_id"],
'integer') .
614 " AND exc_id = " . $this->db->quote($reminder[
"exc_id"],
'integer');
616 $this->db->manipulate($sql);
623 $sql =
"DELETE FROM exc_ass_reminders" .
624 " WHERE ass_id = " . $a_ass_id;
626 $this->db->manipulate($sql);
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
sentReminderPlaceholders(string $a_message, array $a_reminder_data, string $a_reminder_type)
setReminderEnd(int $a_date)
parseGradeReminders(array $a_reminders)
ilMailTemplatePlaceholderResolver $placeholder_resolver
parsePeerReminders(array $a_reminders)
updateRemindersLastDate(array $a_reminders)
deleteReminders(int $a_ass_id)
setReminderFrequency(int $a_num_days)
getReminders(string $a_type="")
Get reminders available by date/frequence.
setReminderStart(int $a_num_days)
__construct(int $a_exc_id=0, int $a_ass_id=0, string $a_type="")
sendReminders(array $reminders)
setReminderStatus(?bool $a_status)
Set reminder for users without submission.
setReminderLastSend(int $a_timestamp)
getReminderMailTemplate()
setReminderMailTemplate(int $a_tpl_id)
static lookupTitle(int $a_id)
static lookupGiversWithPendingFeedback(int $a_ass_id)
Exercise submission //TODO: This class has many static methods related to delivered "files".
static getInstanceByIds(int $a_ass_id, int $a_user_id=0)
static _getLanguageOfUser(int $a_usr_id)
Get language object of user.
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
static getTemplateContextById(string $a_id)
static getNotificationsForObject(int $type, int $id, ?int $page_id=null, bool $ignore_threshold=false)
Get all users/recipients for given object.
const TYPE_EXERCISE_SUBMISSION
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupFullname(int $a_user_id)
static _lookupLogin(int $a_user_id)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...