ILIAS  release_7 Revision v7.30-3-g800a261c036
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 12 of file class.ilBookCronNotification.php.

Constructor & Destructor Documentation

◆ __construct()

ilBookCronNotification::__construct ( )

Constructor.

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

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 }
static getLogger($a_component_id)
Get component logger.
global $DIC
Definition: goto.php:24

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

66 {
68 }
const SCHEDULE_TYPE_DAILY

References ilCronJob\SCHEDULE_TYPE_DAILY.

◆ getDefaultScheduleValue()

ilBookCronNotification::getDefaultScheduleValue ( )

Get schedule value.

Returns
int|array

Reimplemented from ilCronJob.

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

71 {
72 return;
73 }

◆ getDescription()

ilBookCronNotification::getDescription ( )

Get description.

Returns
string

Reimplemented from ilCronJob.

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

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

References $lng.

◆ getId()

ilBookCronNotification::getId ( )

Get id.

Returns
string

Reimplemented from ilCronJob.

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

45 {
46 return "book_notification";
47 }

◆ getTitle()

ilBookCronNotification::getTitle ( )

Get title.

Returns
string

Reimplemented from ilCronJob.

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

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

References $lng.

◆ hasAutoActivation()

ilBookCronNotification::hasAutoActivation ( )

Is to be activated on "installation".

Returns
boolean

Reimplemented from ilCronJob.

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

76 {
77 return false;
78 }

◆ hasFlexibleSchedule()

ilBookCronNotification::hasFlexibleSchedule ( )

Can the schedule be configured?

Returns
boolean

Reimplemented from ilCronJob.

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

81 {
82 return false;
83 }

◆ run()

ilBookCronNotification::run ( )

Run job.

Returns
ilCronJobResult

Reimplemented from ilCronJob.

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

86 {
88
89 $count = $this->sendNotifications();
90
91 if ($count > 0) {
93 }
94
96 $result->setStatus($status);
97
98 return $result;
99 }
$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 207 of file class.ilBookCronNotification.php.

208 {
209 foreach ($notifications as $uid => $n) {
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"] . "), " .
222 ilDatePresentation::formatDate(new ilDate($r["date"], IL_CAL_DATE)) . ", " .
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"] . ", " .
235 ilDatePresentation::formatDate(new ilDate($r["date"], IL_CAL_DATE)) . ", " .
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:13

References $lng, $n, $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 107 of file class.ilBookCronNotification.php.

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

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:

◆ 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 22 of file class.ilBookCronNotification.php.

Referenced by checkAccess().

◆ $book_log

ilBookCronNotification::$book_log
protected

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

Referenced by sendNotifications().

◆ $lng

ilBookCronNotification::$lng
protected

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

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


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