4 define(
"NEWS_NOTICE", 0);
 
    5 define(
"NEWS_MESSAGE", 1);
 
    6 define(
"NEWS_WARNING", 2);
 
    8 include_once(
"./Services/News/classes/class.ilNewsItemGen.php");
 
   36                 $this->limitation = 
true;
 
   47                 $this->limitation = $a_limitation;
 
   70                 $max_items = $news_set->get(
"max_items");
 
   80                         $query = 
"SELECT count(*) cnt ".
 
   88                         $set = $ilDB->query(
$query);
 
   89                         $rec = $ilDB->fetchAssoc($set);
 
  101                         " ORDER BY creation_date ASC";
 
  103                                 $ilDB->setLimit($rec[
"cnt"] - $max_items);
 
  104                                 $del_set = $ilDB->query(
$query);
 
  105                                 while ($del_item = $ilDB->fetchAssoc($del_set))
 
  118                 $a_prevent_aggregation = 
false, $a_per = 0, &$a_cnt = NULL)
 
  120                 global $ilAccess, $ilUser;
 
  127                 include_once(
"./Services/News/classes/class.ilNewsSubscription.php");
 
  128                 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
 
  137                         foreach($pd_items as $item)
 
  139                                 if (!in_array($item[
"ref_id"], $ref_ids))
 
  141                                         $ref_ids[] = $item[
"ref_id"];
 
  153                                 $acc = $ilAccess->checkAccess(
"read", 
"", $ref_id);
 
  172                         $news = $news_item->getNewsForRefId($ref_id, $a_only_public, 
false,
 
  173                                 $per, $a_prevent_aggregation);
 
  176                         if (!is_null($a_cnt))
 
  178                                 $a_cnt[
$ref_id] = count($news);
 
  193                 $a_time_period = 0, $a_prevent_aggregation = 
true, $a_forum_group_sequences = 
false,
 
  194                 $a_no_auto_generated = 
false, $a_ignore_date_filter = 
false)
 
  201                 if ($obj_type == 
"grp" || $obj_type == 
"crs" || $obj_type == 
"cat")
 
  203                         include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
 
  206                         if ($hide_news_per_date && !$a_ignore_date_filter)
 
  213                 if ($obj_type == 
"cat" && !$a_stopnesting)
 
  216                 $a_prevent_aggregation, $starting_date, $a_no_auto_generated);
 
  218                 else if (($obj_type == 
"grp" || $obj_type == 
"crs") &&
 
  222                 $a_prevent_aggregation, $starting_date, $a_no_auto_generated);
 
  227                         $news_item->setContextObjId($obj_id);
 
  228                         $news_item->setContextObjType($obj_type);
 
  229                         $news = $news_item->queryNewsForContext($a_only_public, $a_time_period,
 
  230                 $starting_date, $a_no_auto_generated);
 
  232                         foreach ($news as $k => $v)
 
  234                                 if (!$a_only_public || $v[
"visibility"] == 
NEWS_PUBLIC ||
 
  235                     ($v[
"priority"] == 0 &&
 
  239                                         $news[$k][
"ref_id"] = $a_ref_id;
 
  246                         foreach ($unset as $un)
 
  252                 if (!$a_prevent_aggregation)
 
  256                 else if ($a_forum_group_sequences)
 
  268         $a_prevent_aggregation = 
false, $a_starting_date = 
"", $a_no_auto_generated = 
false)
 
  270                 global $tree, $ilAccess, $ilObjDataCache;
 
  277                 $cur_node = $tree->getNodeData($a_ref_id);
 
  279                 if ($cur_node[
"lft"] != 
"")             
 
  281                         $nodes = $tree->getSubTree($cur_node, 
true);
 
  291                 foreach($nodes as $node)
 
  293                         $ref_ids[] = $node[
"child"];
 
  294                         $obj_ids[] = $node[
"obj_id"];
 
  297                 $ilObjDataCache->preloadReferenceCache($ref_ids);
 
  300                         $ilAccess->preloadActivationTimes($ref_ids);
 
  309                 foreach($nodes as $node)
 
  312                         if (!in_array($node[
"obj_id"], $news_obj_ids))
 
  319                                 $acc = $ilAccess->checkAccess(
"read", 
"", $node[
"child"]);
 
  327                         $ref_id[$node[
"obj_id"]] = $node[
"child"];
 
  328                         $contexts[] = array(
"obj_id" => $node[
"obj_id"],
 
  329                                 "obj_type" => $node[
"type"]);
 
  334             $a_starting_date, $a_no_auto_generated);
 
  337                 foreach ($news as $k => $v)
 
  339                         $news[$k][
"ref_id"] = 
$ref_id[$v[
"context_obj_id"]];
 
  345                 if (!$a_prevent_aggregation)
 
  359                 foreach ($news as $k => $v)
 
  361                         if ($a_group_posting_sequence && $last_aggregation_forum > 0 &&
 
  362                                 $last_aggregation_forum != $news[$k][
"context_obj_id"])
 
  364                                 $forums[$last_aggregation_forum] = 
