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;
87 $this->mob_cnt_play = $a_val;
97 return $this->mob_cnt_play;
107 $this->mob_cnt_download = $a_val;
117 return $this->mob_cnt_download;
127 $query =
"SELECT * FROM il_news_item WHERE id = ".
128 $ilDB->quote($this->
getId(),
"integer");
129 $set = $ilDB->query(
$query);
130 $rec = $ilDB->fetchAssoc($set);
162 $this->
setId($ilDB->nextId(
"il_news_item"));
163 $ilDB->insert(
"il_news_item", array(
164 "id" => array(
"integer", $this->
getId()),
165 "title" => array(
"text", $this->
getTitle()),
166 "content" => array(
"clob", $this->
getContent()),
172 "creation_date" => array(
"timestamp",
ilUtil::now()),
173 "update_date" => array(
"timestamp",
ilUtil::now()),
174 "user_id" => array(
"integer", $this->
getUserId()),
177 "priority" => array(
"integer", $this->
getPriority()),
180 "mob_id" => array(
"integer", $this->
getMobId()),
186 $max_items = $news_set->get(
"max_items");
196 $query =
"SELECT count(*) cnt ".
197 "FROM il_news_item ".
204 $set = $ilDB->query(
$query);
205 $rec = $ilDB->fetchAssoc($set);
211 "FROM il_news_item ".
217 " ORDER BY creation_date ASC";
219 $ilDB->setLimit($rec[
"cnt"] - $max_items);
220 $del_set = $ilDB->query(
$query);
221 while ($del_item = $ilDB->fetchAssoc($del_set))
235 public function update($a_as_new =
false)
240 "title" => array(
"text", $this->
getTitle()),
241 "content" => array(
"clob", $this->
getContent()),
247 "user_id" => array(
"integer", $this->
getUserId()),
250 "priority" => array(
"integer", $this->
getPriority()),
253 "mob_id" => array(
"integer", $this->
getMobId()),
262 $fields[
"creation_date"] = array(
"timestamp", $now);
263 $fields[
"update_date"] = array(
"timestamp", $now);
267 $fields[
"update_date"] = array(
"timestamp", $now);
270 $ilDB->update(
"il_news_item", $fields, array(
271 "id" => array(
"integer", $this->
getId())
281 $a_prevent_aggregation =
false, $a_per = 0, &$a_cnt = NULL)
290 include_once(
"./Services/News/classes/class.ilNewsSubscription.php");
291 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
300 foreach($pd_items as $item)
302 if (!in_array($item[
"ref_id"], $ref_ids))
304 $ref_ids[] = $item[
"ref_id"];
309 include_once
'Services/Membership/classes/class.ilParticipants.php';
312 $items = array_merge($crs_mbs, $grp_mbs);
313 foreach($items as $i)
316 if(is_array($item_references) && count($item_references))
318 foreach($item_references as
$ref_id)
320 if (!in_array($ref_id, $ref_ids))
336 $acc = $ilAccess->checkAccessOfUser($a_user_id,
"read",
"", $ref_id);
355 $news = $news_item->getNewsForRefId($ref_id, $a_only_public,
false,
356 $per, $a_prevent_aggregation,
false,
false,
false, $a_user_id);
359 if (!is_null($a_cnt))
361 $a_cnt[
$ref_id] = count($news);
378 $a_time_period = 0, $a_prevent_aggregation =
true, $a_forum_group_sequences =
false,
379 $a_no_auto_generated =
false, $a_ignore_date_filter =
false, $a_user_id = null)
386 if ($obj_type ==
"grp" || $obj_type ==
"crs" || $obj_type ==
"cat")
388 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
391 if ($hide_news_per_date && !$a_ignore_date_filter)
398 if ($obj_type ==
"cat" && !$a_stopnesting)
401 $a_prevent_aggregation, $starting_date, $a_no_auto_generated);
403 else if (($obj_type ==
"grp" || $obj_type ==
"crs") &&
407 $a_prevent_aggregation, $starting_date, $a_no_auto_generated, $a_user_id);
412 $news_item->setContextObjId($obj_id);
413 $news_item->setContextObjType($obj_type);
414 $news = $news_item->queryNewsForContext($a_only_public, $a_time_period,
415 $starting_date, $a_no_auto_generated);
417 foreach ($news as $k => $v)
419 if (!$a_only_public || $v[
"visibility"] ==
NEWS_PUBLIC ||
420 ($v[
"priority"] == 0 &&
424 $news[$k][
"ref_id"] = $a_ref_id;
431 foreach ($unset as $un)
437 if (!$a_prevent_aggregation)
441 else if ($a_forum_group_sequences)
453 $a_prevent_aggregation =
false, $a_starting_date =
"", $a_no_auto_generated =
false,
456 global $tree, $ilAccess, $ilObjDataCache;
463 $cur_node = $tree->getNodeData($a_ref_id);
468 $nodes = (array) $tree->getSubTree($cur_node,
true);
478 foreach($nodes as $node)
480 $ref_ids[] = $node[
"child"];
481 $obj_ids[] = $node[
"obj_id"];
484 $ilObjDataCache->preloadReferenceCache($ref_ids);
487 include_once
"Services/Object/classes/class.ilObjectActivation.php";
497 foreach($nodes as $node)
500 if (!in_array($node[
"obj_id"], $news_obj_ids))
509 $acc = $ilAccess->checkAccess(
"read",
"", $node[
"child"]);
513 $acc = $ilAccess->checkAccessOfUser($a_user_id,
"read",
"",
522 $ref_id[$node[
"obj_id"]] = $node[
"child"];
523 $contexts[] = array(
"obj_id" => $node[
"obj_id"],
524 "obj_type" => $node[
"type"]);
529 $a_starting_date, $a_no_auto_generated, $a_user_id);
532 foreach ($news as $k => $v)
534 $news[$k][
"ref_id"] =
$ref_id[$v[
"context_obj_id"]];
540 if (!$a_prevent_aggregation)
554 foreach ($news as $k => $v)
556 if ($a_group_posting_sequence && $last_aggregation_forum > 0 &&
557 $last_aggregation_forum != $news[$k][
"context_obj_id"])
559 $forums[$last_aggregation_forum] =
"";
562 if ($news[$k][
"context_obj_type"] ==
"frm")
564 if ($forums[$news[$k][
"context_obj_id"]] ==
"")
567 $forums[$news[$k][
"context_obj_id"]] = $k;
568 $last_aggregation_forum = $news[$k][
"context_obj_id"];
575 $news[$k][
"no_context_title"] =
true;
578 $news[$forums[$news[$k][
"context_obj_id"]]][
"aggregation"][$k]
580 $news[$k][
"agg_ref_id"]
581 = $news[$k][
"ref_id"];
582 $news[$k][
"content"] =
"";
583 $news[$k][
"content_long"] =
"";
588 foreach($to_del as $k)
602 foreach ($news as $k => $v)
605 if ($news[$k][
"context_obj_type"] ==
"file")
607 if ($first_file ==
"")
615 $news[$first_file][
"aggregation"][$k] = $news[$k];
616 $news[$first_file][
"agg_ref_id"] = $a_ref_id;
617 $news[$first_file][
"ref_id"] = $a_ref_id;
621 foreach($to_del as $v)
634 $a_time_period = 0, $a_prevent_aggregation =
false, $a_starting_date =
"",
635 $a_no_auto_generated =
false)
637 global $tree, $ilAccess;
640 $data = $this->
getNewsForRefId($a_ref_id, $a_only_public,
true, $a_time_period,
641 true,
false,
false, $a_no_auto_generated);
642 foreach ($data as $k => $v)
644 $data[$k][
"ref_id"] = $a_ref_id;
648 $nodes = $tree->getChilds($a_ref_id);
652 foreach($nodes as $node)
654 $obj_ids[] = $node[
"obj_id"];
661 foreach($nodes as $node)
664 if (!in_array($node[
"obj_id"], $news_obj_ids))
669 if (!$a_only_public && !$ilAccess->checkAccess(
"read",
"", $node[
"child"]))
673 $ref_id[$node[
"obj_id"]] = $node[
"child"];
674 $contexts[] = array(
"obj_id" => $node[
"obj_id"],
675 "obj_type" => $node[
"type"]);
679 $a_starting_date, $a_no_auto_generated);
680 foreach ($news as $k => $v)
682 $news[$k][
"ref_id"] =
$ref_id[$v[
"context_obj_id"]];
689 if (!$a_prevent_aggregation)
700 function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type =
"")
717 $a_starting_date =
"", $a_no_auto_generated =
false, $a_oldest_first =
false, $a_limit = 0)
722 if ($a_time_period > 0)
724 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
725 $and =
" AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp").
" ";
728 if ($a_starting_date !=
"")
730 $and.=
" AND creation_date > ".$ilDB->quote($a_starting_date,
"timestamp").
" ";
733 if ($a_no_auto_generated)
735 $and.=
" AND priority = 1 AND content_type = ".$ilDB->quote(
"text",
"text").
" ";
741 $and.=
" AND context_sub_obj_id = ".$ilDB->quote($this->
getContextSubObjId(),
"integer").
745 $ordering = ($a_oldest_first)
746 ?
" creation_date ASC, id ASC "
747 :
" creation_date DESC, id DESC ";
752 "FROM il_news_item ".
757 " ORDER BY ".$ordering;
761 $query =
"SELECT il_news_item.* ".
762 ", il_news_read.user_id user_read ".
763 "FROM il_news_item LEFT JOIN il_news_read ".
764 "ON il_news_item.id = il_news_read.news_id AND ".
770 " ORDER BY ".$ordering;
774 $query =
"SELECT il_news_item.* ".
775 ", il_news_read.user_id as user_read ".
776 "FROM il_news_item LEFT JOIN il_news_read ".
777 "ON il_news_item.id = il_news_read.news_id AND ".
778 " il_news_read.user_id = ".$ilDB->quote($ilUser->getId(),
"integer").
780 "context_obj_id = ".$ilDB->quote($this->getContextObjId(),
"integer").
781 " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(),
"text").
783 " ORDER BY ".$ordering;
786 $set = $ilDB->query(
$query);
788 while($rec = $ilDB->fetchAssoc($set))
790 if ($a_limit > 0 && count(
$result) >= $a_limit)
795 ($rec[
"priority"] == 0 &&
797 0, $rec[
"context_obj_id"]))))
808 if ($a_time_period !=
"" && $a_for_rss_use)
810 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
813 if ($keep_rss_min > 0)
816 $a_starting_date, $a_no_auto_generated, $a_oldest_first, $keep_rss_min);
837 if(!$tree->isDeleted($a_ref_id))
841 $node = $tree->getNodeData($a_ref_id);
842 foreach($tree->getSubTree($node) as $child)
844 if($child[
"type"] !=
"rolf")
846 $nodes[$child[
"obj_id"]] = $child[
"type"];
850 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
853 $query = $ilDB->query(
"SELECT id,context_obj_id,context_obj_type".
854 " FROM il_news_item".
855 " WHERE ".$ilDB->in(
"context_obj_id", array_keys($nodes),
false,
"integer").
856 " AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp"));
857 while($rec = $ilDB->fetchAssoc(
$query))
859 if ($nodes[$rec[
"context_obj_id"]] == $rec[
"context_obj_type"])
875 $a_time_period = 0, $a_starting_date =
"", $a_no_auto_generated =
false,
881 if ($a_time_period > 0)
883 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
884 $and =
" AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp").
" ";
887 if ($a_starting_date !=
"")
889 $and.=
" AND creation_date > ".$ilDB->quote($a_starting_date,
"timestamp").
" ";
892 if ($a_no_auto_generated)
894 $and.=
" AND priority = 1 AND content_type = ".$ilDB->quote(
"text",
"text").
" ";
899 foreach($a_contexts as $cont)
901 $ids[] = $cont[
"obj_id"];
902 $type[$cont[
"obj_id"]] = $cont[
"obj_type"];
908 "FROM il_news_item ".
910 $ilDB->in(
"context_obj_id", $ids,
false,
"integer").
" ".
912 " ORDER BY creation_date DESC ";
916 $query =
"SELECT il_news_item.* ".
917 ", il_news_read.user_id as user_read ".
918 "FROM il_news_item LEFT JOIN il_news_read ".
919 "ON il_news_item.id = il_news_read.news_id AND ".
922 $ilDB->in(
"context_obj_id", $ids,
false,
"integer").
" ".
924 " ORDER BY creation_date DESC ";
936 $query =
"SELECT il_news_item.* ".
937 ", il_news_read.user_id as user_read ".
938 "FROM il_news_item LEFT JOIN il_news_read ".
939 "ON il_news_item.id = il_news_read.news_id AND ".
940 " il_news_read.user_id = ".$ilDB->quote(
$user_id,
"integer").
942 $ilDB->in(
"context_obj_id", $ids,
false,
"integer").
" ".
944 " ORDER BY creation_date DESC ";
947 $set = $ilDB->query(
$query);
949 while($rec = $ilDB->fetchAssoc($set))
951 if ($type[$rec[
"context_obj_id"]] == $rec[
"context_obj_type"])
954 ($rec[
"priority"] == 0 &&
956 0, $rec[
"context_obj_id"]))))
973 global
$ilDB, $ilAppEventHandler;
975 $ilDB->replace(
"il_news_read",
977 "user_id" => array(
"integer", $a_user_id),
978 "news_id" => array(
"integer", $a_news_id)
991 $ilAppEventHandler->raise(
"Services/News",
"readNews",
992 array(
"user_id" => $a_user_id,
"news_ids" => array($a_news_id)));
1000 global
$ilDB, $ilAppEventHandler;
1002 $ilDB->manipulate(
"DELETE FROM il_news_read (user_id, news_id) VALUES (".
1003 " WHERE user_id = ".$ilDB->quote($a_user_id,
"integer").
1004 " AND news_id = ".$ilDB->quote($a_news_id,
"integer"));
1006 $ilAppEventHandler->raise(
"Services/News",
"unreadNews",
1007 array(
"user_id" => $a_user_id,
"news_ids" => array($a_news_id)));
1020 foreach($n2 as
$id => $news)
1037 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
1040 $default_visibility = ($news_set->get(
"default_visibility") !=
"")
1041 ? $news_set->get(
"default_visibility")
1044 if ($tree->isInTree($a_ref_id))
1046 $path = $tree->getPathFull($a_ref_id);
1050 if (!in_array(
$row[
"type"], array(
"root",
"cat",
"crs",
"fold",
"grp",
"icrs")))
1065 return $default_visibility;
1073 public function delete()
1078 $ilDB->manipulate(
"DELETE FROM il_news_read ".
1079 " WHERE news_id = ".$ilDB->quote($this->getId(),
"integer"));
1090 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1101 $a_context_obj_type, $a_context_sub_obj_id = 0, $a_context_sub_obj_type =
"")
1105 if ($a_context_obj_id == 0 || $a_context_obj_type ==
"")
1110 if ($a_context_sub_obj_id > 0)
1112 $and =
" AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id,
"integer").
1113 " AND context_sub_obj_type = ".$ilDB->quote($a_context_sub_obj_type,
"text");
1117 $query =
"SELECT * FROM il_news_item".
1118 " WHERE context_obj_id = ".$ilDB->quote($a_context_obj_id,
"integer").
1119 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type,
"text").
1122 $news_set = $ilDB->query(
$query);
1124 while ($news = $ilDB->fetchAssoc($news_set))
1127 $news_obj->delete();
1138 $query =
"SELECT title FROM il_news_item WHERE id = ".
1139 $ilDB->quote($a_news_id,
"integer");
1140 $set = $ilDB->query(
$query);
1141 $rec = $ilDB->fetchAssoc($set);
1142 return $rec[
"title"];
1152 $query =
"SELECT visibility FROM il_news_item WHERE id = ".
1153 $ilDB->quote($a_news_id,
"integer");
1154 $set = $ilDB->query(
$query);
1155 $rec = $ilDB->fetchAssoc($set);
1157 return $rec[
"visibility"];
1167 $query =
"SELECT mob_id FROM il_news_item WHERE id = ".
1168 $ilDB->quote($a_news_id,
"integer");
1169 $set = $ilDB->query(
$query);
1170 $rec = $ilDB->fetchAssoc($set);
1171 return $rec[
"mob_id"];
1177 static function filterObjIdsPerNews($a_obj_ids, $a_time_period = 0, $a_starting_date =
"",$a_ending_date =
'', $ignore_period =
false)
1182 if ($a_time_period > 0)
1184 $limit_ts = date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
1185 $and =
" AND creation_date >= ".$ilDB->quote($limit_ts,
"timestamp").
" ";
1188 if ($a_starting_date !=
"")
1190 $and.=
" AND creation_date >= ".$ilDB->quote($a_starting_date,
"timestamp");
1193 $query =
"SELECT DISTINCT(context_obj_id) AS obj_id FROM il_news_item".
1194 " WHERE ".$ilDB->in(
"context_obj_id", $a_obj_ids,
false,
"integer").
" ".$and;
1197 $set = $ilDB->query(
$query);
1199 while($rec = $ilDB->fetchAssoc($set))
1201 $objs[] = $rec[
"obj_id"];
1211 $a_agg_ref_id = 0, $a_aggregation =
"")
1215 if ($a_agg_ref_id > 0)
1217 $cnt = count($a_aggregation);
1220 if ($a_context_obj_type ==
"frm")
1224 return sprintf($lng->txt(
"news_x_postings"), $cnt);
1228 return $lng->txt(
"news_1_postings");
1233 $up_cnt = $cr_cnt = 0;
1234 foreach($a_aggregation as $item)
1236 if ($item[
"title"] ==
"file_updated")
1248 $tit = $lng->txt(
"news_1_file_created");
1251 else if ($cr_cnt > 1)
1253 $tit = sprintf($lng->txt(
"news_x_files_created"), $cr_cnt);
1258 $tit .= $sep.$lng->txt(
"news_1_file_updated");
1260 else if ($up_cnt > 1)
1262 $tit .= $sep.sprintf($lng->txt(
"news_x_files_updated"), $up_cnt);
1269 if ($a_content_is_lang_var)
1271 return $lng->txt($a_title);
1291 $lng->loadLanguageModule($a_context_obj_type);
1292 return $lng->txt($a_content);
1306 $a_context_obj_type, $a_context_sub_obj_id =
"", $a_context_sub_obj_type =
"")
1312 "FROM il_news_item ".
1314 "context_obj_id = ".$ilDB->quote($a_context_obj_id,
"integer").
1315 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type,
"text").
1316 " AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id,
"integer").
1317 " AND ".$ilDB->equals(
"context_sub_obj_type", $a_context_sub_obj_type,
"text",
true);
1319 $set = $ilDB->query(
$query);
1320 $rec = $ilDB->fetchAssoc($set);
1329 $a_context_obj_type, $a_context_sub_obj_id =
"", $a_context_sub_obj_type =
"",
1330 $a_only_today =
false)
1335 $query =
"SELECT id, update_date ".
1336 "FROM il_news_item ".
1338 "context_obj_id = ".$ilDB->quote($a_context_obj_id,
"integer").
1339 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type,
"text").
1340 " AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id,
"integer").
1341 " AND ".$ilDB->equals(
"context_sub_obj_type", $a_context_sub_obj_type,
"text",
true).
1342 " ORDER BY update_date DESC";
1345 $set = $ilDB->query(
$query);
1346 $rec = $ilDB->fetchAssoc($set);
1348 $id = (int) $rec[
"id"];
1352 if (substr($now, 0, 10) != substr($rec[
"update_date"], 0, 10))
1370 "FROM il_news_item ".
1372 " mob_id = ".$ilDB->quote($a_mob_id,
"integer");
1375 $set = $ilDB->query(
$query);
1376 while ($rec = $ilDB->fetchAssoc($set))
1378 $usages[$rec[
"id"]] = array(
"type" =>
"news",
"id" => $rec[
"id"]);
1392 "FROM il_news_item ".
1394 " id = ".$ilDB->quote($a_news_id,
"integer");
1395 $set = $ilDB->query(
$query);
1396 $rec = $ilDB->fetchAssoc($set);
1398 return $rec[
"context_obj_id"];
1404 $per = $news_set->get(
"pd_period");
1418 $allow_shorter_periods = $news_set->get(
"allow_shorter_periods");
1419 $allow_longer_periods = $news_set->get(
"allow_longer_periods");
1422 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
1428 (!$allow_shorter_periods && ($per < $default_per)) ||
1429 (!$allow_longer_periods && ($per > $default_per))
1432 $per = $default_per;
1441 $rss_period = $news_set->get(
"rss_period");
1442 if ($rss_period == 0)
1467 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1472 if (!$mob->hasPurposeItem($a_purpose))
1477 $m_item = $mob->getMediaItem($a_purpose);
1478 if ($m_item->getLocationType() !=
"Reference")
1480 $file = $mob_dir.
"/".$m_item->getLocation();
1483 if ($a_increase_download_cnt)
1497 if ($a_increase_download_cnt)
1518 $ilDB->manipulate(
"UPDATE il_news_item SET ".
1519 " mob_cnt_download = ".$ilDB->quote($cnt,
"integer").
1520 " WHERE id = ".$ilDB->quote($this->
getId(),
"integer")
1537 $ilDB->manipulate(
"UPDATE il_news_item SET ".
1538 " mob_cnt_play = ".$ilDB->quote($cnt,
"integer").
1539 " WHERE id = ".$ilDB->quote($this->
getId(),
"integer")