5 include_once
"Services/Cron/classes/class.ilCronJob.php";
21 return "mem_notification";
30 return $lng->txt(
"enable_course_group_notifications");
39 return $lng->txt(
"enable_course_group_notifications_desc");
44 return self::SCHEDULE_TYPE_DAILY;
69 $log = $DIC->logger()->mmbr();
70 $log->debug(
"===Member Notifications=== start");
73 $status_details = null;
76 $last_run = $setting->get(get_class($this));
80 $last_run = date(
"Y-m-d H:i:s", strtotime(
"yesterday"));
82 $status_details =
"No previous run found - starting from yesterday.";
85 elseif (strlen($last_run) == 10) {
86 $last_run .=
" 00:00:00";
88 $status_details =
"Switched from daily runs to open schedule.";
92 $log->debug(
"Last run: " . $last_run);
94 include_once(
"./Services/Membership/classes/class.ilMembershipCronNotificationsData.php");
97 $log->debug(
"prepare sending mails");
105 $user_news_aggr = $this->
data->getAggregatedNews();
106 if (
sizeof($user_news_aggr)) {
107 foreach ($user_news_aggr as $user_id => $user_news) {
108 $log->debug(
"sending mails to user " . $user_id .
", nr news: " . count($user_news));
110 $this->
sendMail($user_id, $user_news, $last_run);
122 $log->debug(
"save run");
125 $setting->set(get_class($this), date(
"Y-m-d H:i:s"));
130 if ($status_details) {
131 $result->setMessage($status_details);
134 $log->debug(
"===Member Notifications=== done");
148 protected function parseNewsItem($a_parent_ref_id, array &$a_filter_map, array $a_item, $a_is_sub =
false, $a_user_id = 0)
153 $obj_definiton = $DIC[
"objDefinition"];
155 $lng->loadLanguageModule(
"news");
157 $wrong_parent = (array_key_exists($a_item[
"id"], $a_filter_map) &&
158 $a_parent_ref_id != $a_filter_map[$a_item[
"id"]]);
166 $item_obj_type = $a_item[
"context_obj_type"];
170 if ($a_item[
"aggregation"]) {
172 if ($item_obj_type ==
"file" &&
173 sizeof($a_item[
"aggregation"]) == 1) {
178 foreach ($a_item[
"aggregation"] as $subitem) {
179 $sub_res = $this->
parseNewsItem($a_parent_ref_id, $a_filter_map, $subitem,
true, $a_user_id);
181 $sub[md5($sub_res)] = $sub_res;
189 $a_item[
"context_obj_type"],
191 $a_item[
"content_is_lang_var"],
192 $a_item[
"agg_ref_id"],
193 $a_item[
"aggregation"]
197 $a_item[
"context_obj_type"],
199 $a_item[
"content_is_lang_var"]
204 $a_item[
"context_obj_type"],
206 $a_item[
"content_text_is_lang_var"]
215 switch ($item_obj_type) {
218 $res =
$lng->txt(
"obj_" . $item_obj_type) .
219 ' "' . $item_obj_title .
'": ' .
$title;
221 $res .=
'"' .
$title .
'": "' . $content .
'"';
226 if (!is_array($a_item[
"aggregation"]) ||
227 sizeof($a_item[
"aggregation"]) == 1) {
228 $res =
$lng->txt(
"obj_" . $item_obj_type) .
229 ' "' . $item_obj_title .
'" - ' .
$title;
233 " " .
sizeof($a_item[
"aggregation"]) .
" ",
234 " " .
sizeof($sub) .
" ",
242 $type_txt = ($obj_definiton->isPlugin($item_obj_type))
244 :
$lng->txt(
"obj_" . $item_obj_type);
246 ' "' . $item_obj_title .
'"';
251 $res .=
' - ' . $content;
257 $comments = $this->
data->getComments($a_item[
"id"], $a_user_id);
258 if (count($comments) > 0) {
259 $res .=
"\n" .
$lng->txt(
"news_new_comments") .
" (" . count($comments) .
")";
261 foreach ($comments as
$c) {
271 include_once(
"./Services/Like/classes/class.ilLikeGUI.php");
272 $likes = $this->
data->getLikes($a_item[
"id"], $a_user_id);
273 if (count($likes) > 0) {
274 $res .=
"\n" .
$lng->txt(
"news_new_reactions") .
" (" . count($likes) .
")";
276 foreach ($likes as
$l) {
289 if (is_array($sub) &&
sizeof($sub)) {
290 $res .=
"\n" . implode(
"\n", $sub);
306 $tree = $DIC[
'tree'];
308 $parent_map = $news_map = $parsed_map = array();
311 foreach ($a_objects as $parent_ref_id => $news) {
312 foreach ($news as $item) {
313 $news_map[$item[
"id"]] = $item[
"ref_id"];
314 $parent_map[$item[
"id"]][$parent_ref_id] = $parent_ref_id;
316 if ($item[
"aggregation"]) {
317 foreach ($item[
"aggregation"] as $subitem) {
318 $news_map[$subitem[
"id"]] = $subitem[
"ref_id"];
319 $parent_map[$subitem[
"id"]][$parent_ref_id] = $parent_ref_id;
325 foreach ($parent_map as $news_id => $parents) {
326 if (
sizeof($parents) > 1 && $news_map[$news_id] > 0) {
327 $path =
$tree->getPathId($news_map[$news_id]);
328 $lookup = array_flip(
$path);
331 foreach ($parents as $parent_ref_id) {
332 $level = max($level, $lookup[$parent_ref_id]);
335 $parsed_map[$news_id] =
$path[$level];
349 protected function sendMail($a_user_id, array $a_objects, $a_last_run)
355 $ilClientIniFile = $DIC[
'ilClientIniFile'];
356 $tree = $DIC[
'tree'];
360 include_once
"./Services/Notification/classes/class.ilSystemNotification.php";
362 $ntf->setLangModules(array(
"crs",
"news"));
369 $lng = $ntf->getUserLanguage($a_user_id);
371 include_once
'./Services/Locator/classes/class.ilLocatorGUI.php';
372 require_once
"./Services/UICore/classes/class.ilTemplate.php";
373 require_once
"./Services/Link/classes/class.ilLink.php";
379 foreach ($a_objects as $parent_ref_id => $items) {
384 foreach (
$tree->getPathId($parent_ref_id) as $node) {
395 $log->debug(
"ref id: " . $parent_ref_id .
", items: " . count($items));
399 if (is_array($items)) {
400 foreach ($items as $news_item) {
402 $parsed_item = $this->
parseNewsItem($parent_ref_id, $filter_map, $news_item,
false, $a_user_id);
404 $parsed[md5($parsed_item)] = $parsed_item;
410 if (
sizeof($parsed)) {
411 $parent[
"news"] = implode(
"\n\n", $parsed);
412 $tmp[
$path] = $parent;
418 $log->debug(
"returning");
424 $obj_index = array();
426 foreach ($tmp as
$path => $item) {
429 $txt .=
"(" . $counter .
") " . $item[
"title"] .
"\n" .
430 $item[
"url"] .
"\n\n" .
431 $item[
"news"] .
"\n\n";
433 $obj_index[] =
"(" . $counter .
") " . $item[
"title"];
436 $ntf->setIntroductionLangId(
"crs_intro_course_group_notification_for");
440 $lng->txt(
"crs_intro_course_group_notification_index"),
444 $ntf->addAdditionalInfo(
446 trim(implode(
"\n", $obj_index)),
452 $ntf->addAdditionalInfo(
459 $client = $ilClientIniFile->readVariable(
'client',
'name');
460 $subject = sprintf(
$lng->txt(
"crs_subject_course_group_notification"),
$client);
463 $mail =
new ilMail(ANONYMOUS_USER_ID);
464 $mail->enableSOAP(
false);
470 $ntf->composeAndGetMessage($a_user_id, null,
"read",
true),
482 switch ($a_form_id) {
485 $a_fields[
"enable_course_group_notifications"] = $a_is_active ?
486 $lng->txt(
"enabled") :
487 $lng->txt(
"disabled");
499 $ilSetting->set(
"crsgrp_ntf", (
bool) $a_currently_active);
static _lookupLogin($a_user_id)
lookup login
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
static lookupTxtById($plugin_id, $lang_var)
Cron job application base class.
static getExpressionText($a_const)
Get unicode for const.
static _getStaticLink( $a_ref_id, $a_type='', $a_fallback_goto=true, $append="")
Get static link.
Manage data for ilMembershipCronNotifications cron job.
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.
if($_SERVER['argc']< 4) $client
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
static useRelativeDates()
check if relative dates are used
getDefaultScheduleValue()
foreach($_POST as $key=> $value) $res
static determineNewsContent($a_context_obj_type, $a_content, $a_is_lang_var)
Determine new content.
activationWasToggled($a_currently_active)
static _lookupObjId($a_id)
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
Course/group notifications.
static _lookupType($a_id, $a_reference=false)
lookup object type
addToExternalSettingsForm($a_form_id, array &$a_fields, $a_is_active)
parseNewsItem($a_parent_ref_id, array &$a_filter_map, array $a_item, $a_is_sub=false, $a_user_id=0)
Convert news item to summary html.
static ping($a_job_id)
Keep cron job alive.
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 getLogger($a_component_id)
Get component logger.
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.