"";
 
  367                         if ($news[$k][
"context_obj_type"] == 
"frm")
 
  369                                 if ($forums[$news[$k][
"context_obj_id"]] == 
"")
 
  372                                         $forums[$news[$k][
"context_obj_id"]] = $k;
 
  373                                         $last_aggregation_forum = $news[$k][
"context_obj_id"];
 
  380                                 $news[$k][
"no_context_title"] = 
true;
 
  383                                 $news[$forums[$news[$k][
"context_obj_id"]]][
"aggregation"][$k]
 
  385                                 $news[$k][
"agg_ref_id"]
 
  386                                         = $news[$k][
"ref_id"];
 
  387                                 $news[$k][
"content"] = 
"";
 
  388                                 $news[$k][
"content_long"] = 
"";
 
  393                 foreach($to_del as $k)
 
  407                 foreach ($news as $k => $v)
 
  410                         if ($news[$k][
"context_obj_type"] == 
"file")
 
  412                                 if ($first_file == 
"")
 
  420                                 $news[$first_file][
"aggregation"][$k] = $news[$k];
 
  421                                 $news[$first_file][
"agg_ref_id"] = $a_ref_id;
 
  422                                 $news[$first_file][
"ref_id"] = $a_ref_id;
 
  426                 foreach($to_del as $v)
 
  439                 $a_time_period = 0, $a_prevent_aggregation = 
false, $a_starting_date = 
"",
 
  440         $a_no_auto_generated = 
false)
 
  442                 global $tree, $ilAccess;
 
  446                         true, 
false, 
false, $a_no_auto_generated);
 
  447                 foreach (
$data as $k => $v)
 
  449                         $data[$k][
"ref_id"] = $a_ref_id;
 
  453                 $nodes = $tree->getChilds($a_ref_id);
 
  457                 foreach($nodes as $node)
 
  459                         $obj_ids[] = $node[
"obj_id"];
 
  466                 foreach($nodes as $node)
 
  469                         if (!in_array($node[
"obj_id"], $news_obj_ids))
 
  474                         if (!$a_only_public && !$ilAccess->checkAccess(
"read", 
"", $node[
"child"]))
 
  478                         $ref_id[$node[
"obj_id"]] = $node[
"child"];
 
  479                         $contexts[] = array(
"obj_id" => $node[
"obj_id"],
 
  480                                 "obj_type" => $node[
"type"]);
 
  484             $a_starting_date, $a_no_auto_generated);
 
  485                 foreach ($news as $k => $v)
 
  487                         $news[$k][
"ref_id"] = 
$ref_id[$v[
"context_obj_id"]];
 
  494                 if (!$a_prevent_aggregation)
 
  505         function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type = 
"")
 
  522         $a_starting_date = 
"", $a_no_auto_generated = 
false, $a_oldest_first = 
false)
 
  527                         if ($a_time_period > 0)
 
  529                                 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
 
  530                         $and = 
" AND creation_date >= ".$ilDB->quote($limit_ts, 
"timestamp").
" ";
 
  533                 if ($a_starting_date != 
"")
 
  535                         $and.= 
" AND creation_date > ".$ilDB->quote($a_starting_date, 
"timestamp").
" ";
 
  538                 if ($a_no_auto_generated)
 
  540                         $and.= 
