55 protected int $id = 0;
83 $this->main_tpl =
$DIC->ui()->mainTemplate();
85 $this->db =
$DIC->database();
86 $this->tree =
$DIC->repositoryTree();
87 $this->
access = $DIC->access();
88 $this->obj_data_cache =
$DIC[
"ilObjDataCache"];
89 $this->
user = $DIC->user();
90 $this->
lng = $DIC->language();
91 $this->
ctrl = $DIC->ctrl();
96 $this->limitation =
true;
97 $this->log =
$DIC->logger()->news();
98 $this->media_manager =
$DIC->mediaObjects()->internal()->domain()->mediaObject();
101 public function setId(
int $a_id): void
113 $this->title = $a_title;
123 $this->content = $a_content;
133 $this->context_obj_id = $a_context_obj_id;
143 $this->context_obj_type = $a_context_obj_type;
153 $this->context_sub_obj_id = $a_context_sub_obj_id;
163 $this->context_sub_obj_type = $a_context_sub_obj_type;
173 $this->content_type = $a_content_type;
183 $this->creation_date = $a_creation_date;
193 $this->update_date = $a_update_date;
203 $this->user_id = $a_user_id;
213 $this->update_user_id = $a_val;
225 string $a_visibility =
"users"
227 $this->visibility = $a_visibility;
232 return $this->visibility;
240 $this->content_long = $a_content_long;
245 return $this->content_long;
250 $this->priority = $a_priority;
255 return $this->priority;
259 bool $a_content_is_lang_var =
false
261 $this->content_is_lang_var = $a_content_is_lang_var;
266 return $this->content_is_lang_var;
271 $this->mob_id = $a_mob_id;
276 return $this->mob_id;
284 $this->playtime = $a_playtime;
289 return $this->playtime;
297 $this->limitation = $a_limitation;
302 return $this->limitation;
307 $this->content_text_is_lang_var = $a_val;
312 return $this->content_text_is_lang_var;
317 $this->mob_cnt_play = $a_val;
322 return $this->mob_cnt_play;
327 $this->mob_cnt_download = $a_val;
332 return $this->mob_cnt_download;
337 $this->content_html = $a_val;
342 return $this->content_html;
353 $query =
"SELECT * FROM il_news_item WHERE id = " .
355 $set =
$ilDB->query($query);
356 if ($rec =
$ilDB->fetchAssoc($set)) {
357 $this->setTitle((
string) $rec[
"title"]);
358 $this->setContent((
string) $rec[
"content"]);
359 $this->setContextObjId((
int) $rec[
"context_obj_id"]);
360 $this->setContextObjType($rec[
"context_obj_type"]);
361 $this->setContextSubObjId((
int) $rec[
"context_sub_obj_id"]);
362 $this->setContextSubObjType((
string) $rec[
"context_sub_obj_type"]);
363 $this->setContentType((
string) $rec[
"content_type"]);
364 $this->setCreationDate((
string) $rec[
"creation_date"]);
365 $this->setUpdateDate((
string) $rec[
"update_date"]);
366 $this->setUserId((
int) $rec[
"user_id"]);
367 $this->setUpdateUserId((
int) $rec[
"update_user_id"]);
368 $this->setVisibility((
string) $rec[
"visibility"]);
369 $this->setContentLong((
string) $rec[
"content_long"]);
370 $this->setPriority((
int) $rec[
"priority"]);
371 $this->setContentIsLangVar((
bool) $rec[
"content_is_lang_var"]);
372 $this->setContentTextIsLangVar((
bool) $rec[
"content_text_is_lang_var"]);
373 $this->setMobId((
int) $rec[
"mob_id"]);
374 $this->setPlaytime((
string) $rec[
"playtime"]);
375 $this->setMobPlayCounter((
int) $rec[
"mob_cnt_play"]);
376 $this->setMobDownloadCounter((
int) $rec[
"mob_cnt_download"]);
377 $this->setContentHtml((
bool) $rec[
"content_html"]);
390 $this->setId(
$ilDB->nextId(
"il_news_item"));
391 $ilDB->insert(
"il_news_item", [
392 "id" => [
"integer", $this->
getId()],
393 "title" => [
"text", $this->
getTitle()],
395 "content_html" => [
"integer", (
int) $this->getContentHtml()],
396 "context_obj_id" => [
"integer", $this->getContextObjId()],
397 "context_obj_type" => [
"text", $this->getContextObjType()],
398 "context_sub_obj_id" => [
"integer", $this->getContextSubObjId()],
399 "context_sub_obj_type" => [
"text", $this->getContextSubObjType()],
400 "content_type" => [
"text", $this->getContentType()],
403 "user_id" => [
"integer", $this->getUserId()],
404 "update_user_id" => [
"integer", $this->getUpdateUserId()],
405 "visibility" => [
"text", $this->getVisibility()],
406 "content_long" => [
"clob", $this->getContentLong()],
407 "priority" => [
"integer", $this->getPriority()],
408 "content_is_lang_var" => [
"integer", $this->getContentIsLangVar()],
409 "content_text_is_lang_var" => [
"integer", (
int) $this->getContentTextIsLangVar()],
410 "mob_id" => [
"integer", $this->getMobId()],
411 "playtime" => [
"text", $this->getPlaytime()]
416 $max_items = $news_set->get(
"max_items");
417 if ($max_items <= 0) {
422 if ($this->getLimitation()) {
424 $query =
"SELECT count(*) cnt " .
425 "FROM il_news_item " .
427 "context_obj_id = " .
$ilDB->quote($this->getContextObjId(),
"integer") .
428 " AND context_obj_type = " .
$ilDB->quote($this->getContextObjType(),
"text") .
429 " AND context_sub_obj_id = " .
$ilDB->quote($this->getContextSubObjId(),
"integer") .
430 " AND " .
$ilDB->equals(
"context_sub_obj_type", $this->getContextSubObjType(),
"text",
true) .
" ";
432 $set =
$ilDB->query($query);
433 $rec =
$ilDB->fetchAssoc($set);
436 if (($rec[
"cnt"] > $max_items) && $this->getContextObjId() > 0) {
437 $query =
"SELECT * " .
438 "FROM il_news_item " .
440 "context_obj_id = " .
$ilDB->quote($this->getContextObjId(),
"integer") .
441 " AND context_obj_type = " .
$ilDB->quote($this->getContextObjType(),
"text") .
442 " AND context_sub_obj_id = " .
$ilDB->quote($this->getContextSubObjId(),
"integer") .
443 " AND " .
$ilDB->equals(
"context_sub_obj_type", $this->getContextSubObjType(),
"text",
true) .
444 " ORDER BY creation_date ASC";
446 $ilDB->setLimit($rec[
"cnt"] - $max_items, 0);
447 $del_set =
$ilDB->query($query);
448 while ($del_item =
$ilDB->fetchAssoc($del_set)) {
449 $del_news =
new ilNewsItem((
int) $del_item[
"id"]);
462 public function update(
bool $a_as_new =
false): void
467 "title" => [
"text", $this->
getTitle()],
469 "content_html" => [
"integer", (
int) $this->getContentHtml()],
470 "context_obj_id" => [
"integer", $this->getContextObjId()],
471 "context_obj_type" => [
"text", $this->getContextObjType()],
472 "context_sub_obj_id" => [
"integer", $this->getContextSubObjId()],
473 "context_sub_obj_type" => [
"text", $this->getContextSubObjType()],
474 "content_type" => [
"text", $this->getContentType()],
475 "user_id" => [
"integer", $this->getUserId()],
476 "update_user_id" => [
"integer", $this->getUpdateUserId()],
477 "visibility" => [
"text", $this->getVisibility()],
478 "content_long" => [
"clob", $this->getContentLong()],
479 "priority" => [
"integer", $this->getPriority()],
480 "content_is_lang_var" => [
"integer", $this->getContentIsLangVar()],
481 "content_text_is_lang_var" => [
"integer", (
int) $this->getContentTextIsLangVar()],
482 "mob_id" => [
"integer", $this->getMobId()],
483 "mob_cnt_play" => [
"integer", $this->getMobPlayCounter()],
484 "mob_cnt_download" => [
"integer", $this->getMobDownloadCounter()],
485 "playtime" => [
"text", $this->getPlaytime()]
490 $fields[
"creation_date"] = [
"timestamp", $now];
492 $fields[
"update_date"] = [
"timestamp", $now];
494 $ilDB->update(
"il_news_item", $fields, [
495 "id" => [
"integer", $this->
getId()]
510 bool $a_only_public =
false,
511 bool $a_stopnesting =
false,
513 bool $a_prevent_aggregation =
true,
514 bool $a_forum_group_sequences =
false,
515 bool $a_no_auto_generated =
false,
516 bool $a_ignore_date_filter =
false,
517 ?
int $a_user_id =
null,
519 array $a_excluded = []
521 $obj_id =
ilObject::_lookupObjId($a_ref_id);
526 if ($obj_type ===
"grp" || $obj_type ===
"crs") {
547 "hide_news_per_date",
551 if ($hide_news_per_date && !$a_ignore_date_filter) {
561 if ($obj_type ===
"cat" && !$a_stopnesting) {
562 $news = $this->getAggregatedChildNewsData(
566 $a_prevent_aggregation,
568 $a_no_auto_generated,
571 } elseif (($obj_type ===
"grp" || $obj_type ===
"crs") &&
573 $news = $this->getAggregatedNewsData(
577 $a_prevent_aggregation,
579 $a_no_auto_generated,
586 $news_item->setContextObjId($obj_id);
587 $news_item->setContextObjType($obj_type);
588 $news = $news_item->queryNewsForContext(
592 $a_no_auto_generated,
598 foreach ($news as $k => $v) {
599 if (!$a_only_public || $v[
"visibility"] ==
NEWS_PUBLIC ||
600 ($v[
"priority"] == 0 &&
603 "public_notifications",
607 $news[$k][
"ref_id"] = $a_ref_id;
612 foreach ($unset as $un) {
617 if (!$a_prevent_aggregation) {
618 $news = $this->aggregateForums($news);
619 } elseif ($a_forum_group_sequences) {
620 $news = $this->aggregateForums($news,
true);
634 bool $a_only_public =
false,
636 bool $a_prevent_aggregation =
false,
637 string $a_starting_date =
"",
638 bool $a_no_auto_generated =
false,
639 ?
int $a_user_id =
null,
641 array $a_exclude = []
644 $ilAccess = $this->access;
645 $ilObjDataCache = $this->obj_data_cache;
664 foreach ($nodes as $node) {
665 $ref_ids[] = (
int) $node[
"child"];
666 $obj_ids[] = (
int) $node[
"obj_id"];
669 $ilObjDataCache->preloadReferenceCache($ref_ids);
670 if (!$a_only_public) {
675 $news_obj_ids = self::filterObjIdsPerNews($obj_ids, $a_time_period, $a_starting_date);
680 foreach ($nodes as $node) {
682 if (!in_array($node[
"obj_id"], $news_obj_ids)) {
686 if (!$a_only_public) {
688 $acc = $ilAccess->checkAccess(
"read",
"", (
int) $node[
"child"]);
690 $acc = $ilAccess->checkAccessOfUser(
702 $ref_id[$node[
"obj_id"]] = $node[
"child"];
704 "obj_id" => $node[
"obj_id"],
705 "obj_type" => $node[
"type"]
710 $news = $this->queryNewsForMultipleContexts(
715 $a_no_auto_generated,
722 foreach ($news as $k => $v) {
723 $news[$k][
"ref_id"] =
$ref_id[$v[
"context_obj_id"]];
729 if (!$a_prevent_aggregation) {
730 $data = $this->aggregateFiles(
$data, $a_ref_id);
741 bool $a_group_posting_sequence =
false
745 $last_aggregation_forum = 0;
748 foreach ($news as $k => $v) {
749 if ($a_group_posting_sequence && $last_aggregation_forum > 0 &&
750 $last_aggregation_forum != $v[
"context_obj_id"]) {
751 $forums[$last_aggregation_forum] =
null;
754 if ($v[
"context_obj_type"] ===
"frm") {
755 if (!isset($forums[$v[
"context_obj_id"]])) {
757 $forums[$v[
"context_obj_id"]] = $k;
758 $last_aggregation_forum = $v[
"context_obj_id"];
763 $news[$k][
"no_context_title"] =
true;
766 $news[$forums[$news[$k][
"context_obj_id"]]][
"aggregation"][$k]
768 $news[$k][
"agg_ref_id"]
769 = $news[$k][
"ref_id"];
770 $news[$k][
"content"] =
"";
771 $news[$k][
"content_long"] =
"";
776 foreach ($to_del as $k) {
793 foreach ($news as $k => $v) {
795 if ($v[
"context_obj_type"] ===
"file") {
796 if ($first_file ===
"") {
801 $news[$first_file][
"aggregation"][$k] = $v;
802 $news[$first_file][
"agg_ref_id"] = $a_ref_id;
803 $news[$first_file][
"ref_id"] = $a_ref_id;
807 foreach ($to_del as $v) {
822 bool $a_only_public =
false,
823 int $a_time_period = 0,
824 bool $a_prevent_aggregation =
false,
825 string $a_starting_date =
"",
826 bool $a_no_auto_generated =
false,
827 array $a_excluded = []
830 $ilAccess = $this->access;
833 $data = $this->getNewsForRefId(
840 $a_no_auto_generated,
846 foreach (
$data as $k => $v) {
847 $data[$k][
"ref_id"] = $a_ref_id;
855 foreach ($nodes as $node) {
856 $obj_ids[] = $node[
"obj_id"];
858 $news_obj_ids = self::filterObjIdsPerNews($obj_ids, $a_time_period, $a_starting_date);
863 foreach ($nodes as $node) {
865 if (!in_array($node[
"obj_id"], $news_obj_ids)) {
869 if (!$a_only_public && !$ilAccess->checkAccess(
"read",
"", (
int) $node[
"child"])) {
872 $ref_id[$node[
"obj_id"]] = $node[
"child"];
874 "obj_id" => $node[
"obj_id"],
875 "obj_type" => $node[
"type"]
879 $news = $this->queryNewsForMultipleContexts(
884 $a_no_auto_generated,
889 foreach ($news as $k => $v) {
890 $news[$k][
"ref_id"] =
$ref_id[$v[
"context_obj_id"]];
897 if (!$a_prevent_aggregation) {
898 $data = $this->aggregateFiles(
$data, $a_ref_id);
910 int $a_sub_obj_id = 0,
911 string $a_sub_obj_type =
""
913 $this->setContextObjId($a_obj_id);
914 $this->setContextObjType($a_obj_type);
915 $this->setContextSubObjId($a_sub_obj_id);
916 $this->setContextSubObjType($a_sub_obj_type);
926 if (is_numeric($a_time_period)) {
927 if ($a_time_period > 0) {
928 return date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
932 elseif (preg_match(
"/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/", $a_time_period)) {
933 return $a_time_period;
945 bool $a_for_rss_use =
false,
947 string $a_starting_date =
"",
948 bool $a_no_auto_generated =
false,
949 bool $a_oldest_first =
false,
951 array $a_exclude = []
954 $ilUser = $this->user;
957 if ($a_time_period > 0) {
958 $limit_ts = self::handleTimePeriod($a_time_period);
959 $and =
" AND creation_date >= " .
$ilDB->quote($limit_ts,
"timestamp") .
" ";
962 if ($a_starting_date !==
"") {
963 $and .=
" AND creation_date > " .
$ilDB->quote($a_starting_date,
"timestamp") .
" ";
966 if ($a_no_auto_generated) {
967 $and .=
" AND priority = 1 AND content_type = " .
$ilDB->quote(
"text",
"text") .
" ";
971 if ($this->getContextSubObjId() > 0) {
972 $and .=
" AND context_sub_obj_id = " .
$ilDB->quote($this->getContextSubObjId(),
"integer") .
973 " AND context_sub_obj_type = " .
$ilDB->quote($this->getContextSubObjType(),
"text");
976 if (count($a_exclude) > 0) {
977 $and .=
" AND " .
$ilDB->in(
"id", $a_exclude,
true,
"integer") .
" ";
980 $ordering = ($a_oldest_first)
981 ?
" creation_date ASC, id ASC "
982 :
" creation_date DESC, id DESC ";
984 if ($a_for_rss_use && self::getPrivateFeedId() === 0) {
985 $query =
"SELECT * " .
986 "FROM il_news_item " .
988 "context_obj_id = " .
$ilDB->quote($this->getContextObjId(),
"integer") .
989 " AND context_obj_type = " .
$ilDB->quote($this->getContextObjType(),
"text") .
991 " ORDER BY " . $ordering;
992 } elseif (self::getPrivateFeedId() > 0) {
993 $query =
"SELECT il_news_item.* " .
994 ", il_news_read.user_id user_read " .
995 "FROM il_news_item LEFT JOIN il_news_read " .
996 "ON il_news_item.id = il_news_read.news_id AND " .
997 " il_news_read.user_id = " .
$ilDB->quote(self::getPrivateFeedId(),
"integer") .
999 "context_obj_id = " .
$ilDB->quote($this->getContextObjId(),
"integer") .
1000 " AND context_obj_type = " .
$ilDB->quote($this->getContextObjType(),
"text") .
1002 " ORDER BY " . $ordering;
1004 $query =
"SELECT il_news_item.* " .
1005 ", il_news_read.user_id as user_read " .
1006 "FROM il_news_item LEFT JOIN il_news_read " .
1007 "ON il_news_item.id = il_news_read.news_id AND " .
1008 " il_news_read.user_id = " .
$ilDB->quote($ilUser->getId(),
"integer") .
1010 "context_obj_id = " .
$ilDB->quote($this->getContextObjId(),
"integer") .
1011 " AND context_obj_type = " .
$ilDB->quote($this->getContextObjType(),
"text") .
1013 " ORDER BY " . $ordering;
1016 $set =
$ilDB->query($query);
1018 while ($rec =
$ilDB->fetchAssoc($set)) {
1019 if ($a_limit > 0 && count($result) >= $a_limit) {
1022 if (!$a_for_rss_use || (self::getPrivateFeedId() > 0) || ($rec[
"visibility"] ===
NEWS_PUBLIC ||
1023 ((
int) $rec[
"priority"] === 0 &&
1026 "public_notifications",
1028 (
int) $rec[
"context_obj_id"]
1030 $result[$rec[
"id"]] = $rec;
1039 if ($a_time_period && $a_for_rss_use) {
1044 $this->getContextObjId()
1046 if ($keep_rss_min > 0) {
1047 return $this->queryNewsForContext(
1051 $a_no_auto_generated,
1053 (
int) $keep_rss_min,
1072 $set =
$ilDB->query(
"SELECT * FROM il_news_item " .
1073 " WHERE " .
$ilDB->in(
"id", $a_news_ids,
false,
"integer"));
1074 while ($rec =
$ilDB->fetchAssoc($set)) {
1075 $news[$rec[
"id"]] = $rec;
1093 $this->log->debug(
"time period: " . $a_time_period);
1094 $limit_ts = self::handleTimePeriod($a_time_period);
1097 $query =
$ilDB->query(
$q =
"SELECT id,context_obj_id,context_obj_type" .
1098 " FROM il_news_item" .
1099 " WHERE " .
$ilDB->in(
"context_obj_id", array_keys($objects),
false,
"integer") .
1100 " AND creation_date >= " .
$ilDB->quote($limit_ts,
"timestamp"));
1101 $this->log->debug(
$q);
1102 while ($rec =
$ilDB->fetchAssoc($query)) {
1103 if ($objects[$rec[
"context_obj_id"]][
"type"] == $rec[
"context_obj_type"]) {
1104 $all[] = (
int) $rec[
"id"];
1118 bool $a_for_rss_use =
false,
1120 string $a_starting_date =
"",
1121 bool $a_no_auto_generated =
false,
1122 ?
int $a_user_id =
null,
1124 array $a_exclude = []
1127 $ilUser = $this->user;
1130 if ($a_time_period > 0) {
1131 $limit_ts = self::handleTimePeriod($a_time_period);
1132 $and =
" AND creation_date >= " .
$ilDB->quote($limit_ts,
"timestamp") .
" ";
1135 if ($a_starting_date !==
"") {
1136 $and .=
" AND creation_date > " .
$ilDB->quote($a_starting_date,
"timestamp") .
" ";
1139 if ($a_no_auto_generated) {
1140 $and .=
" AND priority = 1 AND content_type = " .
$ilDB->quote(
"text",
"text") .
" ";
1144 $ilDB->setLimit($a_limit, 0);
1147 if (is_array($a_exclude) && count($a_exclude) > 0) {
1148 $and .=
" AND " .
$ilDB->in(
"id", $a_exclude,
true,
"integer") .
" ";
1154 foreach ($a_contexts as $cont) {
1155 $ids[] = $cont[
"obj_id"];
1156 $type[$cont[
"obj_id"]] = $cont[
"obj_type"];
1159 if ($a_for_rss_use && self::getPrivateFeedId() === 0) {
1160 $query =
"SELECT * " .
1161 "FROM il_news_item " .
1163 $ilDB->in(
"context_obj_id", $ids,
false,
"integer") .
" " .
1165 " ORDER BY creation_date DESC ";
1166 } elseif (self::getPrivateFeedId() > 0) {
1167 $query =
"SELECT il_news_item.* " .
1168 ", il_news_read.user_id as user_read " .
1169 "FROM il_news_item LEFT JOIN il_news_read " .
1170 "ON il_news_item.id = il_news_read.news_id AND " .
1171 " il_news_read.user_id = " .
$ilDB->quote(self::getPrivateFeedId(),
"integer") .
1173 $ilDB->in(
"context_obj_id", $ids,
false,
"integer") .
" " .
1175 " ORDER BY creation_date DESC ";
1182 $query =
"SELECT il_news_item.* " .
1183 ", il_news_read.user_id as user_read " .
1184 "FROM il_news_item LEFT JOIN il_news_read " .
1185 "ON il_news_item.id = il_news_read.news_id AND " .
1186 " il_news_read.user_id = " .
$ilDB->quote(
$user_id,
"integer") .
1188 $ilDB->in(
"context_obj_id", $ids,
false,
"integer") .
" " .
1190 " ORDER BY creation_date DESC ";
1193 $set =
$ilDB->query($query);
1195 while ($rec =
$ilDB->fetchAssoc($set)) {
1196 if ($type[$rec[
"context_obj_id"]] == $rec[
"context_obj_type"]) {
1197 if (!$a_for_rss_use || self::getPrivateFeedId() > 0 || ($rec[
"visibility"] ===
NEWS_PUBLIC ||
1198 ((
int) $rec[
"priority"] === 0 &&
1201 "public_notifications",
1203 (
int) $rec[
"context_obj_id"]
1205 $result[$rec[
"id"]] = $rec;
1225 $ilAppEventHandler =
$DIC[
"ilAppEventHandler"];
1230 "user_id" => [
"integer", $a_user_id],
1231 "news_id" => [
"integer", $a_news_id]
1236 $ilAppEventHandler->raise(
1237 "components/ILIAS/News",
1239 [
"user_id" => $a_user_id,
"news_ids" => [$a_news_id]]
1254 $ilAppEventHandler =
$DIC[
"ilAppEventHandler"];
1256 $ilDB->manipulate(
"DELETE FROM il_news_read (user_id, news_id) VALUES (" .
1257 " WHERE user_id = " .
$ilDB->quote($a_user_id,
"integer") .
1258 " AND news_id = " .
$ilDB->quote($a_news_id,
"integer"));
1260 $ilAppEventHandler->raise(
1261 "components/ILIAS/News",
1263 [
"user_id" => $a_user_id,
"news_ids" => [$a_news_id]]
1275 foreach ($n2 as
$id => $news) {
1290 $tree =
$DIC->repositoryTree();
1293 $default_visibility = ($news_set->get(
"default_visibility") !=
"")
1294 ? $news_set->get(
"default_visibility")
1300 foreach (
$path as $key => $row) {
1301 if (!in_array($row[
"type"], [
"root",
"cat",
"crs",
"fold",
"grp"],
true)) {
1307 "default_visibility",
1309 (
int) $row[
"obj_id"]
1312 if ($visibility !=
"") {
1313 $default_visibility = $visibility;
1318 return $default_visibility;
1326 public function delete():
void
1331 $ilDB->manipulate(
"DELETE FROM il_news_read " .
1332 " WHERE news_id = " .
$ilDB->quote($this->getId(),
"integer"));
1335 $mob = $this->getMobId();
1338 $query =
"DELETE FROM il_news_item" .
1339 " WHERE id = " .
$ilDB->quote($this->
getId(),
"integer");
1340 $ilDB->manipulate($query);
1355 int $a_context_obj_id,
1356 string $a_context_obj_type,
1357 int $a_context_sub_obj_id = 0,
1358 string $a_context_sub_obj_type =
""
1365 if ($a_context_obj_id === 0 || $a_context_obj_type ===
"") {
1369 if ($a_context_sub_obj_id > 0) {
1370 $and =
" AND context_sub_obj_id = " .
$ilDB->quote($a_context_sub_obj_id,
"integer") .
1371 " AND context_sub_obj_type = " .
$ilDB->quote($a_context_sub_obj_type,
"text");
1375 $query =
"SELECT id FROM il_news_item" .
1376 " WHERE context_obj_id = " .
$ilDB->quote($a_context_obj_id,
"integer") .
1377 " AND context_obj_type = " .
$ilDB->quote($a_context_obj_type,
"text") .
1380 $news_set =
$ilDB->query($query);
1383 while ($news =
$ilDB->fetchAssoc($news_set)) {
1384 $news_arr[] =
new ilNewsItem((
int) $news[
"id"]);
1394 int $a_context_obj_id,
1395 string $a_context_obj_type,
1396 int $a_context_sub_obj_id = 0,
1397 string $a_context_sub_obj_type =
""
1399 foreach (self::getNewsOfContext(
1401 $a_context_obj_type,
1402 $a_context_sub_obj_id,
1403 $a_context_sub_obj_type
1419 $query =
"SELECT title FROM il_news_item WHERE id = " .
1420 $ilDB->quote($a_news_id,
"integer");
1421 $set =
$ilDB->query($query);
1422 $rec =
$ilDB->fetchAssoc($set);
1423 return $rec[
"title"] ??
'';
1436 $query =
"SELECT visibility FROM il_news_item WHERE id = " .
1437 $ilDB->quote($a_news_id,
"integer");
1438 $set =
$ilDB->query($query);
1439 $rec =
$ilDB->fetchAssoc($set);
1454 $query =
"SELECT mob_id FROM il_news_item WHERE id = " .
1455 $ilDB->quote($a_news_id,
"integer");
1456 $set =
$ilDB->query($query);
1457 $rec =
$ilDB->fetchAssoc($set);
1458 return (
int) ($rec[
"mob_id"] ?? 0);
1470 string $a_starting_date =
"",
1471 string $a_ending_date =
'',
1472 bool $ignore_period =
false
1479 if ($a_time_period > 0) {
1480 $limit_ts = self::handleTimePeriod($a_time_period);
1481 $and =
" AND creation_date >= " .
$ilDB->quote($limit_ts,
"timestamp") .
" ";
1484 if ($a_starting_date !==
"") {
1485 $and .=
" AND creation_date >= " .
$ilDB->quote($a_starting_date,
"timestamp");
1488 $query =
"SELECT DISTINCT(context_obj_id) AS obj_id FROM il_news_item" .
1489 " WHERE " .
$ilDB->in(
"context_obj_id", $a_obj_ids,
false,
"integer") .
" " . $and;
1492 $set =
$ilDB->query($query);
1494 while ($rec =
$ilDB->fetchAssoc($set)) {
1495 $objs[] = $rec[
"obj_id"];
1506 int $a_agg_ref_id = 0,
1507 array $a_aggregation = []
1513 $query =
"SELECT context_obj_type, content_is_lang_var, title FROM il_news_item WHERE id = " .
1514 $ilDB->quote($a_news_id,
"integer");
1515 $set =
$ilDB->query($query);
1516 $rec =
$ilDB->fetchAssoc($set);
1518 return self::determineNewsTitle(
1519 $rec[
"context_obj_type"],
1521 $rec[
"content_is_lang_var"],
1532 string $a_context_obj_type,
1534 bool $a_content_is_lang_var,
1535 int $a_agg_ref_id = 0,
1536 array $a_aggregation = [],
1541 if (is_null(
$lng)) {
1544 $obj_definition =
$DIC[
"objDefinition"];
1547 if ($a_agg_ref_id > 0) {
1548 $cnt = count($a_aggregation);
1551 if ($a_context_obj_type ===
"frm") {
1553 return sprintf(
$lng->txt(
"news_x_postings"), $cnt);
1556 return $lng->txt(
"news_1_postings");
1560 $up_cnt = $cr_cnt = 0;
1561 foreach ($a_aggregation as $item) {
1563 if ($title ===
'file_updated') {
1570 if ($cr_cnt === 1) {
1571 $tit =
$lng->txt(
"news_1_file_created");
1573 } elseif ($cr_cnt > 1) {
1574 $tit = sprintf(
$lng->txt(
"news_x_files_created"), $cr_cnt);
1577 if ($up_cnt === 1) {
1578 $tit .= $sep .
$lng->txt(
"news_1_file_updated");
1579 } elseif ($up_cnt > 1) {
1580 $tit .= $sep . sprintf(
$lng->txt(
"news_x_files_updated"), $up_cnt);
1585 if ($a_content_is_lang_var) {
1586 if ($obj_definition->isPlugin($a_context_obj_type)) {
1589 return $lng->txt($a_title);
1600 string $a_context_obj_type,
1602 bool $a_is_lang_var,
1607 if (is_null(
$lng)) {
1610 $obj_definition =
$DIC[
"objDefinition"];
1612 if ($a_is_lang_var) {
1613 if ($obj_definition->isPlugin($a_context_obj_type)) {
1616 $lng->loadLanguageModule($a_context_obj_type);
1617 return $lng->txt($a_content);
1628 int $a_context_obj_id,
1629 string $a_context_obj_type,
1630 int $a_context_sub_obj_id = 0,
1631 string $a_context_sub_obj_type =
""
1638 $query =
"SELECT id " .
1639 "FROM il_news_item " .
1641 "context_obj_id = " .
$ilDB->quote($a_context_obj_id,
"integer") .
1642 " AND context_obj_type = " .
$ilDB->quote($a_context_obj_type,
"text") .
1643 " AND context_sub_obj_id = " .
$ilDB->quote($a_context_sub_obj_id,
"integer") .
1644 " AND " .
$ilDB->equals(
"context_sub_obj_type", $a_context_sub_obj_type,
"text",
true);
1646 $set =
$ilDB->query($query);
1647 $rec =
$ilDB->fetchAssoc($set);
1649 return (
int) ($rec[
"id"] ?? 0);
1657 int $a_context_obj_id,
1658 string $a_context_obj_type,
1659 int $a_context_sub_obj_id = 0,
1660 string $a_context_sub_obj_type =
"",
1661 bool $a_only_today =
false
1668 $query =
"SELECT id, update_date " .
1669 "FROM il_news_item " .
1671 "context_obj_id = " .
$ilDB->quote($a_context_obj_id,
"integer") .
1672 " AND context_obj_type = " .
$ilDB->quote($a_context_obj_type,
"text") .
1673 " AND context_sub_obj_id = " .
$ilDB->quote($a_context_sub_obj_id,
"integer") .
1674 " AND " .
$ilDB->equals(
"context_sub_obj_type", $a_context_sub_obj_type,
"text",
true) .
1675 " ORDER BY update_date DESC";
1677 $ilDB->setLimit(1, 0);
1678 $set =
$ilDB->query($query);
1680 if ($rec =
$ilDB->fetchAssoc($set)) {
1682 if ($a_only_today) {
1684 if (strpos($rec[
"update_date"], substr($now, 0, 10)) !== 0) {
1704 $query =
"SELECT id " .
1705 "FROM il_news_item " .
1707 " mob_id = " .
$ilDB->quote($a_mob_id,
"integer");
1710 $set =
$ilDB->query($query);
1711 while ($rec =
$ilDB->fetchAssoc($set)) {
1712 $usages[$rec[
"id"]] = [
"type" =>
"news",
"id" => $rec[
"id"]];
1728 $query =
"SELECT context_obj_id " .
1729 "FROM il_news_item " .
1731 " id = " .
$ilDB->quote($a_news_id,
"integer");
1732 $set =
$ilDB->query($query);
1733 $rec =
$ilDB->fetchAssoc($set);
1735 return $rec[
"context_obj_id"];
1744 $per = $news_set->get(
"pd_period");
1745 if ((
int) $per === 0) {
1758 $allow_shorter_periods = $news_set->get(
"allow_shorter_periods");
1759 $allow_longer_periods = $news_set->get(
"allow_longer_periods");
1760 $default_per = self::_lookupDefaultPDPeriod();
1771 (!$allow_shorter_periods && ($per < $default_per)) ||
1772 (!$allow_longer_periods && ($per > $default_per))
1774 $per = $default_per;
1786 $rss_period = $news_set->get(
"rss_period");
1787 if ((
int) $rss_period === 0) {
1798 self::$privFeedId = $a_userId;
1806 return self::$privFeedId;
1814 string $a_purpose =
"Standard",
1815 bool $a_increase_download_cnt =
false
1817 $mob = $this->getMobId();
1822 if (!$mob->hasPurposeItem($a_purpose)) {
1826 $m_item = $mob->getMediaItem($a_purpose);
1827 if ($m_item->getLocationType() !==
"Reference") {
1828 $this->media_manager->deliverEntry($mob->getId(),
"/" . $m_item->getLocation());
1829 if ($a_increase_download_cnt) {
1830 $this->increaseDownloadCounter();
1832 $this->main_tpl->setOnScreenMessage(
'failure',
"File not found!",
true);
1836 if ($a_increase_download_cnt) {
1837 $this->increaseDownloadCounter();
1852 $cnt = $this->getMobDownloadCounter();
1854 $this->setMobDownloadCounter($cnt);
1856 "UPDATE il_news_item SET " .
1857 " mob_cnt_download = " .
$ilDB->quote($cnt,
"integer") .
1858 " WHERE id = " .
$ilDB->quote($this->getId(),
"integer")
1871 $cnt = $this->getMobPlayCounter();
1873 $this->setMobPlayCounter($cnt);
1875 "UPDATE il_news_item SET " .
1876 " mob_cnt_play = " .
$ilDB->quote($cnt,
"integer") .
1877 " WHERE id = " .
$ilDB->quote($this->getId(),
"integer")
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
News Item DTO for transfer of news items.
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
static _lookup(string $a_type, string $a_setting, int $a_user=0, int $a_block_id=0)
Lookup setting from database.
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
Class ilCtrl provides processing control methods.
Component logger with individual log levels by component id.
A news item can be created by different sources.
static _setUnread(int $a_user_id, int $a_news_id)
Set item unread.
static _lookupUserPDPeriod(int $a_user_id)
getAggregatedChildNewsData(int $a_ref_id, bool $a_only_public=false, int $a_time_period=0, bool $a_prevent_aggregation=false, string $a_starting_date="", bool $a_no_auto_generated=false, array $a_excluded=[])
Get news aggregation for child objects (e.g.
setContentType(string $a_content_type="text")
static getFirstNewsIdForContext(int $a_context_obj_id, string $a_context_obj_type, int $a_context_sub_obj_id=0, string $a_context_sub_obj_type="")
Get first new id of news set related to a certain context.
static getPrivateFeedId()
static _lookupRSSPeriod()
getNewsForRefId(int $a_ref_id, bool $a_only_public=false, bool $a_stopnesting=false, $a_time_period=0, bool $a_prevent_aggregation=true, bool $a_forum_group_sequences=false, bool $a_no_auto_generated=false, bool $a_ignore_date_filter=false, ?int $a_user_id=null, int $a_limit=0, array $a_excluded=[])
Get News For Ref Id.
update(bool $a_as_new=false)
Update item in database.
setPriority(int $a_priority=1)
read()
Read item from database.
static handleTimePeriod($a_time_period)
Convert time period for DB-queries.
static getNewsOfContext(int $a_context_obj_id, string $a_context_obj_type, int $a_context_sub_obj_id=0, string $a_context_sub_obj_type="")
Get all news of a context.
setUserId(int $a_user_id)
static mergeNews(array $n1, array $n2)
Merges two sets of news.
static _lookupMobId(int $a_news_id)
Lookup mob id.
setMobDownloadCounter(int $a_val)
setContextObjType(string $a_context_obj_type)
static determineNewsTitle(string $a_context_obj_type, string $a_title, bool $a_content_is_lang_var, int $a_agg_ref_id=0, array $a_aggregation=[], ?ilLanguage $lng=null)
Determine title for news item entry.
queryNewsForMultipleContexts(array $a_contexts, bool $a_for_rss_use=false, $a_time_period=0, string $a_starting_date="", bool $a_no_auto_generated=false, ?int $a_user_id=null, int $a_limit=0, array $a_exclude=[])
getAggregatedNewsData(int $a_ref_id, bool $a_only_public=false, $a_time_period=0, bool $a_prevent_aggregation=false, string $a_starting_date="", bool $a_no_auto_generated=false, ?int $a_user_id=null, int $a_limit=0, array $a_exclude=[])
Get news aggregation (e.g.
setContextSubObjId(int $a_context_sub_obj_id)
setContentIsLangVar(bool $a_content_is_lang_var=false)
static filterObjIdsPerNews(array $a_obj_ids, $a_time_period=0, string $a_starting_date="", string $a_ending_date='', bool $ignore_period=false)
Checks whether news are available for.
setContent(string $a_content)
setContentTextIsLangVar(bool $a_val=false)
increasePlayCounter()
Increase play counter.
static setPrivateFeedId(int $a_userId)
increaseDownloadCounter()
Increase download counter.
string $context_sub_obj_type
bool $content_is_lang_var
static deleteNewsOfContext(int $a_context_obj_id, string $a_context_obj_type, int $a_context_sub_obj_id=0, string $a_context_sub_obj_type="")
Delete all news of a context.
static _setRead(int $a_user_id, int $a_news_id)
Set item read.
aggregateForums(array $news, bool $a_group_posting_sequence=false)
aggregateFiles(array $news, int $a_ref_id)
setContext(int $a_obj_id, string $a_obj_type, int $a_sub_obj_id=0, string $a_sub_obj_type="")
Set context for news.
MediaObjectManager $media_manager
static _lookupMediaObjectUsages(int $a_mob_id)
Lookup media object usage(s)
static _lookupVisibility(int $a_news_id)
Lookup News Visibility.
setContentHtml(bool $a_val)
static _lookupContextObjId(int $a_news_id)
Context Object ID.
ilObjectDataCache $obj_data_cache
setPlaytime(string $a_playtime)
queryNewsForContext(bool $a_for_rss_use=false, $a_time_period=0, string $a_starting_date="", bool $a_no_auto_generated=false, bool $a_oldest_first=false, int $a_limit=0, array $a_exclude=[])
Query news for a context.
static _getDefaultVisibilityForRefId(int $a_ref_id)
Get default visibility for reference id.
static _lookupTitle(int $a_news_id)
Lookup News Title.
setMobPlayCounter(int $a_val)
static queryNewsByIds(array $a_news_ids)
Query news data by news ids.
static _lookupDefaultPDPeriod()
static determineNewsTitleByNewsId(int $a_news_id, int $a_agg_ref_id=0, array $a_aggregation=[])
Determine title for news item entry.
bool $content_text_is_lang_var
deliverMobFile(string $a_purpose="Standard", bool $a_increase_download_cnt=false)
Deliver mob file.
setLimitation(bool $a_limitation)
Set Limitation for number of items.
setVisibility(string $a_visibility="users")
checkNewsExistsForObjects(array $objects, $a_time_period=1)
setUpdateUserId(int $a_val)
setContextSubObjType(?string $a_context_sub_obj_type)
setContextObjId(int $a_context_obj_id)
setTitle(string $a_title)
getContentTextIsLangVar()
static getLastNewsIdForContext(int $a_context_obj_id, string $a_context_obj_type, int $a_context_sub_obj_id=0, string $a_context_sub_obj_type="", bool $a_only_today=false)
Get last news id of news set related to a certain context.
setContentLong(string $a_content_long)
setCreationDate(string $a_creation_date)
setUpdateDate(string $a_update_date)
static determineNewsContent(string $a_context_obj_type, string $a_content, bool $a_is_lang_var, ?ilLanguage $lng=null)
Determine new content.
ilGlobalTemplateInterface $main_tpl
static preloadData(array $ref_ids)
Preload data to internal cache.
static lookupTxtById(string $plugin_id, string $lang_var)
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
isInTree(?int $a_node_id)
get all information of a node.
getPathFull(int $a_endnode_id, int $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
getChilds(int $a_node_id, string $a_order="", string $a_direction="ASC")
get child nodes of given node
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node
static now()
Return current timestamp in Y-m-d H:i:s format.
static redirect(string $a_script)
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...