ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilConsultationHourCron.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
28 {
29  protected ilLanguage $lng;
30  protected ilDBInterface $db;
31  protected ilSetting $setting;
32 
33  public function __construct()
34  {
35  global $DIC;
36 
37  $this->lng = $DIC->language();
38  $this->lng->loadLanguageModule('dateplaner');
39  $this->db = $DIC->database();
40  $this->setting = $DIC->settings();
41  }
42 
43  public function getId(): string
44  {
45  return "cal_consultation";
46  }
47 
48  public function getTitle(): string
49  {
50  return $this->lng->txt("cal_ch_cron_reminder");
51  }
52 
53  public function getDescription(): string
54  {
55  return $this->lng->txt("cal_ch_cron_reminder_info");
56  }
57 
59  {
60  return CronJobScheduleType::SCHEDULE_TYPE_DAILY;
61  }
62 
63  public function getDefaultScheduleValue(): ?int
64  {
65  return null;
66  }
67 
68  public function hasAutoActivation(): bool
69  {
70  return false;
71  }
72 
73  public function hasFlexibleSchedule(): bool
74  {
75  return false;
76  }
77 
78  public function hasCustomSettings(): bool
79  {
80  return true;
81  }
82 
83  public function run(): ilCronJobResult
84  {
86 
87  $days_before = (int) $this->setting->get('ch_reminder_days');
88  $now = new ilDateTime(time(), IL_CAL_UNIX);
89  $limit = clone $now;
90  $limit->increment(IL_CAL_DAY, $days_before);
91 
92  $counter = 0;
93  $query = 'SELECT * FROM booking_user ' .
94  'JOIN cal_entries ON entry_id = cal_id ' .
95  'WHERE notification_sent = ' . $this->db->quote(0, 'integer') . ' ' .
96  'AND starta > ' . $this->db->quote($now->get(IL_CAL_DATETIME, '', ilTimeZone::UTC), 'timestamp') . ' ' .
97  'AND starta <= ' . $this->db->quote($limit->get(IL_CAL_DATETIME, '', ilTimeZone::UTC), 'timestamp');
98  $res = $this->db->query($query);
99  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
100  $mail = new ilCalendarMailNotification();
101  $mail->setAppointmentId((int) $row->entry_id);
102  $mail->setRecipients(array((int) $row->user_id));
104  $mail->send();
105 
106  // update notification
107  $query = 'UPDATE booking_user ' .
108  'SET notification_sent = ' . $this->db->quote(1, 'integer') . ' ' .
109  'WHERE user_id = ' . $this->db->quote($row->user_id, 'integer') . ' ' .
110  'AND entry_id = ' . $this->db->quote($row->entry_id, 'integer');
111  $this->db->manipulate($query);
112  $counter++;
113  }
114 
115  if ($counter) {
116  $status = ilCronJobResult::STATUS_OK;
117  }
118  $result = new ilCronJobResult();
119  $result->setStatus($status);
120  return $result;
121  }
122 
123  public function addCustomSettingsToForm(ilPropertyFormGUI $a_form): void
124  {
125  $consultation_days = new ilNumberInputGUI($this->lng->txt('cal_ch_cron_reminder_days'), 'ch_reminder_days');
126  $consultation_days->setMinValue(1);
127  $consultation_days->setMaxLength(2);
128  $consultation_days->setSize(2);
129  $consultation_days->setValue((string) $this->setting->get('ch_reminder_days', '2'));
130  $consultation_days->setRequired(true);
131  $a_form->addItem($consultation_days);
132  }
133 
134  public function saveCustomSettings(ilPropertyFormGUI $a_form): bool
135  {
136  $this->setting->set('ch_reminder_days', (string) $a_form->getInput('ch_reminder_days'));
137  return true;
138  }
139 }
$res
Definition: ltiservices.php:69
const IL_CAL_DATETIME
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Distributes calendar mail notifications.
const IL_CAL_UNIX
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
global $DIC
Definition: feed.php:28
const IL_CAL_DAY
final const STATUS_NO_ACTION
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
Reminders for consultation hours.
saveCustomSettings(ilPropertyFormGUI $a_form)