ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilMembershipCronNotifications Class Reference

Course/group notifications. More...

+ Inheritance diagram for ilMembershipCronNotifications:
+ Collaboration diagram for ilMembershipCronNotifications:

Public Member Functions

 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...
 
 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...
 
- 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...
 
 getValidScheduleTypes ()
 Get all available schedule types. 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

 parseNewsItem ($a_parent_ref_id, array &$a_filter_map, array $a_item, $a_is_sub=false)
 Convert news item to summary html. More...
 
 filterDuplicateItems (array $a_objects)
 Filter duplicate news items from structure. More...
 
 sendMail ($a_user_id, array $a_objects, $a_last_run)
 Send news mail for 1 user and n objects. More...
 
- Protected Member Functions inherited from ilCronJob
 checkSchedule ($a_ts_last_run, $a_schedule_type, $a_schedule_value)
 

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

Course/group notifications.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 12 of file class.ilMembershipCronNotifications.php.

Member Function Documentation

◆ activationWasToggled()

ilMembershipCronNotifications::activationWasToggled (   $a_currently_active)

Cron job status was changed.

Parameters
bool$a_currently_active

Reimplemented from ilCronJob.

Definition at line 477 of file class.ilMembershipCronNotifications.php.

478 {
479 global $ilSetting;
480
481 // propagate cron-job setting to object setting
482 $ilSetting->set("crsgrp_ntf", (bool)$a_currently_active);
483 }
global $ilSetting
Definition: privfeed.php:40

References $ilSetting.

◆ addToExternalSettingsForm()

ilMembershipCronNotifications::addToExternalSettingsForm (   $a_form_id,
array &  $a_fields,
  $a_is_active 
)

Add external settings to form.

Parameters
int$a_form_id
array$a_fields
bool$a_is_active

Reimplemented from ilCronJob.

Definition at line 462 of file class.ilMembershipCronNotifications.php.

463 {
464 global $lng;
465
466 switch($a_form_id)
467 {
470 $a_fields["enable_course_group_notifications"] = $a_is_active ?
471 $lng->txt("enabled") :
472 $lng->txt("disabled");
473 break;
474 }
475 }
global $lng
Definition: privfeed.php:40

References $lng, ilAdministrationSettingsFormHandler\FORM_COURSE, and ilAdministrationSettingsFormHandler\FORM_GROUP.

◆ filterDuplicateItems()

ilMembershipCronNotifications::filterDuplicateItems ( array  $a_objects)
protected

Filter duplicate news items from structure.

Parameters
array$a_objects
Returns
array

Definition at line 295 of file class.ilMembershipCronNotifications.php.

296 {
297 global $tree;
298
299 $parent_map = $news_map = $parsed_map = array();
300
301 // gather news ref ids and news parent ref ids
302 foreach($a_objects as $parent_ref_id => $news)
303 {
304 foreach($news as $item)
305 {
306 $news_map[$item["id"]] = $item["ref_id"];
307 $parent_map[$item["id"]][$parent_ref_id] = $parent_ref_id;
308
309 if($item["aggregation"])
310 {
311 foreach($item["aggregation"] as $subitem)
312 {
313 $news_map[$subitem["id"]] = $subitem["ref_id"];
314 $parent_map[$subitem["id"]][$parent_ref_id] = $parent_ref_id;
315 }
316 }
317 }
318 }
319 // if news has multiple parents find "lowest" parent in path
320 foreach($parent_map as $news_id => $parents)
321 {
322 if(sizeof($parents) > 1)
323 {
324 $path = $tree->getPathId($news_map[$news_id]);
325 $lookup = array_flip($path);
326
327 $level = 0;
328 foreach($parents as $parent_ref_id)
329 {
330 $level = max($level, $lookup[$parent_ref_id]);
331 }
332
333 $parsed_map[$news_id] = $path[$level];
334 }
335 }
336
337 return $parsed_map;
338 }
$path
Definition: index.php:22

References $path.

Referenced by sendMail().

+ Here is the caller graph for this function:

◆ getDefaultScheduleType()

ilMembershipCronNotifications::getDefaultScheduleType ( )

Get schedule type.

Returns
int

Reimplemented from ilCronJob.

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

34 {
36 }
const SCHEDULE_TYPE_DAILY

References ilCronJob\SCHEDULE_TYPE_DAILY.

◆ getDefaultScheduleValue()

ilMembershipCronNotifications::getDefaultScheduleValue ( )

Get schedule value.

Returns
int|array

Reimplemented from ilCronJob.

Definition at line 38 of file class.ilMembershipCronNotifications.php.

39 {
40 return;
41 }

◆ getDescription()

ilMembershipCronNotifications::getDescription ( )

Get description.

Returns
string

Reimplemented from ilCronJob.

