5 include_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");
35 return self::SCHEDULE_TYPE_DAILY;
58 $status_details = null;
61 $last_run = $setting->get(get_class($this));
66 $last_run = date(
"Y-m-d H:i:s", strtotime(
"yesterday"));
68 $status_details =
"No previous run found - starting from yesterday.";
71 else if(strlen($last_run) == 10)
73 $last_run .=
" 00:00:00";
75 $status_details =
"Switched from daily runs to open schedule.";
78 include_once
"Services/Membership/classes/class.ilMembershipNotifications.php";
84 $user_news_aggr = array();
86 include_once
"Services/News/classes/class.ilNewsItem.php";
87 foreach($objects as
$ref_id => $user_ids)
91 if($news_item->checkNewsExistsForGroupCourse(
$ref_id, $last_run))
93 foreach($user_ids as $user_id)
96 $user_news = $news_item->getNewsForRefId(
$ref_id,
97 false,
false, $last_run,
false,
false,
false,
false,
101 $user_news_aggr[$user_id][
$ref_id] = $user_news;
118 if(
sizeof($user_news_aggr))
120 foreach($user_news_aggr as $user_id => $user_news)
122 $this->
sendMail($user_id, $user_news, $last_run);
137 $setting->set(get_class($this), date(
"Y-m-d H:i:s"));
144 $result->setMessage($status_details);
159 protected function parseNewsItem($a_parent_ref_id, array &$a_filter_map, array $a_item, $a_is_sub =
false)
163 $wrong_parent = (array_key_exists($a_item[
"id"], $a_filter_map) &&
164 $a_parent_ref_id != $a_filter_map[$a_item[
"id"]]);
173 $item_obj_type = $a_item[
"context_obj_type"];
177 if($a_item[
"aggregation"])
180 if($item_obj_type ==
"file" &&
181 sizeof($a_item[
"aggregation"]) == 1)
188 foreach($a_item[
"aggregation"] as $subitem)
190 $sub_res = $this->
parseNewsItem($a_parent_ref_id, $a_filter_map, $subitem,
true);
193 $sub[md5($sub_res)] = $sub_res;
202 $a_item[
"context_obj_type"],
204 $a_item[
"content_is_lang_var"],
205 $a_item[
"agg_ref_id"],
206 $a_item[
"aggregation"]
212 $a_item[
"context_obj_type"],
214 $a_item[
"content_is_lang_var"]
219 $a_item[
"context_obj_type"],
221 $a_item[
"content_text_is_lang_var"]
224 $title = trim($title);
230 switch($item_obj_type)
235 $res = $lng->txt(
"obj_".$item_obj_type).
236 ' "'.$item_obj_title.
'": '.$title;
240 $res .=
'"'.$title.
'": "'.$content.
'"';
245 if(!is_array($a_item[
"aggregation"]) ||
246 sizeof($a_item[
"aggregation"]) == 1)
248 $res = $lng->txt(
"obj_".$item_obj_type).
249 ' "'.$item_obj_title.
'" - '.$title;
254 $title = str_replace(
255 " ".
sizeof($a_item[
"aggregation"]).
" ",
256 " ".
sizeof($sub).
" ",
264 $res = $lng->txt(
"obj_".$item_obj_type).
265 ' "'.$item_obj_title.
'"';
268 $res .=
': "'.$title.
'"';
272 $res .=
' - '.$content;
283 $res .=
"\n".implode(
"\n", $sub);
299 $parent_map = $news_map = $parsed_map = array();
302 foreach($a_objects as $parent_ref_id => $news)
304 foreach($news as $item)
306 $news_map[$item[
"id"]] = $item[
"ref_id"];
307 $parent_map[$item[
"id"]][$parent_ref_id] = $parent_ref_id;
309 if($item[
"aggregation"])
311 foreach($item[
"aggregation"] as $subitem)
313 $news_map[$subitem[
"id"]] = $subitem[
"ref_id"];
314 $parent_map[$subitem[
"id"]][$parent_ref_id] = $parent_ref_id;
320 foreach($parent_map as $news_id => $parents)
322 if(
sizeof($parents) > 1)
324 $path = $tree->getPathId($news_map[$news_id]);
325 $lookup = array_flip(
$path);
328 foreach($parents as $parent_ref_id)
330 $level = max($level, $lookup[$parent_ref_id]);
333 $parsed_map[$news_id] =
$path[$level];
347 protected function sendMail($a_user_id, array $a_objects, $a_last_run)
351 include_once
"./Services/Notification/classes/class.ilSystemNotification.php";
353 $ntf->setLangModules(array(
"crs",
"news"));
360 $lng = $ntf->getUserLanguage($a_user_id);
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";
371 foreach($a_objects as $parent_ref_id => $news)
377 foreach($tree->getPathId($parent_ref_id) as $node)
387 $parent[
"url"] =
" ".$lng->txt(
"crs_course_group_notification_link").
" ".
ilLink::_getStaticLink($parent_ref_id);
391 foreach($news as $item)
393 $parsed_item = $this->
parseNewsItem($parent_ref_id, $filter_map, $item);
396 $parsed[md5($parsed_item)] = $parsed_item;
402 $parent[
"news"] = implode(
"\n", $parsed);
403 $tmp[
$path] = $parent;
415 $obj_index = array();
417 foreach($tmp as
$path => $item)
421 $txt .=
"(".$counter.
") ".$item[
"title"].
"\n".
423 $item[
"news"].
"\n\n";
425 $obj_index[] =
"(".$counter.
") ".$item[
"title"];
428 $ntf->setIntroductionLangId(
"crs_intro_course_group_notification_for");
432 $lng->txt(
"crs_intro_course_group_notification_index"),
436 $ntf->addAdditionalInfo($period,
437 trim(implode(
"\n", $obj_index)),
442 $ntf->addAdditionalInfo(
"",
447 $client = $ilClientIniFile->readVariable(
'client',
'name');
448 $subject = sprintf($lng->txt(
"crs_subject_course_group_notification"),
$client);
451 $mail =
new ilMail(ANONYMOUS_USER_ID);
452 $mail->enableSOAP(
false);
457 $ntf->composeAndGetMessage($a_user_id, null,
"read",
true),
470 $a_fields[
"enable_course_group_notifications"] = $a_is_active ?
471 $lng->txt(
"enabled") :
472 $lng->txt(
"disabled");
482 $ilSetting->set(
"crsgrp_ntf", (
bool)$a_currently_active);
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 _getStaticLink($a_ref_id, $a_type='', $a_fallback_goto=true, $append="")
Get static link.
Cron job application base class.
static shortenText($a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
static setUseRelativeDates($a_status)
set use relative dates
static _lookupTitle($a_id)
lookup object title
filterDuplicateItems(array $a_objects)
Filter duplicate news items from structure.
parseNewsItem($a_parent_ref_id, array &$a_filter_map, array $a_item, $a_is_sub=false)
Convert news item to summary html.
static useRelativeDates()
check if relative dates are used
getDefaultScheduleValue()
static determineNewsContent($a_context_obj_type, $a_content, $a_is_lang_var)
Determine new content.
Class Mail this class handles base functions for mail handling.
activationWasToggled($a_currently_active)
static _lookupObjId($a_id)
static formatDate(ilDateTime $date)
Format a date public.
Course/group notifications.
static _lookupType($a_id, $a_reference=false)
lookup object type
addToExternalSettingsForm($a_form_id, array &$a_fields, $a_is_active)
static ping($a_job_id)
Keep cron job alive.
static getActiveUsersforAllObjects()
Get active notifications for all objects.
Cron job result data container.
Wrapper classes for system notifications.
sendMail($a_user_id, array $a_objects, $a_last_run)
Send news mail for 1 user and n objects.