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;
67 $this->content_text_is_lang_var = $a_val;
77 return $this->content_text_is_lang_var;
88 $query =
"SELECT * FROM il_news_item WHERE id = ".
89 $ilDB->quote($this->
getId(),
"integer");
90 $set = $ilDB->query(
$query);
91 $rec = $ilDB->fetchAssoc($set);
121 $this->
setId($ilDB->nextId(
"il_news_item"));
122 $ilDB->insert(
"il_news_item", array(
123 "id" => array(
"integer", $this->
getId()),
124 "title" => array(
"text", $this->
getTitle()),
125 "content" => array(
"clob", $this->
getContent()),
131 "creation_date" => array(
"timestamp",
ilUtil::now()),
132 "update_date" => array(
"timestamp",
ilUtil::now()),
133 "user_id" => array(
"integer", $this->
getUserId()),
136 "priority" => array(
"integer", $this->
getPriority()),
139 "mob_id" => array(
"integer", $this->
getMobId()),
145 $max_items = $news_set->get(
"max_items");
155 $query =
"SELECT count(*) cnt ".
156 "FROM il_news_item ".
163 $set = $ilDB->query(
$query);
164 $rec = $ilDB->fetchAssoc($set);
170 "FROM il_news_item ".
176 " ORDER BY creation_date ASC";
178 $ilDB->setLimit($rec[
"cnt"] - $max_items);
179 $del_set = $ilDB->query(
$query);
180 while ($del_item = $ilDB->fetchAssoc($del_set))
194 public function update($a_as_new =
false)
199 "title" => array(
"text", $this->
getTitle()),
200 "content" => array(
"clob", $this->
getContent()),
206 "user_id" => array(
"integer", $this->
getUserId()),
209 "priority" => array(
"integer", $this->
getPriority()),
212 "mob_id" => array(
"integer", $this->
getMobId()),
219 $fields[
"creation_date"] = array(
"timestamp", $now);
220 $fields[
"update_date"] = array(
"timestamp", $now);
224 $fields[
"update_date"] = array(
"timestamp", $now);
227 $ilDB->update(
"il_news_item", $fields, array(
228 "id" => array(
"integer", $this->
getId())
238 $a_prevent_aggregation =
false, $a_per = 0, &$a_cnt = NULL)
240 global $ilAccess, $ilUser;
247 include_once(
"./Services/News/classes/class.ilNewsSubscription.php");
248 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
257 foreach($pd_items as $item)
259 if (!in_array($item[
"ref_id"], $ref_ids))
261 $ref_ids[] = $item[
"ref_id"];
273 $acc = $ilAccess->checkAccess(
"read",
"", $ref_id);
292 $news = $news_item->getNewsForRefId($ref_id, $a_only_public,
false,
293 $per, $a_prevent_aggregation);
296 if (!is_null($a_cnt))
298 $a_cnt[
$ref_id] = count($news);
315 $a_time_period = 0, $a_prevent_aggregation =
true, $a_forum_group_sequences =
false,
316 $a_no_auto_generated =
false, $a_ignore_date_filter =
false, $a_user_id = null)
323 if ($obj_type ==
"grp" || $obj_type ==
"crs" || $obj_type ==
"cat")
325 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
328 if ($hide_news_per_date && !$a_ignore_date_filter)
335 if ($obj_type ==
"cat" && !$a_stopnesting)
338 $a_prevent_aggregation, $starting_date, $a_no_auto_generated);
340 else if (($obj_type ==
"grp" || $obj_type ==
"crs") &&
344 $a_prevent_aggregation, $starting_date, $a_no_auto_generated, $a_user_id);
349 $news_item->setContextObjId($obj_id);
350 $news_item->setContextObjType($obj_type);
351 $news = $news_item->queryNewsForContext($a_only_public, $a_time_period,
352 $starting_date, $a_no_auto_generated);
354 foreach ($news as $k => $v)
356 if (!$a_only_public || $v[
"visibility"] ==
NEWS_PUBLIC ||
357 ($v[
"priority"] == 0 &&
361 $news[$k][
"ref_id"] = $a_ref_id;
368 foreach ($unset as $un)
374 if (!$a_prevent_aggregation)
378 else if ($a_forum_group_sequences)
390 $a_prevent_aggregation =
false, $a_starting_date =
"", $a_no_auto_generated =
false,
393 global $tree, $ilAccess, $ilObjDataCache;
400 $cur_node = $tree->getNodeData($a_ref_id);
402 if ($cur_node[
"lft"] !=
"")
404 $nodes = $tree->getSubTree($cur_node,
true);
414 foreach($nodes as $node)
416 $ref_ids[] = $node[
"child"];
417 $obj_ids[] = $node[
"obj_id"];
420 $ilObjDataCache->preloadReferenceCache($ref_ids);
423 $ilAccess->preloadActivationTimes($ref_ids);
432 foreach($nodes as $node)
435 if (!in_array($node[
"obj_id"], $news_obj_ids))
444 $acc = $ilAccess->checkAccess(
"read",
"", $node[
"child"]);
448 $acc = $ilAccess->checkAccessOfUser($a_user_id,
"read",
"",
457 $ref_id[$node[
"obj_id"]] = $node[
"child"];
458 $contexts[] = array(
"obj_id" => $node[
"obj_id"],
459 "obj_type" => $node[
"type"]);
464 $a_starting_date, $a_no_auto_generated, $a_user_id);
467 foreach ($news as $k => $v)
469 $news[$k][
"ref_id"] =
$ref_id[$v[
"context_obj_id"]];
475 if (!$a_prevent_aggregation)
489 foreach ($news as $k => $v)
491 if ($a_group_posting_sequence && $last_aggregation_forum > 0 &&
492 $last_aggregation_forum != $news[$k][
"context_obj_id"])
494 $forums[$last_aggregation_forum] =
"";
497 if ($news[$k][
"context_obj_type"] ==
"frm")
499 if ($forums[$news[$k][
"context_obj_id"]] ==
"")
502 $forums[$news[$k][
"context_obj_id"]] = $k;
503 $last_aggregation_forum = $news[$k][
"context_obj_id"];
510 $news[$k][
"no_context_title"] =
true;
513 $news[$forums[$news[$k][
"context_obj_id"]]][
"aggregation"][$k]
515 $news[$k][
"agg_ref_id"]
516 = $news[$k][
"ref_id"];
517 $news[$k][
"content"] =
"";
518 $news[$k][
"content_long"] =
"";
523 foreach($to_del as $k)
537 foreach ($news as $k => $v)
540 if ($news[$k][
"context_obj_type"] ==
"file")
542 if ($first_file ==
"")
550 $news[$first_file][
"aggregation"][$k] = $news[$k];
551 $news[$first_file][
"agg_ref_id"] = $a_ref_id;
552 $news[$first_file][
"ref_id"] = $a_ref_id;
556 foreach($to_del as $v)
569 $a_time_period = 0, $a_prevent_aggregation =
false, $a_starting_date =
"",
570 $a_no_auto_generated =
false)
572 global $tree, $ilAccess;
576 true,
false,
false, $a_no_auto_generated);
577 foreach (
$data as $k => $v)
579 $data[$k][
"ref_id"] = $a_ref_id;
583 $nodes = $tree->getChilds($a_ref_id);
587 foreach($nodes as $node)
589 $obj_ids[] = $node[
"obj_id"];
596 foreach($nodes as $node)
599 if (!in_array($node[
"obj_id"], $news_obj_ids))
604 if (!$a_only_public && !$ilAccess->checkAccess(
"read",
"", $node[
"child"]))
608 $ref_id[$node[
"obj_id"]] = $node[
"child"];
609 $contexts[] = array(
"obj_id" => $node[
"obj_id"],
610 "obj_type" => $node[
"type"]);
614 $a_starting_date, $a_no_auto_generated);
615 foreach ($news as $k => $v)
617 $news[$k][
"ref_id"] =
$ref_id[$v[
"context_obj_id"]];
624 if (!$a_prevent_aggregation)
635 function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type =
"")
652 $a_starting_date =
"", $a_no_auto_generated =
false, $a_oldest_first =
false)
657 if ($a_time_period > 0)
659 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
660 $and =
" AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp").
" ";
663 if ($a_starting_date !=
"")
665 $and.=
" AND creation_date > ".$ilDB->quote($a_starting_date,
"timestamp").
" ";
668 if ($a_no_auto_generated)
670 $and.=
" AND priority = 1 AND content_type = ".$ilDB->quote(
"text",
"text").
" ";
676 $and.=
" AND context_sub_obj_id = ".$ilDB->quote($this->
getContextSubObjId(),
"integer").
680 $ordering = ($a_oldest_first)
681 ?
" creation_date ASC, id ASC "
682 :
" creation_date DESC, id DESC ";
687 "FROM il_news_item ".
692 " ORDER BY ".$ordering;
696 $query =
"SELECT il_news_item.* ".
697 ", il_news_read.user_id user_read ".
698 "FROM il_news_item LEFT JOIN il_news_read ".
699 "ON il_news_item.id = il_news_read.news_id AND ".
705 " ORDER BY ".$ordering;
709 $query =
"SELECT il_news_item.* ".
710 ", il_news_read.user_id as user_read ".
711 "FROM il_news_item LEFT JOIN il_news_read ".
712 "ON il_news_item.id = il_news_read.news_id AND ".
713 " il_news_read.user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
715 "context_obj_id = ".$ilDB->quote($this->getContextObjId(),
"integer").
716 " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(),
"text").
718 " ORDER BY ".$ordering;
721 $set = $ilDB->query(
$query);
723 while($rec = $ilDB->fetchAssoc($set))
726 ($rec[
"priority"] == 0 &&
728 0, $rec[
"context_obj_id"]))))
751 $node = $tree->getNodeData($a_ref_id);
752 foreach($tree->getSubTree($node) as $child)
754 if($child[
"type"] !=
"rolf")
756 $nodes[$child[
"obj_id"]] = $child[
"type"];
760 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
764 $query = $ilDB->query(
"SELECT id,context_obj_id,context_obj_type".
765 " FROM il_news_item".
766 " WHERE ".$ilDB->in(
"context_obj_id", array_keys($nodes),
false,
"integer").
767 " AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp"));
768 while($rec = $ilDB->fetchAssoc(
$query))
770 if ($nodes[$rec[
"context_obj_id"]] == $rec[
"context_obj_type"])
785 $a_time_period = 0, $a_starting_date =
"", $a_no_auto_generated =
false,
791 if ($a_time_period > 0)
793 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
794 $and =
" AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp").
" ";
797 if ($a_starting_date !=
"")
799 $and.=
" AND creation_date > ".$ilDB->quote($a_starting_date,
"timestamp").
" ";
802 if ($a_no_auto_generated)
804 $and.=
" AND priority = 1 AND content_type = ".$ilDB->quote(
"text",
"text").
" ";
809 foreach($a_contexts as $cont)
811 $ids[] = $cont[
"obj_id"];
812 $type[$cont[
"obj_id"]] = $cont[
"obj_type"];
818 "FROM il_news_item ".
820 $ilDB->in(
"context_obj_id", $ids,
false,
"integer").
" ".
822 " ORDER BY creation_date DESC ";
826 $query =
"SELECT il_news_item.* ".
827 ", il_news_read.user_id as user_read ".
828 "FROM il_news_item LEFT JOIN il_news_read ".
829 "ON il_news_item.id = il_news_read.news_id AND ".
832 $ilDB->in(
"context_obj_id", $ids,
false,
"integer").
" ".
834 " ORDER BY creation_date DESC ";
846 $query =
"SELECT il_news_item.* ".
847 ", il_news_read.user_id as user_read ".
848 "FROM il_news_item LEFT JOIN il_news_read ".
849 "ON il_news_item.id = il_news_read.news_id AND ".
850 " il_news_read.user_id = ".$ilDB->quote(
$user_id,
"integer").
852 $ilDB->in(
"context_obj_id", $ids,
false,
"integer").
" ".
854 " ORDER BY creation_date DESC ";
857 $set = $ilDB->query(
$query);
859 while($rec = $ilDB->fetchAssoc($set))
861 if ($type[$rec[
"context_obj_id"]] == $rec[
"context_obj_type"])
864 ($rec[
"priority"] == 0 &&
866 0, $rec[
"context_obj_id"]))))
883 global
$ilDB, $ilAppEventHandler;
885 $ilDB->manipulate(
"DELETE FROM il_news_read WHERE ".
886 "user_id = ".$ilDB->quote($a_user_id,
"integer").
887 " AND news_id = ".$ilDB->quote($a_news_id,
"integer"));
888 $ilDB->manipulate(
"INSERT INTO il_news_read (user_id, news_id) VALUES (".
889 $ilDB->quote($a_user_id,
"integer").
",".
890 $ilDB->quote($a_news_id,
"integer").
")");
892 $ilAppEventHandler->raise(
"Services/News",
"readNews",
893 array(
"user_id" => $a_user_id,
"news_ids" => array($a_news_id)));
901 global
$ilDB, $ilAppEventHandler;
903 $ilDB->manipulate(
"DELETE FROM il_news_read (user_id, news_id) VALUES (".
904 " WHERE user_id = ".$ilDB->quote($a_user_id,
"integer").
905 " AND news_id = ".$ilDB->quote($a_news_id,
"integer"));
907 $ilAppEventHandler->raise(
"Services/News",
"unreadNews",
908 array(
"user_id" => $a_user_id,
"news_ids" => array($a_news_id)));
921 foreach($n2 as
$id => $news)
938 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
941 $default_visibility = ($news_set->get(
"default_visibility") !=
"")
942 ? $news_set->get(
"default_visibility")
945 if ($tree->isInTree($a_ref_id))
947 $path = $tree->getPathFull($a_ref_id);
951 if (!in_array(
$row[
"type"], array(
"root",
"cat",
"crs",
"fold",
"grp",
"icrs")))
966 return $default_visibility;
974 public function delete()
979 $ilDB->manipulate(
"DELETE FROM il_news_read ".
980 " WHERE news_id = ".$ilDB->quote($this->getId(),
"integer"));
991 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1002 $a_context_obj_type, $a_context_sub_obj_id = 0, $a_context_sub_obj_type =
"")
1006 if ($a_context_obj_id == 0 || $a_context_obj_type ==
"")
1011 if ($a_context_sub_obj_id > 0)
1013 $and =
" AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id,
"integer").
1014 " AND context_sub_obj_type = ".$ilDB->quote($a_context_sub_obj_type,
"text");
1018 $query =
"SELECT * FROM il_news_item".
1019 " WHERE context_obj_id = ".$ilDB->quote($a_context_obj_id,
"integer").
1020 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type,
"text").
1023 $news_set = $ilDB->query(
$query);
1025 while ($news = $ilDB->fetchAssoc($news_set))
1028 $news_obj->delete();
1039 $query =
"SELECT title FROM il_news_item WHERE id = ".
1040 $ilDB->quote($a_news_id,
"integer");
1041 $set = $ilDB->query(
$query);
1042 $rec = $ilDB->fetchAssoc($set);
1043 return $rec[
"title"];
1053 $query =
"SELECT visibility FROM il_news_item WHERE id = ".
1054 $ilDB->quote($a_news_id,
"integer");
1055 $set = $ilDB->query(
$query);
1056 $rec = $ilDB->fetchAssoc($set);
1058 return $rec[
"visibility"];
1068 $query =
"SELECT mob_id FROM il_news_item WHERE id = ".
1069 $ilDB->quote($a_news_id,
"integer");
1070 $set = $ilDB->query(
$query);
1071 $rec = $ilDB->fetchAssoc($set);
1072 return $rec[
"mob_id"];
1078 static function filterObjIdsPerNews($a_obj_ids, $a_time_period = 0, $a_starting_date =
"",$a_ending_date =
'', $ignore_period =
false)
1083 if ($a_time_period > 0)
1085 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
1086 $and =
" AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp").
" ";
1089 if ($a_starting_date !=
"")
1091 $and.=
" AND creation_date >= ".$ilDB->quote($a_starting_date,
"timestamp");
1094 $query =
"SELECT DISTINCT(context_obj_id) AS obj_id FROM il_news_item".
1095 " WHERE ".$ilDB->in(
"context_obj_id", $a_obj_ids,
false,
"integer").
" ".$and;
1098 $set = $ilDB->query(
$query);
1100 while($rec = $ilDB->fetchAssoc($set))
1102 $objs[] = $rec[
"obj_id"];
1112 $a_agg_ref_id = 0, $a_aggregation =
"")
1116 if ($a_agg_ref_id > 0)
1118 $cnt = count($a_aggregation);
1121 if ($a_context_obj_type ==
"frm")
1125 return sprintf($lng->txt(
"news_x_postings"), $cnt);
1129 return $lng->txt(
"news_1_postings");
1134 $up_cnt = $cr_cnt = 0;
1135 foreach($a_aggregation as $item)
1137 if ($item[
"title"] ==
"file_updated")
1149 $tit = $lng->txt(
"news_1_file_created");
1152 else if ($cr_cnt > 1)
1154 $tit = sprintf($lng->txt(
"news_x_files_created"), $cr_cnt);
1159 $tit .= $sep.$lng->txt(
"news_1_file_updated");
1161 else if ($up_cnt > 1)
1163 $tit .= $sep.sprintf($lng->txt(
"news_x_files_updated"), $up_cnt);
1170 if ($a_content_is_lang_var)
1172 return $lng->txt($a_title);
1192 $lng->loadLanguageModule($a_context_obj_type);
1193 return $lng->txt($a_content);
1207 $a_context_obj_type, $a_context_sub_obj_id =
"", $a_context_sub_obj_type =
"")
1213 "FROM il_news_item ".
1215 "context_obj_id = ".$ilDB->quote($a_context_obj_id,
"integer").
1216 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type,
"text").
1217 " AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id,
"integer").
1218 " AND ".$ilDB->equals(
"context_sub_obj_type", $a_context_sub_obj_type,
"text",
true);
1220 $set = $ilDB->query(
$query);
1221 $rec = $ilDB->fetchAssoc($set);
1230 $a_context_obj_type, $a_context_sub_obj_id =
"", $a_context_sub_obj_type =
"",
1231 $a_only_today =
false)
1236 $query =
"SELECT id, update_date ".
1237 "FROM il_news_item ".
1239 "context_obj_id = ".$ilDB->quote($a_context_obj_id,
"integer").
1240 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type,
"text").
1241 " AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id,
"integer").
1242 " AND ".$ilDB->equals(
"context_sub_obj_type", $a_context_sub_obj_type,
"text",
true).
1243 " ORDER BY update_date DESC";
1246 $set = $ilDB->query(
$query);
1247 $rec = $ilDB->fetchAssoc($set);
1249 $id = (int) $rec[
"id"];
1253 if (substr($now, 0, 10) != substr($rec[
"update_date"], 0, 10))
1271 "FROM il_news_item ".
1273 " mob_id = ".$ilDB->quote($a_mob_id,
"integer");
1276 $set = $ilDB->query(
$query);
1277 while ($rec = $ilDB->fetchAssoc($set))
1279 $usages[$rec[
"id"]] = array(
"type" =>
"news",
"id" => $rec[
"id"]);
1293 "FROM il_news_item ".
1295 " id = ".$ilDB->quote($a_news_id,
"integer");
1296 $set = $ilDB->query(
$query);
1297 $rec = $ilDB->fetchAssoc($set);
1299 return $rec[
"context_obj_id"];
1305 $per = $news_set->get(
"pd_period");
1319 $allow_shorter_periods = $news_set->get(
"allow_shorter_periods");
1320 $allow_longer_periods = $news_set->get(
"allow_longer_periods");
1323 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
1329 (!$allow_shorter_periods && ($per < $default_per)) ||
1330 (!$allow_longer_periods && ($per > $default_per))
1333 $per = $default_per;
1342 $rss_period = $news_set->get(
"rss_period");
1343 if ($rss_period == 0)