Definition at line 26 of file class.ilMembershipCronNotifications.php.

27 {
28 global $lng;
29
30 return $lng->txt("enable_course_group_notifications_desc");
31 }

References $lng.

◆ getId()

ilMembershipCronNotifications::getId ( )

Get id.

Returns
string

Reimplemented from ilCronJob.

Definition at line 14 of file class.ilMembershipCronNotifications.php.

15 {
16 return "mem_notification";
17 }

Referenced by run().

+ Here is the caller graph for this function:

◆ getTitle()

ilMembershipCronNotifications::getTitle ( )

Get title.

Returns
string

Reimplemented from ilCronJob.

Definition at line 19 of file class.ilMembershipCronNotifications.php.

20 {
21 global $lng;
22
23 return $lng->txt("enable_course_group_notifications");
24 }

References $lng.

◆ hasAutoActivation()

ilMembershipCronNotifications::hasAutoActivation ( )

Is to be activated on "installation".

Returns
boolean

Reimplemented from ilCronJob.

Definition at line 43 of file class.ilMembershipCronNotifications.php.

44 {
45 return false;
46 }

◆ hasFlexibleSchedule()

ilMembershipCronNotifications::hasFlexibleSchedule ( )

Can the schedule be configured?

Returns
boolean

Reimplemented from ilCronJob.

Definition at line 48 of file class.ilMembershipCronNotifications.php.

49 {
50 return true;
51 }

◆ parseNewsItem()

ilMembershipCronNotifications::parseNewsItem (   $a_parent_ref_id,
array &  $a_filter_map,
array  $a_item,
  $a_is_sub = false 
)
protected

Convert news item to summary html.

Parameters
int$a_parent_ref_id
array$a_filter_map
array$a_item
bool$a_is_sub
Returns
string

Definition at line 159 of file class.ilMembershipCronNotifications.php.

