ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilBookCronNotification Class Reference

Cron for booking manager notification. More...

+ Inheritance diagram for ilBookCronNotification:
+ Collaboration diagram for ilBookCronNotification:

Public Member Functions

 __construct ()
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 hasAutoActivation ()
 
 hasFlexibleSchedule ()
 
 run ()
 
- Public Member Functions inherited from ilCronJob
 setDateTimeProvider (?Closure $date_time_provider)
 
 isDue (?DateTimeImmutable $last_run, ?CronJobScheduleType $schedule_type, ?int $schedule_value, bool $is_manually_executed=false)
 
 getScheduleType ()
 Get current schedule type (if flexible) More...
 
 getScheduleValue ()
 Get current schedule value (if flexible) More...
 
 setSchedule (?CronJobScheduleType $a_type, ?int $a_value)
 Update current schedule (if flexible) More...
 
 getAllScheduleTypes ()
 Get all available schedule types. More...
 
 getScheduleTypesWithValues ()
 
 getValidScheduleTypes ()
 Returns a collection of all valid schedule types for a specific job. More...
 
 isManuallyExecutable ()
 
 hasCustomSettings ()
 
 addCustomSettingsToForm (ilPropertyFormGUI $a_form)
 
 saveCustomSettings (ilPropertyFormGUI $a_form)
 
 addToExternalSettingsForm (int $a_form_id, array &$a_fields, bool $a_is_active)
 
 activationWasToggled (ilDBInterface $db, ilSetting $setting, bool $a_currently_active)
 Important: This method is (also) called from the setup process, where the constructor of an ilCronJob ist NOT executed. More...
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 hasAutoActivation ()
 Is to be activated on "installation", does only work for ILIAS core cron jobs. More...
 
 hasFlexibleSchedule ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 run ()
 

Protected Member Functions

 sendNotifications ()
 
 sendMails (array $notifications)
 

Protected Attributes

ILIAS BookingManager InternalRepoService $repo
 
ilLanguage $lng
 
ilLogger $book_log
 
- Protected Attributes inherited from ilCronJob
CronJobScheduleType $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

Detailed Description

Cron for booking manager notification.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 25 of file class.ilBookCronNotification.php.

Constructor & Destructor Documentation

◆ __construct()

ilBookCronNotification::__construct ( )

Definition at line 31 of file class.ilBookCronNotification.php.

References $DIC, ilLoggerFactory\getLogger(), and ILIAS\Repository\lng().

32  {
33  global $DIC;
34 
35  $this->lng = $DIC->language();
36 
37  $this->book_log = ilLoggerFactory::getLogger("book");
38  $this->repo = $DIC->bookingManager()
39  ->internal()
40  ->repo();
41  }
static getLogger(string $a_component_id)
Get component logger.
global $DIC
Definition: shib_login.php:25
+ Here is the call graph for this function:

Member Function Documentation

◆ getDefaultScheduleType()

ilBookCronNotification::getDefaultScheduleType ( )

Definition at line 64 of file class.ilBookCronNotification.php.