" AND priority = 1 AND content_type = ".$ilDB->quote(
"text", 
"text").
" ";
 
  546                         $and.= 
" AND context_sub_obj_id = ".$ilDB->quote($this->
getContextSubObjId(), 
"integer").
 
  550                 $ordering = ($a_oldest_first)
 
  551             ? 
" creation_date ASC, id ASC " 
  552             : 
" creation_date DESC, id DESC ";
 
  557                                 "FROM il_news_item ".
 
  562                                         " ORDER BY ".$ordering;
 
  566                         $query = 
"SELECT il_news_item.* ".
 
  567                                 ", il_news_read.user_id user_read ".
 
  568                                 "FROM il_news_item LEFT JOIN il_news_read ".
 
  569                                 "ON il_news_item.id = il_news_read.news_id AND ".
 
  575                                         " ORDER BY ".$ordering;
 
  579                         $query = 
"SELECT il_news_item.* ".
 
  580                                 ", il_news_read.user_id as user_read ".
 
  581                                 "FROM il_news_item LEFT JOIN il_news_read ".
 
  582                                 "ON il_news_item.id = il_news_read.news_id AND ".
 
  583                                 " il_news_read.user_id = ".$ilDB->quote($ilUser->getId(), 
"integer").
 
  585                                         "context_obj_id = ".$ilDB->quote($this->getContextObjId(), 
"integer").
 
  586                                         " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), 
"text").
 
  588                                         " ORDER BY ".$ordering;
 
  591                 $set = $ilDB->query(
$query);
 
  593                 while($rec = $ilDB->fetchAssoc($set))
 
  596                                 ($rec[
"priority"] == 0 &&
 
  598                                 0, $rec[
"context_obj_id"]))))
 
  614         $a_time_period = 0, $a_starting_date = 
"", $a_no_auto_generated = 
false)
 
  619                         if ($a_time_period > 0)
 
  621                                 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
 
  622                         $and = 
" AND creation_date >= ".$ilDB->quote($limit_ts, 
"timestamp").
" ";
 
  625                 if ($a_starting_date != 
"")
 
  627                         $and.= 
" AND creation_date > ".$ilDB->quote($a_starting_date, 
"timestamp").
" ";
 
  630                 if ($a_no_auto_generated)
 
  632                         $and.= 
" AND priority = 1 AND content_type = ".$ilDB->quote(
"text", 
"text").
" ";
 
  637                 foreach($a_contexts as $cont)
 
  639                         $ids[] = $cont[
"obj_id"];
 
  640                         $type[$cont[
"obj_id"]] = $cont[
"obj_type"];
 
  646                                 "FROM il_news_item ".
 
  648                                         $ilDB->in(
"context_obj_id", $ids, 
false, 
"integer").
" ".
 
  650                     " ORDER BY creation_date DESC ";
 
  654                         $query = 
"SELECT il_news_item.* ".
 
  655                                 ", il_news_read.user_id as user_read ".
 
  656                                 "FROM il_news_item LEFT JOIN il_news_read ".
 
  657                                 "ON il_news_item.id = il_news_read.news_id AND ".
 
  660                                         $ilDB->in(
"context_obj_id", $ids, 
false, 
"integer").
" ".
 
  662                     " ORDER BY creation_date DESC ";
 
  666                         $query = 
"SELECT il_news_item.* ".
 
  667                                 ", il_news_read.user_id as user_read ".
 
  668                                 "FROM il_news_item LEFT JOIN il_news_read ".
 
  669                                 "ON il_news_item.id = il_news_read.news_id AND ".
 
  670                                 " il_news_read.user_id = ".$ilDB->quote($ilUser->getId(), 
"integer").
 
  672                                         $ilDB->in(
"context_obj_id", $ids, 
false, 
"integer").
" ".
 
  674                     " ORDER BY creation_date DESC ";
 
  677                 $set = $ilDB->query(
$query);
 
  679                 while($rec = $ilDB->fetchAssoc($set))
 
  681                         if ($type[$rec[
"context_obj_id"]] == $rec[
"context_obj_type"])
 
  684                                         ($rec[
"priority"] == 0 &&
 
  686                                         0, $rec[
"context_obj_id"]))))
 
  703                 global 
