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,
$ilBench;
122 $ilBench->start(
"News",
"getNewsItemsOfUser");
129 include_once(
"./Services/News/classes/class.ilNewsSubscription.php");
130 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
133 $ilBench->start(
"News",
"getNewsItemsOfUser_getRefIds");
140 foreach($pd_items as $item)
142 if (!in_array($item[
"ref_id"], $ref_ids))
144 $ref_ids[] = $item[
"ref_id"];
148 $ilBench->stop(
"News",
"getNewsItemsOfUser_getRefIds");
154 $ilBench->start(
"News",
"getNewsForRefId");
158 $ilBench->start(
"News",
"getAggregatedNewsData_getContexts_checkAccess");
159 $acc = $ilAccess->checkAccess(
"read",
"", $ref_id);
160 $ilBench->stop(
"News",
"getAggregatedNewsData_getContexts_checkAccess");
177 $ilBench->start(
"News",
"getNewsForRefId_getNews");
180 $news = $news_item->getNewsForRefId($ref_id, $a_only_public,
false,
181 $per, $a_prevent_aggregation);
182 $ilBench->stop(
"News",
"getNewsForRefId_getNews");
185 if (!is_null($a_cnt))
187 $a_cnt[
$ref_id] = count($news);
190 $ilBench->start(
"News",
"getNewsForRefId_mergeNews");
192 $ilBench->stop(
"News",
"getNewsForRefId_mergeNews");
194 $ilBench->stop(
"News",
"getNewsForRefId");
199 $ilBench->stop(
"News",
"getNewsItemsOfUser");
209 $a_time_period = 0, $a_prevent_aggregation =
true, $a_forum_group_sequences =
false)
216 if ($obj_type ==
"grp" || $obj_type ==
"crs" || $obj_type ==
"cat")
218 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
221 if ($hide_news_per_date)
228 if ($obj_type ==
"cat" && !$a_stopnesting)
231 $a_prevent_aggregation, $starting_date);
233 else if (($obj_type ==
"grp" || $obj_type ==
"crs") &&
237 $a_prevent_aggregation, $starting_date);
242 $news_item->setContextObjId($obj_id);
243 $news_item->setContextObjType($obj_type);
244 $news = $news_item->queryNewsForContext($a_only_public, $a_time_period,
247 foreach ($news as $k => $v)
249 if (!$a_only_public || $v[
"visibility"] ==
NEWS_PUBLIC ||
250 ($v[
"priority"] == 0 &&
254 $news[$k][
"ref_id"] = $a_ref_id;
261 foreach ($unset as $un)
267 if (!$a_prevent_aggregation)
271 else if ($a_forum_group_sequences)
283 $a_prevent_aggregation =
false, $a_starting_date =
"")
285 global $tree, $ilAccess,
$ilBench, $ilObjDataCache;
287 $ilBench->start(
"News",
"getAggregatedNewsData");
294 $ilBench->start(
"News",
"getAggregatedNewsData_getSubTree");
295 $cur_node = $tree->getNodeData($a_ref_id);
297 if ($cur_node[
"lft"] !=
"")
299 $nodes = $tree->getSubTree($cur_node,
true);
309 foreach($nodes as $node)
311 $ref_ids[] = $node[
"child"];
312 $obj_ids[] = $node[
"obj_id"];
314 $ilBench->stop(
"News",
"getAggregatedNewsData_getSubTree");
316 $ilBench->start(
"News",
"getAggregatedNewsData_preloadActivationTimes");
317 $ilObjDataCache->preloadReferenceCache($ref_ids);
320 $ilAccess->preloadActivationTimes($ref_ids);
322 $ilBench->stop(
"News",
"getAggregatedNewsData_preloadActivationTimes");
329 $ilBench->start(
"News",
"getAggregatedNewsData_getContexts");
331 foreach($nodes as $node)
334 if (!in_array($node[
"obj_id"], $news_obj_ids))
341 $ilBench->start(
"News",
"getAggregatedNewsData_getContexts_checkAccess");
342 $acc = $ilAccess->checkAccess(
"read",
"", $node[
"child"]);
343 $ilBench->stop(
"News",
"getAggregatedNewsData_getContexts_checkAccess");
351 $ref_id[$node[
"obj_id"]] = $node[
"child"];
352 $contexts[] = array(
"obj_id" => $node[
"obj_id"],
353 "obj_type" => $node[
"type"]);
355 $ilBench->stop(
"News",
"getAggregatedNewsData_getContexts");
361 $ilBench->start(
"News",
"getAggregatedNewsData_mergeAndSort");
364 foreach ($news as $k => $v)
366 $news[$k][
"ref_id"] =
$ref_id[$v[
"context_obj_id"]];
372 if (!$a_prevent_aggregation)
379 $ilBench->stop(
"News",
"getAggregatedNewsData_mergeAndSort");
380 $ilBench->stop(
"News",
"getAggregatedNewsData");
391 foreach ($news as $k => $v)
393 if ($a_group_posting_sequence && $last_aggregation_forum > 0 &&
394 $last_aggregation_forum != $news[$k][
"context_obj_id"])
396 $forums[$last_aggregation_forum] =
"";
399 if ($news[$k][
"context_obj_type"] ==
"frm")
401 if ($forums[$news[$k][
"context_obj_id"]] ==
"")
404 $forums[$news[$k][
"context_obj_id"]] = $k;
405 $last_aggregation_forum = $news[$k][
"context_obj_id"];
412 $news[$k][
"no_context_title"] =
true;
415 $news[$forums[$news[$k][
"context_obj_id"]]][
"aggregation"][$k]
417 $news[$k][
"agg_ref_id"]
418 = $news[$k][
"ref_id"];
419 $news[$k][
"content"] =
"";
420 $news[$k][
"content_long"] =
"";
425 foreach($to_del as $k)
439 foreach ($news as $k => $v)
442 if ($news[$k][
"context_obj_type"] ==
"file")
444 if ($first_file ==
"")
452 $news[$first_file][
"aggregation"][$k] = $news[$k];
453 $news[$first_file][
"agg_ref_id"] = $a_ref_id;
454 $news[$first_file][
"ref_id"] = $a_ref_id;
458 foreach($to_del as $v)
471 $a_time_period = 0, $a_prevent_aggregation =
false, $a_starting_date =
"")
475 $ilBench->start(
"News",
"getAggregatedChildNewsData");
479 foreach (
$data as $k => $v)
481 $data[$k][
"ref_id"] = $a_ref_id;
485 $nodes = $tree->getChilds($a_ref_id);
489 foreach($nodes as $node)
491 $obj_ids[] = $node[
"obj_id"];
498 foreach($nodes as $node)
501 if (!in_array($node[
"obj_id"], $news_obj_ids))
506 if (!$a_only_public && !$ilAccess->checkAccess(
"read",
"", $node[
"child"]))
510 $ref_id[$node[
"obj_id"]] = $node[
"child"];
511 $contexts[] = array(
"obj_id" => $node[
"obj_id"],
512 "obj_type" => $node[
"type"]);
517 foreach ($news as $k => $v)
519 $news[$k][
"ref_id"] =
$ref_id[$v[
"context_obj_id"]];
526 if (!$a_prevent_aggregation)
531 $ilBench->stop(
"News",
"getAggregatedChildNewsData");
539 function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type =
"")
552 $a_starting_date =
"")
557 if ($a_time_period > 0)
559 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
560 $and =
" AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp").
" ";
563 if ($a_starting_date !=
"")
565 $and.=
" AND creation_date > ".$ilDB->quote($a_starting_date,
"timestamp").
" ";
571 "FROM il_news_item ".
576 " ORDER BY creation_date DESC ";
580 $query =
"SELECT il_news_item.* ".
581 ", il_news_read.user_id user_read ".
582 "FROM il_news_item LEFT JOIN il_news_read ".
583 "ON il_news_item.id = il_news_read.news_id AND ".
589 " ORDER BY creation_date DESC ";
593 $query =
"SELECT il_news_item.* ".
594 ", il_news_read.user_id as user_read ".
595 "FROM il_news_item LEFT JOIN il_news_read ".
596 "ON il_news_item.id = il_news_read.news_id AND ".
597 " il_news_read.user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
599 "context_obj_id = ".$ilDB->quote($this->getContextObjId(),
"integer").
600 " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(),
"text").
602 " ORDER BY creation_date DESC ";
604 $set = $ilDB->query(
$query);
606 while($rec = $ilDB->fetchAssoc($set))
609 ($rec[
"priority"] == 0 &&
611 0, $rec[
"context_obj_id"]))))
627 $a_time_period = 0, $a_starting_date =
"")
631 $ilBench->start(
"News",
"queryNewsForMultipleContexts");
634 if ($a_time_period > 0)
636 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
637 $and =
" AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp").
" ";
640 if ($a_starting_date !=
"")
642 $and.=
" AND creation_date > ".$ilDB->quote($a_starting_date,
"timestamp").
" ";
647 foreach($a_contexts as $cont)
649 $ids[] = $cont[
"obj_id"];
650 $type[$cont[
"obj_id"]] = $cont[
"obj_type"];
656 "FROM il_news_item ".
658 $ilDB->in(
"context_obj_id", $ids,
false,
"integer").
" ".
660 " ORDER BY creation_date DESC ";
664 $query =
"SELECT il_news_item.* ".
665 ", il_news_read.user_id as user_read ".
666 "FROM il_news_item LEFT JOIN il_news_read ".
667 "ON il_news_item.id = il_news_read.news_id AND ".
670 $ilDB->in(
"context_obj_id", $ids,
false,
"integer").
" ".
672 " ORDER BY creation_date DESC ";
676 $query =
"SELECT il_news_item.* ".
677 ", il_news_read.user_id as user_read ".
678 "FROM il_news_item LEFT JOIN il_news_read ".
679 "ON il_news_item.id = il_news_read.news_id AND ".
680 " il_news_read.user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
682 $ilDB->in(
"context_obj_id", $ids,
false,
"integer").
" ".
684 " ORDER BY creation_date DESC ";
687 $set = $ilDB->query(
$query);
689 while($rec = $ilDB->fetchAssoc($set))
691 if (
$type[$rec[
"context_obj_id"]] == $rec[
"context_obj_type"])
694 ($rec[
"priority"] == 0 &&
696 0, $rec[
"context_obj_id"]))))
703 $ilBench->stop(
"News",
"queryNewsForMultipleContexts");
715 global
$ilDB, $ilAppEventHandler;
717 $ilDB->manipulate(
"DELETE FROM il_news_read WHERE ".
718 "user_id = ".$ilDB->quote($a_user_id,
"integer").
719 " AND news_id = ".$ilDB->quote($a_news_id,
"integer"));
720 $ilDB->manipulate(
"INSERT INTO il_news_read (user_id, news_id) VALUES (".
721 $ilDB->quote($a_user_id,
"integer").
",".
722 $ilDB->quote($a_news_id,
"integer").
")");
724 $ilAppEventHandler->raise(
"Services/News",
"readNews",
725 array(
"user_id" => $a_user_id,
"news_ids" => array($a_news_id)));
733 global
$ilDB, $ilAppEventHandler;
735 $ilDB->manipulate(
"DELETE FROM il_news_read (user_id, news_id) VALUES (".
736 " WHERE user_id = ".$ilDB->quote($a_user_id,
"integer").
737 " AND news_id = ".$ilDB->quote($a_news_id,
"integer"));
739 $ilAppEventHandler->raise(
"Services/News",
"unreadNews",
740 array(
"user_id" => $a_user_id,
"news_ids" => array($a_news_id)));
753 foreach($n2 as
$id => $news)
770 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
773 $default_visibility = ($news_set->get(
"default_visibility") !=
"")
774 ? $news_set->get(
"default_visibility")
777 if ($tree->isInTree($a_ref_id))
779 $path = $tree->getPathFull($a_ref_id);
783 if (!in_array(
$row[
"type"], array(
"root",
"cat",
"crs",
"fold",
"grp",
"icrs")))
798 return $default_visibility;
806 public function delete()
811 $ilDB->manipulate(
"DELETE FROM il_news_read ".
812 " WHERE news_id = ".$ilDB->quote($this->getId(),
"integer"));
823 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
838 if ($a_context_obj_id == 0 || $a_context_obj_type ==
"")
844 $query =
"SELECT * FROM il_news_item".
845 " WHERE context_obj_id = ".$ilDB->quote($a_context_obj_id,
"integer").
846 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type,
"text");
848 $news_set = $ilDB->query(
$query);
850 while ($news = $ilDB->fetchAssoc($news_set))
864 $query =
"SELECT title FROM il_news_item WHERE id = ".
865 $ilDB->quote($a_news_id,
"integer");
866 $set = $ilDB->query(
$query);
867 $rec = $ilDB->fetchAssoc($set);
868 return $rec[
"title"];
878 $query =
"SELECT visibility FROM il_news_item WHERE id = ".
879 $ilDB->quote($a_news_id,
"integer");
880 $set = $ilDB->query(
$query);
881 $rec = $ilDB->fetchAssoc($set);
883 return $rec[
"visibility"];
894 if ($a_time_period > 0)
896 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
897 $and =
" AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp").
" ";
900 if ($a_starting_date !=
"")
902 $and.=
" AND creation_date >= ".$ilDB->quote($a_starting_date,
"timestamp");
905 $query =
"SELECT DISTINCT(context_obj_id) AS obj_id FROM il_news_item".
906 " WHERE ".$ilDB->in(
"context_obj_id", $a_obj_ids,
false,
"integer").
" ".$and;
909 $set = $ilDB->query(
$query);
911 while($rec = $ilDB->fetchAssoc($set))
913 $objs[] = $rec[
"obj_id"];
923 $a_agg_ref_id = 0, $a_aggregation =
"")
927 if ($a_agg_ref_id > 0)
929 $cnt = count($a_aggregation);
932 if ($a_context_obj_type ==
"frm")
936 return sprintf($lng->txt(
"news_x_postings"), $cnt);
940 return $lng->txt(
"news_1_postings");
945 $up_cnt = $cr_cnt = 0;
946 foreach($a_aggregation as $item)
948 if ($item[
"title"] ==
"file_updated")
960 $tit = $lng->txt(
"news_1_file_created");
963 else if ($cr_cnt > 1)
965 $tit = sprintf($lng->txt(
"news_x_files_created"), $cr_cnt);
970 $tit .= $sep.$lng->txt(
"news_1_file_updated");
972 else if ($up_cnt > 1)
974 $tit .= $sep.sprintf($lng->txt(
"news_x_files_updated"), $up_cnt);
981 if ($a_content_is_lang_var)
983 return $lng->txt($a_title);
999 $a_context_obj_type, $a_context_sub_obj_id =
"", $a_context_sub_obj_type =
"")
1005 "FROM il_news_item ".
1007 "context_obj_id = ".$ilDB->quote($a_context_obj_id,
"integer").
1008 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type,
"text").
1009 " AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id,
"integer").
1010 " AND ".$ilDB->equals(
"context_sub_obj_type", $a_context_sub_obj_type,
"text",
true);
1012 $set = $ilDB->query(
$query);
1013 $rec = $ilDB->fetchAssoc($set);
1026 "FROM il_news_item ".
1028 " mob_id = ".$ilDB->quote($a_mob_id,
"integer");
1031 $set = $ilDB->query(
$query);
1032 while ($rec = $ilDB->fetchAssoc($set))
1034 $usages[$rec[
"id"]] = array(
"type" =>
"news",
"id" => $rec[
"id"]);
1048 "FROM il_news_item ".
1050 " id = ".$ilDB->quote($a_news_id,
"integer");
1051 $set = $ilDB->query(
$query);
1052 $rec = $ilDB->fetchAssoc($set);
1054 return $rec[
"context_obj_id"];
1060 $per = $news_set->get(
"pd_period");
1074 $allow_shorter_periods = $news_set->get(
"allow_shorter_periods");
1075 $allow_longer_periods = $news_set->get(
"allow_longer_periods");
1078 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
1084 (!$allow_shorter_periods && ($per < $default_per)) ||
1085 (!$allow_longer_periods && ($per > $default_per))
1088 $per = $default_per;
1097 $rss_period = $news_set->get(
"rss_period");
1098 if ($rss_period == 0)