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;
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"]);
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) {
400 include_once
"./Services/Notification/classes/class.ilNotification.php";
404 foreach (
$users as $user_id) {
406 $unike_usr_id = array();
407 foreach ($exc_refs as $exc_ref) {
408 if ($this->access->checkAccessOfUser($user_id,
"write",
"", $exc_ref)) {
409 if (!in_array($user_id, $unike_usr_id)) {
410 $member_data = array(
411 "exc_id" => $rem[
"exc_id"],
412 "exc_ref" => $exc_ref,
413 "ass_id" => $rem[
"ass_id"],
414 "member_id" => $user_id,
415 "reminder_type" => $rem[
"type"],
416 "template_id" => $rem[
"template_id"]
418 array_push($users_to_remind, $member_data);
419 array_push($unike_usr_id, $user_id);
427 return $users_to_remind;
432 $reminders = $a_reminders;
433 $users_to_remind = array();
435 foreach ($reminders as $reminder) {
437 foreach ($giver_ids as $giver_id) {
439 $days_diff = ((
$state->getPeerReviewDeadline() - time()) / (60 * 60 * 24));
441 if (
$state->isPeerReviewAllowed() && $days_diff < $reminder[
"start"]) {
443 foreach ($exc_refs as $exc_ref) {
444 if ($this->access->checkAccessOfUser($giver_id,
"read",
"", $exc_ref)) {
445 $member_data = array(
446 "exc_id" => $reminder[
"exc_id"],
447 "exc_ref" => $exc_ref,
448 "ass_id" => $reminder[
"ass_id"],
449 "member_id" => $giver_id,
450 "reminder_type" => $reminder[
"type"],
451 "template_id" => $reminder[
"template_id"]
453 array_push($users_to_remind, $member_data);
460 return $users_to_remind;
468 $submit_reminders = $this->
getReminders(self::SUBMIT_REMINDER);
471 $grade_reminders = $this->
getReminders(self::GRADE_REMINDER);
474 $peer_reminders = $this->
getReminders(self::FEEDBACK_REMINDER);
492 $reminders = array_merge($parsed_submit_reminders, $parsed_grade_reminders, $parsed_peer_reminders);
494 $reminders_sent = $this->sendReminders($reminders);
496 return $reminders_sent;
503 protected function sendReminders($reminders)
509 foreach ($reminders as $reminder) {
513 $this->log->debug(
"Sending reminder type = " .
$rmd_type);
518 $templateService = $DIC[
'mail.texttemplates.service'];
523 $this->log->debug(
"** send reminder WITH template.");
524 $subject =
$tpl->getSubject();
526 $placeholder_params = array(
527 "exc_id" => $reminder[
"exc_id"],
528 "exc_ref" => $reminder[
"exc_ref"],
529 "ass_id" => $reminder[
"ass_id"],
530 "member_id" => $reminder[
"member_id"]
534 $this->log->debug(
"** send reminder WITHOUT template.");
540 include_once
"./Services/Language/classes/class.ilLanguageFactory.php";
542 $ulng->loadLanguageModule(
'exc');
544 $link =
ilLink::_getLink($reminder[
"exc_ref"],
"exc", array(),
"_" . $reminder[
"ass_id"]);
548 $this->log->debug(
"send: MAIL TYPE = " .
$rmd_type .
", user: " . $reminder[
"member_id"] .
", ass: " . $reminder[
"ass_id"]);
552 $subject = sprintf($ulng->txt(
'exc_reminder_submit_subject'), $ass_title);
553 $message .= $ulng->txt(
'exc_reminder_submit_body') .
":\n\n";
557 $subject = sprintf($ulng->txt(
'exc_reminder_grade_subject'), $ass_title);
558 $message .= $ulng->txt(
'exc_reminder_grade_body') .
":\n\n";
562 $subject = sprintf($ulng->txt(
'exc_reminder_peer_subject'), $ass_title);
563 $message .= $ulng->txt(
'exc_reminder_peer_body') .
":\n\n";
567 $message .= $ulng->txt(
'obj_exc') .
": " . $exc_title .
"\n";
568 $message .= $ulng->txt(
'obj_ass') .
": " . $ass_title .
"\n";
569 $message .=
"\n" . $ulng->txt(
'exc_reminder_link') .
": " . $link;
571 $mail_obj =
new ilMail(ANONYMOUS_USER_ID);
572 $mail_obj->appendInstallationSignature(
true);
585 return sizeof($reminders);
593 switch ($a_reminder_type) {
594 case \ilExAssignmentReminder::SUBMIT_REMINDER:
597 case \ilExAssignmentReminder::GRADE_REMINDER:
600 case \ilExAssignmentReminder::FEEDBACK_REMINDER:
607 $user = new \ilObjUser($a_reminder_data[
"member_id"]);
609 $processor = new \ilMailTemplatePlaceholderResolver(
$context, $a_message);
610 $a_message = $processor->resolve(
$user, $a_reminder_data);
624 $today = date(
"Y-m-d");
625 foreach ($a_reminders as $reminder) {
626 $sql =
"UPDATE exc_ass_reminders" .
627 " SET last_send = " . $this->db->quote(time(),
'integer') .
628 " , last_send_day = " . $this->db->quote($today,
'date') .
629 " WHERE type = " . $this->db->quote($reminder[
"reminder_type"],
'text') .
630 " AND ass_id = " . $this->db->quote($reminder[
"ass_id"],
'integer') .
631 " AND exc_id = " . $this->db->quote($reminder[
"exc_id"],
'integer');
633 $this->db->manipulate($sql);
643 $sql =
"DELETE FROM exc_ass_reminders" .
644 " WHERE ass_id = " . $a_ass_id;
646 $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
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
getReminderStatus()
Get the reminder status.
checkReminders()
CRON send reminders.
catch(Exception $e) $message
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.
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)