ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilNewsItem.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4define("NEWS_NOTICE", 0);
5define("NEWS_MESSAGE", 1);
6define("NEWS_WARNING", 2);
7
8define("NEWS_TEXT", "text");
9define("NEWS_HTML", "html");
10define("NEWS_AUDIO", "audio");
11define("NEWS_USERS", "users");
12define("NEWS_PUBLIC", "public");
13
14
15
33{
37 protected $db;
38
42 protected $tree;
43
47 protected $access;
48
52 protected $obj_data_cache;
53
57 protected $user;
58
62 protected $lng;
63
67 protected $ctrl;
68
69 protected $id;
70 protected $title;
71 protected $content;
75 protected $content_html;
76 protected $context_obj_id;
80 protected $content_type = "text";
81 protected $creation_date;
82 protected $update_date;
83 protected $user_id;
87 protected $update_user_id;
88 protected $visibility = "users";
89 protected $content_long;
90 protected $priority = 1;
91 protected $content_is_lang_var = 0;
92 protected $mob_id;
93 protected $playtime;
94
95 private static $privFeedId = false;
96 private $limitation;
97
103 public function __construct($a_id = 0)
104 {
105 global $DIC;
106
107 $this->db = $DIC->database();
108 $this->tree = $DIC->repositoryTree();
109 $this->access = $DIC->access();
110 $this->obj_data_cache = $DIC["ilObjDataCache"];
111 $this->user = $DIC->user();
112 $this->lng = $DIC->language();
113 $this->ctrl = $DIC->ctrl();
114 if ($a_id > 0) {
115 $this->setId($a_id);
116 $this->read();
117 }
118 $this->limitation = true;
119 }
120
126 public function setId($a_id)
127 {
128 $this->id = $a_id;
129 }
130
136 public function getId()
137 {
138 return $this->id;
139 }
140
146 public function setTitle($a_title)
147 {
148 $this->title = $a_title;
149 }
150
156 public function getTitle()
157 {
158 return $this->title;
159 }
160
166 public function setContent($a_content)
167 {
168 $this->content = $a_content;
169 }
170
176 public function getContent()
177 {
178 return $this->content;
179 }
180
186 public function setContextObjId($a_context_obj_id)
187 {
188 $this->context_obj_id = $a_context_obj_id;
189 }
190
196 public function getContextObjId()
197 {
199 }
200
206 public function setContextObjType($a_context_obj_type)
207 {
208 $this->context_obj_type = $a_context_obj_type;
209 }
210
216 public function getContextObjType()
217 {
219 }
220
226 public function setContextSubObjId($a_context_sub_obj_id)
227 {
228 $this->context_sub_obj_id = $a_context_sub_obj_id;
229 }
230
236 public function getContextSubObjId()
237 {
239 }
240
246 public function setContextSubObjType($a_context_sub_obj_type)
247 {
248 $this->context_sub_obj_type = $a_context_sub_obj_type;
249 }
250
256 public function getContextSubObjType()
257 {
259 }
260
266 public function setContentType($a_content_type = "text")
267 {
268 $this->content_type = $a_content_type;
269 }
270
276 public function getContentType()
277 {
278 return $this->content_type;
279 }
280
286 public function setCreationDate($a_creation_date)
287 {
288 $this->creation_date = $a_creation_date;
289 }
290
296 public function getCreationDate()
297 {
299 }
300
306 public function setUpdateDate($a_update_date)
307 {
308 $this->update_date = $a_update_date;
309 }
310
316 public function getUpdateDate()
317 {
318 return $this->update_date;
319 }
320
326 public function setUserId($a_user_id)
327 {
328 $this->user_id = $a_user_id;
329 }
330
336 public function getUserId()
337 {
338 return $this->user_id;
339 }
340
346 public function setUpdateUserId($a_val)
347 {
348 $this->update_user_id = $a_val;
349 }
350
356 public function getUpdateUserId()
357 {
359 }
360
366 public function setVisibility($a_visibility = "users")
367 {
368 $this->visibility = $a_visibility;
369 }
370
376 public function getVisibility()
377 {
378 return $this->visibility;
379 }
380
386 public function setContentLong($a_content_long)
387 {
388 $this->content_long = $a_content_long;
389 }
390
396 public function getContentLong()
397 {
398 return $this->content_long;
399 }
400
406 public function setPriority($a_priority = 1)
407 {
408 $this->priority = $a_priority;
409 }
410
416 public function getPriority()
417 {
418 return $this->priority;
419 }
420
426 public function setContentIsLangVar($a_content_is_lang_var = 0)
427 {
428 $this->content_is_lang_var = $a_content_is_lang_var;
429 }
430
436 public function getContentIsLangVar()
437 {
439 }
440
446 public function setMobId($a_mob_id)
447 {
448 $this->mob_id = $a_mob_id;
449 }
450
456 public function getMobId()
457 {
458 return $this->mob_id;
459 }
460
466 public function setPlaytime($a_playtime)
467 {
468 $this->playtime = $a_playtime;
469 }
470
476 public function getPlaytime()
477 {
478 return $this->playtime;
479 }
480
481
487 public function setLimitation($a_limitation)
488 {
489 $this->limitation = $a_limitation;
490 }
491
497 public function getLimitation()
498 {
499 return $this->limitation;
500 }
501
507 public function setContentTextIsLangVar($a_val = 0)
508 {
509 $this->content_text_is_lang_var = $a_val;
510 }
511
517 public function getContentTextIsLangVar()
518 {
519 return $this->content_text_is_lang_var;
520 }
521
527 public function setMobPlayCounter($a_val)
528 {
529 $this->mob_cnt_play = $a_val;
530 }
531
537 public function getMobPlayCounter()
538 {
539 return $this->mob_cnt_play;
540 }
541
547 public function setMobDownloadCounter($a_val)
548 {
549 $this->mob_cnt_download = $a_val;
550 }
551
557 public function getMobDownloadCounter()
558 {
559 return $this->mob_cnt_download;
560 }
561
567 public function setContentHtml($a_val)
568 {
569 $this->content_html = $a_val;
570 }
571
577 public function getContentHtml()
578 {
579 return $this->content_html;
580 }
581
586 public function read()
587 {
589
590 $query = "SELECT * FROM il_news_item WHERE id = " .
591 $ilDB->quote($this->getId(), "integer");
592 $set = $ilDB->query($query);
593 $rec = $ilDB->fetchAssoc($set);
594
595 $this->setTitle($rec["title"]);
596 $this->setContent($rec["content"]);
597 $this->setContextObjId((int) $rec["context_obj_id"]);
598 $this->setContextObjType($rec["context_obj_type"]);
599 $this->setContextSubObjId((int) $rec["context_sub_obj_id"]);
600 $this->setContextSubObjType($rec["context_sub_obj_type"]);
601 $this->setContentType($rec["content_type"]);
602 $this->setCreationDate($rec["creation_date"]);
603 $this->setUpdateDate($rec["update_date"]);
604 $this->setUserId($rec["user_id"]);
605 $this->setUpdateUserId($rec["update_user_id"]);
606 $this->setVisibility($rec["visibility"]);
607 $this->setContentLong($rec["content_long"]);
608 $this->setPriority($rec["priority"]);
609 $this->setContentIsLangVar($rec["content_is_lang_var"]);
610 $this->setContentTextIsLangVar((int) $rec["content_text_is_lang_var"]);
611 $this->setMobId($rec["mob_id"]);
612 $this->setPlaytime($rec["playtime"]);
613 $this->setMobPlayCounter($rec["mob_cnt_play"]);
614 $this->setMobDownloadCounter($rec["mob_cnt_download"]);
615 $this->setContentHtml($rec["content_html"]);
616 }
617
622 public function create()
623 {
625
626 // insert new record into db
627 $this->setId($ilDB->nextId("il_news_item"));
628 $ilDB->insert("il_news_item", array(
629 "id" => array("integer", $this->getId()),
630 "title" => array("text", $this->getTitle()),
631 "content" => array("clob", $this->getContent()),
632 "content_html" => array("integer", (int) $this->getContentHtml()),
633 "context_obj_id" => array("integer", (int) $this->getContextObjId()),
634 "context_obj_type" => array("text", $this->getContextObjType()),
635 "context_sub_obj_id" => array("integer", (int) $this->getContextSubObjId()),
636 "context_sub_obj_type" => array("text", $this->getContextSubObjType()),
637 "content_type" => array("text", $this->getContentType()),
638 "creation_date" => array("timestamp", ilUtil::now()),
639 "update_date" => array("timestamp", ilUtil::now()),
640 "user_id" => array("integer", $this->getUserId()),
641 "update_user_id" => array("integer", (int) $this->getUpdateUserId()),
642 "visibility" => array("text", $this->getVisibility()),
643 "content_long" => array("clob", $this->getContentLong()),
644 "priority" => array("integer", $this->getPriority()),
645 "content_is_lang_var" => array("integer", $this->getContentIsLangVar()),
646 "content_text_is_lang_var" => array("integer", (int) $this->getContentTextIsLangVar()),
647 "mob_id" => array("integer", $this->getMobId()),
648 "playtime" => array("text", $this->getPlaytime())
649 ));
650
651
652 $news_set = new ilSetting("news");
653 $max_items = $news_set->get("max_items");
654 if ($max_items <= 0) {
655 $max_items = 50;
656 }
657
658 // limit number of news
659 if ($this->getLimitation()) {
660 // Determine how many rows should be deleted
661 $query = "SELECT count(*) cnt " .
662 "FROM il_news_item " .
663 "WHERE " .
664 "context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
665 " AND context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text") .
666 " AND context_sub_obj_id = " . $ilDB->quote($this->getContextSubObjId(), "integer") .
667 " AND " . $ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true) . " ";
668
669 $set = $ilDB->query($query);
670 $rec = $ilDB->fetchAssoc($set);
671
672 // if we have more records than allowed, delete them
673 if (($rec["cnt"] > $max_items) && $this->getContextObjId() > 0) {
674 $query = "SELECT * " .
675 "FROM il_news_item " .
676 "WHERE " .
677 "context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
678 " AND context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text") .
679 " AND context_sub_obj_id = " . $ilDB->quote($this->getContextSubObjId(), "integer") .
680 " AND " . $ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true) .
681 " ORDER BY creation_date ASC";
682
683 $ilDB->setLimit($rec["cnt"] - $max_items);
684 $del_set = $ilDB->query($query);
685 while ($del_item = $ilDB->fetchAssoc($del_set)) {
686 $del_news = new ilNewsItem($del_item["id"]);
687 $del_news->delete();
688 }
689 }
690 }
691 }
692
699 public function update($a_as_new = false)
700 {
702
703 $fields = array(
704 "title" => array("text", $this->getTitle()),
705 "content" => array("clob", $this->getContent()),
706 "content_html" => array("integer", (int) $this->getContentHtml()),
707 "context_obj_id" => array("integer", $this->getContextObjId()),
708 "context_obj_type" => array("text", $this->getContextObjType()),
709 "context_sub_obj_id" => array("integer", $this->getContextSubObjId()),
710 "context_sub_obj_type" => array("text", $this->getContextSubObjType()),
711 "content_type" => array("text", $this->getContentType()),
712 "user_id" => array("integer", $this->getUserId()),
713 "update_user_id" => array("integer", (int) $this->getUpdateUserId()),
714 "visibility" => array("text", $this->getVisibility()),
715 "content_long" => array("clob", $this->getContentLong()),
716 "priority" => array("integer", $this->getPriority()),
717 "content_is_lang_var" => array("integer", $this->getContentIsLangVar()),
718 "content_text_is_lang_var" => array("integer", (int) $this->getContentTextIsLangVar()),
719 "mob_id" => array("integer", $this->getMobId()),
720 "mob_cnt_play" => array("integer", $this->getMobPlayCounter()),
721 "mob_cnt_download" => array("integer", $this->getMobDownloadCounter()),
722 "playtime" => array("text", $this->getPlaytime())
723 );
724
725 $now = ilUtil::now();
726 if ($a_as_new) {
727 $fields["creation_date"] = array("timestamp", $now);
728 $fields["update_date"] = array("timestamp", $now);
729 } else {
730 $fields["update_date"] = array("timestamp", $now);
731 }
732
733 $ilDB->update("il_news_item", $fields, array(
734 "id" => array("integer", $this->getId())
735 ));
736 }
737
738
743 public static function _getNewsItemsOfUser(
744 $a_user_id,
745 $a_only_public = false,
746 $a_prevent_aggregation = false,
747 $a_per = 0,
748 &$a_cnt = null
749 ) {
750 global $DIC;
751
752 $ilAccess = $DIC->access();
753
754 $news_item = new ilNewsItem();
755 $news_set = new ilSetting("news");
756
757 $per = $a_per;
758
759 include_once("./Services/News/classes/class.ilNewsSubscription.php");
760 include_once("./Services/Block/classes/class.ilBlockSetting.php");
761
762 // this is currently not used
763 $ref_ids = ilNewsSubscription::_getSubscriptionsOfUser($a_user_id);
764
765 if (ilObjUser::_lookupPref($a_user_id, "pd_items_news") != "n") {
766 // get all items of the personal desktop
767 $pd_items = ilObjUser::_lookupDesktopItems($a_user_id);
768 foreach ($pd_items as $item) {
769 if (!in_array($item["ref_id"], $ref_ids)) {
770 $ref_ids[] = $item["ref_id"];
771 }
772 }
773
774 // get all memberships
775 include_once 'Services/Membership/classes/class.ilParticipants.php';
776 $crs_mbs = ilParticipants::_getMembershipByType($a_user_id, 'crs');
777 $grp_mbs = ilParticipants::_getMembershipByType($a_user_id, 'grp');
778 $items = array_merge($crs_mbs, $grp_mbs);
779 foreach ($items as $i) {
780 $item_references = ilObject::_getAllReferences($i);
781 if (is_array($item_references) && count($item_references)) {
782 foreach ($item_references as $ref_id) {
783 if (!in_array($ref_id, $ref_ids)) {
784 $ref_ids[] = $ref_id;
785 }
786 }
787 }
788 }
789 }
790
791 $data = array();
792
793 foreach ($ref_ids as $ref_id) {
794 if (!$a_only_public) {
795 // this loop should not cost too much performance
796 $acc = $ilAccess->checkAccessOfUser($a_user_id, "read", "", $ref_id);
797
798 if (!$acc) {
799 continue;
800 }
801 }
802 if (ilNewsItem::getPrivateFeedId() != false) {
803 global $DIC;
804
805 $rbacsystem = $DIC->rbac()->system();
806 $acc = $rbacsystem->checkAccessOfUser(ilNewsItem::getPrivateFeedId(), "read", $ref_id);
807
808 if (!$acc) {
809 continue;
810 }
811 }
812
813 $obj_id = ilObject::_lookupObjId($ref_id);
814 $obj_type = ilObject::_lookupType($obj_id);
815 $news = $news_item->getNewsForRefId(
816 $ref_id,
817 $a_only_public,
818 false,
819 $per,
820 $a_prevent_aggregation,
821 false,
822 false,
823 false,
824 $a_user_id
825 );
826
827 // counter
828 if (!is_null($a_cnt)) {
829 $a_cnt[$ref_id] = count($news);
830 }
831
833 }
834
835 $data = ilUtil::sortArray($data, "creation_date", "desc", false, true);
836
837 return $data;
838 }
839
858 public function getNewsForRefId(
859 $a_ref_id,
860 $a_only_public = false,
861 $a_stopnesting = false,
862 $a_time_period = 0,
863 $a_prevent_aggregation = true,
864 $a_forum_group_sequences = false,
865 $a_no_auto_generated = false,
866 $a_ignore_date_filter = false,
867 $a_user_id = null,
868 $a_limit = 0,
869 $a_excluded = array()
870 ) {
871 $obj_id = ilObject::_lookupObjId($a_ref_id);
872 $obj_type = ilObject::_lookupType($obj_id);
873
874 // get starting date
875 $starting_date = "";
876 if ($obj_type == "grp" || $obj_type == "crs" || $obj_type == "cat") {
877 include_once("./Services/Block/classes/class.ilBlockSetting.php");
878 $hide_news_per_date = ilBlockSetting::_lookup(
879 "news",
880 "hide_news_per_date",
881 0,
882 $obj_id
883 );
884 if ($hide_news_per_date && !$a_ignore_date_filter) {
885 $starting_date = ilBlockSetting::_lookup(
886 "news",
887 "hide_news_date",
888 0,
889 $obj_id
890 );
891 }
892 }
893
894 if ($obj_type == "cat" && !$a_stopnesting) {
895 $news = $this->getAggregatedChildNewsData(
896 $a_ref_id,
897 $a_only_public,
898 $a_time_period,
899 $a_prevent_aggregation,
900 $starting_date,
901 $a_no_auto_generated
902 );
903 } elseif (($obj_type == "grp" || $obj_type == "crs") &&
904 !$a_stopnesting) {
905 $news = $this->getAggregatedNewsData(
906 $a_ref_id,
907 $a_only_public,
908 $a_time_period,
909 $a_prevent_aggregation,
910 $starting_date,
911 $a_no_auto_generated,
912 $a_user_id,
913 $a_limit,
914 $a_excluded
915 );
916 } else {
917 $news_item = new ilNewsItem();
918 $news_item->setContextObjId($obj_id);
919 $news_item->setContextObjType($obj_type);
920 $news = $news_item->queryNewsForContext(
921 $a_only_public,
922 $a_time_period,
923 $starting_date,
924 $a_no_auto_generated
925 );
926 $unset = array();
927 foreach ($news as $k => $v) {
928 if (!$a_only_public || $v["visibility"] == NEWS_PUBLIC ||
929 ($v["priority"] == 0 &&
931 "news",
932 "public_notifications",
933 0,
934 $obj_id
935 ))) {
936 $news[$k]["ref_id"] = $a_ref_id;
937 } else {
938 $unset[] = $k;
939 }
940 }
941 foreach ($unset as $un) {
942 unset($news[$un]);
943 }
944 }
945
946 if (!$a_prevent_aggregation) {
947 $news = $this->aggregateForums($news);
948 } elseif ($a_forum_group_sequences) {
949 $news = $this->aggregateForums($news, true);
950 }
951
952 return $news;
953 }
954
959 public function getAggregatedNewsData(
960 $a_ref_id,
961 $a_only_public = false,
962 $a_time_period = 0,
963 $a_prevent_aggregation = false,
964 $a_starting_date = "",
965 $a_no_auto_generated = false,
966 $a_user_id = null,
967 $a_limit = 0,
968 $a_exclude = array()
969 ) {
971 $ilAccess = $this->access;
972 $ilObjDataCache = $this->obj_data_cache;
973
974 // get news of parent object
975
976 $data = array();
977
978 // get subtree
979 $cur_node = $tree->getNodeData($a_ref_id);
980
981 // do not check for lft (materialized path)
982 if ($cur_node) {
983 $nodes = (array) $tree->getSubTree($cur_node, true);
984 } else {
985 $nodes = array();
986 }
987
988 // preload object data cache
989 $ref_ids = array();
990 $obj_ids = array();
991 foreach ($nodes as $node) {
992 $ref_ids[] = $node["child"];
993 $obj_ids[] = $node["obj_id"];
994 }
995
996 $ilObjDataCache->preloadReferenceCache($ref_ids);
997 if (!$a_only_public) {
998 include_once "Services/Object/classes/class.ilObjectActivation.php";
1000 }
1001
1002 // no check, for which of the objects any news are available
1003 $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $a_time_period, $a_starting_date);
1004 //$news_obj_ids = $obj_ids;
1005
1006 // get news for all subtree nodes
1007 $contexts = array();
1008 foreach ($nodes as $node) {
1009 // only go on, if news are available
1010 if (!in_array($node["obj_id"], $news_obj_ids)) {
1011 continue;
1012 }
1013
1014 if (!$a_only_public) {
1015 if (!$a_user_id) {
1016 $acc = $ilAccess->checkAccess("read", "", $node["child"]);
1017 } else {
1018 $acc = $ilAccess->checkAccessOfUser(
1019 $a_user_id,
1020 "read",
1021 "",
1022 $node["child"]
1023 );
1024 }
1025 if (!$acc) {
1026 continue;
1027 }
1028 }
1029
1030 $ref_id[$node["obj_id"]] = $node["child"];
1031 $contexts[] = array("obj_id" => $node["obj_id"],
1032 "obj_type" => $node["type"]);
1033 }
1034
1035 // sort and return
1036 $news = $this->queryNewsForMultipleContexts(
1037 $contexts,
1038 $a_only_public,
1039 $a_time_period,
1040 $a_starting_date,
1041 $a_no_auto_generated,
1042 $a_user_id,
1043 $a_limit,
1044 $a_exclude
1045 );
1046
1047 $to_del = array();
1048 foreach ($news as $k => $v) {
1049 $news[$k]["ref_id"] = $ref_id[$v["context_obj_id"]];
1050 }
1051
1053 $data = ilUtil::sortArray($data, "creation_date", "desc", false, true);
1054
1055 if (!$a_prevent_aggregation) {
1056 $data = $this->aggregateFiles($data, $a_ref_id);
1057 }
1058
1059 return $data;
1060 }
1061
1068 protected function aggregateForums($news, $a_group_posting_sequence = false)
1069 {
1070 $to_del = array();
1071 $forums = array();
1072
1073 // aggregate
1074 foreach ($news as $k => $v) {
1075 if ($a_group_posting_sequence && $last_aggregation_forum > 0 &&
1076 $last_aggregation_forum != $news[$k]["context_obj_id"]) {
1077 $forums[$last_aggregation_forum] = "";
1078 }
1079
1080 if ($news[$k]["context_obj_type"] == "frm") {
1081 if ($forums[$news[$k]["context_obj_id"]] == "") {
1082 // $forums[forum_id] = news_id;
1083 $forums[$news[$k]["context_obj_id"]] = $k;
1084 $last_aggregation_forum = $news[$k]["context_obj_id"];
1085 } else {
1086 $to_del[] = $k;
1087 }
1088
1089 $news[$k]["no_context_title"] = true;
1090
1091 // aggregate every forum into it's "k" news
1092 $news[$forums[$news[$k]["context_obj_id"]]]["aggregation"][$k]
1093 = $news[$k];
1094 $news[$k]["agg_ref_id"]
1095 = $news[$k]["ref_id"];
1096 $news[$k]["content"] = "";
1097 $news[$k]["content_long"] = "";
1098 }
1099 }
1100
1101 // delete double entries
1102 foreach ($to_del as $k) {
1103 unset($news[$k]);
1104 }
1105 //var_dump($news[14]["aggregation"]);
1106
1107
1108 return $news;
1109 }
1110
1117 protected function aggregateFiles($news, $a_ref_id)
1118 {
1119 $first_file = "";
1120 $to_del = array();
1121 foreach ($news as $k => $v) {
1122 // aggregate file related news
1123 if ($news[$k]["context_obj_type"] == "file") {
1124 if ($first_file == "") {
1125 $first_file = $k;
1126 } else {
1127 $to_del[] = $k;
1128 }
1129 $news[$first_file]["aggregation"][$k] = $news[$k];
1130 $news[$first_file]["agg_ref_id"] = $a_ref_id;
1131 $news[$first_file]["ref_id"] = $a_ref_id;
1132 }
1133 }
1134
1135 foreach ($to_del as $v) {
1136 unset($news[$v]);
1137 }
1138
1139 return $news;
1140 }
1141
1142
1154 protected function getAggregatedChildNewsData(
1155 $a_ref_id,
1156 $a_only_public = false,
1157 $a_time_period = 0,
1158 $a_prevent_aggregation = false,
1159 $a_starting_date = "",
1160 $a_no_auto_generated = false
1161 ) {
1163 $ilAccess = $this->access;
1164
1165 // get news of parent object
1166 $data = $this->getNewsForRefId(
1167 $a_ref_id,
1168 $a_only_public,
1169 true,
1170 $a_time_period,
1171 true,
1172 false,
1173 false,
1174 $a_no_auto_generated
1175 );
1176 foreach ($data as $k => $v) {
1177 $data[$k]["ref_id"] = $a_ref_id;
1178 }
1179
1180 // get childs
1181 $nodes = $tree->getChilds($a_ref_id);
1182
1183 // no check, for which of the objects any news are available
1184 $obj_ids = array();
1185 foreach ($nodes as $node) {
1186 $obj_ids[] = $node["obj_id"];
1187 }
1188 $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $a_time_period, $a_starting_date);
1189 //$news_obj_ids = $obj_ids;
1190
1191 // get news for all subtree nodes
1192 $contexts = array();
1193 foreach ($nodes as $node) {
1194 // only go on, if news are available
1195 if (!in_array($node["obj_id"], $news_obj_ids)) {
1196 continue;
1197 }
1198
1199 if (!$a_only_public && !$ilAccess->checkAccess("read", "", $node["child"])) {
1200 continue;
1201 }
1202 $ref_id[$node["obj_id"]] = $node["child"];
1203 $contexts[] = array("obj_id" => $node["obj_id"],
1204 "obj_type" => $node["type"]);
1205 }
1206
1207 $news = $this->queryNewsForMultipleContexts(
1208 $contexts,
1209 $a_only_public,
1210 $a_time_period,
1211 $a_starting_date,
1212 $a_no_auto_generated
1213 );
1214 foreach ($news as $k => $v) {
1215 $news[$k]["ref_id"] = $ref_id[$v["context_obj_id"]];
1216 }
1218
1219 // sort and return
1220 $data = ilUtil::sortArray($data, "creation_date", "desc", false, true);
1221
1222 if (!$a_prevent_aggregation) {
1223 $data = $this->aggregateFiles($data, $a_ref_id);
1224 }
1225
1226 return $data;
1227 }
1228
1237 public function setContext(int $a_obj_id, string $a_obj_type, int $a_sub_obj_id = 0, string $a_sub_obj_type = "")
1238 {
1239 $this->setContextObjId($a_obj_id);
1240 $this->setContextObjType($a_obj_type);
1241 $this->setContextSubObjId($a_sub_obj_id);
1242 $this->setContextSubObjType($a_sub_obj_type);
1243 }
1244
1251 protected static function handleTimePeriod($a_time_period)
1252 {
1253 // time period is number of days
1254 if (is_numeric($a_time_period)) {
1255 if ($a_time_period > 0) {
1256 return date('Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
1257 }
1258 }
1259 // time period is datetime
1260 elseif (preg_match("/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/", $a_time_period)) {
1261 return $a_time_period;
1262 }
1263 // :TODO: what to return?
1264 }
1265
1275 public function queryNewsForContext(
1276 $a_for_rss_use = false,
1277 $a_time_period = 0,
1278 $a_starting_date = "",
1279 $a_no_auto_generated = false,
1280 $a_oldest_first = false,
1281 $a_limit = 0
1282 ) {
1283 $ilDB = $this->db;
1285 $lng = $this->lng;
1286
1287 $and = "";
1288 if ($a_time_period > 0) {
1289 $limit_ts = self::handleTimePeriod($a_time_period);
1290 $and = " AND creation_date >= " . $ilDB->quote($limit_ts, "timestamp") . " ";
1291 }
1292
1293 if ($a_starting_date != "") {
1294 $and .= " AND creation_date > " . $ilDB->quote($a_starting_date, "timestamp") . " ";
1295 }
1296
1297 if ($a_no_auto_generated) {
1298 $and .= " AND priority = 1 AND content_type = " . $ilDB->quote("text", "text") . " ";
1299 }
1300
1301 // this is changed with 4.1 (news table for lm pages)
1302 if ($this->getContextSubObjId() > 0) {
1303 $and .= " AND context_sub_obj_id = " . $ilDB->quote($this->getContextSubObjId(), "integer") .
1304 " AND context_sub_obj_type = " . $ilDB->quote($this->getContextSubObjType(), "text");
1305 }
1306
1307 $ordering = ($a_oldest_first)
1308 ? " creation_date ASC, id ASC "
1309 : " creation_date DESC, id DESC ";
1310
1311 if ($a_for_rss_use && ilNewsItem::getPrivateFeedId() == false) {
1312 $query = "SELECT * " .
1313 "FROM il_news_item " .
1314 " WHERE " .
1315 "context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
1316 " AND context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text") .
1317 $and .
1318 " ORDER BY " . $ordering;
1319 } elseif (ilNewsItem::getPrivateFeedId() != false) {
1320 $query = "SELECT il_news_item.* " .
1321 ", il_news_read.user_id user_read " .
1322 "FROM il_news_item LEFT JOIN il_news_read " .
1323 "ON il_news_item.id = il_news_read.news_id AND " .
1324 " il_news_read.user_id = " . $ilDB->quote(ilNewsItem::getPrivateFeedId(), "integer") .
1325 " WHERE " .
1326 "context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
1327 " AND context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text") .
1328 $and .
1329 " ORDER BY " . $ordering;
1330 } else {
1331 $query = "SELECT il_news_item.* " .
1332 ", il_news_read.user_id as user_read " .
1333 "FROM il_news_item LEFT JOIN il_news_read " .
1334 "ON il_news_item.id = il_news_read.news_id AND " .
1335 " il_news_read.user_id = " . $ilDB->quote($ilUser->getId(), "integer") .
1336 " WHERE " .
1337 "context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
1338 " AND context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text") .
1339 $and .
1340 " ORDER BY " . $ordering;
1341 }
1342 //echo $query;
1343 $set = $ilDB->query($query);
1344 $result = array();
1345 while ($rec = $ilDB->fetchAssoc($set)) {
1346 if ($a_limit > 0 && count($result) >= $a_limit) {
1347 continue;
1348 }
1349 if (!$a_for_rss_use || (ilNewsItem::getPrivateFeedId() != false) || ($rec["visibility"] == NEWS_PUBLIC ||
1350 ($rec["priority"] == 0 &&
1352 "news",
1353 "public_notifications",
1354 0,
1355 $rec["context_obj_id"]
1356 )))) {
1357 $result[$rec["id"]] = $rec;
1358 }
1359 }
1360
1361 // do we get data for rss and may the time limit by an issue?
1362 // do a second query without time limit.
1363 // this is not very performant, but I do not have a better
1364 // idea. The keep_rss_min setting is currently (Jul 2012) only set
1365 // by mediacasts
1366 if ($a_time_period != "" && $a_for_rss_use) {
1367 include_once("./Services/Block/classes/class.ilBlockSetting.php");
1368 $keep_rss_min = ilBlockSetting::_lookup(
1369 "news",
1370 "keep_rss_min",
1371 0,
1372 $this->getContextObjId()
1373 );
1374 if ($keep_rss_min > 0) {
1375 return $this->queryNewsForContext(
1376 true,
1377 0,
1378 $a_starting_date,
1379 $a_no_auto_generated,
1380 $a_oldest_first,
1381 $keep_rss_min
1382 );
1383 }
1384 }
1385
1386 return $result;
1387 }
1388
1395 public static function queryNewsByIds(array $a_news_ids)
1396 {
1397 global $DIC;
1398 $ilDB = $DIC->database();
1399 $news = array();
1400 $set = $ilDB->query("SELECT * FROM il_news_item " .
1401 " WHERE " . $ilDB->in("id", $a_news_ids, false, "integer"));
1402 while ($rec = $ilDB->fetchAssoc($set)) {
1403 $news[$rec["id"]] = $rec;
1404 }
1405 return $news;
1406 }
1407
1415 public function checkNewsExistsForObjects($objects, $a_time_period = 1)
1416 {
1417 $ilDB = $this->db;
1418
1419 $all = array();
1420
1421 $limit_ts = self::handleTimePeriod($a_time_period);
1422
1423 // are there any news items for relevant objects and?
1424 $query = $ilDB->query("SELECT id,context_obj_id,context_obj_type" .
1425 " FROM il_news_item" .
1426 " WHERE " . $ilDB->in("context_obj_id", array_keys($objects), false, "integer") .
1427 " AND creation_date >= " . $ilDB->quote($limit_ts, "timestamp"));
1428 while ($rec = $ilDB->fetchAssoc($query)) {
1429 if ($objects[$rec["context_obj_id"]]["type"] == $rec["context_obj_type"]) {
1430 $all[] = $rec["id"];
1431 }
1432 }
1433
1434 return $all;
1435 }
1436
1451 $a_contexts,
1452 $a_for_rss_use = false,
1453 $a_time_period = 0,
1454 $a_starting_date = "",
1455 $a_no_auto_generated = false,
1456 $a_user_id = null,
1457 $a_limit = 0,
1458 $a_exclude = array()
1459 ) {
1460 $ilDB = $this->db;
1462 $lng = $this->lng;
1464
1465 $and = "";
1466 if ($a_time_period > 0) {
1467 $limit_ts = self::handleTimePeriod($a_time_period);
1468 $and = " AND creation_date >= " . $ilDB->quote($limit_ts, "timestamp") . " ";
1469 }
1470
1471 if ($a_starting_date != "") {
1472 $and .= " AND creation_date > " . $ilDB->quote($a_starting_date, "timestamp") . " ";
1473 }
1474
1475 if ($a_no_auto_generated) {
1476 $and .= " AND priority = 1 AND content_type = " . $ilDB->quote("text", "text") . " ";
1477 }
1478
1479 if ($a_limit > 0) {
1480 $ilDB->setLimit($a_limit, 0);
1481 }
1482
1483 if (is_array($a_exclude) && count($a_exclude) > 0) {
1484 $and .= " AND " . $ilDB->in("id", $a_exclude, true, "integer") . " ";
1485 }
1486
1487 $ids = array();
1488 $type = array();
1489
1490 foreach ($a_contexts as $cont) {
1491 $ids[] = $cont["obj_id"];
1492 $type[$cont["obj_id"]] = $cont["obj_type"];
1493 }
1494
1495 if ($a_for_rss_use && ilNewsItem::getPrivateFeedId() == false) {
1496 $query = "SELECT * " .
1497 "FROM il_news_item " .
1498 " WHERE " .
1499 $ilDB->in("context_obj_id", $ids, false, "integer") . " " .
1500 $and .
1501 " ORDER BY creation_date DESC ";
1502 } elseif (ilNewsItem::getPrivateFeedId() != false) {
1503 $query = "SELECT il_news_item.* " .
1504 ", il_news_read.user_id as user_read " .
1505 "FROM il_news_item LEFT JOIN il_news_read " .
1506 "ON il_news_item.id = il_news_read.news_id AND " .
1507 " il_news_read.user_id = " . $ilDB->quote(ilNewsItem::getPrivateFeedId(), "integer") .
1508 " WHERE " .
1509 $ilDB->in("context_obj_id", $ids, false, "integer") . " " .
1510 $and .
1511 " ORDER BY creation_date DESC ";
1512 } else {
1513 if ($a_user_id) {
1514 $user_id = $a_user_id;
1515 } else {
1516 $user_id = $ilUser->getId();
1517 }
1518 $query = "SELECT il_news_item.* " .
1519 ", il_news_read.user_id as user_read " .
1520 "FROM il_news_item LEFT JOIN il_news_read " .
1521 "ON il_news_item.id = il_news_read.news_id AND " .
1522 " il_news_read.user_id = " . $ilDB->quote($user_id, "integer") .
1523 " WHERE " .
1524 $ilDB->in("context_obj_id", $ids, false, "integer") . " " .
1525 $and .
1526 " ORDER BY creation_date DESC ";
1527 }
1528
1529 $set = $ilDB->query($query);
1530 $result = array();
1531 while ($rec = $ilDB->fetchAssoc($set)) {
1532 if ($type[$rec["context_obj_id"]] == $rec["context_obj_type"]) {
1533 if (!$a_for_rss_use || ilNewsItem::getPrivateFeedId() != false || ($rec["visibility"] == NEWS_PUBLIC ||
1534 ($rec["priority"] == 0 &&
1536 "news",
1537 "public_notifications",
1538 0,
1539 $rec["context_obj_id"]
1540 )))) {
1541 $result[$rec["id"]] = $rec;
1542 }
1543 }
1544 }
1545
1546 return $result;
1547 }
1548
1549
1554 public static function _setRead($a_user_id, $a_news_id)
1555 {
1556 global $DIC;
1557
1558 $ilDB = $DIC->database();
1559 $ilAppEventHandler = $DIC["ilAppEventHandler"];
1560
1561 $ilDB->replace(
1562 "il_news_read",
1563 array(
1564 "user_id" => array("integer", $a_user_id),
1565 "news_id" => array("integer", $a_news_id)
1566 ),
1567 array()
1568 );
1569
1570 /*
1571 $ilDB->manipulate("DELETE FROM il_news_read WHERE ".
1572 "user_id = ".$ilDB->quote($a_user_id, "integer").
1573 " AND news_id = ".$ilDB->quote($a_news_id, "integer"));
1574 $ilDB->manipulate("INSERT INTO il_news_read (user_id, news_id) VALUES (".
1575 $ilDB->quote($a_user_id, "integer").",".
1576 $ilDB->quote($a_news_id, "integer").")");*/
1577
1578 $ilAppEventHandler->raise(
1579 "Services/News",
1580 "readNews",
1581 array("user_id" => $a_user_id, "news_ids" => array($a_news_id))
1582 );
1583 }
1584
1589 public static function _setUnread($a_user_id, $a_news_id)
1590 {
1591 global $DIC;
1592
1593 $ilDB = $DIC->database();
1594 $ilAppEventHandler = $DIC["ilAppEventHandler"];
1595
1596 $ilDB->manipulate("DELETE FROM il_news_read (user_id, news_id) VALUES (" .
1597 " WHERE user_id = " . $ilDB->quote($a_user_id, "integer") .
1598 " AND news_id = " . $ilDB->quote($a_news_id, "integer"));
1599
1600 $ilAppEventHandler->raise(
1601 "Services/News",
1602 "unreadNews",
1603 array("user_id" => $a_user_id, "news_ids" => array($a_news_id))
1604 );
1605 }
1606
1615 public static function mergeNews($n1, $n2)
1616 {
1617 foreach ($n2 as $id => $news) {
1618 $n1[$id] = $news;
1619 }
1620
1621 return $n1;
1622 }
1623
1629 public static function _getDefaultVisibilityForRefId($a_ref_id)
1630 {
1631 global $DIC;
1632
1633 $tree = $DIC->repositoryTree();
1634 $ilSetting = $DIC->settings();
1635
1636 include_once("./Services/Block/classes/class.ilBlockSetting.php");
1637
1638 $news_set = new ilSetting("news");
1639 $default_visibility = ($news_set->get("default_visibility") != "")
1640 ? $news_set->get("default_visibility")
1641 : "users";
1642
1643 if ($tree->isInTree($a_ref_id)) {
1644 $path = $tree->getPathFull($a_ref_id);
1645
1646 foreach ($path as $key => $row) {
1647 if (!in_array($row["type"], array("root", "cat","crs", "fold", "grp"))) {
1648 continue;
1649 }
1650
1652 "news",
1653 "default_visibility",
1654 0,
1655 $row["obj_id"]
1656 );
1657
1658 if ($visibility != "") {
1659 $default_visibility = $visibility;
1660 }
1661 }
1662 }
1663
1664 return $default_visibility;
1665 }
1666
1667
1672 public function delete()
1673 {
1674 $ilDB = $this->db;
1675
1676 // delete il_news_read entries
1677 $ilDB->manipulate("DELETE FROM il_news_read " .
1678 " WHERE news_id = " . $ilDB->quote($this->getId(), "integer"));
1679
1680 // delete multimedia object
1681 $mob = $this->getMobId();
1682
1683 // delete
1684 $query = "DELETE FROM il_news_item" .
1685 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
1686 $ilDB->manipulate($query);
1687
1688 // delete mob after news, to have a "mob usage" of 0
1689 if ($mob > 0 and ilObject::_exists($mob)) {
1690 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1691 $mob = new ilObjMediaObject($mob);
1692 $mob->delete();
1693 }
1694 }
1695
1700 public static function getNewsOfContext(
1701 $a_context_obj_id,
1702 $a_context_obj_type,
1703 $a_context_sub_obj_id = 0,
1704 $a_context_sub_obj_type = ""
1705 ) {
1706 global $DIC;
1707
1708 $ilDB = $DIC->database();
1709
1710 if ($a_context_obj_id == 0 || $a_context_obj_type == "") {
1711 return [];
1712 }
1713
1714 if ($a_context_sub_obj_id > 0) {
1715 $and = " AND context_sub_obj_id = " . $ilDB->quote($a_context_sub_obj_id, "integer") .
1716 " AND context_sub_obj_type = " . $ilDB->quote($a_context_sub_obj_type, "text");
1717 }
1718
1719 // get news records
1720 $query = "SELECT * FROM il_news_item" .
1721 " WHERE context_obj_id = " . $ilDB->quote($a_context_obj_id, "integer") .
1722 " AND context_obj_type = " . $ilDB->quote($a_context_obj_type, "text") .
1723 $and;
1724
1725 $news_set = $ilDB->query($query);
1726
1727 $news_arr = [];
1728 while ($news = $ilDB->fetchAssoc($news_set)) {
1729 $news_arr[] = new ilNewsItem($news["id"]);
1730 }
1731 return $news_arr;
1732 }
1733
1738 public static function deleteNewsOfContext(
1739 $a_context_obj_id,
1740 $a_context_obj_type,
1741 $a_context_sub_obj_id = 0,
1742 $a_context_sub_obj_type = ""
1743 ) {
1744 foreach (self::getNewsOfContext(
1745 $a_context_obj_id,
1746 $a_context_obj_type,
1747 $a_context_sub_obj_id,
1748 $a_context_sub_obj_type
1749 ) as $n) {
1750 $n->delete();
1751 }
1752 }
1753
1758 public static function _lookupTitle($a_news_id)
1759 {
1760 global $DIC;
1761
1762 $ilDB = $DIC->database();
1763
1764 $query = "SELECT title FROM il_news_item WHERE id = " .
1765 $ilDB->quote($a_news_id, "integer");
1766 $set = $ilDB->query($query);
1767 $rec = $ilDB->fetchAssoc($set);
1768 return $rec["title"];
1769 }
1770
1775 public static function _lookupVisibility($a_news_id)
1776 {
1777 global $DIC;
1778
1779 $ilDB = $DIC->database();
1780
1781 $query = "SELECT visibility FROM il_news_item WHERE id = " .
1782 $ilDB->quote($a_news_id, "integer");
1783 $set = $ilDB->query($query);
1784 $rec = $ilDB->fetchAssoc($set);
1785
1786 return $rec["visibility"];
1787 }
1788
1793 public static function _lookupMobId($a_news_id)
1794 {
1795 global $DIC;
1796
1797 $ilDB = $DIC->database();
1798
1799 $query = "SELECT mob_id FROM il_news_item WHERE id = " .
1800 $ilDB->quote($a_news_id, "integer");
1801 $set = $ilDB->query($query);
1802 $rec = $ilDB->fetchAssoc($set);
1803 return $rec["mob_id"];
1804 }
1805
1810 public static function filterObjIdsPerNews($a_obj_ids, $a_time_period = 0, $a_starting_date = "", $a_ending_date = '', $ignore_period = false)
1811 {
1812 global $DIC;
1813
1814 $ilDB = $DIC->database();
1815
1816 $and = "";
1817 if ($a_time_period > 0) {
1818 $limit_ts = self::handleTimePeriod($a_time_period);
1819 $and = " AND creation_date >= " . $ilDB->quote($limit_ts, "timestamp") . " ";
1820 }
1821
1822 if ($a_starting_date != "") {
1823 $and .= " AND creation_date >= " . $ilDB->quote($a_starting_date, "timestamp");
1824 }
1825
1826 $query = "SELECT DISTINCT(context_obj_id) AS obj_id FROM il_news_item" .
1827 " WHERE " . $ilDB->in("context_obj_id", $a_obj_ids, false, "integer") . " " . $and;
1828 //" WHERE context_obj_id IN (".implode(ilUtil::quoteArray($a_obj_ids),",").")".$and;
1829
1830 $set = $ilDB->query($query);
1831 $objs = array();
1832 while ($rec = $ilDB->fetchAssoc($set)) {
1833 $objs[] = $rec["obj_id"];
1834 }
1835
1836 return $objs;
1837 }
1838
1842 public static function determineNewsTitleByNewsId($a_news_id, $a_agg_ref_id = 0, $a_aggregation = "")
1843 {
1844 global $DIC;
1845
1846 $ilDB = $DIC->database();
1847
1848 $query = "SELECT context_obj_type, content_is_lang_var, title FROM il_news_item WHERE id = " .
1849 $ilDB->quote($a_news_id, "integer");
1850 $set = $ilDB->query($query);
1851 $rec = $ilDB->fetchAssoc($set);
1852
1854 $rec["context_obj_type"],
1855 $rec["title"],
1856 $rec["content_is_lang_var"],
1857 $a_agg_ref_id,
1858 $a_aggregation
1859 );
1860 }
1861
1866 public static function determineNewsTitle(
1867 $a_context_obj_type,
1868 $a_title,
1869 $a_content_is_lang_var,
1870 $a_agg_ref_id = 0,
1871 $a_aggregation = ""
1872 ) {
1873 global $DIC;
1874
1875 $lng = $DIC->language();
1876 $obj_definition = $DIC["objDefinition"];
1877
1878 if ($a_agg_ref_id > 0) {
1879 $cnt = count($a_aggregation);
1880
1881 // forums
1882 if ($a_context_obj_type == "frm") {
1883 if ($cnt > 1) {
1884 return sprintf($lng->txt("news_x_postings"), $cnt);
1885 } else {
1886 return $lng->txt("news_1_postings");
1887 }
1888 } else { // files
1889 $up_cnt = $cr_cnt = 0;
1890 foreach ($a_aggregation as $item) {
1891 if ($item["title"] == "file_updated") {
1892 $up_cnt++;
1893 } else {
1894 $cr_cnt++;
1895 }
1896 }
1897 $sep = "";
1898 if ($cr_cnt == 1) {
1899 $tit = $lng->txt("news_1_file_created");
1900 $sep = "<br />";
1901 } elseif ($cr_cnt > 1) {
1902 $tit = sprintf($lng->txt("news_x_files_created"), $cr_cnt);
1903 $sep = "<br />";
1904 }
1905 if ($up_cnt == 1) {
1906 $tit .= $sep . $lng->txt("news_1_file_updated");
1907 } elseif ($up_cnt > 1) {
1908 $tit .= $sep . sprintf($lng->txt("news_x_files_updated"), $up_cnt);
1909 }
1910 return $tit;
1911 }
1912 } else {
1913 if ($a_content_is_lang_var) {
1914 if ($obj_definition->isPlugin($a_context_obj_type)) {
1915 return ilObjectPlugin::lookupTxtById($a_context_obj_type, $a_title);
1916 }
1917 return $lng->txt($a_title);
1918 } else {
1919 return $a_title;
1920 }
1921 }
1922
1923 return "";
1924 }
1925
1930 public static function determineNewsContent($a_context_obj_type, $a_content, $a_is_lang_var)
1931 {
1932 global $DIC;
1933
1934 $lng = $DIC->language();
1935 $obj_definition = $DIC["objDefinition"];
1936
1937 if ($a_is_lang_var) {
1938 if ($obj_definition->isPlugin($a_context_obj_type)) {
1939 return ilObjectPlugin::lookupTxtById($a_context_obj_type, $a_content);
1940 }
1941 $lng->loadLanguageModule($a_context_obj_type);
1942 return $lng->txt($a_content);
1943 } else {
1944 return $a_content;
1945 }
1946 }
1947
1948
1949
1954 public static function getFirstNewsIdForContext(
1955 $a_context_obj_id,
1956 $a_context_obj_type,
1957 $a_context_sub_obj_id = "",
1958 $a_context_sub_obj_type = ""
1959 ) {
1960 global $DIC;
1961
1962 $ilDB = $DIC->database();
1963
1964 // Determine how many rows should be deleted
1965 $query = "SELECT * " .
1966 "FROM il_news_item " .
1967 "WHERE " .
1968 "context_obj_id = " . $ilDB->quote($a_context_obj_id, "integer") .
1969 " AND context_obj_type = " . $ilDB->quote($a_context_obj_type, "text") .
1970 " AND context_sub_obj_id = " . $ilDB->quote($a_context_sub_obj_id, "integer") .
1971 " AND " . $ilDB->equals("context_sub_obj_type", $a_context_sub_obj_type, "text", true);
1972
1973 $set = $ilDB->query($query);
1974 $rec = $ilDB->fetchAssoc($set);
1975
1976 return $rec["id"];
1977 }
1978
1983 public static function getLastNewsIdForContext(
1984 $a_context_obj_id,
1985 $a_context_obj_type,
1986 $a_context_sub_obj_id = "",
1987 $a_context_sub_obj_type = "",
1988 $a_only_today = false
1989 ) {
1990 global $DIC;
1991
1992 $ilDB = $DIC->database();
1993
1994 // Determine how many rows should be deleted
1995 $query = "SELECT id, update_date " .
1996 "FROM il_news_item " .
1997 "WHERE " .
1998 "context_obj_id = " . $ilDB->quote($a_context_obj_id, "integer") .
1999 " AND context_obj_type = " . $ilDB->quote($a_context_obj_type, "text") .
2000 " AND context_sub_obj_id = " . $ilDB->quote($a_context_sub_obj_id, "integer") .
2001 " AND " . $ilDB->equals("context_sub_obj_type", $a_context_sub_obj_type, "text", true) .
2002 " ORDER BY update_date DESC";
2003
2004 $ilDB->setLimit(1);
2005 $set = $ilDB->query($query);
2006 $rec = $ilDB->fetchAssoc($set);
2007
2008 $id = (int) $rec["id"];
2009 if ($a_only_today) {
2010 $now = ilUtil::now();
2011 if (substr($now, 0, 10) != substr($rec["update_date"], 0, 10)) {
2012 $id = 0;
2013 }
2014 }
2015
2016 return $id;
2017 }
2018
2019
2024 public static function _lookupMediaObjectUsages($a_mob_id)
2025 {
2026 global $DIC;
2027
2028 $ilDB = $DIC->database();
2029
2030 $query = "SELECT * " .
2031 "FROM il_news_item " .
2032 "WHERE " .
2033 " mob_id = " . $ilDB->quote($a_mob_id, "integer");
2034
2035 $usages = array();
2036 $set = $ilDB->query($query);
2037 while ($rec = $ilDB->fetchAssoc($set)) {
2038 $usages[$rec["id"]] = array("type" => "news", "id" => $rec["id"]);
2039 }
2040
2041 return $usages;
2042 }
2043
2048 public static function _lookupContextObjId($a_news_id)
2049 {
2050 global $DIC;
2051
2052 $ilDB = $DIC->database();
2053
2054 $query = "SELECT * " .
2055 "FROM il_news_item " .
2056 "WHERE " .
2057 " id = " . $ilDB->quote($a_news_id, "integer");
2058 $set = $ilDB->query($query);
2059 $rec = $ilDB->fetchAssoc($set);
2060
2061 return $rec["context_obj_id"];
2062 }
2063
2067 public static function _lookupDefaultPDPeriod()
2068 {
2069 $news_set = new ilSetting("news");
2070 $per = $news_set->get("pd_period");
2071 if ($per == 0) {
2072 $per = 30;
2073 }
2074
2075 return $per;
2076 }
2077
2081 public static function _lookupUserPDPeriod($a_user_id)
2082 {
2083 $news_set = new ilSetting("news");
2084 $allow_shorter_periods = $news_set->get("allow_shorter_periods");
2085 $allow_longer_periods = $news_set->get("allow_longer_periods");
2086 $default_per = ilNewsItem::_lookupDefaultPDPeriod();
2087
2088 include_once("./Services/Block/classes/class.ilBlockSetting.php");
2090 "pdnews",
2091 "news_pd_period",
2092 $a_user_id,
2093 0
2094 );
2095
2096 // news period information
2097 if ($per <= 0 ||
2098 (!$allow_shorter_periods && ($per < $default_per)) ||
2099 (!$allow_longer_periods && ($per > $default_per))
2100 ) {
2101 $per = $default_per;
2102 }
2103
2104 return $per;
2105 }
2106
2110 public static function _lookupRSSPeriod()
2111 {
2112 $news_set = new ilSetting("news");
2113 $rss_period = $news_set->get("rss_period");
2114 if ($rss_period == 0) { // default to two weeks
2115 $rss_period = 14;
2116 }
2117 return $rss_period;
2118 }
2119
2123 public static function setPrivateFeedId($a_userId)
2124 {
2125 ilNewsItem::$privFeedId = $a_userId;
2126 }
2127
2131 public static function getPrivateFeedId()
2132 {
2134 }
2135
2144 public function deliverMobFile($a_purpose = "Standard", $a_increase_download_cnt = false)
2145 {
2146 $mob = $this->getMobId();
2147 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
2148 $mob = new ilObjMediaObject($mob);
2149 $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
2150
2151 // check purpose
2152 if (!$mob->hasPurposeItem($a_purpose)) {
2153 return false;
2154 }
2155
2156 $m_item = $mob->getMediaItem($a_purpose);
2157 if ($m_item->getLocationType() != "Reference") {
2158 $file = $mob_dir . "/" . $m_item->getLocation();
2159 if (file_exists($file) && is_file($file)) {
2160 if ($a_increase_download_cnt) {
2161 $this->increaseDownloadCounter();
2162 }
2163 ilUtil::deliverFile($file, $m_item->getLocation(), "", false, false, false);
2164 return true;
2165 } else {
2166 ilUtil::sendFailure("File not found!", true);
2167 return false;
2168 }
2169 } else {
2170 if ($a_increase_download_cnt) {
2171 $this->increaseDownloadCounter();
2172 }
2173 ilUtil::redirect($m_item->getLocation());
2174 }
2175 }
2176
2181 public function increaseDownloadCounter()
2182 {
2183 $ilDB = $this->db;
2184
2185 $cnt = $this->getMobDownloadCounter();
2186 $cnt++;
2187 $this->setMobDownloadCounter($cnt);
2188 $ilDB->manipulate(
2189 "UPDATE il_news_item SET " .
2190 " mob_cnt_download = " . $ilDB->quote($cnt, "integer") .
2191 " WHERE id = " . $ilDB->quote($this->getId(), "integer")
2192 );
2193 }
2194
2200 public function increasePlayCounter()
2201 {
2202 $ilDB = $this->db;
2203
2204 $cnt = $this->getMobPlayCounter();
2205 $cnt++;
2206 $this->setMobPlayCounter($cnt);
2207 $ilDB->manipulate(
2208 "UPDATE il_news_item SET " .
2209 " mob_cnt_play = " . $ilDB->quote($cnt, "integer") .
2210 " WHERE id = " . $ilDB->quote($this->getId(), "integer")
2211 );
2212 }
2213
2220 public static function prepareNewsDataFromCache($a_cres)
2221 {
2222 global $DIC;
2223
2224 $ilDB = $DIC->database();
2225
2226 $data = $a_cres;
2227 $news_ids = array_keys($data);
2228 $set = $ilDB->query("SELECT id FROM il_news_item " .
2229 " WHERE " . $ilDB->in("id", $news_ids, false, "integer"));
2230 $existing_ids = array();
2231 while ($rec = $ilDB->fetchAssoc($set)) {
2232 $existing_ids[] = $rec["id"];
2233 }
2234 //var_dump($existing_ids);
2235 $existing_news = array();
2236 foreach ($data as $k => $v) {
2237 if (in_array($k, $existing_ids)) {
2238 $existing_news[$k] = $v;
2239 }
2240 }
2241
2242 //var_dump($data);
2243 //var_dump($existing_news);
2244
2245 return $existing_news;
2246 }
2247}
$result
user()
Definition: user.php:4
$n
Definition: RandomTest.php:85
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
const NEWS_PUBLIC
static _lookup($a_type, $a_setting, $a_user=0, $a_block_id=0)
Lookup setting from database.
update($a_as_new=false)
Update item in database.
deliverMobFile($a_purpose="Standard", $a_increase_download_cnt=false)
Deliver mob file.
static _getDefaultVisibilityForRefId($a_ref_id)
Get default visibility for reference id.
static _lookupVisibility($a_news_id)
Lookup News Visibility.
getNewsForRefId( $a_ref_id, $a_only_public=false, $a_stopnesting=false, $a_time_period=0, $a_prevent_aggregation=true, $a_forum_group_sequences=false, $a_no_auto_generated=false, $a_ignore_date_filter=false, $a_user_id=null, $a_limit=0, $a_excluded=array())
Get News For Ref Id.
static _lookupTitle($a_news_id)
Lookup News Title.
setContent($a_content)
Set Content.
__construct($a_id=0)
Constructor.
static getPrivateFeedId()
static _lookupRSSPeriod()
setMobId($a_mob_id)
Set MobId.
getContentIsLangVar()
Get ContentIsLangVar.
static _setUnread($a_user_id, $a_news_id)
Set item unread.
setCreationDate($a_creation_date)
Set CreationDate.
static _lookupMobId($a_news_id)
Lookup mob id.
static getLastNewsIdForContext( $a_context_obj_id, $a_context_obj_type, $a_context_sub_obj_id="", $a_context_sub_obj_type="", $a_only_today=false)
Get last news id of news set related to a certain context.
read()
Read item from database.
setMobPlayCounter($a_val)
Set mob play counter.
getUpdateDate()
Get UpdateDate.
static handleTimePeriod($a_time_period)
Convert time period for DB-queries.
getPlaytime()
Get Playtime.
getAggregatedNewsData( $a_ref_id, $a_only_public=false, $a_time_period=0, $a_prevent_aggregation=false, $a_starting_date="", $a_no_auto_generated=false, $a_user_id=null, $a_limit=0, $a_exclude=array())
Get news aggregation (e.g.
aggregateForums($news, $a_group_posting_sequence=false)
setContentIsLangVar($a_content_is_lang_var=0)
Set ContentIsLangVar.
getContextSubObjId()
Get ContextSubObjId.
getContextSubObjType()
Get ContextSubObjType.
setUserId($a_user_id)
Set UserId.
static deleteNewsOfContext( $a_context_obj_id, $a_context_obj_type, $a_context_sub_obj_id=0, $a_context_sub_obj_type="")
Delete all news of a context.
setContextObjId($a_context_obj_id)
Set ContextObjId.
getMobId()
Get MobId.
setContextSubObjId($a_context_sub_obj_id)
Set ContextSubObjId.
checkNewsExistsForObjects($objects, $a_time_period=1)
static getNewsOfContext( $a_context_obj_id, $a_context_obj_type, $a_context_sub_obj_id=0, $a_context_sub_obj_type="")
Get all news of a context.
increasePlayCounter()
Increase play counter.
setLimitation($a_limitation)
Set Limitation for number of items.
increaseDownloadCounter()
Increase download counter.
static _setRead($a_user_id, $a_news_id)
Set item read.
getVisibility()
Get Visibility.
static filterObjIdsPerNews($a_obj_ids, $a_time_period=0, $a_starting_date="", $a_ending_date='', $ignore_period=false)
Checks whether news are available for.
setUpdateDate($a_update_date)
Set UpdateDate.
getTitle()
Get Title.
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 determineNewsContent($a_context_obj_type, $a_content, $a_is_lang_var)
Determine new content.
setTitle($a_title)
Set Title.
static prepareNewsDataFromCache($a_cres)
Prepare news data from cache.
getContentType()
Get ContentType.
setUpdateUserId($a_val)
Set update user id.
getLimitation()
Get Limitation for number of items.
static _getNewsItemsOfUser( $a_user_id, $a_only_public=false, $a_prevent_aggregation=false, $a_per=0, &$a_cnt=null)
Get all news items for a user.
setPlaytime($a_playtime)
Set Playtime.
getContent()
Get Content.
queryNewsForContext( $a_for_rss_use=false, $a_time_period=0, $a_starting_date="", $a_no_auto_generated=false, $a_oldest_first=false, $a_limit=0)
Query news for a context.
static _lookupUserPDPeriod($a_user_id)
setContextObjType($a_context_obj_type)
Set ContextObjType.
setPriority($a_priority=1)
Set Priority.
setContentLong($a_content_long)
Set ContentLong.
static determineNewsTitleByNewsId($a_news_id, $a_agg_ref_id=0, $a_aggregation="")
Determine title for news item entry.
static $privFeedId
static queryNewsByIds(array $a_news_ids)
Query news data by news ids.
static setPrivateFeedId($a_userId)
getContentLong()
Get ContentLong.
static mergeNews($n1, $n2)
Merges two sets of news.
static _lookupDefaultPDPeriod()
static determineNewsTitle( $a_context_obj_type, $a_title, $a_content_is_lang_var, $a_agg_ref_id=0, $a_aggregation="")
Determine title for news item entry.
setContentTextIsLangVar($a_val=0)
Set content text ist lang var.
getPriority()
Get Priority.
setVisibility($a_visibility="users")
Set Visibility.
getContextObjId()
Get ContextObjId.
setId($a_id)
Set Id.
setContentType($a_content_type="text")
Set ContentType.
getMobPlayCounter()
Get mob play counter.
queryNewsForMultipleContexts( $a_contexts, $a_for_rss_use=false, $a_time_period=0, $a_starting_date="", $a_no_auto_generated=false, $a_user_id=null, $a_limit=0, $a_exclude=array())
Query News for multiple Contexts.
setContextSubObjType($a_context_sub_obj_type)
Set ContextSubObjType.
setContentHtml($a_val)
Is content HTML (tiny used?)
getAggregatedChildNewsData( $a_ref_id, $a_only_public=false, $a_time_period=0, $a_prevent_aggregation=false, $a_starting_date="", $a_no_auto_generated=false)
Get news aggregation for child objects (e.g.
static getFirstNewsIdForContext( $a_context_obj_id, $a_context_obj_type, $a_context_sub_obj_id="", $a_context_sub_obj_type="")
Get first new id of news set related to a certain context.
getMobDownloadCounter()
Get mob download counter.
setMobDownloadCounter($a_val)
Set mob download counter.
getUserId()
Get UserId.
getCreationDate()
Get CreationDate.
getContentTextIsLangVar()
Get content text ist lang var.
aggregateFiles($news, $a_ref_id)
static _lookupContextObjId($a_news_id)
Context Object ID.
getContextObjType()
Get ContextObjType.
getUpdateUserId()
Get update user id.
getContentHtml()
Get content as html.
static _lookupMediaObjectUsages($a_mob_id)
Lookup media object usage(s)
static _getSubscriptionsOfUser($a_user_id)
Get subscriptions of user.
Class ilObjMediaObject.
static _getDirectory($a_mob_id)
Get absolute directory.
static _lookupPref($a_usr_id, $a_keyword)
static _lookupDesktopItems($user_id, $a_types="")
get all desktop items of user and specified type
static preloadData(array $a_ref_ids)
Preload data to internal cache.
static lookupTxtById($plugin_id, $lang_var)
static _lookupObjId($a_id)
static _getAllReferences($a_id)
get all reference ids of object
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getMembershipByType($a_usr_id, $a_type, $a_only_member_role=false)
get membership by type Get course or group membership
ILIAS Setting Class.
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static now()
Return current timestamp in Y-m-d H:i:s format.
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
$key
Definition: croninfo.php:18
$i
Definition: disco.tpl.php:19
global $ilCtrl
Definition: ilias.php:18
$row
global $ilSetting
Definition: privfeed.php:17
$query
$type
global $DIC
Definition: saml.php:7
global $ilDB
$ilUser
Definition: imgupload.php:18
$data
Definition: bench.php:6
$a_content
Definition: workflow.php:93