ILIAS  release_8 Revision v8.24
ilBookCronNotification Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

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

Public Member Functions

 __construct ()
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 hasAutoActivation ()
 Is to be activated on "installation", does only work for ILIAS core cron jobs. More...
 
 hasFlexibleSchedule ()
 
 run ()
 
- Public Member Functions inherited from ilCronJob
 setDateTimeProvider (?Closure $date_time_provider)
 
 isDue (?DateTimeImmutable $last_run, ?int $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 (?int $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

ilLanguage $lng
 
ilAccessHandler $access
 
ilLogger $book_log
 
- Protected Attributes inherited from ilCronJob
int $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

Additional Inherited Members

- Data Fields inherited from ilCronJob
const SCHEDULE_TYPE_DAILY = 1
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_MINUTES = 2
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_HOURS = 3
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_DAYS = 4
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_WEEKLY = 5
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_MONTHLY = 6
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_QUARTERLY = 7
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_YEARLY = 8
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Cron for booking manager notification

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

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

Constructor & Destructor Documentation

◆ __construct()

ilBookCronNotification::__construct ( )

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

30 {
31 global $DIC;
32
33 $this->lng = $DIC->language();
34 if (isset($DIC["ilAccess"])) {
35 $this->access = $DIC->access();
36 }
37
38 $this->book_log = ilLoggerFactory::getLogger("book");
39 }
static getLogger(string $a_component_id)
Get component logger.
global $DIC
Definition: feed.php:28

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

+ 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 233 of file class.ilBookCronNotification.php.

237 : bool {
239 foreach (ilObject::_getAllReferences($obj_id) as $ref_id) {
240 if ($access->checkAccessOfUser($uid, $perm, "", $ref_id)) {
241 return true;
242 }
243 }
244 return false;
245 }
static _getAllReferences(int $id)
get all reference ids for object ID
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)
$ref_id
Definition: ltiauth.php:67

References $ref_id.

Referenced by sendNotifications().

+ Here is the caller graph for this function:

◆ getDefaultScheduleType()

ilBookCronNotification::getDefaultScheduleType ( )

Reimplemented from ilCronJob.

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

62 : int
63 {
65 }
const SCHEDULE_TYPE_DAILY
@depracated This will be replaced with an ENUM in ILIAS 9

References ilCronJob\SCHEDULE_TYPE_DAILY.

◆ getDefaultScheduleValue()

ilBookCronNotification::getDefaultScheduleValue ( )

Reimplemented from ilCronJob.

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

67 : ?int
68 {
69 return null;
70 }

◆ getDescription()

ilBookCronNotification::getDescription ( )

Reimplemented from ilCronJob.

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

54 : string
55 {
57
58 $lng->loadLanguageModule("book");
59 return $lng->txt("book_notification_info");
60 }
loadLanguageModule(string $a_module)
Load language module.
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...

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

+ Here is the call graph for this function:

◆ getId()

ilBookCronNotification::getId ( )

Reimplemented from ilCronJob.

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

41 : string
42 {
43 return "book_notification";
44 }

◆ getTitle()

ilBookCronNotification::getTitle ( )

Reimplemented from ilCronJob.

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

46 : string
47 {
49
50 $lng->loadLanguageModule("book");
51 return $lng->txt("book_notification");
52 }

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

+ Here is the call graph for this function:

◆ hasAutoActivation()

ilBookCronNotification::hasAutoActivation ( )

Is to be activated on "installation", does only work for ILIAS core cron jobs.

Reimplemented from ilCronJob.

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

72 : bool
73 {
74 return false;
75 }

◆ hasFlexibleSchedule()

ilBookCronNotification::hasFlexibleSchedule ( )

Reimplemented from ilCronJob.

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

77 : bool
78 {
79 return false;
80 }

◆ run()

ilBookCronNotification::run ( )

Reimplemented from ilCronJob.

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

83 {
85
86 $count = $this->sendNotifications();
87
88 if ($count > 0) {
90 }
91
92 $result = new ilCronJobResult();
93 $result->setStatus($status);
94
95 return $result;
96 }

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

+ Here is the call graph for this function:

◆ sendMails()

ilBookCronNotification::sendMails ( array  $notifications)
protected

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

188 : void {
189 foreach ($notifications as $uid => $n) {
190 $ntf = new ilSystemNotification();
191 $lng = $ntf->getUserLanguage($uid);
192 $lng->loadLanguageModule("book");
193
194 $txt = "";
195 if (is_array($n["personal"] ?? null)) {
196 $txt .= "\n" . $lng->txt("book_your_reservations") . "\n";
197 $txt .= "-----------------------------------------\n";
198 foreach ($n["personal"] as $obj_id => $reservs) {
199 $txt .= ilObject::_lookupTitle($obj_id) . ":\n";
200 foreach ($reservs as $r) {
201 $txt .= "- " . $r["title"] . " (" . $r["counter"] . "), " .
202 ilDatePresentation::formatDate(new ilDate($r["date"], IL_CAL_DATE)) . ", " .
203 $r["slot"] . "\n";
204 }
205 }
206 }
207
208 if (is_array($n["admin"] ?? null)) {
209 $txt .= "\n" . $lng->txt("book_reservation_overview") . "\n";
210 $txt .= "-----------------------------------------\n";
211 foreach ($n["admin"] as $obj_id => $reservs) {
212 $txt .= ilObject::_lookupTitle($obj_id) . ":\n";
213 foreach ($reservs as $r) {
214 $txt .= "- " . $r["title"] . " (" . $r["counter"] . "), " . $r["user_name"] . ", " .
215 ilDatePresentation::formatDate(new ilDate($r["date"], IL_CAL_DATE)) . ", " .
216 $r["slot"] . "\n";
217 }
218 }
219 }
220
221 $ntf->setLangModules(array("book"));
222 $ntf->setSubjectLangId("book_booking_reminders");
223 $ntf->setIntroductionLangId("book_rem_intro");
224 $ntf->addAdditionalInfo("", $txt);
225 $ntf->setReasonLangId("book_rem_reason");
226 $this->book_log->debug("send Mail: " . $uid);
227 $ntf->sendMailAndReturnRecipients([$uid]);
228 }
229 }
const IL_CAL_DATE
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
Class for single dates.
getUserLanguage()
Return language of user.
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$txt
Definition: error.php:13

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

Referenced by sendNotifications().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendNotifications()

ilBookCronNotification::sendNotifications ( )
protected

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

98 : int
99 {
101
102 $log->debug("start");
103
104
105 $notifications = [];
106
107 /*
108 * pool id 123 > 2 days, ...
109 */
111 // determine reservations from max(next day $last_to_ts) up to "rmd_day" days + 1
112 // per pool id
113 $next_day_ts = mktime(0, 0, 0, date('n'), (int) date('j') + 1);
114 $log->debug("next day ts: " . $next_day_ts);
115 $last_reminder_to_ts = $p["last_remind_ts"];
116 // for debug purposes
117 // $last_reminder_to_ts-= 24*60*60;
118 $log->debug("last_reminder ts: " . $last_reminder_to_ts);
119 $from_ts = max($next_day_ts, $last_reminder_to_ts);
120 $log->debug("from ts: " . $from_ts);
121 $to_ts = mktime(0, 0, 0, date('n'), (int) date('j') + $p["reminder_day"] + 1);
122 $res = [];
123
124 // overwrite from to current time, see #26216, this ensures
125 // that all reservations are sent, some multiple times (each day)
126 // we include all reservations from now to the period set in the pool settings
127 $from_ts = time();
128
129 // additional logging info, see #26216
130 $log->debug("pool id: "
131 . $p["booking_pool_id"]
132 . "(" . ilObject::_lookupTitle($p["booking_pool_id"]) . ") "
133 . ", "
134 . date("Y-m-d, H:i:s", $from_ts)
135 . " to " . date("Y-m-d, H:i:s", $to_ts));
136
137
138 if ($to_ts > $from_ts) {
140 $repo = $f->getRepo();
141 $res = $repo->getListByDate(true, null, [
142 "from" => $from_ts,
143 "to" => $to_ts
144 ], [$p["booking_pool_id"]]);
145 }
146
147 $log->debug("reservations: " . count($res));
148
149 //var_dump($res); exit;
150
151 // get subscriber of pool id
153 $log->debug("users: " . count($user_ids));
154
155 // group by user, type, pool
156 foreach ($res as $r) {
157
158 // users
159 $log->debug("check notification of user id: " . $r["user_id"]);
160 if (in_array($r["user_id"], $user_ids)) {
161 if ($this->checkAccess("read", $r["user_id"], $p["booking_pool_id"])) {
162 $log->debug("got read");
163 $notifications[$r["user_id"]]["personal"][$r["pool_id"]][] = $r;
164 }
165 }
166
167 // admins
168 foreach ($user_ids as $uid) {
169 $log->debug("check write for user id: " . $uid . ", pool: " . $p["booking_pool_id"]);
170
171 if ($this->checkAccess("write", $uid, $p["booking_pool_id"])) {
172 $log->debug("got write");
173 $notifications[$uid]["admin"][$r["pool_id"]][] = $r;
174 }
175 }
176 }
177 ilObjBookingPool::writeLastReminderTimestamp($p["booking_pool_id"], $to_ts);
178 }
179
180 // send mails
181 $this->sendMails($notifications);
182
183 return count($notifications);
184 }
checkAccess(string $perm, int $uid, int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 getPoolsWithReminders()
Get pools with reminders.
$res
Definition: ltiservices.php:69
$log
Definition: result.php:33

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

Referenced by run().

+ 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 26 of file class.ilBookCronNotification.php.

◆ $book_log

ilLogger ilBookCronNotification::$book_log
protected

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

Referenced by sendNotifications().

◆ $lng

ilLanguage ilBookCronNotification::$lng
protected

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

Referenced by getDescription(), getTitle(), and sendMails().


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