4 define(
"NEWS_NOTICE", 0);
5 define(
"NEWS_MESSAGE", 1);
6 define(
"NEWS_WARNING", 2);
8 include_once(
"./Services/News/classes/class.ilNewsItemGen.php");
35 $this->limitation =
true;
46 $this->limitation = $a_limitation;
69 $max_items = $news_set->get(
"max_items");
79 $query =
"SELECT count(*) cnt ".
87 $set = $ilDB->query(
$query);
88 $rec = $ilDB->fetchAssoc($set);
100 " ORDER BY creation_date ASC";
102 $ilDB->setLimit($rec[
"cnt"] - $max_items);
103 $del_set = $ilDB->query(
$query);
104 while ($del_item = $ilDB->fetchAssoc($del_set))
117 $a_prevent_aggregation =
false, $a_per = 0, &$a_cnt = NULL)
119 global $ilAccess, $ilUser;
126 include_once(
"./Services/News/classes/class.ilNewsSubscription.php");
127 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
136 foreach($pd_items as $item)
138 if (!in_array($item[
"ref_id"], $ref_ids))
140 $ref_ids[] = $item[
"ref_id"];
152 $acc = $ilAccess->checkAccess(
"read",
"", $ref_id);
171 $news = $news_item->getNewsForRefId($ref_id, $a_only_public,
false,
172 $per, $a_prevent_aggregation);
175 if (!is_null($a_cnt))
177 $a_cnt[
$ref_id] = count($news);
192 $a_time_period = 0, $a_prevent_aggregation =
true, $a_forum_group_sequences =
false,
193 $a_no_auto_generated =
false, $a_ignore_date_filter =
false)
200 if ($obj_type ==
"grp" || $obj_type ==
"crs" || $obj_type ==
"cat")
202 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
205 if ($hide_news_per_date && !$a_ignore_date_filter)
212 if ($obj_type ==
"cat" && !$a_stopnesting)
215 $a_prevent_aggregation, $starting_date, $a_no_auto_generated);
217 else if (($obj_type ==
"grp" || $obj_type ==
"crs") &&
221 $a_prevent_aggregation, $starting_date, $a_no_auto_generated);
226 $news_item->setContextObjId($obj_id);
227 $news_item->setContextObjType($obj_type);
228 $news = $news_item->queryNewsForContext($a_only_public, $a_time_period,
229 $starting_date, $a_no_auto_generated);
231 foreach ($news as $k => $v)
233 if (!$a_only_public || $v[
"visibility"] ==
NEWS_PUBLIC ||
234 ($v[
"priority"] == 0 &&
238 $news[$k][
"ref_id"] = $a_ref_id;
245 foreach ($unset as $un)
258 $a_prevent_aggregation =
false, $a_starting_date =
"", $a_no_auto_generated =
false)
260 global $tree, $ilAccess, $ilObjDataCache;
267 $cur_node = $tree->getNodeData($a_ref_id);
269 if ($cur_node[
"lft"] !=
"")
271 $nodes = $tree->getSubTree($cur_node,
true);
281 foreach($nodes as $node)
283 $ref_ids[] = $node[
"child"];
284 $obj_ids[] = $node[
"obj_id"];
287 $ilObjDataCache->preloadReferenceCache($ref_ids);
290 $ilAccess->preloadActivationTimes($ref_ids);
299 foreach($nodes as $node)
302 if (!in_array($node[
"obj_id"], $news_obj_ids))
309 $acc = $ilAccess->checkAccess(
"read",
"", $node[
"child"]);
317 $ref_id[$node[
"obj_id"]] = $node[
"child"];
318 $contexts[] = array(
"obj_id" => $node[
"obj_id"],
319 "obj_type" => $node[
"type"]);
324 $a_starting_date, $a_no_auto_generated);
327 foreach ($news as $k => $v)
329 $news[$k][
"ref_id"] =
$ref_id[$v[
"context_obj_id"]];
335 if (!$a_prevent_aggregation)
347 foreach ($news as $k => $v)
350 if ($news[$k][
"context_obj_type"] ==
"file")
352 if ($first_file ==
"")
360 $news[$first_file][
"aggregation"][$k] = $news[$k];
361 $news[$first_file][
"agg_ref_id"] = $a_ref_id;
362 $news[$first_file][
"ref_id"] = $a_ref_id;
366 foreach($to_del as $v)
379 $a_time_period = 0, $a_prevent_aggregation =
false, $a_starting_date =
"",
380 $a_no_auto_generated =
false)
382 global $tree, $ilAccess;
386 true,
false,
false, $a_no_auto_generated);
387 foreach (
$data as $k => $v)
389 $data[$k][
"ref_id"] = $a_ref_id;
393 $nodes = $tree->getChilds($a_ref_id);
397 foreach($nodes as $node)
399 $obj_ids[] = $node[
"obj_id"];
406 foreach($nodes as $node)
409 if (!in_array($node[
"obj_id"], $news_obj_ids))
414 if (!$a_only_public && !$ilAccess->checkAccess(
"read",
"", $node[
"child"]))
418 $ref_id[$node[
"obj_id"]] = $node[
"child"];
419 $contexts[] = array(
"obj_id" => $node[
"obj_id"],
420 "obj_type" => $node[
"type"]);
424 $a_starting_date, $a_no_auto_generated);
425 foreach ($news as $k => $v)
427 $news[$k][
"ref_id"] =
$ref_id[$v[
"context_obj_id"]];
434 if (!$a_prevent_aggregation)
445 function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type =
"")
462 $a_starting_date =
"", $a_no_auto_generated =
false, $a_oldest_first =
false)
467 if ($a_time_period > 0)
469 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
470 $and =
" AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp").
" ";
473 if ($a_starting_date !=
"")
475 $and.=
" AND creation_date > ".$ilDB->quote($a_starting_date,
"timestamp").
" ";
478 if ($a_no_auto_generated)
480 $and.=
" AND priority = 1 AND content_type = ".$ilDB->quote(
"text",
"text").
" ";
486 $and.=
" AND context_sub_obj_id = ".$ilDB->quote($this->
getContextSubObjId(),
"integer").
490 $ordering = ($a_oldest_first)
491 ?
" creation_date ASC, id ASC "
492 :
" creation_date DESC, id DESC ";
497 "FROM il_news_item ".
502 " ORDER BY ".$ordering;
506 $query =
"SELECT il_news_item.* ".
507 ", il_news_read.user_id user_read ".
508 "FROM il_news_item LEFT JOIN il_news_read ".
509 "ON il_news_item.id = il_news_read.news_id AND ".
515 " ORDER BY ".$ordering;
519 $query =
"SELECT il_news_item.* ".
520 ", il_news_read.user_id as user_read ".
521 "FROM il_news_item LEFT JOIN il_news_read ".
522 "ON il_news_item.id = il_news_read.news_id AND ".
523 " il_news_read.user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
525 "context_obj_id = ".$ilDB->quote($this->getContextObjId(),
"integer").
526 " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(),
"text").
528 " ORDER BY ".$ordering;
531 $set = $ilDB->query(
$query);
533 while($rec = $ilDB->fetchAssoc($set))
536 ($rec[
"priority"] == 0 &&
538 0, $rec[
"context_obj_id"]))))
540 $result[$rec[
"id"]] = $rec;
554 $a_time_period = 0, $a_starting_date =
"", $a_no_auto_generated =
false)
559 if ($a_time_period > 0)
561 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
562 $and =
" AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp").
" ";
565 if ($a_starting_date !=
"")
567 $and.=
" AND creation_date > ".$ilDB->quote($a_starting_date,
"timestamp").
" ";
570 if ($a_no_auto_generated)
572 $and.=
" AND priority = 1 AND content_type = ".$ilDB->quote(
"text",
"text").
" ";
577 foreach($a_contexts as $cont)
579 $ids[] = $cont[
"obj_id"];
580 $type[$cont[
"obj_id"]] = $cont[
"obj_type"];
586 "FROM il_news_item ".
588 $ilDB->in(
"context_obj_id", $ids,
false,
"integer").
" ".
590 " ORDER BY creation_date DESC ";
594 $query =
"SELECT il_news_item.* ".
595 ", il_news_read.user_id as user_read ".
596 "FROM il_news_item LEFT JOIN il_news_read ".
597 "ON il_news_item.id = il_news_read.news_id AND ".
600 $ilDB->in(
"context_obj_id", $ids,
false,
"integer").
" ".
602 " ORDER BY creation_date DESC ";
606 $query =
"SELECT il_news_item.* ".
607 ", il_news_read.user_id as user_read ".
608 "FROM il_news_item LEFT JOIN il_news_read ".
609 "ON il_news_item.id = il_news_read.news_id AND ".
610 " il_news_read.user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
612 $ilDB->in(
"context_obj_id", $ids,
false,
"integer").
" ".
614 " ORDER BY creation_date DESC ";
617 $set = $ilDB->query(
$query);
619 while($rec = $ilDB->fetchAssoc($set))
621 if (
$type[$rec[
"context_obj_id"]] == $rec[
"context_obj_type"])
624 ($rec[
"priority"] == 0 &&
626 0, $rec[
"context_obj_id"]))))
628 $result[$rec[
"id"]] = $rec;
643 global
$ilDB, $ilAppEventHandler;
645 $ilDB->manipulate(
"DELETE FROM il_news_read WHERE ".
646 "user_id = ".$ilDB->quote($a_user_id,
"integer").
647 " AND news_id = ".$ilDB->quote($a_news_id,
"integer"));
648 $ilDB->manipulate(
"INSERT INTO il_news_read (user_id, news_id) VALUES (".
649 $ilDB->quote($a_user_id,
"integer").
",".
650 $ilDB->quote($a_news_id,
"integer").
")");
652 $ilAppEventHandler->raise(
"Services/News",
"readNews",
653 array(
"user_id" => $a_user_id,
"news_ids" => array($a_news_id)));
661 global
$ilDB, $ilAppEventHandler;
663 $ilDB->manipulate(
"DELETE FROM il_news_read (user_id, news_id) VALUES (".
664 " WHERE user_id = ".$ilDB->quote($a_user_id,
"integer").
665 " AND news_id = ".$ilDB->quote($a_news_id,
"integer"));
667 $ilAppEventHandler->raise(
"Services/News",
"unreadNews",
668 array(
"user_id" => $a_user_id,
"news_ids" => array($a_news_id)));
681 foreach($n2 as
$id => $news)
698 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
701 $default_visibility = ($news_set->get(
"default_visibility") !=
"")
702 ? $news_set->get(
"default_visibility")
705 if ($tree->isInTree($a_ref_id))
707 $path = $tree->getPathFull($a_ref_id);
711 if (!in_array(
$row[
"type"], array(
"root",
"cat",
"crs",
"fold",
"grp",
"icrs")))
726 return $default_visibility;
734 public function delete()
739 $ilDB->manipulate(
"DELETE FROM il_news_read ".
740 " WHERE news_id = ".$ilDB->quote($this->getId(),
"integer"));
751 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
762 $a_context_obj_type, $a_context_sub_obj_id = 0, $a_context_sub_obj_type =
"")
766 if ($a_context_obj_id == 0 || $a_context_obj_type ==
"")
771 if ($a_context_sub_obj_id > 0)
773 $and =
" AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id,
"integer").
774 " AND context_sub_obj_type = ".$ilDB->quote($a_context_sub_obj_type,
"text");
778 $query =
"SELECT * FROM il_news_item".
779 " WHERE context_obj_id = ".$ilDB->quote($a_context_obj_id,
"integer").
780 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type,
"text").
783 $news_set = $ilDB->query(
$query);
785 while ($news = $ilDB->fetchAssoc($news_set))
799 $query =
"SELECT title FROM il_news_item WHERE id = ".
800 $ilDB->quote($a_news_id,
"integer");
801 $set = $ilDB->query(
$query);
802 $rec = $ilDB->fetchAssoc($set);
803 return $rec[
"title"];
813 $query =
"SELECT visibility FROM il_news_item WHERE id = ".
814 $ilDB->quote($a_news_id,
"integer");
815 $set = $ilDB->query(
$query);
816 $rec = $ilDB->fetchAssoc($set);
818 return $rec[
"visibility"];
828 $query =
"SELECT mob_id FROM il_news_item WHERE id = ".
829 $ilDB->quote($a_news_id,
"integer");
830 $set = $ilDB->query(
$query);
831 $rec = $ilDB->fetchAssoc($set);
832 return $rec[
"mob_id"];
838 static function filterObjIdsPerNews($a_obj_ids, $a_time_period = 0, $a_starting_date =
"",$a_ending_date =
'', $ignore_period =
false)
843 if ($a_time_period > 0)
845 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
846 $and =
" AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp").
" ";
849 if ($a_starting_date !=
"")
851 $and.=
" AND creation_date >= ".$ilDB->quote($a_starting_date,
"timestamp");
854 $query =
"SELECT DISTINCT(context_obj_id) AS obj_id FROM il_news_item".
855 " WHERE ".$ilDB->in(
"context_obj_id", $a_obj_ids,
false,
"integer").
" ".$and;
858 $set = $ilDB->query(
$query);
860 while($rec = $ilDB->fetchAssoc($set))
862 $objs[] = $rec[
"obj_id"];
872 $a_agg_ref_id = 0, $a_aggregation =
"")
876 if ($a_agg_ref_id > 0)
878 $cnt = count($a_aggregation);
880 $up_cnt = $cr_cnt = 0;
881 foreach($a_aggregation as $item)
883 if ($item[
"title"] ==
"file_updated")
895 $tit = $lng->txt(
"news_1_file_created");
898 else if ($cr_cnt > 1)
900 $tit = sprintf($lng->txt(
"news_x_files_created"), $cr_cnt);
905 $tit .= $sep.$lng->txt(
"news_1_file_updated");
907 else if ($up_cnt > 1)
909 $tit .= $sep.sprintf($lng->txt(
"news_x_files_updated"), $up_cnt);
915 if ($a_content_is_lang_var)
917 return $lng->txt($a_title);
933 $a_context_obj_type, $a_context_sub_obj_id =
"", $a_context_sub_obj_type =
"")
939 "FROM il_news_item ".
941 "context_obj_id = ".$ilDB->quote($a_context_obj_id,
"integer").
942 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type,
"text").
943 " AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id,
"integer").
944 " AND ".$ilDB->equals(
"context_sub_obj_type", $a_context_sub_obj_type,
"text",
true);
946 $set = $ilDB->query(
$query);
947 $rec = $ilDB->fetchAssoc($set);
960 "FROM il_news_item ".
962 " mob_id = ".$ilDB->quote($a_mob_id,
"integer");
965 $set = $ilDB->query(
$query);
966 while ($rec = $ilDB->fetchAssoc($set))
968 $usages[$rec[
"id"]] = array(
"type" =>
"news",
"id" => $rec[
"id"]);
982 "FROM il_news_item ".
984 " id = ".$ilDB->quote($a_news_id,
"integer");
985 $set = $ilDB->query(
$query);
986 $rec = $ilDB->fetchAssoc($set);
988 return $rec[
"context_obj_id"];
994 $per = $news_set->get(
"pd_period");
1008 $allow_shorter_periods = $news_set->get(
"allow_shorter_periods");
1009 $allow_longer_periods = $news_set->get(
"allow_longer_periods");
1012 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
1018 (!$allow_shorter_periods && ($per < $default_per)) ||
1019 (!$allow_longer_periods && ($per > $default_per))
1022 $per = $default_per;
1031 $rss_period = $news_set->get(
"rss_period");
1032 if ($rss_period == 0)