160 {
161 global $lng;
162
163 $wrong_parent = (array_key_exists($a_item["id"], $a_filter_map) &&
164 $a_parent_ref_id != $a_filter_map[$a_item["id"]]);
165
166 // #18223
167 if($wrong_parent)
168 {
169 return;
170 }
171
172 $item_obj_title = trim(ilObject::_lookupTitle($a_item["context_obj_id"]));
173 $item_obj_type = $a_item["context_obj_type"];
174
175 // sub-items
176 $sub = null;
177 if($a_item["aggregation"])
178 {
179 $do_sub = true;
180 if($item_obj_type == "file" &&
181 sizeof($a_item["aggregation"]) == 1)
182 {
183 $do_sub = false;
184 }
185 if($do_sub)
186 {
187 $sub = array();
188 foreach($a_item["aggregation"] as $subitem)
189 {
190 $sub_res = $this->parseNewsItem($a_parent_ref_id, $a_filter_map, $subitem, true);
191 if($sub_res)
192 {
193 $sub[md5($sub_res)] = $sub_res;
194 }
195 }
196 }
197 }
198
199 if(!$a_is_sub)
200 {
202 $a_item["context_obj_type"],
203 $a_item["title"],
204 $a_item["content_is_lang_var"],
205 $a_item["agg_ref_id"],
206 $a_item["aggregation"]
207 );
208 }
209 else
210 {
212 $a_item["context_obj_type"],
213 $a_item["title"],
214 $a_item["content_is_lang_var"]
215 );
216 }
217
219 $a_item["context_obj_type"],
220 $a_item["content"],
221 $a_item["content_text_is_lang_var"]
222 );
223
224 $title = trim($title);
225
226 // #18067 / #18186
227 $content = ilUtil::shortenText(trim(strip_tags($content)), 200, true);
228
229 $res = "";
230 switch($item_obj_type)
231 {
232 case "frm":
233 if(!$a_is_sub)
234 {
235 $res = $lng->txt("obj_".$item_obj_type).
236 ' "'.$item_obj_title.'": '.$title;
237 }
238 else
239 {
240 $res .= '"'.$title.'": "'.$content.'"';
241 }
242 break;
243
244 case "file":
245 if(!is_array($a_item["aggregation"]) ||
246 sizeof($a_item["aggregation"]) == 1)
247 {
248 $res = $lng->txt("obj_".$item_obj_type).
249 ' "'.$item_obj_title.'" - '.$title;
250 }
251 else
252 {
253 // if files were removed from aggregation update summary count
254 $title = str_replace(
255 " ".sizeof($a_item["aggregation"])." ",
256 " ".sizeof($sub)." ",
257 $title
258 );
259 $res = $title;
260 }
261 break;
262
263 default:
264 $res = $lng->txt("obj_".$item_obj_type).
265 ' "'.$item_obj_title.'"';
266 if($title)
267 {
268 $res .= ': "'.$title.'"';
269 }
270 if($content)
271 {
272 $res .= ' - '.$content;
273 }
274 break;
275 }
276
277 $res = $a_is_sub
278 ? "- ".$res
279 : "# ".$res;
280
281 if(sizeof($sub))
282 {
283 $res .= "\n".implode("\n", $sub);
284 }
285
286 return trim($res);
287 }
parseNewsItem($a_parent_ref_id, array &$a_filter_map, array $a_item, $a_is_sub=false)
Convert news item to summary html.
static determineNewsContent($a_context_obj_type, $a_content, $a_is_lang_var)
Determine new content.
static determineNewsTitle($a_context_obj_type, $a_title, $a_content_is_lang_var, $a_agg_ref_id=0, $a_aggregation="")
Determine title for news item entry.
static _lookupTitle($a_id)
lookup object title
static shortenText($a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.

References $lng, $res, ilObject\_lookupTitle(), ilNewsItem\determineNewsContent(), ilNewsItem\determineNewsTitle(), parseNewsItem(), and ilUtil\shortenText().

Referenced by parseNewsItem(), and sendMail().

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

◆ run()

ilMembershipCronNotifications::run ( )

Run job.

Returns
ilCronJobResult

Reimplemented from ilCronJob.

Definition at line 53 of file class.ilMembershipCronNotifications.php.

54 {
55 global $lng, $ilDB;
56
58 $status_details = null;
59
60 $setting = new ilSetting("cron");
61 $last_run = $setting->get(get_class($this));
62
63 // no last run?
64 if(!$last_run)
65 {
66 $last_run = date("Y-m-d H:i:s", strtotime("yesterday"));
67
68 $status_details = "No previous run found - starting from yesterday.";
69 }
70 // migration: used to be date-only value
71 else if(strlen($last_run) == 10)
72 {
73 $last_run .= " 00:00:00";
74
75 $status_details = "Switched from daily runs to open schedule.";
76 }
77
78 include_once "Services/Membership/classes/class.ilMembershipNotifications.php";
80 if(sizeof($objects))
81 {
82 // gather news for each user over all objects
83
84 $user_news_aggr = array();
85
86 include_once "Services/News/classes/class.ilNewsItem.php";
87 foreach($objects as $ref_id => $user_ids)
88 {
89 // gather news per object
90 $news_item = new ilNewsItem();
91 if($news_item->checkNewsExistsForGroupCourse($ref_id, $last_run))
92 {
93 foreach($user_ids as $user_id)
94 {
95 // gather news for user
96 $user_news = $news_item->getNewsForRefId($ref_id,
97 false, false, $last_run, false, false, false, false,
98 $user_id);
99 if($user_news)
100 {
101 $user_news_aggr[$user_id][$ref_id] = $user_news;
102
103 // #17928
104 ilCronManager::ping($this->getId());
105 }
106 }
107 }
108 }
109 unset($objects);
110
111
112 // send mails (1 max for each user)
113
114 $old_lng = $lng;
117
118 if(sizeof($user_news_aggr))
119 {
120 foreach($user_news_aggr as $user_id => $user_news)
121 {
122 $this->sendMail($user_id, $user_news, $last_run);
123
124 // #17928
125 ilCronManager::ping($this->getId());
126 }
127
128 // mails were sent - set cron job status accordingly
130 }
131
133 $lng = $old_lng;
134 }
135
136 // save last run
137 $setting->set(get_class($this), date("Y-m-d H:i:s"));
138
139 $result = new ilCronJobResult();
140 $result->setStatus($status);
141
142 if($status_details)
143 {
144 $result->setMessage($status_details);
145 }
146
147 return $result;
148 }
$result
Cron job result data container.
static ping($a_job_id)
Keep cron job alive.
static setUseRelativeDates($a_status)
set use relative dates
static useRelativeDates()
check if relative dates are used
sendMail($a_user_id, array $a_objects, $a_last_run)
Send news mail for 1 user and n objects.
static getActiveUsersforAllObjects()
Get active notifications for all objects.
ILIAS Setting Class.
$ref_id
Definition: sahs_server.php:39
global $ilDB

References $ilDB, $lng, $ref_id, $result, ilMembershipNotifications\getActiveUsersforAllObjects(), getId(), ilCronManager\ping(), sendMail(), ilDatePresentation\setUseRelativeDates(), ilCronJobResult\STATUS_NO_ACTION, ilCronJobResult\STATUS_OK, and ilDatePresentation\useRelativeDates().

+ Here is the call graph for this function:

◆ sendMail()

ilMembershipCronNotifications::sendMail (   $a_user_id,
array  $a_objects,
  $a_last_run 
)
protected

Send news mail for 1 user and n objects.

Parameters
int$a_user_id
array$a_objects
string$a_last_run

Definition at line 347 of file class.ilMembershipCronNotifications.php.

348 {
349 global $lng, $ilUser, $ilClientIniFile, $tree;
350
351 include_once "./Services/Notification/classes/class.ilSystemNotification.php";
352 $ntf = new ilSystemNotification();
353 $ntf->setLangModules(array("crs", "news"));
354 // no single object anymore
355 // $ntf->setRefId($a_ref_id);
356 // $ntf->setGotoLangId('url');
357 // $ntf->setSubjectLangId('crs_subject_course_group_notification');
358
359 // user specific language
360 $lng = $ntf->getUserLanguage($a_user_id);
361
362 include_once './Services/Locator/classes/class.ilLocatorGUI.php';
363 require_once "HTML/Template/ITX.php";
364 require_once "./Services/UICore/classes/class.ilTemplateHTMLITX.php";
365 require_once "./Services/UICore/classes/class.ilTemplate.php";
366 require_once "./Services/Link/classes/class.ilLink.php";
367
368 $filter_map = $this->filterDuplicateItems($a_objects);
369
370 $tmp = array();
371 foreach($a_objects as $parent_ref_id => $news)
372 {
373 $parent = array();
374
375 // path
376 $path = array();
377 foreach($tree->getPathId($parent_ref_id) as $node)
378 {
379 $path[] = $node;
380 }
381 $path = implode("-", $path);
382
383 $parent_obj_id = ilObject::_lookupObjId($parent_ref_id);
384 $parent_type = ilObject::_lookupType($parent_obj_id);
385
386 $parent["title"] = $lng->txt("obj_".$parent_type).' "'.ilObject::_lookupTitle($parent_obj_id).'"';
387 $parent["url"] = " ".$lng->txt("crs_course_group_notification_link")." ".ilLink::_getStaticLink($parent_ref_id);
388
389 // news summary
390 $parsed = array();
391 foreach($news as $item)
392 {
393 $parsed_item = $this->parseNewsItem($parent_ref_id, $filter_map, $item);
394 if($parsed_item)
395 {
396 $parsed[md5($parsed_item)] = $parsed_item;
397 }
398 }
399 // any news?
400 if(sizeof($parsed))
401 {
402 $parent["news"] = implode("\n", $parsed);
403 $tmp[$path] = $parent;
404 }
405 }
406
407 // any objects?
408 if(!sizeof($tmp))
409 {
410 return;
411 }
412
413 ksort($tmp);
414 $counter = 0;
415 $obj_index = array();
416 $txt = "";
417 foreach($tmp as $path => $item)
418 {
419 $counter++;
420
421 $txt .= "(".$counter.") ".$item["title"]."\n".
422 $item["url"]."\n\n".
423 $item["news"]."\n\n";
424
425 $obj_index[] = "(".$counter.") ".$item["title"];
426 }
427
428 $ntf->setIntroductionLangId("crs_intro_course_group_notification_for");
429
430 // index
431 $period = sprintf(
432 $lng->txt("crs_intro_course_group_notification_index"),
435 );
436 $ntf->addAdditionalInfo($period,
437 trim(implode("\n", $obj_index)),
438 true,
439 true);
440
441 // object list
442 $ntf->addAdditionalInfo("",
443 trim($txt),
444 true);
445
446 // :TODO: does it make sense to add client to subject?
447 $client = $ilClientIniFile->readVariable('client', 'name');
448 $subject = sprintf($lng->txt("crs_subject_course_group_notification"), $client);
449
450 // #10044
451 $mail = new ilMail(ANONYMOUS_USER_ID);
452 $mail->enableSOAP(false); // #10410
453 $mail->sendMail(ilObjUser::_lookupLogin($a_user_id),
454 null,
455 null,
456 $subject,
457 $ntf->composeAndGetMessage($a_user_id, null, "read", true),
458 null,
459 array("system"));
460 }
const IL_CAL_UNIX
const IL_CAL_DATETIME
static formatDate(ilDateTime $date)
Format a date @access public.
@classDescription Date and time handling
Class Mail this class handles base functions for mail handling.
filterDuplicateItems(array $a_objects)
Filter duplicate news items from structure.
static _lookupLogin($a_user_id)
lookup login
static _lookupObjId($a_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
Wrapper classes for system notifications.
$txt
Definition: error.php:12
global $ilUser
Definition: imgupload.php:15

References $client, $ilUser, $lng, $path, $txt, ilLink\_getStaticLink(), ilObjUser\_lookupLogin(), ilObject\_lookupObjId(), ilObject\_lookupTitle(), ilObject\_lookupType(), filterDuplicateItems(), ilDatePresentation\formatDate(), IL_CAL_DATETIME, IL_CAL_UNIX, and parseNewsItem().

Referenced by run().

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

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