ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 ILIAS\Cron\CronJob
 setDateTimeProvider (?\Closure $date_time_provider)
 
 isDue (?\DateTimeImmutable $last_run, ?JobScheduleType $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 (?JobScheduleType $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 ()
 
 usesLegacyForms ()
 
 getCustomConfigurationInput (\ILIAS\UI\Factory $ui_factory, \ILIAS\Refinery\Factory $factory, \ilLanguage $lng)
 
 addCustomSettingsToForm (\ilPropertyFormGUI $a_form)
 
 saveCustomConfiguration (mixed $form_data)
 
 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 ILIAS\Cron\CronJob
JobScheduleType $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 27 of file class.ilBookCronNotification.php.

Constructor & Destructor Documentation

◆ __construct()

ilBookCronNotification::__construct ( )

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

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

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

Member Function Documentation

◆ getDefaultScheduleType()

ilBookCronNotification::getDefaultScheduleType ( )

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

67  {
68  return JobScheduleType::DAILY;
69  }

◆ getDefaultScheduleValue()

ilBookCronNotification::getDefaultScheduleValue ( )

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

References null.

71  : ?int
72  {
73  return null;
74  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ getDescription()

ilBookCronNotification::getDescription ( )

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

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

58  : string
59  {
60  $lng = $this->lng;
61 
62  $lng->loadLanguageModule("book");
63  return $lng->txt("book_notification_info");
64  }
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 45 of file class.ilBookCronNotification.php.

45  : string
46  {
47  return "book_notification";
48  }

◆ getTitle()

ilBookCronNotification::getTitle ( )

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

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

50  : string
51  {
52  $lng = $this->lng;
53 
54  $lng->loadLanguageModule("book");
55  return $lng->txt("book_notification");
56  }
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 76 of file class.ilBookCronNotification.php.

76  : bool
77  {
78  return false;
79  }

◆ hasFlexibleSchedule()

ilBookCronNotification::hasFlexibleSchedule ( )

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

81  : bool
82  {
83  return false;
84  }

◆ run()

ilBookCronNotification::run ( )

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

References sendNotifications().

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

◆ sendMails()

ilBookCronNotification::sendMails ( array  $notifications)
protected

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

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

Referenced by sendNotifications().

200  : void {
201  foreach ($notifications as $uid => $n) {
202  $ntf = new ilSystemNotification();
203  $lng = $ntf->getUserLanguage($uid);
204  $lng->loadLanguageModule("book");
205 
206  $txt = "";
207  if (is_array($n["personal"] ?? null)) {
208  $txt .= "\n" . $lng->txt("book_your_reservations") . "\n";
209  $txt .= "-----------------------------------------\n";
210  foreach ($n["personal"] as $obj_id => $reservs) {
211  $txt .= ilObject::_lookupTitle($obj_id) . ":\n";
212  foreach ($reservs as $r) {
213  $txt .= "- " . $r["title"] . " (" . $r["counter"] . "), " .
214  ilDatePresentation::formatDate(new ilDate($r["date"], IL_CAL_DATE)) . ", " .
215  $r["slot"] . "\n";
216  }
217  }
218  }
219 
220  if (is_array($n["admin"] ?? null)) {
221  $txt .= "\n" . $lng->txt("book_reservation_overview") . "\n";
222  $txt .= "-----------------------------------------\n";
223  foreach ($n["admin"] as $obj_id => $reservs) {
224  $txt .= ilObject::_lookupTitle($obj_id) . ":\n";
225  foreach ($reservs as $r) {
226  $txt .= "- " . $r["title"] . " (" . $r["counter"] . "), " . $r["user_name"] . ", " .
227  ilDatePresentation::formatDate(new ilDate($r["date"], IL_CAL_DATE)) . ", " .
228  $r["slot"] . "\n";
229  if ($r["message"] != "") {
230  $txt .= " " . $lng->txt("book_message") .
231  ": " . $r["message"];
232  }
233  }
234  }
235  }
236  $ntf->setLangModules(array("book"));
237  $ntf->setSubjectLangId("book_booking_reminders");
238  $ntf->setIntroductionLangId("book_rem_intro");
239  $ntf->addAdditionalInfo("", $txt);
240  $ntf->setReasonLangId("book_rem_reason");
241  $this->book_log->debug("send Mail: " . $uid);
242  $ntf->sendMailAndReturnRecipients([$uid]);
243  }
244  }
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.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static _lookupTitle(int $obj_id)
$txt
Definition: error.php:31
const IL_CAL_DATE
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
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 102 of file class.ilBookCronNotification.php.

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

Referenced by run().

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

Referenced by sendNotifications().

◆ $lng

ilLanguage ilBookCronNotification::$lng
protected

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

Referenced by getDescription(), and getTitle().

◆ $repo

ILIAS BookingManager InternalRepoService ilBookCronNotification::$repo
protected

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


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