ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilBookCronNotification Class Reference

Cron for booking manager notification. More...

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

Public Member Functions

 __construct ()
 Constructor. More...
 
 getId ()
 Get id. More...
 
 getTitle ()
 Get title. More...
 
 getDescription ()
 Get description. More...
 
 getDefaultScheduleType ()
 Get schedule type. More...
 
 getDefaultScheduleValue ()
 Get schedule value. More...
 
 hasAutoActivation ()
 Is to be activated on "installation". More...
 
 hasFlexibleSchedule ()
 Can the schedule be configured? More...
 
 run ()
 Run job. More...
 
- Public Member Functions inherited from ilCronJob
 isActive ($a_ts_last_run, $a_schedule_type, $a_schedule_value, $a_manual=false)
 Is job currently active? More...
 
 getScheduleType ()
 Get current schedule type (if flexible) More...
 
 getScheduleValue ()
 Get current schedule value (if flexible) More...
 
 setSchedule ($a_type, $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...
 
 getTitle ()
 Get title. More...
 
 getDescription ()
 Get description. More...
 
 isManuallyExecutable ()
 Defines whether or not a cron job can be started manually. More...
 
 hasCustomSettings ()
 Has cron job any custom setting which can be edited? More...
 
 addCustomSettingsToForm (ilPropertyFormGUI $a_form)
 Add custom settings to form. More...
 
 saveCustomSettings (ilPropertyFormGUI $a_form)
 Save custom settings. More...
 
 addToExternalSettingsForm ($a_form_id, array &$a_fields, $a_is_active)
 Add external settings to form. More...
 
 activationWasToggled ($a_currently_active)
 Cron job status was changed. More...
 
 getId ()
 Get id. More...
 
 hasAutoActivation ()
 Is to be activated on "installation". More...
 
 hasFlexibleSchedule ()
 Can the schedule be configured? More...
 
 getDefaultScheduleType ()
 Get schedule type. More...
 
 getDefaultScheduleValue ()
 Get schedule value. More...
 
 run ()
 Run job. More...
 

Protected Member Functions

 sendNotifications ()
 Send notifications. More...
 
 sendMails ($notifications)
 Send mails. More...
 
 checkAccess ($perm, $uid, $obj_id)
 check access on obj id More...
 
 sendUserNotifications ($res)
 Send user notifications. More...
 
 sendAdminNotifications ($res)
 Send admin notifications. More...
 
- Protected Member Functions inherited from ilCronJob
 checkSchedule ($a_ts_last_run, $a_schedule_type, $a_schedule_value)
 

Protected Attributes

 $lng
 
 $access
 
 $book_log
 

Additional Inherited Members

- Data Fields inherited from ilCronJob
const SCHEDULE_TYPE_DAILY = 1
 
const SCHEDULE_TYPE_IN_MINUTES = 2
 
const SCHEDULE_TYPE_IN_HOURS = 3
 
const SCHEDULE_TYPE_IN_DAYS = 4
 
const SCHEDULE_TYPE_WEEKLY = 5
 
const SCHEDULE_TYPE_MONTHLY = 6
 
const SCHEDULE_TYPE_QUARTERLY = 7
 
const SCHEDULE_TYPE_YEARLY = 8
 

Detailed Description

Cron for booking manager notification.

Author
Alex Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..com

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

Constructor & Destructor Documentation

◆ __construct()

ilBookCronNotification::__construct ( )

Constructor.

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

34 {
35 global $DIC;
36
37 $this->lng = $DIC->language();
38 if (isset($DIC["ilAccess"])) {
39 $this->access = $DIC->access();
40 }
41
42 $this->book_log = ilLoggerFactory::getLogger("book");
43 }
static getLogger($a_component_id)
Get component logger.
global $DIC
Definition: saml.php:7

References $DIC, and ilLoggerFactory\getLogger().

+ Here is the call graph for this function:

Member Function Documentation

◆ checkAccess()

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

check access on obj id

Parameters

return

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

258 {
260 foreach (ilObject::_getAllReferences($obj_id) as $ref_id) {
261 if ($access->checkAccessOfUser($uid, $perm, "", $ref_id)) {
262 return true;
263 }
264 }
265 return false;
266 }
static _getAllReferences($a_id)
get all reference ids of object

References $access, and ilObject\_getAllReferences().

Referenced by sendNotifications().

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

◆ getDefaultScheduleType()

ilBookCronNotification::getDefaultScheduleType ( )

Get schedule type.

Returns
int

Reimplemented from ilCronJob.

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

67 {
69 }
const SCHEDULE_TYPE_DAILY

References ilCronJob\SCHEDULE_TYPE_DAILY.

◆ getDefaultScheduleValue()

ilBookCronNotification::getDefaultScheduleValue ( )

Get schedule value.

Returns
int|array

Reimplemented from ilCronJob.

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

72 {
73 return;
74 }

◆ getDescription()

ilBookCronNotification::getDescription ( )

Get description.

Returns
string

Reimplemented from ilCronJob.

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

59 {
61
62 $lng->loadLanguageModule("book");
63 return $lng->txt("book_notification_info");
64 }

References $lng.

◆ getId()

ilBookCronNotification::getId ( )

Get id.

Returns
string

Reimplemented from ilCronJob.

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

46 {
47 return "book_notification";
48 }

◆ getTitle()

ilBookCronNotification::getTitle ( )

Get title.

Returns
string

Reimplemented from ilCronJob.

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

51 {
53
54 $lng->loadLanguageModule("book");
55 return $lng->txt("book_notification");
56 }

References $lng.

◆ hasAutoActivation()

ilBookCronNotification::hasAutoActivation ( )

Is to be activated on "installation".

Returns
boolean

Reimplemented from ilCronJob.

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

77 {
78 return false;
79 }

◆ hasFlexibleSchedule()

ilBookCronNotification::hasFlexibleSchedule ( )

Can the schedule be configured?

Returns
boolean

Reimplemented from ilCronJob.

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

82 {
83 return false;
84 }

◆ run()

ilBookCronNotification::run ( )

Run job.

Returns
ilCronJobResult

Reimplemented from ilCronJob.

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

87 {
89
90 $count = $this->sendNotifications();
91
92 if ($count > 0) {
94 }
95
97 $result->setStatus($status);
98
99 return $result;
100 }
$result
Cron job result data container.

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

+ Here is the call graph for this function:

◆ sendAdminNotifications()

ilBookCronNotification::sendAdminNotifications (   $res)
protected

Send admin notifications.

Returns
int

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

300 {
301 }

◆ sendMails()

ilBookCronNotification::sendMails (   $notifications)
protected

Send mails.

Parameters

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

207 {
208 foreach ($notifications as $uid => $n) {
209 include_once "./Services/Notification/classes/class.ilSystemNotification.php";
210 $ntf = new ilSystemNotification();
211 $lng = $ntf->getUserLanguage($uid);
212 $lng->loadLanguageModule("book");
213
214 $txt = "";
215 if (is_array($n["personal"])) {
216 $txt .= "\n" . $lng->txt("book_your_reservations") . "\n";
217 $txt .= "-----------------------------------------\n";
218 foreach ($n["personal"] as $obj_id => $reservs) {
219 $txt .= ilObject::_lookupTitle($obj_id) . ":\n";
220 foreach ($reservs as $r) {
221 $txt .= "- " . $r["title"] . " (" . $r["counter"] . "), " .
223 $r["slot"] . "\n";
224 }
225 }
226 }
227
228 if (is_array($n["admin"])) {
229 $txt .= "\n" . $lng->txt("book_reservation_overview") . "\n";
230 $txt .= "-----------------------------------------\n";
231 foreach ($n["admin"] as $obj_id => $reservs) {
232 $txt .= ilObject::_lookupTitle($obj_id) . ":\n";
233 foreach ($reservs as $r) {
234 $txt .= "- " . $r["title"] . " (" . $r["counter"] . "), " . $r["user_name"] . ", " .
236 $r["slot"] . "\n";
237 }
238 }
239 }
240
241 $ntf->setLangModules(array("book"));
242 $ntf->setSubjectLangId("book_booking_reminders");
243 $ntf->setIntroductionLangId("book_rem_intro");
244 $ntf->addAdditionalInfo("", $txt);
245 $ntf->setReasonLangId("book_rem_reason");
246 $ntf->sendMail(array($uid));
247 }
248 }
$n
Definition: RandomTest.php:85
const IL_CAL_DATE
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
Class for single dates.
static _lookupTitle($a_id)
lookup object title
Wrapper classes for system notifications.
$txt
Definition: error.php:11
$r
Definition: example_031.php:79

References $lng, $n, $r, $txt, ilObject\_lookupTitle(), ilDatePresentation\formatDate(), and IL_CAL_DATE.

Referenced by sendNotifications().

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

◆ sendNotifications()

ilBookCronNotification::sendNotifications ( )
protected

Send notifications.

Parameters

return int

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

109 {
111
112 // get all booking pools with notification setting
113
114
115
116 $log->debug("start");
117
118
119 $notifications = [];
120
121 /*
122 * pool id 123 > 2 days, ...
123 */
125 // determine reservations from max(next day $last_to_ts) up to "rmd_day" days + 1
126 // per pool id
127 $next_day_ts = mktime(0, 0, 0, date('n'), date('j') + 1);
128 $log->debug("next day ts: " . $next_day_ts);
129 $last_reminder_to_ts = $p["last_remind_ts"];
130 // for debug purposes
131 // $last_reminder_to_ts-= 24*60*60;
132 $log->debug("last_reminder ts: " . $last_reminder_to_ts);
133 $from_ts = max($next_day_ts, $last_reminder_to_ts);
134 $log->debug("from ts: " . $from_ts);
135 $to_ts = mktime(0, 0, 0, date('n'), date('j') + $p["reminder_day"] + 1);
136 $res = [];
137
138 // overwrite from to current time, see #26216, this ensures
139 // that all reservations are sent, some multiple times (each day)
140 // we include all reservations from now to the period set in the pool settings
141 $from_ts = time();
142
143 // additional logging info, see #26216
144 $log->debug("pool id: "
145 . $p["booking_pool_id"]
146 . "(" . ilObject::_lookupTitle($p["booking_pool_id"]) . ") "
147 . ", "
148 . date("Y-m-d, H:i:s", $from_ts)
149 . " to " . date("Y-m-d, H:i:s", $to_ts));
150
151
152 if ($to_ts > $from_ts) {
154 "from" => $from_ts,
155 "to" => $to_ts
156 ], [$p["booking_pool_id"]]);
157 }
158
159 $log->debug("reservations: " . count($res));
160
161 //var_dump($res); exit;
162
163 // get subscriber of pool id
165
166 $log->debug("users: " . count($user_ids));
167
168 // group by user, type, pool
169 foreach ($res as $r) {
170
171 // users
172 $log->debug("check notification of user id: " . $r["user_id"]);
173 if (in_array($r["user_id"], $user_ids)) {
174 if ($this->checkAccess("read", $r["user_id"], $p["booking_pool_id"])) {
175 $log->debug("got read");
176 $notifications[$r["user_id"]]["personal"][$r["pool_id"]][] = $r;
177 }
178 }
179
180 // admins
181 foreach ($user_ids as $uid) {
182 $log->debug("check write for user id: " . $uid . ", pool: " . $p["booking_pool_id"]);
183
184 if ($this->checkAccess("write", $uid, $p["booking_pool_id"])) {
185 $log->debug("got write");
186 $notifications[$uid]["admin"][$r["pool_id"]][] = $r;
187 }
188 }
189 }
190 ilObjBookingPool::writeLastReminderTimestamp($p["booking_pool_id"], $to_ts);
191 }
192
193 $log->debug("notifications to users: " . count($notifications));
194
195 // send mails
196 $this->sendMails($notifications);
197
198 return count($notifications);
199 }
checkAccess($perm, $uid, $obj_id)
check access on obj id
sendMails($notifications)
Send mails.
static getListByDate( $a_has_schedule, array $a_object_ids=null, array $filter=null, array $a_pool_ids=null)
List all reservations by date.
static getNotificationsForObject($type, $id, $page_id=null, $ignore_threshold=false)
Get all users for given object.
static writeLastReminderTimestamp($a_obj_id, $a_ts)
Write last reminder timestamp.
static getPoolsWithReminders()
Get poos with reminders.
$log
Definition: sabredav.php:21
foreach($_POST as $key=> $value) $res

References $book_log, $log, $r, $res, ilObject\_lookupTitle(), checkAccess(), ilBookingReservation\getListByDate(), 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:

◆ sendUserNotifications()

ilBookCronNotification::sendUserNotifications (   $res)
protected

Send user notifications.

Returns
int

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

275 {
276 /*
277 * Your reservations for tomorrow
278 *
279 * Pool Title
280 * Pool Link
281 * - Object (cnt), From - To
282 * - ...
283 *
284 * Reservations for tomorrow
285 *
286 * Pool Title
287 * Pool Link
288 * - Object (cnt), From - To
289 * - ...
290 *
291 */
292 }

Field Documentation

◆ $access

ilBookCronNotification::$access
protected

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

Referenced by checkAccess().

◆ $book_log

ilBookCronNotification::$book_log
protected

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

Referenced by sendNotifications().

◆ $lng

ilBookCronNotification::$lng
protected

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

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


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