51 protected int $id = 0;
79 $this->main_tpl =
$DIC->ui()->mainTemplate();
81 $this->db =
$DIC->database();
82 $this->tree =
$DIC->repositoryTree();
83 $this->
access = $DIC->access();
84 $this->obj_data_cache =
$DIC[
"ilObjDataCache"];
85 $this->
user = $DIC->user();
86 $this->
lng = $DIC->language();
87 $this->
ctrl = $DIC->ctrl();
92 $this->limitation =
true;
93 $this->log =
$DIC->logger()->news();
96 public function setId(
int $a_id): void
108 $this->title = $a_title;
118 $this->content = $a_content;
128 $this->context_obj_id = $a_context_obj_id;
138 $this->context_obj_type = $a_context_obj_type;
148 $this->context_sub_obj_id = $a_context_sub_obj_id;
158 $this->context_sub_obj_type = $a_context_sub_obj_type;
168 $this->content_type = $a_content_type;
178 $this->creation_date = $a_creation_date;
188 $this->update_date = $a_update_date;
198 $this->user_id = $a_user_id;
208 $this->update_user_id = $a_val;
220 string $a_visibility =
"users"
222 $this->visibility = $a_visibility;
227 return $this->visibility;
235 $this->content_long = $a_content_long;
240 return $this->content_long;
245 $this->priority = $a_priority;
250 return $this->priority;
254 bool $a_content_is_lang_var =
false
256 $this->content_is_lang_var = $a_content_is_lang_var;
261 return $this->content_is_lang_var;
266 $this->mob_id = $a_mob_id;
271 return $this->mob_id;
279 $this->playtime = $a_playtime;
284 return $this->playtime;
292 $this->limitation = $a_limitation;
297 return $this->limitation;
302 $this->content_text_is_lang_var = $a_val;
307 return $this->content_text_is_lang_var;
312 $this->mob_cnt_play = $a_val;
317 return $this->mob_cnt_play;
322 $this->mob_cnt_download = $a_val;
327 return $this->mob_cnt_download;
332 $this->content_html = $a_val;
337 return $this->content_html;
348 $query =
"SELECT * FROM il_news_item WHERE id = " .
351 if ($rec =
$ilDB->fetchAssoc($set)) {
352 $this->setTitle((
string) $rec[
"title"]);
353 $this->setContent((
string) $rec[
"content"]);
354 $this->setContextObjId((
int) $rec[
"context_obj_id"]);
355 $this->setContextObjType($rec[
"context_obj_type"]);
356 $this->setContextSubObjId((
int) $rec[
"context_sub_obj_id"]);
357 $this->setContextSubObjType((
string) $rec[
"context_sub_obj_type"]);
358 $this->setContentType((
string) $rec[
"content_type"]);
359 $this->setCreationDate((
string) $rec[
"creation_date"]);
360 $this->setUpdateDate((
string) $rec[
"update_date"]);
361 $this->setUserId((
int) $rec[
"user_id"]);
362 $this->setUpdateUserId((
int) $rec[
"update_user_id"]);
363 $this->setVisibility((
string) $rec[
"visibility"]);
364 $this->setContentLong((
string) $rec[
"content_long"]);
365 $this->setPriority((
int) $rec[
"priority"]);
366 $this->setContentIsLangVar((
bool) $rec[
"content_is_lang_var"]);
367 $this->setContentTextIsLangVar((
bool) $rec[
"content_text_is_lang_var"]);
368 $this->setMobId((
int) $rec[
"mob_id"]);
369 $this->setPlaytime((
string) $rec[
"playtime"]);
370 $this->setMobPlayCounter((
int) $rec[
"mob_cnt_play"]);
371 $this->setMobDownloadCounter((
int) $rec[
"mob_cnt_download"]);
372 $this->setContentHtml((
bool) $rec[
"content_html"]);
385 $this->setId(
$ilDB->nextId(
"il_news_item"));
386 $ilDB->insert(
"il_news_item", [
387 "id" => [
"integer", $this->
getId()],
388 "title" => [
"text", $this->getTitle()],
390 "content_html" => [
"integer", (
int) $this->getContentHtml()],
391 "context_obj_id" => [
"integer", $this->getContextObjId()],
392 "context_obj_type" => [
"text", $this->getContextObjType()],
393 "context_sub_obj_id" => [
"integer", $this->getContextSubObjId()],
394 "context_sub_obj_type" => [
"text", $this->getContextSubObjType()],
395 "content_type" => [
"text", $this->getContentType()],
398 "user_id" => [
"integer", $this->getUserId()],
399 "update_user_id" => [
"integer", $this->getUpdateUserId()],
400 "visibility" => [
"text", $this->getVisibility()],
401 "content_long" => [
"clob", $this->getContentLong()],
402 "priority" => [
"integer", $this->getPriority()],
403 "content_is_lang_var" => [
"integer", $this->getContentIsLangVar()],
404 "content_text_is_lang_var" => [
"integer", (
int) $this->getContentTextIsLangVar()],
405 "mob_id" => [
"integer", $this->getMobId()],
406 "playtime" => [
"text", $this->getPlaytime()]
411 $max_items = $news_set->get(
"max_items");
412 if ($max_items <= 0) {
417 if ($this->getLimitation()) {
419 $query =
"SELECT count(*) cnt " .
420 "FROM il_news_item " .
422 "context_obj_id = " .
$ilDB->quote($this->getContextObjId(),
"integer") .
423 " AND context_obj_type = " .
$ilDB->quote($this->getContextObjType(),
"text") .
424 " AND context_sub_obj_id = " .
$ilDB->quote($this->getContextSubObjId(),
"integer") .
425 " AND " .
$ilDB->equals(
"context_sub_obj_type", $this->getContextSubObjType(),
"text",
true) .
" ";
428 $rec =
$ilDB->fetchAssoc($set);
431 if (($rec[
"cnt"] > $max_items) && $this->getContextObjId() > 0) {
433 "FROM il_news_item " .
435 "context_obj_id = " .
$ilDB->quote($this->getContextObjId(),
"integer") .
436 " AND context_obj_type = " .
$ilDB->quote($this->getContextObjType(),
"text") .
437 " AND context_sub_obj_id = " .
$ilDB->quote($this->getContextSubObjId(),
"integer") .
438 " AND " .
$ilDB->equals(
"context_sub_obj_type", $this->getContextSubObjType(),
"text",
true) .
439 " ORDER BY creation_date ASC";
441 $ilDB->setLimit($rec[
"cnt"] - $max_items, 0);
443 while ($del_item =
$ilDB->fetchAssoc($del_set)) {
444 $del_news =
new ilNewsItem((
int) $del_item[
"id"]);
457 public function update(
bool $a_as_new =
false): void
462 "title" => [
"text", $this->getTitle()],
464 "content_html" => [
"integer", (
int) $this->getContentHtml()],
465 "context_obj_id" => [
"integer", $this->getContextObjId()],
466 "context_obj_type" => [
"text", $this->getContextObjType()],
467 "context_sub_obj_id" => [
"integer", $this->getContextSubObjId()],
468 "context_sub_obj_type" => [
"text", $this->getContextSubObjType()],
469 "content_type" => [
"text", $this->getContentType()],
470 "user_id" => [
"integer", $this->getUserId()],
471 "update_user_id" => [
"integer", $this->getUpdateUserId()],
472 "visibility" => [
"text", $this->getVisibility()],
473 "content_long" => [
"clob", $this->getContentLong()],
474 "priority" => [
"integer", $this->getPriority()],
475 "content_is_lang_var" => [
"integer", $this->getContentIsLangVar()],
476 "content_text_is_lang_var" => [
"integer", (
int) $this->getContentTextIsLangVar()],
477 "mob_id" => [
"integer", $this->getMobId()],
478 "mob_cnt_play" => [
"integer", $this->getMobPlayCounter()],
479 "mob_cnt_download" => [
"integer", $this->getMobDownloadCounter()],
480 "playtime" => [
"text", $this->getPlaytime()]
485 $fields[
"creation_date"] = [
"timestamp", $now];
487 $fields[
"update_date"] = [
"timestamp", $now];
489 $ilDB->update(
"il_news_item", $fields, [
490 "id" => [
"integer", $this->
getId()]
501 bool $a_only_public =
false,
502 bool $a_prevent_aggregation =
false,
508 $ilAccess =
$DIC->access();
521 $pd_items = $fav_rep->getFavouritesOfUser($a_user_id);
522 foreach ($pd_items as $item) {
523 if (!in_array($item[
"ref_id"], $ref_ids)) {
524 $ref_ids[] = (
int) $item[
"ref_id"];
531 $items = array_merge($crs_mbs, $grp_mbs);
532 foreach ($items as
$i) {
534 if (is_array($item_references) && count($item_references)) {
535 foreach ($item_references as
$ref_id) {
536 if (!in_array(
$ref_id, $ref_ids)) {
546 foreach ($ref_ids as
$ref_id) {
547 if (!$a_only_public) {
549 $acc = $ilAccess->checkAccessOfUser($a_user_id,
"read",
"",
$ref_id);
555 if (self::getPrivateFeedId() > 0) {
558 $rbacsystem =
$DIC->rbac()->system();
559 $acc = $rbacsystem->checkAccessOfUser(self::getPrivateFeedId(),
"read",
$ref_id);
568 $news = $news_item->getNewsForRefId(
573 $a_prevent_aggregation,
581 if (!is_null($a_cnt)) {
582 $a_cnt[
$ref_id] = count($news);
603 bool $a_only_public =
false,
604 bool $a_stopnesting =
false,
606 bool $a_prevent_aggregation =
true,
607 bool $a_forum_group_sequences =
false,
608 bool $a_no_auto_generated =
false,
609 bool $a_ignore_date_filter =
false,
610 int $a_user_id =
null,
612 array $a_excluded = []
614 $obj_id =
ilObject::_lookupObjId($a_ref_id);
619 if ($obj_type ===
"grp" || $obj_type ===
"crs") {
640 "hide_news_per_date",
644 if ($hide_news_per_date && !$a_ignore_date_filter) {
654 if ($obj_type ===
"cat" && !$a_stopnesting) {
655 $news = $this->getAggregatedChildNewsData(
659 $a_prevent_aggregation,
663 } elseif (($obj_type ===
"grp" || $obj_type ===
"crs") &&
665 $news = $this->getAggregatedNewsData(
669 $a_prevent_aggregation,
671 $a_no_auto_generated,
678 $news_item->setContextObjId($obj_id);
679 $news_item->setContextObjType($obj_type);
680 $news = $news_item->queryNewsForContext(
687 foreach ($news as $k => $v) {
688 if (!$a_only_public || $v[
"visibility"] ==
NEWS_PUBLIC ||
689 ($v[
"priority"] == 0 &&
692 "public_notifications",
696 $news[$k][
"ref_id"] = $a_ref_id;
701 foreach ($unset as $un) {
706 if (!$a_prevent_aggregation) {
707 $news = $this->aggregateForums($news);
708 } elseif ($a_forum_group_sequences) {
709 $news = $this->aggregateForums($news,
true);
722 bool $a_only_public =
false,
724 bool $a_prevent_aggregation =
false,
725 string $a_starting_date =
"",
726 bool $a_no_auto_generated =
false,
727 int $a_user_id =
null,
729 array $a_exclude = []
732 $ilAccess = $this->access;
733 $ilObjDataCache = $this->obj_data_cache;
752 foreach ($nodes as $node) {
753 $ref_ids[] = (
int) $node[
"child"];
754 $obj_ids[] = (
int) $node[
"obj_id"];
757 $ilObjDataCache->preloadReferenceCache($ref_ids);
758 if (!$a_only_public) {
763 $news_obj_ids = self::filterObjIdsPerNews($obj_ids, $a_time_period, $a_starting_date);
768 foreach ($nodes as $node) {
770 if (!in_array($node[
"obj_id"], $news_obj_ids)) {
774 if (!$a_only_public) {
776 $acc = $ilAccess->checkAccess(
"read",
"", (
int) $node[
"child"]);
778 $acc = $ilAccess->checkAccessOfUser(
790 $ref_id[$node[
"obj_id"]] = $node[
"child"];
792 "obj_id" => $node[
"obj_id"],
793 "obj_type" => $node[
"type"]
798 $news = $this->queryNewsForMultipleContexts(
803 $a_no_auto_generated,
810 foreach ($news as $k => $v) {
811 $news[$k][
"ref_id"] =
$ref_id[$v[
"context_obj_id"]];
817 if (!$a_prevent_aggregation) {
818 $data = $this->aggregateFiles(
$data, $a_ref_id);
829 bool $a_group_posting_sequence =
false
833 $last_aggregation_forum = 0;
836 foreach ($news as $k => $v) {
837 if ($a_group_posting_sequence && $last_aggregation_forum > 0 &&
838 $last_aggregation_forum != $v[
"context_obj_id"]) {
839 $forums[$last_aggregation_forum] =
null;
842 if ($v[
"context_obj_type"] ===
"frm") {
843 if (!isset($forums[$v[
"context_obj_id"]])) {
845 $forums[$v[
"context_obj_id"]] = $k;
846 $last_aggregation_forum = $v[
"context_obj_id"];
851 $news[$k][
"no_context_title"] =
true;
854 $news[$forums[$news[$k][
"context_obj_id"]]][
"aggregation"][$k]
856 $news[$k][
"agg_ref_id"]
857 = $news[$k][
"ref_id"];
858 $news[$k][
"content"] =
"";
859 $news[$k][
"content_long"] =
"";
864 foreach ($to_del as $k) {
881 foreach ($news as $k => $v) {
883 if ($v[
"context_obj_type"] ===
"file") {
884 if ($first_file ===
"") {
889 $news[$first_file][
"aggregation"][$k] = $v;
890 $news[$first_file][
"agg_ref_id"] = $a_ref_id;
891 $news[$first_file][
"ref_id"] = $a_ref_id;
895 foreach ($to_del as $v) {
909 bool $a_only_public =
false,
910 int $a_time_period = 0,
911 bool $a_prevent_aggregation =
false,
912 string $a_starting_date =
"",
913 bool $a_no_auto_generated =
false
916 $ilAccess = $this->access;
919 $data = $this->getNewsForRefId(
929 foreach (
$data as $k => $v) {
930 $data[$k][
"ref_id"] = $a_ref_id;
938 foreach ($nodes as $node) {
939 $obj_ids[] = $node[
"obj_id"];
941 $news_obj_ids = self::filterObjIdsPerNews($obj_ids, $a_time_period, $a_starting_date);
946 foreach ($nodes as $node) {
948 if (!in_array($node[
"obj_id"], $news_obj_ids)) {
952 if (!$a_only_public && !$ilAccess->checkAccess(
"read",
"", (
int) $node[
"child"])) {
955 $ref_id[$node[
"obj_id"]] = $node[
"child"];
957 "obj_id" => $node[
"obj_id"],
958 "obj_type" => $node[
"type"]
962 $news = $this->queryNewsForMultipleContexts(
969 foreach ($news as $k => $v) {
970 $news[$k][
"ref_id"] =
$ref_id[$v[
"context_obj_id"]];
977 if (!$a_prevent_aggregation) {
978 $data = $this->aggregateFiles(
$data, $a_ref_id);
990 int $a_sub_obj_id = 0,
991 string $a_sub_obj_type =
""
993 $this->setContextObjId($a_obj_id);
994 $this->setContextObjType($a_obj_type);
995 $this->setContextSubObjId($a_sub_obj_id);
996 $this->setContextSubObjType($a_sub_obj_type);
1006 if (is_numeric($a_time_period)) {
1007 if ($a_time_period > 0) {
1008 return date(
'Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
1012 elseif (preg_match(
"/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/", $a_time_period)) {
1013 return $a_time_period;
1024 bool $a_for_rss_use =
false,
1026 string $a_starting_date =
"",
1027 bool $a_no_auto_generated =
false,
1028 bool $a_oldest_first =
false,
1035 if ($a_time_period > 0) {
1036 $limit_ts = self::handleTimePeriod($a_time_period);
1037 $and =
" AND creation_date >= " .
$ilDB->quote($limit_ts,
"timestamp") .
" ";
1040 if ($a_starting_date !==
"") {
1041 $and .=
" AND creation_date > " .
$ilDB->quote($a_starting_date,
"timestamp") .
" ";
1044 if ($a_no_auto_generated) {
1045 $and .=
" AND priority = 1 AND content_type = " .
$ilDB->quote(
"text",
"text") .
" ";
1049 if ($this->getContextSubObjId() > 0) {
1050 $and .=
" AND context_sub_obj_id = " .
$ilDB->quote($this->getContextSubObjId(),
"integer") .
1051 " AND context_sub_obj_type = " .
$ilDB->quote($this->getContextSubObjType(),
"text");
1054 $ordering = ($a_oldest_first)
1055 ?
" creation_date ASC, id ASC "
1056 :
" creation_date DESC, id DESC ";
1058 if ($a_for_rss_use && self::getPrivateFeedId() === 0) {
1060 "FROM il_news_item " .
1062 "context_obj_id = " .
$ilDB->quote($this->getContextObjId(),
"integer") .
1063 " AND context_obj_type = " .
$ilDB->quote($this->getContextObjType(),
"text") .
1065 " ORDER BY " . $ordering;
1066 } elseif (self::getPrivateFeedId() > 0) {
1067 $query =
"SELECT il_news_item.* " .
1068 ", il_news_read.user_id user_read " .
1069 "FROM il_news_item LEFT JOIN il_news_read " .
1070 "ON il_news_item.id = il_news_read.news_id AND " .
1071 " il_news_read.user_id = " .
$ilDB->quote(self::getPrivateFeedId(),
"integer") .
1073 "context_obj_id = " .
$ilDB->quote($this->getContextObjId(),
"integer") .
1074 " AND context_obj_type = " .
$ilDB->quote($this->getContextObjType(),
"text") .
1076 " ORDER BY " . $ordering;
1078 $query =
"SELECT il_news_item.* " .
1079 ", il_news_read.user_id as user_read " .
1080 "FROM il_news_item LEFT JOIN il_news_read " .
1081 "ON il_news_item.id = il_news_read.news_id AND " .
1082 " il_news_read.user_id = " .
$ilDB->quote(
$ilUser->getId(),
"integer") .
1084 "context_obj_id = " .
$ilDB->quote($this->getContextObjId(),
"integer") .
1085 " AND context_obj_type = " .
$ilDB->quote($this->getContextObjType(),
"text") .
1087 " ORDER BY " . $ordering;
1092 while ($rec =
$ilDB->fetchAssoc($set)) {
1093 if ($a_limit > 0 && count($result) >= $a_limit) {
1096 if (!$a_for_rss_use || (self::getPrivateFeedId() > 0) || ($rec[
"visibility"] ===
NEWS_PUBLIC ||
1097 ((
int) $rec[
"priority"] === 0 &&
1100 "public_notifications",
1102 (
int) $rec[
"context_obj_id"]
1104 $result[$rec[
"id"]] = $rec;
1113 if ($a_time_period && $a_for_rss_use) {
1118 $this->getContextObjId()
1120 if ($keep_rss_min > 0) {
1121 return $this->queryNewsForContext(
1125 $a_no_auto_generated,
1145 $set =
$ilDB->query(
"SELECT * FROM il_news_item " .
1146 " WHERE " .
$ilDB->in(
"id", $a_news_ids,
false,
"integer"));
1147 while ($rec =
$ilDB->fetchAssoc($set)) {
1148 $news[$rec[
"id"]] = $rec;
1166 $this->log->debug(
"time period: " . $a_time_period);
1167 $limit_ts = self::handleTimePeriod($a_time_period);
1170 $query =
$ilDB->query($q =
"SELECT id,context_obj_id,context_obj_type" .
1171 " FROM il_news_item" .
1172 " WHERE " .
$ilDB->in(
"context_obj_id", array_keys($objects),
false,
"integer") .
1173 " AND creation_date >= " .
$ilDB->quote($limit_ts,
"timestamp"));
1174 $this->log->debug($q);
1176 if ($objects[$rec[
"context_obj_id"]][
"type"] == $rec[
"context_obj_type"]) {
1177 $all[] = (
int) $rec[
"id"];
1190 bool $a_for_rss_use =
false,
1192 string $a_starting_date =
"",
1193 bool $a_no_auto_generated =
false,
1194 int $a_user_id =
null,
1196 array $a_exclude = []
1202 if ($a_time_period > 0) {
1203 $limit_ts = self::handleTimePeriod($a_time_period);
1204 $and =
" AND creation_date >= " .
$ilDB->quote($limit_ts,
"timestamp") .
" ";
1207 if ($a_starting_date !==
"") {
1208 $and .=
" AND creation_date > " .
$ilDB->quote($a_starting_date,
"timestamp") .
" ";
1211 if ($a_no_auto_generated) {
1212 $and .=
" AND priority = 1 AND content_type = " .
$ilDB->quote(
"text",
"text") .
" ";
1216 $ilDB->setLimit($a_limit, 0);
1219 if (is_array($a_exclude) && count($a_exclude) > 0) {
1220 $and .=
" AND " .
$ilDB->in(
"id", $a_exclude,
true,
"integer") .
" ";
1226 foreach ($a_contexts as $cont) {
1227 $ids[] = $cont[
"obj_id"];
1228 $type[$cont[
"obj_id"]] = $cont[
"obj_type"];
1231 if ($a_for_rss_use && self::getPrivateFeedId() === 0) {
1233 "FROM il_news_item " .
1235 $ilDB->in(
"context_obj_id", $ids,
false,
"integer") .
" " .
1237 " ORDER BY creation_date DESC ";
1238 } elseif (self::getPrivateFeedId() > 0) {
1239 $query =
"SELECT il_news_item.* " .
1240 ", il_news_read.user_id as user_read " .
1241 "FROM il_news_item LEFT JOIN il_news_read " .
1242 "ON il_news_item.id = il_news_read.news_id AND " .
1243 " il_news_read.user_id = " .
$ilDB->quote(self::getPrivateFeedId(),
"integer") .
1245 $ilDB->in(
"context_obj_id", $ids,
false,
"integer") .
" " .
1247 " ORDER BY creation_date DESC ";
1250 $user_id = $a_user_id;
1254 $query =
"SELECT il_news_item.* " .
1255 ", il_news_read.user_id as user_read " .
1256 "FROM il_news_item LEFT JOIN il_news_read " .
1257 "ON il_news_item.id = il_news_read.news_id AND " .
1258 " il_news_read.user_id = " .
$ilDB->quote($user_id,
"integer") .
1260 $ilDB->in(
"context_obj_id", $ids,
false,
"integer") .
" " .
1262 " ORDER BY creation_date DESC ";
1267 while ($rec =
$ilDB->fetchAssoc($set)) {
1268 if (
$type[$rec[
"context_obj_id"]] == $rec[
"context_obj_type"]) {
1269 if (!$a_for_rss_use || self::getPrivateFeedId() > 0 || ($rec[
"visibility"] ===
NEWS_PUBLIC ||
1270 ((
int) $rec[
"priority"] === 0 &&
1273 "public_notifications",
1275 (
int) $rec[
"context_obj_id"]
1277 $result[$rec[
"id"]] = $rec;
1297 $ilAppEventHandler =
$DIC[
"ilAppEventHandler"];
1302 "user_id" => [
"integer", $a_user_id],
1303 "news_id" => [
"integer", $a_news_id]
1308 $ilAppEventHandler->raise(
1311 [
"user_id" => $a_user_id,
"news_ids" => [$a_news_id]]
1326 $ilAppEventHandler =
$DIC[
"ilAppEventHandler"];
1328 $ilDB->manipulate(
"DELETE FROM il_news_read (user_id, news_id) VALUES (" .
1329 " WHERE user_id = " .
$ilDB->quote($a_user_id,
"integer") .
1330 " AND news_id = " .
$ilDB->quote($a_news_id,
"integer"));
1332 $ilAppEventHandler->raise(
1335 [
"user_id" => $a_user_id,
"news_ids" => [$a_news_id]]
1347 foreach ($n2 as
$id => $news) {
1362 $tree =
$DIC->repositoryTree();
1365 $default_visibility = ($news_set->get(
"default_visibility") !=
"")
1366 ? $news_set->get(
"default_visibility")
1373 if (!in_array($row[
"type"], [
"root",
"cat",
"crs",
"fold",
"grp"],
true)) {
1379 "default_visibility",
1381 (
int) $row[
"obj_id"]
1384 if ($visibility !=
"") {
1385 $default_visibility = $visibility;
1390 return $default_visibility;
1398 public function delete():
void
1403 $ilDB->manipulate(
"DELETE FROM il_news_read " .
1404 " WHERE news_id = " .
$ilDB->quote($this->getId(),
"integer"));
1407 $mob = $this->getMobId();
1410 $query =
"DELETE FROM il_news_item" .
1411 " WHERE id = " .
$ilDB->quote($this->
getId(),
"integer");
1427 int $a_context_obj_id,
1428 string $a_context_obj_type,
1429 int $a_context_sub_obj_id = 0,
1430 string $a_context_sub_obj_type =
""
1437 if ($a_context_obj_id === 0 || $a_context_obj_type ===
"") {
1441 if ($a_context_sub_obj_id > 0) {
1442 $and =
" AND context_sub_obj_id = " .
$ilDB->quote($a_context_sub_obj_id,
"integer") .
1443 " AND context_sub_obj_type = " .
$ilDB->quote($a_context_sub_obj_type,
"text");
1447 $query =
"SELECT id FROM il_news_item" .
1448 " WHERE context_obj_id = " .
$ilDB->quote($a_context_obj_id,
"integer") .
1449 " AND context_obj_type = " .
$ilDB->quote($a_context_obj_type,
"text") .
1455 while ($news =
$ilDB->fetchAssoc($news_set)) {
1456 $news_arr[] =
new ilNewsItem((
int) $news[
"id"]);
1466 int $a_context_obj_id,
1467 string $a_context_obj_type,
1468 int $a_context_sub_obj_id = 0,
1469 string $a_context_sub_obj_type =
""
1471 foreach (self::getNewsOfContext(
1473 $a_context_obj_type,
1474 $a_context_sub_obj_id,
1475 $a_context_sub_obj_type
1491 $query =
"SELECT title FROM il_news_item WHERE id = " .
1492 $ilDB->quote($a_news_id,
"integer");
1494 $rec =
$ilDB->fetchAssoc($set);
1495 return $rec[
"title"] ??
'';
1508 $query =
"SELECT visibility FROM il_news_item WHERE id = " .
1509 $ilDB->quote($a_news_id,
"integer");
1511 $rec =
$ilDB->fetchAssoc($set);
1526 $query =
"SELECT mob_id FROM il_news_item WHERE id = " .
1527 $ilDB->quote($a_news_id,
"integer");
1529 $rec =
$ilDB->fetchAssoc($set);
1530 return (
int) ($rec[
"mob_id"] ?? 0);
1542 string $a_starting_date =
"",
1543 string $a_ending_date =
'',
1544 bool $ignore_period =
false
1551 if ($a_time_period > 0) {
1552 $limit_ts = self::handleTimePeriod($a_time_period);
1553 $and =
" AND creation_date >= " .
$ilDB->quote($limit_ts,
"timestamp") .
" ";
1556 if ($a_starting_date !==
"") {
1557 $and .=
" AND creation_date >= " .
$ilDB->quote($a_starting_date,
"timestamp");
1560 $query =
"SELECT DISTINCT(context_obj_id) AS obj_id FROM il_news_item" .
1561 " WHERE " .
$ilDB->in(
"context_obj_id", $a_obj_ids,
false,
"integer") .
" " . $and;
1566 while ($rec =
$ilDB->fetchAssoc($set)) {
1567 $objs[] = $rec[
"obj_id"];
1578 int $a_agg_ref_id = 0,
1579 array $a_aggregation = []
1585 $query =
"SELECT context_obj_type, content_is_lang_var, title FROM il_news_item WHERE id = " .
1586 $ilDB->quote($a_news_id,
"integer");
1588 $rec =
$ilDB->fetchAssoc($set);
1590 return self::determineNewsTitle(
1591 $rec[
"context_obj_type"],
1593 $rec[
"content_is_lang_var"],
1604 string $a_context_obj_type,
1606 bool $a_content_is_lang_var,
1607 int $a_agg_ref_id = 0,
1608 array $a_aggregation = []
1613 $obj_definition =
$DIC[
"objDefinition"];
1616 if ($a_agg_ref_id > 0) {
1617 $cnt = count($a_aggregation);
1620 if ($a_context_obj_type ===
"frm") {
1622 return sprintf(
$lng->txt(
"news_x_postings"), $cnt);
1625 return $lng->txt(
"news_1_postings");
1629 $up_cnt = $cr_cnt = 0;
1630 foreach ($a_aggregation as $item) {
1631 if ($item[
"title"] ===
"file_updated") {
1638 if ($cr_cnt === 1) {
1639 $tit =
$lng->txt(
"news_1_file_created");
1641 } elseif ($cr_cnt > 1) {
1642 $tit = sprintf(
$lng->txt(
"news_x_files_created"), $cr_cnt);
1645 if ($up_cnt === 1) {
1646 $tit .= $sep .
$lng->txt(
"news_1_file_updated");
1647 } elseif ($up_cnt > 1) {
1648 $tit .= $sep . sprintf(
$lng->txt(
"news_x_files_updated"), $up_cnt);
1653 if ($a_content_is_lang_var) {
1654 if ($obj_definition->isPlugin($a_context_obj_type)) {
1657 return $lng->txt($a_title);
1668 string $a_context_obj_type,
1675 $obj_definition =
$DIC[
"objDefinition"];
1677 if ($a_is_lang_var) {
1678 if ($obj_definition->isPlugin($a_context_obj_type)) {
1681 $lng->loadLanguageModule($a_context_obj_type);
1682 return $lng->txt($a_content);
1693 int $a_context_obj_id,
1694 string $a_context_obj_type,
1695 int $a_context_sub_obj_id = 0,
1696 string $a_context_sub_obj_type =
""
1704 "FROM il_news_item " .
1706 "context_obj_id = " .
$ilDB->quote($a_context_obj_id,
"integer") .
1707 " AND context_obj_type = " .
$ilDB->quote($a_context_obj_type,
"text") .
1708 " AND context_sub_obj_id = " .
$ilDB->quote($a_context_sub_obj_id,
"integer") .
1709 " AND " .
$ilDB->equals(
"context_sub_obj_type", $a_context_sub_obj_type,
"text",
true);
1712 $rec =
$ilDB->fetchAssoc($set);
1714 return (
int) ($rec[
"id"] ?? 0);
1722 int $a_context_obj_id,
1723 string $a_context_obj_type,
1724 int $a_context_sub_obj_id = 0,
1725 string $a_context_sub_obj_type =
"",
1726 bool $a_only_today =
false
1733 $query =
"SELECT id, update_date " .
1734 "FROM il_news_item " .
1736 "context_obj_id = " .
$ilDB->quote($a_context_obj_id,
"integer") .
1737 " AND context_obj_type = " .
$ilDB->quote($a_context_obj_type,
"text") .
1738 " AND context_sub_obj_id = " .
$ilDB->quote($a_context_sub_obj_id,
"integer") .
1739 " AND " .
$ilDB->equals(
"context_sub_obj_type", $a_context_sub_obj_type,
"text",
true) .
1740 " ORDER BY update_date DESC";
1742 $ilDB->setLimit(1, 0);
1745 if ($rec =
$ilDB->fetchAssoc($set)) {
1747 if ($a_only_today) {
1749 if (strpos($rec[
"update_date"], substr($now, 0, 10)) !== 0) {
1770 "FROM il_news_item " .
1772 " mob_id = " .
$ilDB->quote($a_mob_id,
"integer");
1776 while ($rec =
$ilDB->fetchAssoc($set)) {
1777 $usages[$rec[
"id"]] = [
"type" =>
"news",
"id" => $rec[
"id"]];
1793 $query =
"SELECT context_obj_id " .
1794 "FROM il_news_item " .
1796 " id = " .
$ilDB->quote($a_news_id,
"integer");
1798 $rec =
$ilDB->fetchAssoc($set);
1800 return $rec[
"context_obj_id"];
1809 $per = $news_set->get(
"pd_period");
1810 if ((
int) $per === 0) {
1823 $allow_shorter_periods = $news_set->get(
"allow_shorter_periods");
1824 $allow_longer_periods = $news_set->get(
"allow_longer_periods");
1825 $default_per = self::_lookupDefaultPDPeriod();
1836 (!$allow_shorter_periods && ($per < $default_per)) ||
1837 (!$allow_longer_periods && ($per > $default_per))
1839 $per = $default_per;
1851 $rss_period = $news_set->get(
"rss_period");
1852 if ((
int) $rss_period === 0) {
1863 self::$privFeedId = $a_userId;
1871 return self::$privFeedId;
1879 string $a_purpose =
"Standard",
1880 bool $a_increase_download_cnt =
false
1882 $mob = $this->getMobId();
1887 if (!$mob->hasPurposeItem($a_purpose)) {
1891 $m_item = $mob->getMediaItem($a_purpose);
1892 if ($m_item->getLocationType() !==
"Reference") {
1893 $file = $mob_dir .
"/" . $m_item->getLocation();
1894 if (file_exists($file) && is_file($file)) {
1895 if ($a_increase_download_cnt) {
1896 $this->increaseDownloadCounter();
1902 $this->main_tpl->setOnScreenMessage(
'failure',
"File not found!",
true);
1906 if ($a_increase_download_cnt) {
1907 $this->increaseDownloadCounter();
1921 $cnt = $this->getMobDownloadCounter();
1923 $this->setMobDownloadCounter($cnt);
1925 "UPDATE il_news_item SET " .
1926 " mob_cnt_download = " .
$ilDB->quote($cnt,
"integer") .
1927 " WHERE id = " .
$ilDB->quote($this->getId(),
"integer")
1940 $cnt = $this->getMobPlayCounter();
1942 $this->setMobPlayCounter($cnt);
1944 "UPDATE il_news_item SET " .
1945 " mob_cnt_play = " .
$ilDB->quote($cnt,
"integer") .
1946 " WHERE id = " .
$ilDB->quote($this->getId(),
"integer")
1961 $news_ids = array_keys(
$data);
1962 $set =
$ilDB->query(
"SELECT id FROM il_news_item " .
1963 " WHERE " .
$ilDB->in(
"id", $news_ids,
false,
"integer"));
1965 while ($rec =
$ilDB->fetchAssoc($set)) {
1966 $existing_ids[] = (
int) $rec[
"id"];
1969 $existing_news = [];
1970 foreach (
$data as $k => $v) {
1971 if (in_array($k, $existing_ids)) {
1972 $existing_news[$k] = $v;
1976 return $existing_news;
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
const NEWS_NOTICE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
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)
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=[])
Determine title for news item entry.
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()
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 _getNewsItemsOfUser(int $a_user_id, bool $a_only_public=false, bool $a_prevent_aggregation=false, int $a_per=0, array &$a_cnt=[])
Get all news items for a user.
static _lookupMobId(int $a_news_id)
Lookup mob id.
setMobDownloadCounter(int $a_val)
setContextObjType(string $a_context_obj_type)
setContextSubObjId(int $a_context_sub_obj_id)
static prepareNewsDataFromCache(array $a_cres)
Prepare news data from cache.
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.
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)
Query news for a context.
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.
static _lookupMediaObjectUsages(int $a_mob_id)
Lookup media object usage(s)
static _lookupVisibility(int $a_news_id)
Lookup News Visibility.
setContentHtml(bool $a_val)
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)
Get news aggregation for child objects (e.g.
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=[])
static _lookupContextObjId(int $a_news_id)
Context Object ID.
ilObjectDataCache $obj_data_cache
setPlaytime(string $a_playtime)
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.
static determineNewsContent(string $a_context_obj_type, string $a_content, bool $a_is_lang_var)
Determine new content.
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)
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.
setTitle(string $a_title)
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.
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)
ilGlobalTemplateInterface $main_tpl
static _lookupPref(int $a_usr_id, string $a_keyword)
static preloadData(array $ref_ids)
Preload data to internal cache.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupTxtById(string $plugin_id, string $lang_var)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _lookupObjId(int $ref_id)
static _getMembershipByType(int $a_usr_id, array $a_type, bool $a_only_member_role=false)
get membership by type Get course or group membership
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...