24 define(
"NEWS_NOTICE", 0);
25 define(
"NEWS_MESSAGE", 1);
26 define(
"NEWS_WARNING", 2);
28 include_once(
"./Services/News/classes/class.ilNewsItemGen.php");
56 $this->limitation =
true;
67 $this->limitation = $a_limitation;
90 $max_items = $news_set->get(
"max_items");
100 $query =
"SELECT count(*) AS cnt ".
101 "FROM il_news_item ".
108 $set = $ilDB->query($query);
114 $query =
"SELECT * ".
115 "FROM il_news_item ".
121 " ORDER BY creation_date ASC".
122 " LIMIT ".($rec[
"cnt"] - $max_items);
124 $del_set = $ilDB->query($query);
138 $a_prevent_aggregation =
false, $a_per = 0, &$a_cnt = NULL)
140 global $ilAccess, $ilUser,
$ilBench;
142 $ilBench->start(
"News",
"getNewsItemsOfUser");
149 include_once(
"./Services/News/classes/class.ilNewsSubscription.php");
150 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
153 $ilBench->start(
"News",
"getNewsItemsOfUser_getRefIds");
160 foreach($pd_items as $item)
162 if (!in_array($item[
"ref_id"], $ref_ids))
164 $ref_ids[] = $item[
"ref_id"];
168 $ilBench->stop(
"News",
"getNewsItemsOfUser_getRefIds");
174 $ilBench->start(
"News",
"getNewsForRefId");
178 $ilBench->start(
"News",
"getAggregatedNewsData_getContexts_checkAccess");
179 $acc = $ilAccess->checkAccess(
"read",
"", $ref_id);
180 $ilBench->stop(
"News",
"getAggregatedNewsData_getContexts_checkAccess");
197 $ilBench->start(
"News",
"getNewsForRefId_getNews");
200 $news = $news_item->getNewsForRefId($ref_id, $a_only_public,
false,
201 $per, $a_prevent_aggregation);
202 $ilBench->stop(
"News",
"getNewsForRefId_getNews");
205 if (!is_null($a_cnt))
207 $a_cnt[
$ref_id] = count($news);
210 $ilBench->start(
"News",
"getNewsForRefId_mergeNews");
212 $ilBench->stop(
"News",
"getNewsForRefId_mergeNews");
214 $ilBench->stop(
"News",
"getNewsForRefId");
219 $ilBench->stop(
"News",
"getNewsItemsOfUser");
229 $a_time_period = 0, $a_prevent_aggregation =
true, $a_forum_group_sequences =
false)
236 if ($obj_type ==
"grp" || $obj_type ==
"crs" || $obj_type ==
"cat")
238 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
241 if ($hide_news_per_date)
248 if ($obj_type ==
"cat" && !$a_stopnesting)
251 $a_prevent_aggregation, $starting_date);
253 else if (($obj_type ==
"grp" || $obj_type ==
"crs") &&
257 $a_prevent_aggregation, $starting_date);
262 $news_item->setContextObjId($obj_id);
263 $news_item->setContextObjType($obj_type);
264 $news = $news_item->queryNewsForContext($a_only_public, $a_time_period,
267 foreach ($news as $k => $v)
269 if (!$a_only_public || $v[
"visibility"] ==
NEWS_PUBLIC ||
270 ($v[
"priority"] == 0 &&
274 $news[$k][
"ref_id"] = $a_ref_id;
281 foreach ($unset as $un)
287 if (!$a_prevent_aggregation)
291 else if ($a_forum_group_sequences)
303 $a_prevent_aggregation =
false, $a_starting_date =
"")
305 global $tree, $ilAccess,
$ilBench, $ilObjDataCache;
307 $ilBench->start(
"News",
"getAggregatedNewsData");
314 $ilBench->start(
"News",
"getAggregatedNewsData_getSubTree");
315 $cur_node = $tree->getNodeData($a_ref_id);
317 if ($cur_node[
"lft"] !=
"")
319 $nodes = $tree->getSubTree($cur_node,
true);
329 foreach($nodes as $node)
331 $ref_ids[] = $node[
"child"];
332 $obj_ids[] = $node[
"obj_id"];
334 $ilBench->stop(
"News",
"getAggregatedNewsData_getSubTree");
336 $ilBench->start(
"News",
"getAggregatedNewsData_preloadActivationTimes");
337 $ilObjDataCache->preloadReferenceCache($ref_ids);
340 $ilAccess->preloadActivationTimes($ref_ids);
342 $ilBench->stop(
"News",
"getAggregatedNewsData_preloadActivationTimes");
349 $ilBench->start(
"News",
"getAggregatedNewsData_getContexts");
351 foreach($nodes as $node)
354 if (!in_array($node[
"obj_id"], $news_obj_ids))
361 $ilBench->start(
"News",
"getAggregatedNewsData_getContexts_checkAccess");
362 $acc = $ilAccess->checkAccess(
"read",
"", $node[
"child"]);
363 $ilBench->stop(
"News",
"getAggregatedNewsData_getContexts_checkAccess");
371 $ref_id[$node[
"obj_id"]] = $node[
"child"];
372 $contexts[] = array(
"obj_id" => $node[
"obj_id"],
373 "obj_type" => $node[
"type"]);
375 $ilBench->stop(
"News",
"getAggregatedNewsData_getContexts");
381 $ilBench->start(
"News",
"getAggregatedNewsData_mergeAndSort");
384 foreach ($news as $k => $v)
386 $news[$k][
"ref_id"] =
$ref_id[$v[
"context_obj_id"]];
392 if (!$a_prevent_aggregation)
399 $ilBench->stop(
"News",
"getAggregatedNewsData_mergeAndSort");
400 $ilBench->stop(
"News",
"getAggregatedNewsData");
411 foreach ($news as $k => $v)
413 if ($a_group_posting_sequence && $last_aggregation_forum > 0 &&
414 $last_aggregation_forum != $news[$k][
"context_obj_id"])
416 $forums[$last_aggregation_forum] =
"";
419 if ($news[$k][
"context_obj_type"] ==
"frm")
421 if ($forums[$news[$k][
"context_obj_id"]] ==
"")
424 $forums[$news[$k][
"context_obj_id"]] = $k;
425 $last_aggregation_forum = $news[$k][
"context_obj_id"];
432 $news[$k][
"no_context_title"] =
true;
435 $news[$forums[$news[$k][
"context_obj_id"]]][
"aggregation"][$k]
437 $news[$k][
"agg_ref_id"]
438 = $news[$k][
"ref_id"];
439 $news[$k][
"content"] =
"";
440 $news[$k][
"content_long"] =
"";
445 foreach($to_del as $k)
459 foreach ($news as $k => $v)
462 if ($news[$k][
"context_obj_type"] ==
"file")
464 if ($first_file ==
"")
472 $news[$first_file][
"aggregation"][$k] = $news[$k];
473 $news[$first_file][
"agg_ref_id"] = $a_ref_id;
474 $news[$first_file][
"ref_id"] = $a_ref_id;
478 foreach($to_del as $v)
491 $a_time_period = 0, $a_prevent_aggregation =
false, $a_starting_date =
"")
495 $ilBench->start(
"News",
"getAggregatedChildNewsData");
499 foreach (
$data as $k => $v)
501 $data[$k][
"ref_id"] = $a_ref_id;
505 $nodes = $tree->getChilds($a_ref_id);
509 foreach($nodes as $node)
511 $obj_ids[] = $node[
"obj_id"];
518 foreach($nodes as $node)
521 if (!in_array($node[
"obj_id"], $news_obj_ids))
526 if (!$a_only_public && !$ilAccess->checkAccess(
"read",
"", $node[
"child"]))
530 $ref_id[$node[
"obj_id"]] = $node[
"child"];
531 $contexts[] = array(
"obj_id" => $node[
"obj_id"],
532 "obj_type" => $node[
"type"]);
537 foreach ($news as $k => $v)
539 $news[$k][
"ref_id"] =
$ref_id[$v[
"context_obj_id"]];
546 if (!$a_prevent_aggregation)
551 $ilBench->stop(
"News",
"getAggregatedChildNewsData");
559 function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type =
"")
572 $a_starting_date =
"")
574 global $ilDB, $ilUser,
$lng;
576 $and = ($a_time_period > 0)
577 ?
" AND (TO_DAYS(now()) - TO_DAYS(creation_date)) <= ".((
int)$a_time_period)
580 if ($a_starting_date !=
"")
582 $and.=
" AND creation_date > ".$ilDB->quote($a_starting_date).
" ";
587 $query =
"SELECT * ".
588 "FROM il_news_item ".
593 " ORDER BY creation_date DESC ";
597 $query =
"SELECT il_news_item.* ".
598 ", il_news_read.user_id as user_read ".
599 "FROM il_news_item LEFT JOIN il_news_read ".
600 "ON il_news_item.id = il_news_read.news_id AND ".
601 " il_news_read.user_id = ".ilNewsItem::getPrivateFeedId().
606 " ORDER BY creation_date DESC ";
610 $query =
"SELECT il_news_item.* ".
611 ", il_news_read.user_id as user_read ".
612 "FROM il_news_item LEFT JOIN il_news_read ".
613 "ON il_news_item.id = il_news_read.news_id AND ".
614 " il_news_read.user_id = ".$ilDB->quote($ilUser->getId()).
616 "context_obj_id = ".$ilDB->quote($this->getContextObjId()).
617 " AND context_obj_type = ".$ilDB->quote($this->getContextObjType()).
619 " ORDER BY creation_date DESC ";
621 $set = $ilDB->query($query);
626 ($rec[
"priority"] == 0 &&
628 0, $rec[
"context_obj_id"]))))
644 $a_time_period = 0, $a_starting_date =
"")
648 $ilBench->start(
"News",
"queryNewsForMultipleContexts");
650 $and = ($a_time_period > 0)
651 ?
" AND (TO_DAYS(now()) - TO_DAYS(creation_date)) <= ".((
int)$a_time_period)
654 if ($a_starting_date !=
"")
656 $and.=
" AND creation_date > ".$ilDB->quote($a_starting_date).
" ";
661 foreach($a_contexts as $cont)
663 $ids[] = $cont[
"obj_id"];
664 $type[$cont[
"obj_id"]] = $cont[
"obj_type"];
669 $query =
"SELECT * ".
670 "FROM il_news_item ".
674 " ORDER BY creation_date DESC ";
678 $query =
"SELECT il_news_item.* ".
679 ", il_news_read.user_id as user_read ".
680 "FROM il_news_item LEFT JOIN il_news_read ".
681 "ON il_news_item.id = il_news_read.news_id AND ".
682 " il_news_read.user_id = ".ilNewsItem::getPrivateFeedId().
686 " ORDER BY creation_date DESC ";
690 $query =
"SELECT il_news_item.* ".
691 ", il_news_read.user_id as user_read ".
692 "FROM il_news_item LEFT JOIN il_news_read ".
693 "ON il_news_item.id = il_news_read.news_id AND ".
694 " il_news_read.user_id = ".$ilDB->quote($ilUser->getId()).
698 " ORDER BY creation_date DESC ";
701 $set = $ilDB->query($query);
705 if ($type[$rec[
"context_obj_id"]] == $rec[
"context_obj_type"])
708 ($rec[
"priority"] == 0 &&
710 0, $rec[
"context_obj_id"]))))
717 $ilBench->stop(
"News",
"queryNewsForMultipleContexts");
729 global $ilDB, $ilAppEventHandler;
731 $q =
"REPLACE INTO il_news_read (user_id, news_id) VALUES (".
732 $ilDB->quote($a_user_id).
",".$ilDB->quote($a_news_id).
")";
735 $ilAppEventHandler->raise(
"Services/News",
"readNews",
736 array(
"user_id" => $a_user_id,
"news_ids" => array($a_news_id)));
744 global $ilDB, $ilAppEventHandler;
746 $q =
"DELETE FROM il_news_read (user_id, news_id) VALUES (".
747 " WHERE user_id = ".$ilDB->quote($a_user_id).
748 " AND news_id = ".$ilDB->quote($a_news_id);
751 $ilAppEventHandler->raise(
"Services/News",
"unreadNews",
752 array(
"user_id" => $a_user_id,
"news_ids" => array($a_news_id)));
765 foreach($n2 as
$id => $news)
782 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
785 $default_visibility = ($news_set->get(
"default_visibility") !=
"")
786 ? $news_set->get(
"default_visibility")
789 if ($tree->isInTree($a_ref_id))
791 $path = $tree->getPathFull($a_ref_id);
793 foreach ($path as $key => $row)
795 if (!in_array($row[
"type"], array(
"root",
"cat",
"crs",
"fold",
"grp",
"icrs")))
810 return $default_visibility;
818 public function delete()
823 $query =
"DELETE FROM il_news_read ".
824 " WHERE news_id = ".$ilDB->quote($this->
getId());
825 $ilDB->query($query);
836 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
851 if ($a_context_obj_id == 0 || $a_context_obj_type ==
"")
857 $query =
"SELECT * FROM il_news_item".
858 " WHERE context_obj_id = ".$ilDB->quote($a_context_obj_id).
859 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type);
861 $news_set = $ilDB->query($query);
877 $query =
"SELECT title FROM il_news_item WHERE id = ".
878 $ilDB->quote($a_news_id);
879 $set = $ilDB->query($query);
881 return $rec[
"title"];
891 $query =
"SELECT visibility FROM il_news_item WHERE id = ".
892 $ilDB->quote($a_news_id);
893 $set = $ilDB->query($query);
896 return $rec[
"visibility"];
906 $and = ($a_time_period > 0)
907 ?
" AND (TO_DAYS(now()) - TO_DAYS(creation_date)) <= ".((
int)$a_time_period)
910 if ($a_starting_date !=
"")
912 $and.=
" AND creation_date >= ".$ilDB->quote($a_starting_date);
915 $query =
"SELECT DISTINCT(context_obj_id) AS obj_id FROM il_news_item".
918 $set = $ilDB->query($query);
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 =
"")
1013 $query =
"SELECT * ".
1014 "FROM il_news_item ".
1016 "context_obj_id = ".$ilDB->quote($a_context_obj_id).
1017 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type).
1018 " AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id).
1019 " AND context_sub_obj_type = ".$ilDB->quote($a_context_sub_obj_type);
1021 $set = $ilDB->query($query);
1034 $query =
"SELECT * ".
1035 "FROM il_news_item ".
1037 " mob_id = ".$ilDB->quote($a_mob_id);
1040 $set = $ilDB->query($query);
1043 $usages[$rec[
"id"]] = array(
"type" =>
"news",
"id" => $rec[
"id"]);
1056 $query =
"SELECT * ".
1057 "FROM il_news_item ".
1059 " id = ".$ilDB->quote($a_news_id);
1060 $set = $ilDB->query($query);
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)