$ilDB, $ilAppEventHandler;
 
  705                 $ilDB->manipulate(
"DELETE FROM il_news_read WHERE ".
 
  706                         "user_id = ".$ilDB->quote($a_user_id, 
"integer").
 
  707                         " AND news_id = ".$ilDB->quote($a_news_id, 
"integer"));
 
  708                 $ilDB->manipulate(
"INSERT INTO il_news_read (user_id, news_id) VALUES (".
 
  709                         $ilDB->quote($a_user_id, 
"integer").
",".
 
  710                         $ilDB->quote($a_news_id, 
"integer").
")");
 
  712                 $ilAppEventHandler->raise(
"Services/News", 
"readNews",
 
  713                         array(
"user_id" => $a_user_id, 
"news_ids" => array($a_news_id)));
 
  721                 global 
$ilDB, $ilAppEventHandler;
 
  723                 $ilDB->manipulate(
"DELETE FROM il_news_read (user_id, news_id) VALUES (".
 
  724                         " WHERE user_id = ".$ilDB->quote($a_user_id, 
"integer").
 
  725                         " AND news_id = ".$ilDB->quote($a_news_id, 
"integer"));
 
  727                 $ilAppEventHandler->raise(
"Services/News", 
"unreadNews",
 
  728                         array(
"user_id" => $a_user_id, 
"news_ids" => array($a_news_id)));
 
  741                 foreach($n2 as 
$id => $news)
 
  758                 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
 
  761                 $default_visibility = ($news_set->get(
"default_visibility") != 
"")
 
  762                                 ? $news_set->get(
"default_visibility")
 
  765                 if ($tree->isInTree($a_ref_id))
 
  767                         $path = $tree->getPathFull($a_ref_id);
 
  771                                 if (!in_array(
$row[
"type"], array(
"root", 
"cat",
"crs", 
"fold", 
"grp", 
"icrs")))
 
  786                 return $default_visibility;
 
  794         public function delete()
 
  799                 $ilDB->manipulate(
"DELETE FROM il_news_read ".
 
  800                         " WHERE news_id = ".$ilDB->quote($this->getId(), 
"integer"));
 
  811                         include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
 
  822                 $a_context_obj_type, $a_context_sub_obj_id = 0, $a_context_sub_obj_type = 
"")
 
  826                 if ($a_context_obj_id == 0 || $a_context_obj_type == 
"")
 
  831                 if ($a_context_sub_obj_id > 0)
 
  833                         $and = 
" AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id, 
"integer").
 
  834                                 " AND context_sub_obj_type = ".$ilDB->quote($a_context_sub_obj_type, 
"text");
 
  838                 $query = 
"SELECT * FROM il_news_item".
 
  839                         " WHERE context_obj_id = ".$ilDB->quote($a_context_obj_id, 
"integer").
 
  840                         " AND context_obj_type = ".$ilDB->quote($a_context_obj_type, 
"text").
 
  843                 $news_set = $ilDB->query(
$query);
 
  845                 while ($news = $ilDB->fetchAssoc($news_set))
 
  859                 $query = 
"SELECT title FROM il_news_item WHERE id = ".
 
  860                         $ilDB->quote($a_news_id, 
"integer");
 
  861                 $set = $ilDB->query(
$query);
 
  862                 $rec = $ilDB->fetchAssoc($set);
 
  863                 return $rec[
"title"];
 
  873                 $query = 
"SELECT visibility FROM il_news_item WHERE id = ".
 
  874                         $ilDB->quote($a_news_id, 
"integer");
 
  875                 $set = $ilDB->query(
$query);
 
  876                 $rec = $ilDB->fetchAssoc($set);
 
  878                 return $rec[
"visibility"];
 
  888                 $query = 
"SELECT mob_id FROM il_news_item WHERE id = ".
 
  889                         $ilDB->quote($a_news_id, 
"integer");
 
  890                 $set = $ilDB->query(
$query);
 
  891                 $rec = $ilDB->fetchAssoc($set);
 
  892                 return $rec[
"mob_id"];
 
  898         static function filterObjIdsPerNews($a_obj_ids, $a_time_period = 0, $a_starting_date = 
"",$a_ending_date = 
'', $ignore_period = 
false)
 
  903                         if ($a_time_period > 0)
 
  905                                 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
 
  906             $and = 
