38 public function __construct($a_exc_id =
"", $a_ass_id =
"", $a_type =
"")
41 $this->db = $DIC->database();
42 $this->tree = $DIC->repositoryTree();
43 $this->access = $DIC->access();
47 $this->ass_id = $a_ass_id;
50 $this->exc_id = $a_exc_id;
53 $this->rmd_type = $a_type;
55 if ($a_exc_id and $a_ass_id and $a_type) {
71 $this->rmd_status = $a_status;
89 $this->rmd_start = $a_num_days;
107 $this->rmd_end = $a_date;
125 $this->rmd_frequency = $a_num_days;
139 $this->rmd_last_send = $a_timestamp;
149 $this->rmd_tpl_id = $a_tpl_id;
159 $this->db->insert(
"exc_ass_reminders", array(
160 "type" => array(
"text", $this->rmd_type),
161 "ass_id" => array(
"integer", $this->ass_id),
162 "exc_id" => array(
"integer", $this->exc_id),
185 "type" => array(
"text", $this->rmd_type),
186 "exc_id" => array(
"integer", $this->exc_id),
187 "ass_id" => array(
"integer", $this->ass_id)
195 $set = $this->db->query(
"SELECT status, start, freq, end, last_send, template_id" .
196 " FROM exc_ass_reminders" .
197 " WHERE type ='" . $this->rmd_type .
"'" .
198 " AND ass_id = " . $this->ass_id .
199 " AND exc_id = " . $this->exc_id);
201 $rec = $this->db->fetchAssoc($set);
202 if (is_array($rec)) {
231 $today = date(
"Y-m-d");
233 $this->log->debug(
"Get reminders $a_type.");
238 if ($a_type == self::SUBMIT_REMINDER || $a_type == self::GRADE_REMINDER || $a_type == self::FEEDBACK_REMINDER) {
239 $and_type =
" AND type = '" . $a_type .
"'";
242 $query =
"SELECT last_send_day, ass_id, exc_id, status, start, freq, end, type, last_send, template_id" .
243 " FROM exc_ass_reminders" .
244 " WHERE status = 1" .
245 " AND start <= " .
$now .
246 " AND end > " . (
$now - 86400) .
252 $array_data = array();
253 while ($rec = $this->db->fetchAssoc(
$result)) {
255 "ass_id" => $rec[
"ass_id"],
256 "exc_id" => $rec[
"exc_id"],
257 "start" => $rec[
"start"],
258 "end" => $rec[
"end"],
259 "freq" => $rec[
"freq"],
260 "type" => $rec[
"type"],
261 "last_send" => $rec[
"last_send"],
262 "last_send_day" => $rec[
"last_send_day"],
263 "template_id" => $rec[
"template_id"]
266 $end_day = date(
"Y-m-d", $rec[
"end"]);
270 if ($rec[
"last_send_day"] !=
"") {
271 $date =
new DateTime($rec[
"last_send_day"]);
272 $date->add(
new DateInterval(
'P' . $rec[
"freq"] .
'D'));
273 $next_send = $date->format(
'Y-m-d');
275 $this->log->debug(
"ass: " . $rec[
"ass_id"] .
", last send: " . $rec[
"last_send_day"] .
276 ", freq: " . $rec[
"freq"] .
", end_day: $end_day, today: " . $today .
", next send: $next_send");
277 if ($rec[
"last_send_day"] ==
"" || $next_send <= $today) {
278 if ($end_day >= $today) {
279 $this->log->debug(
"included");
280 array_push($array_data, $rem);
296 $reminders = $a_reminders;
297 $users_to_remind = array();
299 foreach ($reminders as $rem) {
306 foreach ($exc_refs as $exc_ref) {
309 if ($course_ref_id = $this->tree->checkForParentType($exc_ref,
'crs')) {
311 $participants_class =
"ilCourseParticipants";
312 $parent_ref_id = $course_ref_id;
313 $parent_obj_type =
'crs';
316 } elseif ($group_ref_id = $parent_ref_id = $this->tree->checkForParentType($exc_ref,
'grp')) {
318 $participants_class =
"ilGroupParticipants";
319 $parent_ref_id = $group_ref_id;
320 $parent_obj_type =
'grp';
326 $parent_obj_id = $obj->getId();
327 $participants_ids = $participants_class::getInstance($parent_ref_id)->getMembers();
329 foreach ($participants_ids as $member_id) {
330 $this->log->debug(
"submission reminder: ass: $ass_id, member: $member_id.");
333 if ($this->access->checkAccessOfUser($member_id,
"read",
"", $exc_ref)) {
336 $deadline_day = date(
"Y-m-d", $state->getOfficialDeadline());
337 $today = date(
"Y-m-d");
338 $date =
new DateTime($deadline_day);
339 $date->sub(
new DateInterval(
'P' . $rem[
"start"] .
'D'));
340 $send_from = $date->format(
'Y-m-d');
341 $this->log->debug(
"today: $today, send from: $send_from, start: " . $rem[
"start"] .
", submission allowed: " . $state->isSubmissionAllowed());
344 if ($state->isSubmissionAllowed() && $send_from <= $today) {
348 if (!$submission->getLastSubmission()) {
349 $member_data = array(
350 "parent_type" => $parent_obj_type,
351 "parent_id" => $parent_obj_id,
353 "exc_ref" => $exc_ref,
355 "member_id" => $member_id,
356 "reminder_type" => $rem[
"type"],
357 "template_id" => $rem[
"template_id"]
359 array_push($users_to_remind, $member_data);
366 return $users_to_remind;
371 $reminders = $a_reminders;
372 $users_to_remind = array();
374 $has_pending_to_grade =
false;
376 foreach ($reminders as $rem) {
379 $members_data = $ass_obj->getMemberListData();
382 foreach ($members_data as $member_id => $assignment_data) {
385 $has_pending_to_grade =
true;
398 if ($has_pending_to_grade) {
402 foreach ($users as $user_id) {
404 $unike_usr_id = array();
405 foreach ($exc_refs as $exc_ref) {
406 if ($this->access->checkAccessOfUser($user_id,
"write",
"", $exc_ref)) {
407 if (!in_array($user_id, $unike_usr_id)) {
408 $member_data = array(
409 "exc_id" => $rem[
"exc_id"],
410 "exc_ref" => $exc_ref,
411 "ass_id" => $rem[
"ass_id"],
412 "member_id" => $user_id,
413 "reminder_type" => $rem[
"type"],
414 "template_id" => $rem[
"template_id"]
416 array_push($users_to_remind, $member_data);
417 array_push($unike_usr_id, $user_id);
425 return $users_to_remind;
430 $reminders = $a_reminders;
431 $users_to_remind = array();
433 $this->log->debug(
"Peer Reminders: " . count($a_reminders));
435 foreach ($reminders as $reminder) {
436 $this->log->debug(
"Init peer review: " . $reminder[
"ass_id"]);
438 $pr->initPeerReviews();
440 foreach ($giver_ids as $giver_id) {
442 $days_diff = (($state->getPeerReviewDeadline() - time()) / (60 * 60 * 24));
444 if ($state->isPeerReviewAllowed() && $days_diff < $reminder[
"start"]) {
446 foreach ($exc_refs as $exc_ref) {
447 if ($this->access->checkAccessOfUser($giver_id,
"read",
"", $exc_ref)) {
448 $member_data = array(
449 "exc_id" => $reminder[
"exc_id"],
450 "exc_ref" => $exc_ref,
451 "ass_id" => $reminder[
"ass_id"],
452 "member_id" => $giver_id,
453 "reminder_type" => $reminder[
"type"],
454 "template_id" => $reminder[
"template_id"]
456 array_push($users_to_remind, $member_data);
463 return $users_to_remind;
471 $submit_reminders = $this->
getReminders(self::SUBMIT_REMINDER);
474 $grade_reminders = $this->
getReminders(self::GRADE_REMINDER);
477 $peer_reminders = $this->
getReminders(self::FEEDBACK_REMINDER);
495 $reminders = array_merge($parsed_submit_reminders, $parsed_grade_reminders, $parsed_peer_reminders);
497 $reminders_sent = $this->sendReminders($reminders);
499 return $reminders_sent;
506 protected function sendReminders($reminders)
512 foreach ($reminders as $reminder) {
513 $template_id = $reminder[
'template_id'];
516 $this->log->debug(
"Sending reminder type = " .
$rmd_type);
521 $templateService = $DIC[
'mail.texttemplates.service'];
522 $tpl = $templateService->loadTemplateForId((
int) $template_id);
526 $this->log->debug(
"** send reminder WITH template.");
527 $subject =
$tpl->getSubject();
529 $placeholder_params = array(
530 "exc_id" => $reminder[
"exc_id"],
531 "exc_ref" => $reminder[
"exc_ref"],
532 "ass_id" => $reminder[
"ass_id"],
533 "member_id" => $reminder[
"member_id"]
537 $this->log->debug(
"** send reminder WITHOUT template.");
544 $ulng->loadLanguageModule(
'exc');
546 $link =
ilLink::_getLink($reminder[
"exc_ref"],
"exc", array(),
"_" . $reminder[
"ass_id"]);
550 $this->log->debug(
"send: MAIL TYPE = " .
$rmd_type .
", user: " . $reminder[
"member_id"] .
", ass: " . $reminder[
"ass_id"]);
554 $subject = sprintf($ulng->txt(
'exc_reminder_submit_subject'), $ass_title);
555 $message .= $ulng->txt(
'exc_reminder_submit_body') .
":\n\n";
559 $subject = sprintf($ulng->txt(
'exc_reminder_grade_subject'), $ass_title);
560 $message .= $ulng->txt(
'exc_reminder_grade_body') .
":\n\n";
564 $subject = sprintf($ulng->txt(
'exc_reminder_peer_subject'), $ass_title);
565 $message .= $ulng->txt(
'exc_reminder_peer_body') .
":\n\n";
569 $message .= $ulng->txt(
'obj_exc') .
": " . $exc_title .
"\n";
570 $message .= $ulng->txt(
'obj_ass') .
": " . $ass_title .
"\n";
571 $message .=
"\n" . $ulng->txt(
'exc_reminder_link') .
": " . $link;
574 $mail_obj->appendInstallationSignature(
true);
586 return sizeof($reminders);
594 switch ($a_reminder_type) {
595 case \ilExAssignmentReminder::SUBMIT_REMINDER:
598 case \ilExAssignmentReminder::GRADE_REMINDER:
601 case \ilExAssignmentReminder::FEEDBACK_REMINDER:
608 $user = new \ilObjUser($a_reminder_data[
"member_id"]);
610 $processor = new \ilMailTemplatePlaceholderResolver(
$context, $a_message);
611 $a_message = $processor->resolve($user, $a_reminder_data);
625 $today = date(
"Y-m-d");
626 foreach ($a_reminders as $reminder) {
627 $sql =
"UPDATE exc_ass_reminders" .
628 " SET last_send = " . $this->db->quote(time(),
'integer') .
629 " , last_send_day = " . $this->db->quote($today,
'date') .
630 " WHERE type = " . $this->db->quote($reminder[
"reminder_type"],
'text') .
631 " AND ass_id = " . $this->db->quote($reminder[
"ass_id"],
'integer') .
632 " AND exc_id = " . $this->db->quote($reminder[
"exc_id"],
'integer');
634 $this->db->manipulate($sql);
644 $sql =
"DELETE FROM exc_ass_reminders" .
645 " WHERE ass_id = " . $a_ass_id;
647 $this->db->manipulate($sql);
static _lookupLogin($a_user_id)
lookup login
setReminderStatus($a_status)
Set reminder for users without submission.
getReminderMailTemplate()
getReminders($a_type="")
Get reminders available by date/frequence.
static _lookupFullname($a_user_id)
Lookup Full Name.
parseGradeReminders($a_reminders)
static getTemplateContextById($a_id)
updateRemindersLastDate($a_reminders)
Update reminders last_send value with the current timestamp.
deleteReminders($a_ass_id)
remove reminders from DB when the parent assignment is deleted.
getReminderStart()
Get num days before the deadline to start sending notifications.
static _lookupTitle($a_id)
lookup object title
parsePeerReminders($a_reminders)
static _getAllReferences($a_id)
get all reference ids of object
static getInstanceByIds($a_ass_id, $a_user_id=0)
Get instance by IDs (recommended for consumer code)
static getNotificationsForObject($type, $id, $page_id=null, $ignore_threshold=false)
Get all users for given object.
getReminderEnd()
get the ending of the reminder
getReminderStatus()
Get the reminder status.
checkReminders()
CRON send reminders.
static lookupGiversWithPendingFeedback($a_ass_id)
TODO: import/export reminder data with the exercise/assignment.
setReminderFrequency($a_num_days)
Set frequency in days.
setReminderStart($a_num_days)
Set num days before the deadline to start sending notifications.
const TYPE_EXERCISE_SUBMISSION
static _getLanguageOfUser($a_usr_id)
Get language object of user.
setReminderEnd($a_date)
Set the ending of the reminder.
initFromDB(array $a_set)
Import DB record.
setReminderMailTemplate($a_tpl_id)
Exercise submission //TODO: This class has to much static methods related to delivered "files"...
static getLogger($a_component_id)
Get component logger.
parseSubmissionReminders($a_reminders)
Filter the reminders by object(crs,grp) by active status and if have members.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
sentReminderPlaceholders($a_message, $a_reminder_data, $a_reminder_type)
getReminderFrequency()
get submit reminder frequency in days.
static _getLink($a_ref_id, $a_type='', $a_params=array(), $append="")
static lookupTitle($a_id)
Lookup title.
__construct($a_exc_id="", $a_ass_id="", $a_type="")
setReminderLastSend($a_timestamp)