ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilConsultationHourCron.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
30{
31 protected ilLanguage $lng;
32 protected ilDBInterface $db;
34
35 public function __construct()
36 {
37 global $DIC;
38
39 $this->lng = $DIC->language();
40 $this->lng->loadLanguageModule('dateplaner');
41 $this->db = $DIC->database();
42 $this->setting = $DIC->settings();
43 }
44
45 public function getId(): string
46 {
47 return "cal_consultation";
48 }
49
50 public function getTitle(): string
51 {
52 return $this->lng->txt("cal_ch_cron_reminder");
53 }
54
55 public function getDescription(): string
56 {
57 return $this->lng->txt("cal_ch_cron_reminder_info");
58 }
59
61 {
62 return JobScheduleType::DAILY;
63 }
64
65 public function getDefaultScheduleValue(): ?int
66 {
67 return null;
68 }
69
70 public function hasAutoActivation(): bool
71 {
72 return false;
73 }
74
75 public function hasFlexibleSchedule(): bool
76 {
77 return false;
78 }
79
80 public function hasCustomSettings(): bool
81 {
82 return true;
83 }
84
85 public function run(): JobResult
86 {
87 $status = JobResult::STATUS_NO_ACTION;
88
89 $days_before = (int) $this->setting->get('ch_reminder_days');
90 $now = new ilDateTime(time(), IL_CAL_UNIX);
91 $limit = clone $now;
92 $limit->increment(IL_CAL_DAY, $days_before);
93
94 $counter = 0;
95 $query = 'SELECT * FROM booking_user ' .
96 'JOIN cal_entries ON entry_id = cal_id ' .
97 'WHERE notification_sent = ' . $this->db->quote(0, 'integer') . ' ' .
98 'AND starta > ' . $this->db->quote($now->get(IL_CAL_DATETIME, '', ilTimeZone::UTC), 'timestamp') . ' ' .
99 'AND starta <= ' . $this->db->quote($limit->get(IL_CAL_DATETIME, '', ilTimeZone::UTC), 'timestamp');
100 $res = $this->db->query($query);
101 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
102 $mail = new ilCalendarMailNotification();
103 $mail->setAppointmentId((int) $row->entry_id);
104 $mail->setRecipients(array((int) $row->user_id));
106 $mail->send();
107
108 // update notification
109 $query = 'UPDATE booking_user ' .
110 'SET notification_sent = ' . $this->db->quote(1, 'integer') . ' ' .
111 'WHERE user_id = ' . $this->db->quote($row->user_id, 'integer') . ' ' .
112 'AND entry_id = ' . $this->db->quote($row->entry_id, 'integer');
113 $this->db->manipulate($query);
114 $counter++;
115 }
116
117 if ($counter) {
118 $status = JobResult::STATUS_OK;
119 }
120 $result = new JobResult();
121 $result->setStatus($status);
122 return $result;
123 }
124
125 public function addCustomSettingsToForm(ilPropertyFormGUI $a_form): void
126 {
127 $consultation_days = new ilNumberInputGUI($this->lng->txt('cal_ch_cron_reminder_days'), 'ch_reminder_days');
128 $consultation_days->setMinValue(1);
129 $consultation_days->setMaxLength(2);
130 $consultation_days->setSize(2);
131 $consultation_days->setValue((string) $this->setting->get('ch_reminder_days', '2'));
132 $consultation_days->setRequired(true);
133 $a_form->addItem($consultation_days);
134 }
135
136 public function saveCustomSettings(ilPropertyFormGUI $a_form): bool
137 {
138 $this->setting->set('ch_reminder_days', (string) $a_form->getInput('ch_reminder_days'));
139 return true;
140 }
141}
const IL_CAL_UNIX
const IL_CAL_DATETIME
const IL_CAL_DAY
Distributes calendar mail notifications.
Reminders for consultation hours.
saveCustomSettings(ilPropertyFormGUI $a_form)
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
@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-...
ILIAS Setting Class.
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26
$counter