ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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)
 
 checkAccess (string $perm, int $uid, int $obj_id)
 

Protected Attributes

ILIAS BookingManager InternalRepoService $repo
 
ilLanguage $lng
 
ilAccessHandler $access
 
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 32 of file class.ilBookCronNotification.php.

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

33  {
34  global $DIC;
35 
36  $this->lng = $DIC->language();
37  if (isset($DIC["ilAccess"])) {
38  $this->access = $DIC->access();
39  }
40 
41  $this->book_log = ilLoggerFactory::getLogger("book");
42  $this->repo = $DIC->bookingManager()
43  ->internal()
44  ->repo();
45  }
static getLogger(string $a_component_id)
Get component logger.
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ checkAccess()

ilBookCronNotification::checkAccess ( string  $perm,
int  $uid,
int  $obj_id 
)
protected

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

References $access, $ref_id, ilObject\_getAllReferences(), and ilRBACAccessHandler\checkAccessOfUser().

Referenced by sendNotifications().

244  : bool {
246  foreach (ilObject::_getAllReferences($obj_id) as $ref_id) {
247  if ($access->checkAccessOfUser($uid, $perm, "", $ref_id)) {
248  return true;
249  }
250  }
251  return false;
252  }
static _getAllReferences(int $id)
get all reference ids for object ID
$ref_id
Definition: ltiauth.php:67
checkAccessOfUser(int $a_user_id, string $a_permission, string $a_cmd, int $a_ref_id, string $a_type="", ?int $a_obj_id=null, ?int $a_tree_id=null)
check access for an object (provide $a_type and $a_obj_id if available for better performance) ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultScheduleType()

ilBookCronNotification::getDefaultScheduleType ( )

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

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

◆ getDefaultScheduleValue()

ilBookCronNotification::getDefaultScheduleValue ( )

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

73  : ?int
74  {
75  return null;
76  }

◆ getDescription()

ilBookCronNotification::getDescription ( )

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

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

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

47  : string
48  {
49  return "book_notification";
50  }

◆ getTitle()

ilBookCronNotification::getTitle ( )

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

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

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

78  : bool
79  {
80  return false;
81  }

◆ hasFlexibleSchedule()

ilBookCronNotification::hasFlexibleSchedule ( )

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

83  : bool
84  {
85  return false;
86  }

◆ run()

ilBookCronNotification::run ( )

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

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

89  {
91 
92  $count = $this->sendNotifications();
93 
94  if ($count > 0) {
96  }
97 
98  $result = new ilCronJobResult();
99  $result->setStatus($status);
100 
101  return $result;
102  }
final const STATUS_NO_ACTION
+ Here is the call graph for this function:

◆ sendMails()

ilBookCronNotification::sendMails ( array  $notifications)
protected

Definition at line 190 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().

192  : void {
193  foreach ($notifications as $uid => $n) {
194  $ntf = new ilSystemNotification();
195  $lng = $ntf->getUserLanguage($uid);
196  $lng->loadLanguageModule("book");
197 
198  $txt = "";
199  if (is_array($n["personal"] ?? null)) {
200  $txt .= "\n" . $lng->txt("book_your_reservations") . "\n";
201  $txt .= "-----------------------------------------\n";
202  foreach ($n["personal"] as $obj_id => $reservs) {
203  $txt .= ilObject::_lookupTitle($obj_id) . ":\n";
204  foreach ($reservs as $r) {
205  $txt .= "- " . $r["title"] . " (" . $r["counter"] . "), " .
206  ilDatePresentation::formatDate(new ilDate($r["date"], IL_CAL_DATE)) . ", " .
207  $r["slot"] . "\n";
208  }
209  }
210  }
211 
212  if (is_array($n["admin"] ?? null)) {
213  $txt .= "\n" . $lng->txt("book_reservation_overview") . "\n";
214  $txt .= "-----------------------------------------\n";
215  foreach ($n["admin"] as $obj_id => $reservs) {
216  $txt .= ilObject::_lookupTitle($obj_id) . ":\n";
217  foreach ($reservs as $r) {
218  $txt .= "- " . $r["title"] . " (" . $r["counter"] . "), " . $r["user_name"] . ", " .
219  ilDatePresentation::formatDate(new ilDate($r["date"], IL_CAL_DATE)) . ", " .
220  $r["slot"] . "\n";
221  if ($r["message"] != "") {
222  $txt .= " " . $lng->txt("book_message") .
223  ": " . $r["message"];
224  }
225  }
226  }
227  }
228  $ntf->setLangModules(array("book"));
229  $ntf->setSubjectLangId("book_booking_reminders");
230  $ntf->setIntroductionLangId("book_rem_intro");
231  $ntf->addAdditionalInfo("", $txt);
232  $ntf->setReasonLangId("book_rem_reason");
233  $this->book_log->debug("send Mail: " . $uid);
234  $ntf->sendMailAndReturnRecipients([$uid]);
235  }
236  }
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.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
loadLanguageModule(string $a_module)
Load language module.
static _lookupTitle(int $obj_id)
$txt
Definition: error.php:14
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 104 of file class.ilBookCronNotification.php.

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

Referenced by run().

104  : int
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 ($this->checkAccess("read", $r["user_id"], $p["booking_pool_id"])) {
166  $log->debug("got read");
167  $notifications[$r["user_id"]]["personal"][$r["pool_id"]][] = $r;
168  }
169  }
170 
171  // admins
172  foreach ($user_ids as $uid) {
173  $log->debug("check write for user id: " . $uid . ", pool: " . $p["booking_pool_id"]);
174 
175  if ($this->checkAccess("write", $uid, $p["booking_pool_id"])) {
176  $log->debug("got write");
177  $notifications[$uid]["admin"][$r["pool_id"]][] = $r;
178  }
179  }
180  }
181  ilObjBookingPool::writeLastReminderTimestamp($p["booking_pool_id"], $to_ts);
182  }
183 
184  // send mails
185  $this->sendMails($notifications);
186 
187  return count($notifications);
188  }
$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)
$log
Definition: result.php:33
ILIAS BookingManager InternalRepoService $repo
checkAccess(string $perm, int $uid, int $obj_id)
$r
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $access

ilAccessHandler ilBookCronNotification::$access
protected

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

Referenced by checkAccess().

◆ $book_log

ilLogger ilBookCronNotification::$book_log
protected

Definition at line 30 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: