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 $log->debug(
"===Member Notifications=== start");
61 $status_details = null;
64 $last_run = $setting->get(get_class($this));
68 $last_run =
date(
"Y-m-d H:i:s", strtotime(
"yesterday"));
70 $status_details =
"No previous run found - starting from yesterday.";
73 elseif (strlen($last_run) == 10) {
74 $last_run .=
" 00:00:00";
76 $status_details =
"Switched from daily runs to open schedule.";
79 include_once
"Services/Membership/classes/class.ilMembershipNotifications.php";
82 if (
sizeof($objects)) {
83 $log->debug(
"nr of objects: " . count($objects));
87 $user_news_aggr =
array();
89 include_once
"Services/News/classes/class.ilNewsItem.php";
90 foreach ($objects as $ref_id => $user_ids) {
91 $log->debug(
"handle ref id " . $ref_id .
", users: " . count($user_ids));
95 if ($news_item->checkNewsExistsForGroupCourse($ref_id, $last_run)) {
96 foreach ($user_ids as $user_id) {
98 $user_news = $news_item->getNewsForRefId(
110 $user_news_aggr[$user_id][$ref_id] = $user_news;
120 $log->debug(
"prepare sending mails");
128 if (
sizeof($user_news_aggr)) {
129 foreach ($user_news_aggr as $user_id => $user_news) {
130 $log->debug(
"sending mails to user " . $user_id .
", nr news: " . count($user_news));
132 $this->
sendMail($user_id, $user_news, $last_run);
146 $log->debug(
"save run");
149 $setting->set(get_class($this),
date(
"Y-m-d H:i:s"));
154 if ($status_details) {
155 $result->setMessage($status_details);
158 $log->debug(
"===Member Notifications=== done");
176 $lng->loadLanguageModule(
"news");
178 $wrong_parent = (array_key_exists($a_item[
"id"], $a_filter_map) &&
179 $a_parent_ref_id != $a_filter_map[$a_item[
"id"]]);
187 $item_obj_type = $a_item[
"context_obj_type"];
191 if ($a_item[
"aggregation"]) {
193 if ($item_obj_type ==
"file" &&
194 sizeof($a_item[
"aggregation"]) == 1) {
199 foreach ($a_item[
"aggregation"] as $subitem) {
200 $sub_res = $this->
parseNewsItem($a_parent_ref_id, $a_filter_map, $subitem,
true);
202 $sub[md5($sub_res)] = $sub_res;
210 $a_item[
"context_obj_type"],
212 $a_item[
"content_is_lang_var"],
213 $a_item[
"agg_ref_id"],
214 $a_item[
"aggregation"]
218 $a_item[
"context_obj_type"],
220 $a_item[
"content_is_lang_var"]
225 $a_item[
"context_obj_type"],
227 $a_item[
"content_text_is_lang_var"]
236 switch ($item_obj_type) {
239 $res = $lng->txt(
"obj_" . $item_obj_type) .
240 ' "' . $item_obj_title .
'": ' .
$title;
242 $res .=
'"' .
$title .
'": "' . $content .
'"';
247 if (!is_array($a_item[
"aggregation"]) ||
248 sizeof($a_item[
"aggregation"]) == 1) {
249 $res = $lng->txt(
"obj_" . $item_obj_type) .
250 ' "' . $item_obj_title .
'" - ' .
$title;
254 " " .
sizeof($a_item[
"aggregation"]) .
" ",
255 " " .
sizeof($sub) .
" ",
263 $res = $lng->txt(
"obj_" . $item_obj_type) .
264 ' "' . $item_obj_title .
'"';
269 $res .=
' - ' . $content;
278 if (is_array($sub) &&
sizeof($sub)) {
279 $res .=
"\n" . implode(
"\n", $sub);
295 $parent_map = $news_map = $parsed_map =
array();
298 foreach ($a_objects as $parent_ref_id => $news) {
299 foreach ($news as $item) {
300 $news_map[$item[
"id"]] = $item[
"ref_id"];
301 $parent_map[$item[
"id"]][$parent_ref_id] = $parent_ref_id;
303 if ($item[
"aggregation"]) {
304 foreach ($item[
"aggregation"] as $subitem) {
305 $news_map[$subitem[
"id"]] = $subitem[
"ref_id"];
306 $parent_map[$subitem[
"id"]][$parent_ref_id] = $parent_ref_id;
312 foreach ($parent_map as $news_id => $parents) {
313 if (
sizeof($parents) > 1 && isset($news_map[$news_id])) {
314 $path = $tree->getPathId($news_map[$news_id]);
315 $lookup = array_flip(
$path);
318 foreach ($parents as $parent_ref_id) {
319 $level = max($level, $lookup[$parent_ref_id]);
322 $parsed_map[$news_id] =
$path[$level];
340 include_once
"./Services/Notification/classes/class.ilSystemNotification.php";
342 $ntf->setLangModules(
array(
"crs",
"news"));
349 $lng = $ntf->getUserLanguage($a_user_id);
351 include_once
'./Services/Locator/classes/class.ilLocatorGUI.php';
352 require_once
"./Services/UICore/classes/class.ilTemplate.php";
353 require_once
"./Services/Link/classes/class.ilLink.php";
358 foreach ($a_objects as $parent_ref_id => $news) {
363 foreach ($tree->getPathId($parent_ref_id) as $node) {
371 $parent[
"title"] = $lng->txt(
"obj_" . $parent_type) .
' "' .
ilObject::_lookupTitle($parent_obj_id) .
'"';
372 $parent[
"url"] =
" " . $lng->txt(
"crs_course_group_notification_link") .
" " .
ilLink::_getStaticLink($parent_ref_id);
376 foreach ($news as $item) {
377 $parsed_item = $this->
parseNewsItem($parent_ref_id, $filter_map, $item);
379 $parsed[md5($parsed_item)] = $parsed_item;
383 if (
sizeof($parsed)) {
384 $parent[
"news"] = implode(
"\n", $parsed);
385 $tmp[
$path] = $parent;
396 $obj_index =
array();
398 foreach ($tmp as
$path => $item) {
402 $item[
"url"] .
"\n\n" .
403 $item[
"news"] .
"\n\n";
405 $obj_index[] =
"(" .
$counter .
") " . $item[
"title"];
408 $ntf->setIntroductionLangId(
"crs_intro_course_group_notification_for");
412 $lng->txt(
"crs_intro_course_group_notification_index"),
416 $ntf->addAdditionalInfo(
418 trim(implode(
"\n", $obj_index)),
424 $ntf->addAdditionalInfo(
431 $client = $ilClientIniFile->readVariable(
'client',
'name');
432 $subject = sprintf($lng->txt(
"crs_subject_course_group_notification"),
$client);
435 $mail =
new ilMail(ANONYMOUS_USER_ID);
436 $mail->enableSOAP(
false);
442 $ntf->composeAndGetMessage($a_user_id, null,
"read",
true),
452 switch ($a_form_id) {
455 $a_fields[
"enable_course_group_notifications"] = $a_is_active ?
456 $lng->txt(
"enabled") :
457 $lng->txt(
"disabled");
467 $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.
Cron job application base class.
static _getStaticLink( $a_ref_id, $a_type='', $a_fallback_goto=true, $append="")
Get static link.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date public.
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()
foreach($_POST as $key=> $value) $res
static determineNewsContent($a_context_obj_type, $a_content, $a_is_lang_var)
Determine new content.
This class handles base functions for mail handling.
activationWasToggled($a_currently_active)
static _lookupObjId($a_id)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
Course/group notifications.
Create styles array
The data for the language used.
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 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.
static getActiveUsersforAllObjects()
Get active notifications for all objects.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
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.