5include_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");
 
   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"]
 
  209        $title = trim($title);
 
  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;
 
  232                    $title = str_replace(
 
  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 . 
'"';
 
  248                    $res .= 
': "' . $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);
 
  293        $res = str_replace(
"<br />", 
" ", 
$res);
 
  309        $tree = 
$DIC[
'tree'];
 
  311        $parent_map = $news_map = $parsed_map = array();
 
  314        foreach ($a_objects as $parent_ref_id => $news) {
 
  315            foreach ($news as $item) {
 
  316                $news_map[$item[
"id"]] = $item[
"ref_id"];
 
  317                $parent_map[$item[
"id"]][$parent_ref_id] = $parent_ref_id;
 
  319                if ($item[
"aggregation"]) {
 
  320                    foreach ($item[
"aggregation"] as $subitem) {
 
  321                        $news_map[$subitem[
"id"]] = $subitem[
"ref_id"];
 
  322                        $parent_map[$subitem[
"id"]][$parent_ref_id] = $parent_ref_id;
 
  328        foreach ($parent_map as $news_id => $parents) {
 
  329            if (
sizeof($parents) > 1 && $news_map[$news_id] > 0) {
 
  330                $path = $tree->getPathId($news_map[$news_id]);
 
  331                $lookup = array_flip($path);
 
  334                foreach ($parents as $parent_ref_id) {
 
  335                    $level = max($level, $lookup[$parent_ref_id]);
 
  338                $parsed_map[$news_id] = $path[$level];
 
  352    protected function sendMail($a_user_id, array $a_objects, $a_last_run)
 
  358        $ilClientIniFile = 
$DIC[
'ilClientIniFile'];
 
  359        $tree = 
$DIC[
'tree'];
 
  363        include_once 
"./Services/Notification/classes/class.ilSystemNotification.php";
 
  365        $ntf->setLangModules(array(
"crs", 
"news"));
 
  372        $lng = $ntf->getUserLanguage($a_user_id);
 
  374        include_once 
'./Services/Locator/classes/class.ilLocatorGUI.php';
 
  375        require_once 
"./Services/UICore/classes/class.ilTemplate.php";
 
  376        require_once 
"./Services/Link/classes/class.ilLink.php";
 
  382        foreach ($a_objects as $parent_ref_id => $items) {
 
  387            foreach ($tree->getPathId($parent_ref_id) as $node) {
 
  390            $path = implode(
"-", $path);
 
  398            $log->debug(
"ref id: " . $parent_ref_id . 
", items: " . count($items));
 
  402            if (is_array($items)) {
 
  403                foreach ($items as $news_item) {
 
  405                    $parsed_item = $this->
parseNewsItem($parent_ref_id, $filter_map, $news_item, 
false, $a_user_id);
 
  407                        $parsed[md5($parsed_item)] = $parsed_item;
 
  413            if (
sizeof($parsed)) {
 
  414                $parent[
"news"] = implode(
"\n\n", $parsed);
 
  415                $tmp[$path] = $parent;
 
  421            $log->debug(
"returning");
 
  427        $obj_index = array();
 
  429        foreach ($tmp as $path => $item) {
 
  432            $txt .= 
"(" . $counter . 
") " . $item[
"title"] . 
"\n" .
 
  433                $item[
"url"] . 
"\n\n" .
 
  434                $item[
"news"] . 
"\n\n";
 
  436            $obj_index[] = 
"(" . $counter . 
") " . $item[
"title"];
 
  439        $ntf->setIntroductionLangId(
"crs_intro_course_group_notification_for");
 
  443            $lng->txt(
"crs_intro_course_group_notification_index"),
 
  447        $ntf->addAdditionalInfo(
 
  449            trim(implode(
"\n", $obj_index)),
 
  455        $ntf->addAdditionalInfo(
 
  462        $client = $ilClientIniFile->readVariable(
'client', 
'name');
 
  463        $subject = sprintf(
$lng->txt(
"crs_subject_course_group_notification"), 
$client);
 
  465        $mail_content = $ntf->composeAndGetMessage($a_user_id, 
null, 
"read", 
true);
 
  466        $log->debug(
"sending mail content: ".$mail_content);
 
  469        $mail = 
new ilMail(ANONYMOUS_USER_ID);
 
  486        switch ($a_form_id) {
 
  489                $a_fields[
"enable_course_group_notifications"] = $a_is_active ?
 
  490                    $lng->txt(
"enabled") :
 
  491                    $lng->txt(
"disabled");
 
  503        $ilSetting->set(
"crsgrp_ntf", (
bool) $a_currently_active);
 
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 formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
static setUseRelativeDates($a_status)
set use relative dates
static useRelativeDates()
check if relative dates are used
@classDescription Date and time handling
static getExpressionText($a_const)
Get unicode for const.
static _getStaticLink( $a_ref_id, $a_type='', $a_fallback_goto=true, $append="")
Get static link.
static getLogger($a_component_id)
Get component logger.
Manage data for ilMembershipCronNotifications cron job.
Course/group notifications.
getDefaultScheduleValue()
Get schedule value.
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.
sendMail($a_user_id, array $a_objects, $a_last_run)
Send news mail for 1 user and n objects.
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 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 lookupTxtById($plugin_id, $lang_var)
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 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:
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
if($_SERVER['argc']< 4) $client
foreach($_POST as $key=> $value) $res