" AND creation_date >= ".$ilDB->quote($limit_ts, 
"timestamp").
" ";
 
  909                 if ($a_starting_date != 
"")
 
  911                         $and.= 
" AND creation_date >= ".$ilDB->quote($a_starting_date, 
"timestamp");
 
  914                 $query = 
"SELECT DISTINCT(context_obj_id) AS obj_id FROM il_news_item".
 
  915                         " WHERE ".$ilDB->in(
"context_obj_id", $a_obj_ids, 
false, 
"integer").
" ".$and;
 
  918                 $set = $ilDB->query(
$query);
 
  920                 while($rec = $ilDB->fetchAssoc($set))
 
  922                         $objs[] = $rec[
"obj_id"];
 
  932                 $a_agg_ref_id = 0, $a_aggregation = 
"")
 
  936                 if ($a_agg_ref_id > 0)
 
  938                         $cnt = count($a_aggregation);
 
  941                         if ($a_context_obj_type == 
"frm")
 
  945                                         return sprintf($lng->txt(
"news_x_postings"), $cnt);
 
  949                                         return $lng->txt(
"news_1_postings");
 
  954                                 $up_cnt = $cr_cnt = 0;
 
  955                                 foreach($a_aggregation as $item)
 
  957                                         if ($item[
"title"] == 
"file_updated")
 
  969                                         $tit = $lng->txt(
"news_1_file_created");
 
  972                                 else if ($cr_cnt > 1)
 
  974                                         $tit = sprintf($lng->txt(
"news_x_files_created"), $cr_cnt);
 
  979                                         $tit .= $sep.$lng->txt(
"news_1_file_updated");
 
  981                                 else if ($up_cnt > 1)
 
  983                                         $tit .= $sep.sprintf($lng->txt(
"news_x_files_updated"), $up_cnt);
 
  990                         if ($a_content_is_lang_var)
 
  992                                 return $lng->txt($a_title);
 
 1008                 $a_context_obj_type, $a_context_sub_obj_id = 
"", $a_context_sub_obj_type = 
"")
 
 1014                         "FROM il_news_item ".
 
 1016                                 "context_obj_id = ".$ilDB->quote($a_context_obj_id, 
"integer").
 
 1017                                 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type, 
"text").
 
 1018                                 " AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id, 
"integer").
 
 1019                                 " AND ".$ilDB->equals(
"context_sub_obj_type", $a_context_sub_obj_type, 
"text", 
true);
 
 1021                 $set = $ilDB->query(
$query);
 
 1022                 $rec = $ilDB->fetchAssoc($set);
 
 1035                         "FROM il_news_item ".
 
 1037                                 " mob_id = ".$ilDB->quote($a_mob_id, 
"integer");
 
 1040                 $set = $ilDB->query(
$query);
 
 1041                 while ($rec = $ilDB->fetchAssoc($set))
 
 1043                         $usages[$rec[
"id"]] = array(
"type" => 
"news", 
"id" => $rec[
"id"]);
 
 1057                         "FROM il_news_item ".
 
 1059                                 " id = ".$ilDB->quote($a_news_id, 
"integer");
 
 1060                 $set = $ilDB->query(
$query);
 
 1061                 $rec = $ilDB->fetchAssoc($set);
 
 1063                 return $rec[
"context_obj_id"];
 
 1069                 $per = $news_set->get(
"pd_period");
 
 1083                 $allow_shorter_periods = $news_set->get(
"allow_shorter_periods");
 
 1084                 $allow_longer_periods = $news_set->get(
"allow_longer_periods");
 
 1087                 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
 
 1093                         (!$allow_shorter_periods && ($per < $default_per)) ||
 
 1094                         (!$allow_longer_periods && ($per > $default_per))
 
 1097                         $per = $default_per;
 
 1106                 $rss_period = $news_set->get(
"rss_period");
 
 1107                 if ($rss_period == 0)