65  {
66  return CronJobScheduleType::SCHEDULE_TYPE_DAILY;
67  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ getDefaultScheduleValue()

ilBookCronNotification::getDefaultScheduleValue ( )

Definition at line 69 of file class.ilBookCronNotification.php.

69  : ?int
70  {
71  return null;
72  }

◆ getDescription()

ilBookCronNotification::getDescription ( )

Definition at line 56 of file class.ilBookCronNotification.php.

References $lng, ilLanguage\loadLanguageModule(), and ilLanguage\txt().

56  : string
57  {
58  $lng = $this->lng;
59 
60  $lng->loadLanguageModule("book");
61  return $lng->txt("book_notification_info");
62  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
loadLanguageModule(string $a_module)
Load language module.
+ Here is the call graph for this function:

◆ getId()

ilBookCronNotification::getId ( )

Definition at line 43 of file class.ilBookCronNotification.php.

43  : string
44  {
45  return "book_notification";
46  }

◆ getTitle()

ilBookCronNotification::getTitle ( )

Definition at line 48 of file class.ilBookCronNotification.php.

References $lng, ilLanguage\loadLanguageModule(), and ilLanguage\txt().

48  : string
49  {
50  $lng = $this->lng;
51 
52  $lng->loadLanguageModule("book");
53  return $lng->txt("book_notification");
54  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
loadLanguageModule(string $a_module)
Load language module.
+ Here is the call graph for this function:

◆ hasAutoActivation()

ilBookCronNotification::hasAutoActivation ( )

Definition at line 74 of file class.ilBookCronNotification.php.

74  : bool
75  {
76  return false;
77  }

◆ hasFlexibleSchedule()

ilBookCronNotification::hasFlexibleSchedule ( )

Definition at line 79 of file class.ilBookCronNotification.php.

79  : bool
80  {
81  return false;
82  }

◆ run()

ilBookCronNotification::run ( )

Definition at line 84 of file class.ilBookCronNotification.php.

References sendNotifications(), ilCronJobResult\STATUS_NO_ACTION, and ilCronJobResult\STATUS_OK.

85  {
87 
88  $count = $this->sendNotifications();
89 
90  if ($count > 0) {
92  }
93 
94  $result = new ilCronJobResult();
95  $result->setStatus($status);
96 
97  return $result;
98  }
final const STATUS_NO_ACTION
+ Here is the call graph for this function:

◆ sendMails()

ilBookCronNotification::sendMails ( array  $notifications)
protected

Definition at line 196 of file class.ilBookCronNotification.php.

References $r, $txt, ilObject\_lookupTitle(), ilDatePresentation\formatDate(), ilLanguage\getUserLanguage(), IL_CAL_DATE, ilLanguage\loadLanguageModule(), and ilLanguage\txt().

Referenced by sendNotifications().

198  : void {
199  foreach ($notifications as $uid => $n) {
200  $ntf = new ilSystemNotification();
201  $lng = $ntf->getUserLanguage($uid);
202  $lng->loadLanguageModule("book");
203 
204  $txt = "";
205  if (is_array($n["personal"] ?? null)) {
206  $txt .= "\n" . $lng->txt("book_your_reservations") . "\n";
207  $txt .= "-----------------------------------------\n";
208  foreach ($n["personal"] as $obj_id => $reservs) {
209  $txt .= ilObject::_lookupTitle($obj_id) . ":\n";
210  foreach ($reservs as $r) {
211  $txt .= "- " . $r["title"] . " (" . $r["counter"] . "), " .
212  ilDatePresentation::formatDate(new ilDate($r["date"], IL_CAL_DATE)) . ", " .
213  $r["slot"] . "\n";
214  }
215  }
216  }
217 
218  if (is_array($n["admin"] ?? null)) {
219  $txt .= "\n" . $lng->txt("book_reservation_overview") . "\n";
220  $txt .= "-----------------------------------------\n";
221  foreach ($n["admin"] as $obj_id => $reservs) {
222  $txt .= ilObject::_lookupTitle($obj_id) . ":\n";
223  foreach ($reservs as $r) {
224  $txt .= "- " . $r["title"] . " (" . $r["counter"] . "), " . $r["user_name"] . ", " .
225  ilDatePresentation::formatDate(new ilDate($r["date"], IL_CAL_DATE)) . ", " .
226  $r["slot"] . "\n";
227  if ($r["message"] != "") {
228  $txt .= " " . $lng->txt("book_message") .
229  ": " . $r["message"];
230  }
231  }
232  }
233  }
234  $ntf->setLangModules(array("book"));
235  $ntf->setSubjectLangId("book_booking_reminders");
236  $ntf->setIntroductionLangId("book_rem_intro");
237  $ntf->addAdditionalInfo("", $txt);
238  $ntf->setReasonLangId("book_rem_reason");
239  $this->book_log->debug("send Mail: " . $uid);
240  $ntf->sendMailAndReturnRecipients([$uid]);
241  }
242  }
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ilObjUser $user=null,)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
getUserLanguage()
Return language of user.
loadLanguageModule(string $a_module)
Load language module.
static _lookupTitle(int $obj_id)
$txt
Definition: error.php:30
const IL_CAL_DATE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$r
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendNotifications()

ilBookCronNotification::sendNotifications ( )
protected

Definition at line 100 of file class.ilBookCronNotification.php.

References $book_log, $DIC, $log, $r, $res, ilObject\_lookupTitle(), ilNotification\getNotificationsForObject(), ilObjBookingPool\getPoolsWithReminders(), sendMails(), ilNotification\TYPE_BOOK, and ilObjBookingPool\writeLastReminderTimestamp().

Referenced by run().

100  : int
101  {
102  global $DIC;
103 
104  $access = $DIC->bookingManager()->internal()->domain()->access();
105 
107 
108  $log->debug("start");
109 
110 
111  $notifications = [];
112 
113  /*
114  * pool id 123 > 2 days, ...
115  */
116  foreach (ilObjBookingPool::getPoolsWithReminders() as $p) {
117  // determine reservations from max(next day $last_to_ts) up to "rmd_day" days + 1
118  // per pool id
119  $next_day_ts = mktime(0, 0, 0, date('n'), (int) date('j') + 1);
120  $log->debug("next day ts: " . $next_day_ts);
121  $last_reminder_to_ts = $p["last_remind_ts"];
122  // for debug purposes
123  // $last_reminder_to_ts-= 24*60*60;
124  $log->debug("last_reminder ts: " . $last_reminder_to_ts);
125  $from_ts = max($next_day_ts, $last_reminder_to_ts);
126  $log->debug("from ts: " . $from_ts);
127  $to_ts = mktime(0, 0, 0, date('n'), (int) date('j') + $p["reminder_day"] + 1);
128  $res = [];
129 
130  // overwrite from to current time, see #26216, this ensures
131  // that all reservations are sent, some multiple times (each day)
132  // we include all reservations from now to the period set in the pool settings
133  $from_ts = time();
134 
135  // additional logging info, see #26216
136  $log->debug("pool id: "
137  . $p["booking_pool_id"]
138  . "(" . ilObject::_lookupTitle($p["booking_pool_id"]) . ") "
139  . ", "
140  . date("Y-m-d, H:i:s", $from_ts)
141  . " to " . date("Y-m-d, H:i:s", $to_ts));
142 
143 
144  if ($to_ts > $from_ts) {
145  $repo = $this->repo->reservation();
146  $res = $repo->getListByDate(true, null, [
147  "from" => $from_ts,
148  "to" => $to_ts
149  ], [$p["booking_pool_id"]]);
150  }
151 
152  $log->debug("reservations: " . count($res));
153 
154  //var_dump($res); exit;
155 
156  // get subscriber of pool id
157  $user_ids = ilNotification::getNotificationsForObject(ilNotification::TYPE_BOOK, $p["booking_pool_id"]);
158  $log->debug("users: " . count($user_ids));
159 
160  // group by user, type, pool
161  foreach ($res as $r) {
162  // users
163  $log->debug("check notification of user id: " . $r["user_id"]);
164  if (in_array($r["user_id"], $user_ids)) {
165  if ($access->canRetrieveNotificationsForOwnReservationsByObjId(
166  (int) $p["booking_pool_id"],
167  (int) $r["user_id"]
168  )) {
169  $log->debug("got read");
170  $notifications[$r["user_id"]]["personal"][$r["pool_id"]][] = $r;
171  }
172  }
173 
174  // admins
175  foreach ($user_ids as $uid) {
176  $log->debug("check write for user id: " . $uid . ", pool: " . $p["booking_pool_id"]);
177 
178  if ($access->canRetrieveNotificationsForAllReservationsByObjId(
179  (int) $p["booking_pool_id"],
180  (int) $r["user_id"]
181  )) {
182  $log->debug("got write");
183  $notifications[$uid]["admin"][$r["pool_id"]][] = $r;
184  }
185  }
186  }
187  ilObjBookingPool::writeLastReminderTimestamp($p["booking_pool_id"], $to_ts);
188  }
189 
190  // send mails
191  $this->sendMails($notifications);
192 
193  return count($notifications);
194  }
$res
Definition: ltiservices.php:69
static getPoolsWithReminders()
Get pools with reminders.
static getNotificationsForObject(int $type, int $id, ?int $page_id=null, bool $ignore_threshold=false)
Get all users/recipients for given object.
static writeLastReminderTimestamp(int $a_obj_id, int $a_ts)
static _lookupTitle(int $obj_id)
global $DIC
Definition: shib_login.php:25
$log
Definition: ltiresult.php:34
ILIAS BookingManager InternalRepoService $repo
$r
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $book_log

ilLogger ilBookCronNotification::$book_log
protected

Definition at line 29 of file class.ilBookCronNotification.php.

Referenced by sendNotifications().

◆ $lng

ilLanguage ilBookCronNotification::$lng
protected

Definition at line 28 of file class.ilBookCronNotification.php.

Referenced by getDescription(), and getTitle().

◆ $repo

ILIAS BookingManager InternalRepoService ilBookCronNotification::$repo
protected

Definition at line 27 of file class.ilBookCronNotification.php.


The documentation for this class was generated from the following file: