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)
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"];
266 include_once
'Services/Membership/classes/class.ilParticipants.php';
269 $items = array_merge($crs_mbs, $grp_mbs);
270 foreach($items as $i)
273 if(is_array($item_references) && count($item_references))
275 foreach($item_references as
$ref_id)
277 if (!in_array($ref_id, $ref_ids))
293 $acc = $ilAccess->checkAccessOfUser($a_user_id,
"read",
"", $ref_id);
312 $news = $news_item->getNewsForRefId($ref_id, $a_only_public,
false,
313 $per, $a_prevent_aggregation,
false,
false,
false, $a_user_id);
316 if (!is_null($a_cnt))
318 $a_cnt[
$ref_id] = count($news);
335 $a_time_period = 0, $a_prevent_aggregation =
true, $a_forum_group_sequences =
false,
336 $a_no_auto_generated =
false, $a_ignore_date_filter =
false, $a_user_id = null)
343 if ($obj_type ==
"grp" || $obj_type ==
"crs" || $obj_type ==
"cat")
345 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
348 if ($hide_news_per_date && !$a_ignore_date_filter)
355 if ($obj_type ==
"cat" && !$a_stopnesting)
358 $a_prevent_aggregation, $starting_date, $a_no_auto_generated);
360 else if (($obj_type ==
"grp" || $obj_type ==
"crs") &&
364 $a_prevent_aggregation, $starting_date, $a_no_auto_generated, $a_user_id);
369 $news_item->setContextObjId($obj_id);
370 $news_item->setContextObjType($obj_type);
371 $news = $news_item->queryNewsForContext($a_only_public, $a_time_period,
372 $starting_date, $a_no_auto_generated);
374 foreach ($news as $k => $v)
376 if (!$a_only_public || $v[
"visibility"] ==
NEWS_PUBLIC ||
377 ($v[
"priority"] == 0 &&
381 $news[$k][
"ref_id"] = $a_ref_id;
388 foreach ($unset as $un)
394 if (!$a_prevent_aggregation)
398 else if ($a_forum_group_sequences)
410 $a_prevent_aggregation =
false, $a_starting_date =
"", $a_no_auto_generated =
false,
413 global $tree, $ilAccess, $ilObjDataCache;
420 $cur_node = $tree->getNodeData($a_ref_id);
422 if ($cur_node[
"lft"] !=
"")
424 $nodes = $tree->getSubTree($cur_node,
true);
434 foreach($nodes as $node)
436 $ref_ids[] = $node[
"child"];
437 $obj_ids[] = $node[
"obj_id"];
440 $ilObjDataCache->preloadReferenceCache($ref_ids);
443 include_once
"Services/Object/classes/class.ilObjectActivation.php";
453 foreach($nodes as $node)
456 if (!in_array($node[
"obj_id"], $news_obj_ids))
465 $acc = $ilAccess->checkAccess(
"read",
"", $node[
"child"]);
469 $acc = $ilAccess->checkAccessOfUser($a_user_id,
"read",
"",
478 $ref_id[$node[
"obj_id"]] = $node[
"child"];
479 $contexts[] = array(
"obj_id" => $node[
"obj_id"],
480 "obj_type" => $node[
"type"]);
485 $a_starting_date, $a_no_auto_generated, $a_user_id);
488 foreach ($news as $k => $v)
490 $news[$k][
"ref_id"] =
$ref_id[$v[
"context_obj_id"]];
496 if (!$a_prevent_aggregation)
510 foreach ($news as $k => $v)
512 if ($a_group_posting_sequence && $last_aggregation_forum > 0 &&
513 $last_aggregation_forum != $news[$k][
"context_obj_id"])
515 $forums[$last_aggregation_forum] =
"";
518 if ($news[$k][
"context_obj_type"] ==
"frm")
520 if ($forums[$news[$k][
"context_obj_id"]] ==
"")
523 $forums[$news[$k][
"context_obj_id"]] = $k;
524 $last_aggregation_forum = $news[$k][
"context_obj_id"];
531 $news[$k][
"no_context_title"] =
true;
534 $news[$forums[$news[$k][
"context_obj_id"]]][
"aggregation"][$k]
536 $news[$k][
"agg_ref_id"]
537 = $news[$k][
"ref_id"];
538 $news[$k][
"content"] =
"";
539 $news[$k][
"content_long"] =
"";
544 foreach($to_del as $k)
558 foreach ($news as $k => $v)
561 if ($news[$k][
"context_obj_type"] ==
"file")
563 if ($first_file ==
"")
571 $news[$first_file][
"aggregation"][$k] = $news[$k];
572 $news[$first_file][
"agg_ref_id"] = $a_ref_id;
573 $news[$first_file][
"ref_id"] = $a_ref_id;
577 foreach($to_del as $v)
590 $a_time_period = 0, $a_prevent_aggregation =
false, $a_starting_date =
"",
591 $a_no_auto_generated =
false)
593 global $tree, $ilAccess;
597 true,
false,
false, $a_no_auto_generated);
598 foreach (
$data as $k => $v)
600 $data[$k][
"ref_id"] = $a_ref_id;
604 $nodes = $tree->getChilds($a_ref_id);
608 foreach($nodes as $node)
610 $obj_ids[] = $node[
"obj_id"];
617 foreach($nodes as $node)
620 if (!in_array($node[
"obj_id"], $news_obj_ids))
625 if (!$a_only_public && !$ilAccess->checkAccess(
"read",
"", $node[
"child"]))
629 $ref_id[$node[
"obj_id"]] = $node[
"child"];
630 $contexts[] = array(
"obj_id" => $node[
"obj_id"],
631 "obj_type" => $node[
"type"]);
635 $a_starting_date, $a_no_auto_generated);
636 foreach ($news as $k => $v)
638 $news[$k][
"ref_id"] =
$ref_id[$v[
"context_obj_id"]];
645 if (!$a_prevent_aggregation)
656 function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type =
"")
673 $a_starting_date =
"", $a_no_auto_generated =
false, $a_oldest_first =
false, $a_limit = 0)
678 if ($a_time_period > 0)
680 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
681 $and =
" AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp").
" ";
684 if ($a_starting_date !=
"")
686 $and.=
" AND creation_date > ".$ilDB->quote($a_starting_date,
"timestamp").
" ";
689 if ($a_no_auto_generated)
691 $and.=
" AND priority = 1 AND content_type = ".$ilDB->quote(
"text",
"text").
" ";
697 $and.=
" AND context_sub_obj_id = ".$ilDB->quote($this->
getContextSubObjId(),
"integer").
701 $ordering = ($a_oldest_first)
702 ?
" creation_date ASC, id ASC "
703 :
" creation_date DESC, id DESC ";
708 "FROM il_news_item ".
713 " ORDER BY ".$ordering;
717 $query =
"SELECT il_news_item.* ".
718 ", il_news_read.user_id user_read ".
719 "FROM il_news_item LEFT JOIN il_news_read ".
720 "ON il_news_item.id = il_news_read.news_id AND ".
726 " ORDER BY ".$ordering;
730 $query =
"SELECT il_news_item.* ".
731 ", il_news_read.user_id as user_read ".
732 "FROM il_news_item LEFT JOIN il_news_read ".
733 "ON il_news_item.id = il_news_read.news_id AND ".
734 " il_news_read.user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
736 "context_obj_id = ".$ilDB->quote($this->getContextObjId(),
"integer").
737 " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(),
"text").
739 " ORDER BY ".$ordering;
742 $set = $ilDB->query(
$query);
744 while($rec = $ilDB->fetchAssoc($set))
746 if ($a_limit > 0 && count(
$result) >= $a_limit)
751 ($rec[
"priority"] == 0 &&
753 0, $rec[
"context_obj_id"]))))
764 if ($a_time_period !=
"" && $a_for_rss_use)
766 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
769 if ($keep_rss_min > 0)
772 $a_starting_date, $a_no_auto_generated, $a_oldest_first, $keep_rss_min);
793 if(!$tree->isDeleted($a_ref_id))
797 $node = $tree->getNodeData($a_ref_id);
798 foreach($tree->getSubTree($node) as $child)
800 if($child[
"type"] !=
"rolf")
802 $nodes[$child[
"obj_id"]] = $child[
"type"];
806 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
809 $query = $ilDB->query(
"SELECT id,context_obj_id,context_obj_type".
810 " FROM il_news_item".
811 " WHERE ".$ilDB->in(
"context_obj_id", array_keys($nodes),
false,
"integer").
812 " AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp"));
813 while($rec = $ilDB->fetchAssoc(
$query))
815 if ($nodes[$rec[
"context_obj_id"]] == $rec[
"context_obj_type"])
831 $a_time_period = 0, $a_starting_date =
"", $a_no_auto_generated =
false,
837 if ($a_time_period > 0)
839 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
840 $and =
" AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp").
" ";
843 if ($a_starting_date !=
"")
845 $and.=
" AND creation_date > ".$ilDB->quote($a_starting_date,
"timestamp").
" ";
848 if ($a_no_auto_generated)
850 $and.=
" AND priority = 1 AND content_type = ".$ilDB->quote(
"text",
"text").
" ";
855 foreach($a_contexts as $cont)
857 $ids[] = $cont[
"obj_id"];
858 $type[$cont[
"obj_id"]] = $cont[
"obj_type"];
864 "FROM il_news_item ".
866 $ilDB->in(
"context_obj_id", $ids,
false,
"integer").
" ".
868 " ORDER BY creation_date DESC ";
872 $query =
"SELECT il_news_item.* ".
873 ", il_news_read.user_id as user_read ".
874 "FROM il_news_item LEFT JOIN il_news_read ".
875 "ON il_news_item.id = il_news_read.news_id AND ".
878 $ilDB->in(
"context_obj_id", $ids,
false,
"integer").
" ".
880 " ORDER BY creation_date DESC ";
892 $query =
"SELECT il_news_item.* ".
893 ", il_news_read.user_id as user_read ".
894 "FROM il_news_item LEFT JOIN il_news_read ".
895 "ON il_news_item.id = il_news_read.news_id AND ".
896 " il_news_read.user_id = ".$ilDB->quote(
$user_id,
"integer").
898 $ilDB->in(
"context_obj_id", $ids,
false,
"integer").
" ".
900 " ORDER BY creation_date DESC ";
903 $set = $ilDB->query(
$query);
905 while($rec = $ilDB->fetchAssoc($set))
907 if ($type[$rec[
"context_obj_id"]] == $rec[
"context_obj_type"])
910 ($rec[
"priority"] == 0 &&
912 0, $rec[
"context_obj_id"]))))
929 global $ilDB, $ilAppEventHandler;
931 $ilDB->replace(
"il_news_read",
933 "user_id" => array(
"integer", $a_user_id),
934 "news_id" => array(
"integer", $a_news_id)
947 $ilAppEventHandler->raise(
"Services/News",
"readNews",
948 array(
"user_id" => $a_user_id,
"news_ids" => array($a_news_id)));
956 global $ilDB, $ilAppEventHandler;
958 $ilDB->manipulate(
"DELETE FROM il_news_read (user_id, news_id) VALUES (".
959 " WHERE user_id = ".$ilDB->quote($a_user_id,
"integer").
960 " AND news_id = ".$ilDB->quote($a_news_id,
"integer"));
962 $ilAppEventHandler->raise(
"Services/News",
"unreadNews",
963 array(
"user_id" => $a_user_id,
"news_ids" => array($a_news_id)));
976 foreach($n2 as
$id => $news)
993 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
996 $default_visibility = ($news_set->get(
"default_visibility") !=
"")
997 ? $news_set->get(
"default_visibility")
1000 if ($tree->isInTree($a_ref_id))
1002 $path = $tree->getPathFull($a_ref_id);
1006 if (!in_array(
$row[
"type"], array(
"root",
"cat",
"crs",
"fold",
"grp",
"icrs")))
1021 return $default_visibility;
1029 public function delete()
1034 $ilDB->manipulate(
"DELETE FROM il_news_read ".
1035 " WHERE news_id = ".$ilDB->quote($this->getId(),
"integer"));
1046 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1057 $a_context_obj_type, $a_context_sub_obj_id = 0, $a_context_sub_obj_type =
"")
1061 if ($a_context_obj_id == 0 || $a_context_obj_type ==
"")
1066 if ($a_context_sub_obj_id > 0)
1068 $and =
" AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id,
"integer").
1069 " AND context_sub_obj_type = ".$ilDB->quote($a_context_sub_obj_type,
"text");
1073 $query =
"SELECT * FROM il_news_item".
1074 " WHERE context_obj_id = ".$ilDB->quote($a_context_obj_id,
"integer").
1075 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type,
"text").
1078 $news_set = $ilDB->query(
$query);
1080 while ($news = $ilDB->fetchAssoc($news_set))
1083 $news_obj->delete();
1094 $query =
"SELECT title FROM il_news_item WHERE id = ".
1095 $ilDB->quote($a_news_id,
"integer");
1096 $set = $ilDB->query(
$query);
1097 $rec = $ilDB->fetchAssoc($set);
1098 return $rec[
"title"];
1108 $query =
"SELECT visibility FROM il_news_item WHERE id = ".
1109 $ilDB->quote($a_news_id,
"integer");
1110 $set = $ilDB->query(
$query);
1111 $rec = $ilDB->fetchAssoc($set);
1113 return $rec[
"visibility"];
1123 $query =
"SELECT mob_id FROM il_news_item WHERE id = ".
1124 $ilDB->quote($a_news_id,
"integer");
1125 $set = $ilDB->query(
$query);
1126 $rec = $ilDB->fetchAssoc($set);
1127 return $rec[
"mob_id"];
1133 static function filterObjIdsPerNews($a_obj_ids, $a_time_period = 0, $a_starting_date =
"",$a_ending_date =
'', $ignore_period =
false)
1138 if ($a_time_period > 0)
1140 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
1141 $and =
" AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp").
" ";
1144 if ($a_starting_date !=
"")
1146 $and.=
" AND creation_date >= ".$ilDB->quote($a_starting_date,
"timestamp");
1149 $query =
"SELECT DISTINCT(context_obj_id) AS obj_id FROM il_news_item".
1150 " WHERE ".$ilDB->in(
"context_obj_id", $a_obj_ids,
false,
"integer").
" ".$and;
1153 $set = $ilDB->query(
$query);
1155 while($rec = $ilDB->fetchAssoc($set))
1157 $objs[] = $rec[
"obj_id"];
1167 $a_agg_ref_id = 0, $a_aggregation =
"")
1171 if ($a_agg_ref_id > 0)
1173 $cnt = count($a_aggregation);
1176 if ($a_context_obj_type ==
"frm")
1180 return sprintf($lng->txt(
"news_x_postings"), $cnt);
1184 return $lng->txt(
"news_1_postings");
1189 $up_cnt = $cr_cnt = 0;
1190 foreach($a_aggregation as $item)
1192 if ($item[
"title"] ==
"file_updated")
1204 $tit = $lng->txt(
"news_1_file_created");
1207 else if ($cr_cnt > 1)
1209 $tit = sprintf($lng->txt(
"news_x_files_created"), $cr_cnt);
1214 $tit .= $sep.$lng->txt(
"news_1_file_updated");
1216 else if ($up_cnt > 1)
1218 $tit .= $sep.sprintf($lng->txt(
"news_x_files_updated"), $up_cnt);
1225 if ($a_content_is_lang_var)
1227 return $lng->txt($a_title);
1247 $lng->loadLanguageModule($a_context_obj_type);
1248 return $lng->txt($a_content);
1262 $a_context_obj_type, $a_context_sub_obj_id =
"", $a_context_sub_obj_type =
"")
1268 "FROM il_news_item ".
1270 "context_obj_id = ".$ilDB->quote($a_context_obj_id,
"integer").
1271 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type,
"text").
1272 " AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id,
"integer").
1273 " AND ".$ilDB->equals(
"context_sub_obj_type", $a_context_sub_obj_type,
"text",
true);
1275 $set = $ilDB->query(
$query);
1276 $rec = $ilDB->fetchAssoc($set);
1285 $a_context_obj_type, $a_context_sub_obj_id =
"", $a_context_sub_obj_type =
"",
1286 $a_only_today =
false)
1291 $query =
"SELECT id, update_date ".
1292 "FROM il_news_item ".
1294 "context_obj_id = ".$ilDB->quote($a_context_obj_id,
"integer").
1295 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type,
"text").
1296 " AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id,
"integer").
1297 " AND ".$ilDB->equals(
"context_sub_obj_type", $a_context_sub_obj_type,
"text",
true).
1298 " ORDER BY update_date DESC";
1301 $set = $ilDB->query(
$query);
1302 $rec = $ilDB->fetchAssoc($set);
1304 $id = (int) $rec[
"id"];
1308 if (substr($now, 0, 10) != substr($rec[
"update_date"], 0, 10))
1326 "FROM il_news_item ".
1328 " mob_id = ".$ilDB->quote($a_mob_id,
"integer");
1331 $set = $ilDB->query(
$query);
1332 while ($rec = $ilDB->fetchAssoc($set))
1334 $usages[$rec[
"id"]] = array(
"type" =>
"news",
"id" => $rec[
"id"]);
1348 "FROM il_news_item ".
1350 " id = ".$ilDB->quote($a_news_id,
"integer");
1351 $set = $ilDB->query(
$query);
1352 $rec = $ilDB->fetchAssoc($set);
1354 return $rec[
"context_obj_id"];
1360 $per = $news_set->get(
"pd_period");
1374 $allow_shorter_periods = $news_set->get(
"allow_shorter_periods");
1375 $allow_longer_periods = $news_set->get(
"allow_longer_periods");
1378 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
1384 (!$allow_shorter_periods && ($per < $default_per)) ||
1385 (!$allow_longer_periods && ($per > $default_per))
1388 $per = $default_per;
1397 $rss_period = $news_set->get(
"rss_period");
1398 if ($rss_period == 0)