ILIAS  release_8 Revision v8.24
class.ilConsultationHourCron.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27{
28 protected ilLanguage $lng;
29 protected ilDBInterface $db;
31
32 public function __construct()
33 {
34 global $DIC;
35
36 $this->lng = $DIC->language();
37 $this->lng->loadLanguageModule('dateplaner');
38 $this->db = $DIC->database();
39 $this->setting = $DIC->settings();
40 }
41
42 public function getId(): string
43 {
44 return "cal_consultation";
45 }
46
47 public function getTitle(): string
48 {
49 return $this->lng->txt("cal_ch_cron_reminder");
50 }
51
52 public function getDescription(): string
53 {
54 return $this->lng->txt("cal_ch_cron_reminder_info");
55 }
56
57 public function getDefaultScheduleType(): int
58 {
60 }
61
62 public function getDefaultScheduleValue(): ?int
63 {
64 return null;
65 }
66
67 public function hasAutoActivation(): bool
68 {
69 return false;
70 }
71
72 public function hasFlexibleSchedule(): bool
73 {
74 return false;
75 }
76
77 public function hasCustomSettings(): bool
78 {
79 return true;
80 }
81
82 public function run(): ilCronJobResult
83 {
85
86 $days_before = (int) $this->setting->get('ch_reminder_days');
87 $now = new ilDateTime(time(), IL_CAL_UNIX);
88 $limit = clone $now;
89 $limit->increment(IL_CAL_DAY, $days_before);
90
91 $counter = 0;
92 $query = 'SELECT * FROM booking_user ' .
93 'JOIN cal_entries ON entry_id = cal_id ' .
94 'WHERE notification_sent = ' . $this->db->quote(0, 'integer') . ' ' .
95 'AND starta > ' . $this->db->quote($now->get(IL_CAL_DATETIME, '', ilTimeZone::UTC), 'timestamp') . ' ' .
96 'AND starta <= ' . $this->db->quote($limit->get(IL_CAL_DATETIME, '', ilTimeZone::UTC), 'timestamp');
97 $res = $this->db->query($query);
98 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
99 $mail = new ilCalendarMailNotification();
100 $mail->setAppointmentId((int) $row->entry_id);
101 $mail->setRecipients(array((int) $row->user_id));
103 $mail->send();
104
105 // update notification
106 $query = 'UPDATE booking_user ' .
107 'SET notification_sent = ' . $this->db->quote(1, 'integer') . ' ' .
108 'WHERE user_id = ' . $this->db->quote($row->user_id, 'integer') . ' ' .
109 'AND entry_id = ' . $this->db->quote($row->entry_id, 'integer');
110 $this->db->manipulate($query);
111 $counter++;
112 }
113
114 if ($counter) {
116 }
117 $result = new ilCronJobResult();
118 $result->setStatus($status);
119 return $result;
120 }
121
122 public function addCustomSettingsToForm(ilPropertyFormGUI $a_form): void
123 {
124 $consultation_days = new ilNumberInputGUI($this->lng->txt('cal_ch_cron_reminder_days'), 'ch_reminder_days');
125 $consultation_days->setMinValue(1);
126 $consultation_days->setMaxLength(2);
127 $consultation_days->setSize(2);
128 $consultation_days->setValue((string) $this->setting->get('ch_reminder_days', '2'));
129 $consultation_days->setRequired(true);
130 $a_form->addItem($consultation_days);
131 }
132
133 public function saveCustomSettings(ilPropertyFormGUI $a_form): bool
134 {
135 $this->setting->set('ch_reminder_days', (string) $a_form->getInput('ch_reminder_days'));
136 return true;
137 }
138}
const IL_CAL_UNIX
const IL_CAL_DATETIME
const IL_CAL_DAY
Distributes calendar mail notifications.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
saveCustomSettings(ilPropertyFormGUI $a_form)
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
const SCHEDULE_TYPE_DAILY
@depracated This will be replaced with an ENUM in ILIAS 9
@classDescription Date and time handling
language handling
This class represents a number property in a property form.
This class represents a property form user interface.
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-...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query