5include_once
"Services/Cron/classes/class.ilCronJob.php";
16 return "mem_notification";
23 return $lng->txt(
"enable_course_group_notifications");
30 return $lng->txt(
"enable_course_group_notifications_desc");
58 $log->debug(
"===Member Notifications=== start");
61 $status_details =
null;
64 $last_run = $setting->get(get_class($this));
69 $last_run =
date(
"Y-m-d H:i:s", strtotime(
"yesterday"));
71 $status_details =
"No previous run found - starting from yesterday.";
74 else if(strlen($last_run) == 10)
76 $last_run .=
" 00:00:00";
78 $status_details =
"Switched from daily runs to open schedule.";
81 include_once
"Services/Membership/classes/class.ilMembershipNotifications.php";
86 $log->debug(
"nr of objects: ".count($objects));
90 $user_news_aggr = array();
92 include_once
"Services/News/classes/class.ilNewsItem.php";
93 foreach($objects as
$ref_id => $user_ids)
95 $log->debug(
"handle ref id ".
$ref_id.
", users: ".count($user_ids));
99 if($news_item->checkNewsExistsForGroupCourse(
$ref_id, $last_run))
101 foreach($user_ids as $user_id)
104 $user_news = $news_item->getNewsForRefId(
$ref_id,
105 false,
false, $last_run,
false,
false,
false,
false,
109 $user_news_aggr[$user_id][
$ref_id] = $user_news;
119 $log->debug(
"prepare sending mails");
127 if(
sizeof($user_news_aggr))
129 foreach($user_news_aggr as $user_id => $user_news)
131 $log->debug(
"sending mails to user ".$user_id.
", nr news: ".count($user_news));
133 $this->
sendMail($user_id, $user_news, $last_run);
147 $log->debug(
"save run");
150 $setting->set(get_class($this),
date(
"Y-m-d H:i:s"));
157 $result->setMessage($status_details);
160 $log->debug(
"===Member Notifications=== done");
174 protected function parseNewsItem($a_parent_ref_id, array &$a_filter_map, array $a_item, $a_is_sub =
false)
178 $wrong_parent = (array_key_exists($a_item[
"id"], $a_filter_map) &&
179 $a_parent_ref_id != $a_filter_map[$a_item[
"id"]]);
188 $item_obj_type = $a_item[
"context_obj_type"];
192 if($a_item[
"aggregation"])
195 if($item_obj_type ==
"file" &&
196 sizeof($a_item[
"aggregation"]) == 1)
203 foreach($a_item[
"aggregation"] as $subitem)
205 $sub_res = $this->
parseNewsItem($a_parent_ref_id, $a_filter_map, $subitem,
true);
208 $sub[md5($sub_res)] = $sub_res;
217 $a_item[
"context_obj_type"],
219 $a_item[
"content_is_lang_var"],
220 $a_item[
"agg_ref_id"],
221 $a_item[
"aggregation"]
227 $a_item[
"context_obj_type"],
229 $a_item[
"content_is_lang_var"]
234 $a_item[
"context_obj_type"],
236 $a_item[
"content_text_is_lang_var"]
245 switch($item_obj_type)
250 $res =
$lng->txt(
"obj_".$item_obj_type).
251 ' "'.$item_obj_title.
'": '.
$title;
255 $res .=
'"'.$title.
'": "'.$content.
'"';
260 if(!is_array($a_item[
"aggregation"]) ||
261 sizeof($a_item[
"aggregation"]) == 1)
263 $res =
$lng->txt(
"obj_".$item_obj_type).
264 ' "'.$item_obj_title.
'" - '.
$title;
270 " ".
sizeof($a_item[
"aggregation"]).
" ",
271 " ".
sizeof($sub).
" ",
279 $res =
$lng->txt(
"obj_".$item_obj_type).
280 ' "'.$item_obj_title.
'"';
283 $res .=
': "'.$title.
'"';
287 $res .=
' - '.$content;
298 $res .=
"\n".implode(
"\n", $sub);
314 $parent_map = $news_map = $parsed_map = array();
317 foreach($a_objects as $parent_ref_id => $news)
319 foreach($news as $item)
321 $news_map[$item[
"id"]] = $item[
"ref_id"];
322 $parent_map[$item[
"id"]][$parent_ref_id] = $parent_ref_id;
324 if($item[
"aggregation"])
326 foreach($item[
"aggregation"] as $subitem)
328 $news_map[$subitem[
"id"]] = $subitem[
"ref_id"];
329 $parent_map[$subitem[
"id"]][$parent_ref_id] = $parent_ref_id;
335 foreach($parent_map as $news_id => $parents)
337 if(
sizeof($parents) > 1)
339 $path = $tree->getPathId($news_map[$news_id]);
340 $lookup = array_flip(
$path);
343 foreach($parents as $parent_ref_id)
345 $level = max($level, $lookup[$parent_ref_id]);
348 $parsed_map[$news_id] =
$path[$level];
362 protected function sendMail($a_user_id, array $a_objects, $a_last_run)
366 include_once
"./Services/Notification/classes/class.ilSystemNotification.php";
368 $ntf->setLangModules(array(
"crs",
"news"));
375 $lng = $ntf->getUserLanguage($a_user_id);
377 include_once
'./Services/Locator/classes/class.ilLocatorGUI.php';
378 require_once
"./Services/UICore/classes/class.ilTemplate.php";
379 require_once
"./Services/Link/classes/class.ilLink.php";
384 foreach($a_objects as $parent_ref_id => $news)
390 foreach($tree->getPathId($parent_ref_id) as $node)
400 $parent[
"url"] =
" ".$lng->txt(
"crs_course_group_notification_link").
" ".
ilLink::_getStaticLink($parent_ref_id);
404 foreach($news as $item)
406 $parsed_item = $this->
parseNewsItem($parent_ref_id, $filter_map, $item);
409 $parsed[md5($parsed_item)] = $parsed_item;
415 $parent[
"news"] = implode(
"\n", $parsed);
416 $tmp[
$path] = $parent;
428 $obj_index = array();
430 foreach($tmp as
$path => $item)
434 $txt .=
"(".$counter.
") ".$item[
"title"].
"\n".
436 $item[
"news"].
"\n\n";
438 $obj_index[] =
"(".$counter.
") ".$item[
"title"];
441 $ntf->setIntroductionLangId(
"crs_intro_course_group_notification_for");
445 $lng->txt(
"crs_intro_course_group_notification_index"),
449 $ntf->addAdditionalInfo($period,
450 trim(implode(
"\n", $obj_index)),
455 $ntf->addAdditionalInfo(
"",
460 $client = $ilClientIniFile->readVariable(
'client',
'name');
464 $mail =
new ilMail(ANONYMOUS_USER_ID);
465 $mail->enableSOAP(
false);
470 $ntf->composeAndGetMessage($a_user_id,
null,
"read",
true),
483 $a_fields[
"enable_course_group_notifications"] = $a_is_active ?
484 $lng->txt(
"enabled") :
485 $lng->txt(
"disabled");
495 $ilSetting->set(
"crsgrp_ntf", (
bool)$a_currently_active);
sprintf('%.4f', $callTime)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
An exception for terminatinating execution or to throw for unit testing.
Cron job result data container.
Cron job application base class.
const SCHEDULE_TYPE_DAILY
static ping($a_job_id)
Keep cron job alive.
static setUseRelativeDates($a_status)
set use relative dates
static formatDate(ilDateTime $date)
Format a date @access public.
static useRelativeDates()
check if relative dates are used
@classDescription Date and time handling
static _getStaticLink($a_ref_id, $a_type='', $a_fallback_goto=true, $append="")
Get static link.
static getLogger($a_component_id)
Get component logger.
This class handles base functions for mail handling.
Course/group notifications.
getDefaultScheduleValue()
Get schedule value.
sendMail($a_user_id, array $a_objects, $a_last_run)
Send news mail for 1 user and n objects.
parseNewsItem($a_parent_ref_id, array &$a_filter_map, array $a_item, $a_is_sub=false)
Convert news item to summary html.
getDescription()
Get description.
activationWasToggled($a_currently_active)
Cron job status was changed.
getDefaultScheduleType()
Get schedule type.
filterDuplicateItems(array $a_objects)
Filter duplicate news items from structure.
addToExternalSettingsForm($a_form_id, array &$a_fields, $a_is_active)
Add external settings to form.
hasFlexibleSchedule()
Can the schedule be configured?
hasAutoActivation()
Is to be activated on "installation".
static getActiveUsersforAllObjects()
Get active notifications for all objects.
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 _lookupLogin($a_user_id)
lookup login
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
Wrapper classes for system notifications.
static shortenText($a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.