ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 define("NEWS_NOTICE", 0);
5 define("NEWS_MESSAGE", 1);
6 define("NEWS_WARNING", 2);
7 
8 define("NEWS_TEXT", "text");
9 define("NEWS_HTML", "html");
10 define("NEWS_AUDIO", "audio");
11 define("NEWS_USERS", "users");
12 define("NEWS_PUBLIC", "public");
13 
14 
15 
29 {
33  protected $db;
34 
38  protected $tree;
39 
43  protected $access;
44 
48  protected $obj_data_cache;
49 
53  protected $user;
54 
58  protected $lng;
59 
63  protected $ctrl;
64 
65  protected $id;
66  protected $title;
67  protected $content;
71  protected $content_html;
72  protected $context_obj_id;
73  protected $context_obj_type;
76  protected $content_type = "text";
77  protected $creation_date;
78  protected $update_date;
79  protected $user_id;
83  protected $update_user_id;
84  protected $visibility = "users";
85  protected $content_long;
86  protected $priority = 1;
87  protected $content_is_lang_var = 0;
88  protected $mob_id;
89  protected $playtime;
90 
91  private static $privFeedId = false;
92  private $limitation;
93 
99  public function __construct($a_id = 0)
100  {
101  global $DIC;
102 
103  $this->db = $DIC->database();
104  $this->tree = $DIC->repositoryTree();
105  $this->access = $DIC->access();
106  $this->obj_data_cache = $DIC["ilObjDataCache"];
107  $this->user = $DIC->user();
108  $this->lng = $DIC->language();
109  $this->ctrl = $DIC->ctrl();
110  if ($a_id > 0) {
111  $this->setId($a_id);
112  $this->read();
113  }
114  $this->limitation = true;
115  }
116 
122  public function setId($a_id)
123  {
124  $this->id = $a_id;
125  }
126 
132  public function getId()
133  {
134  return $this->id;
135  }
136 
142  public function setTitle($a_title)
143  {
144  $this->title = $a_title;
145  }
146 
152  public function getTitle()
153  {
154  return $this->title;
155  }
156 
162  public function setContent($a_content)
163  {
164  $this->content = $a_content;
165  }
166 
172  public function getContent()
173  {
174  return $this->content;
175  }
176 
182  public function setContextObjId($a_context_obj_id)
183  {
184  $this->context_obj_id = $a_context_obj_id;
185  }
186 
192  public function getContextObjId()
193  {
194  return $this->context_obj_id;
195  }
196 
202  public function setContextObjType($a_context_obj_type)
203  {
204  $this->context_obj_type = $a_context_obj_type;
205  }
206 
212  public function getContextObjType()
213  {
215  }
216 
222  public function setContextSubObjId($a_context_sub_obj_id)
223  {
224  $this->context_sub_obj_id = $a_context_sub_obj_id;
225  }
226 
232  public function getContextSubObjId()
233  {
235  }
236 
242  public function setContextSubObjType($a_context_sub_obj_type)
243  {
244  $this->context_sub_obj_type = $a_context_sub_obj_type;
245  }
246 
252  public function getContextSubObjType()
253  {
255  }
256 
262  public function setContentType($a_content_type = "text")
263  {
264  $this->content_type = $a_content_type;
265  }
266 
272  public function getContentType()
273  {
274  return $this->content_type;
275  }
276 
282  public function setCreationDate($a_creation_date)
283  {
284  $this->creation_date = $a_creation_date;
285  }
286 
292  public function getCreationDate()
293  {
294  return $this->creation_date;
295  }
296 
302  public function setUpdateDate($a_update_date)
303  {
304  $this->update_date = $a_update_date;
305  }
306 
312  public function getUpdateDate()
313  {
314  return $this->update_date;
315  }
316 
322  public function setUserId($a_user_id)
323  {
324  $this->user_id = $a_user_id;
325  }
326 
332  public function getUserId()
333  {
334  return $this->user_id;
335  }
336 
342  public function setUpdateUserId($a_val)
343  {
344  $this->update_user_id = $a_val;
345  }
346 
352  public function getUpdateUserId()
353  {
354  return $this->update_user_id;
355  }
356 
362  public function setVisibility($a_visibility = "users")
363  {
364  $this->visibility = $a_visibility;
365  }
366 
372  public function getVisibility()
373  {
374  return $this->visibility;
375  }
376 
382  public function setContentLong($a_content_long)
383  {
384  $this->content_long = $a_content_long;
385  }
386 
392  public function getContentLong()
393  {
394  return $this->content_long;
395  }
396 
402  public function setPriority($a_priority = 1)
403  {
404  $this->priority = $a_priority;
405  }
406 
412  public function getPriority()
413  {
414  return $this->priority;
415  }
416 
422  public function setContentIsLangVar($a_content_is_lang_var = 0)
423  {
424  $this->content_is_lang_var = $a_content_is_lang_var;
425  }
426 
432  public function getContentIsLangVar()
433  {
435  }
436 
442  public function setMobId($a_mob_id)
443  {
444  $this->mob_id = $a_mob_id;
445  }
446 
452  public function getMobId()
453  {
454  return $this->mob_id;
455  }
456 
462  public function setPlaytime($a_playtime)
463  {
464  $this->playtime = $a_playtime;
465  }
466 
472  public function getPlaytime()
473  {
474  return $this->playtime;
475  }
476 
477 
483  public function setLimitation($a_limitation)
484  {
485  $this->limitation = $a_limitation;
486  }
487 
493  public function getLimitation()
494  {
495  return $this->limitation;
496  }
497 
503  public function setContentTextIsLangVar($a_val = 0)
504  {
505  $this->content_text_is_lang_var = $a_val;
506  }
507 
513  public function getContentTextIsLangVar()
514  {
515  return $this->content_text_is_lang_var;
516  }
517 
523  public function setMobPlayCounter($a_val)
524  {
525  $this->mob_cnt_play = $a_val;
526  }
527 
533  public function getMobPlayCounter()
534  {
535  return $this->mob_cnt_play;
536  }
537 
543  public function setMobDownloadCounter($a_val)
544  {
545  $this->mob_cnt_download = $a_val;
546  }
547 
553  public function getMobDownloadCounter()
554  {
555  return $this->mob_cnt_download;
556  }
557 
563  public function setContentHtml($a_val)
564  {
565  $this->content_html = $a_val;
566  }
567 
573  public function getContentHtml()
574  {
575  return $this->content_html;
576  }
577 
581  public function read()
582  {
583  $ilDB = $this->db;
584 
585  $query = "SELECT * FROM il_news_item WHERE id = " .
586  $ilDB->quote($this->getId(), "integer");
587  $set = $ilDB->query($query);
588  $rec = $ilDB->fetchAssoc($set);
589 
590  $this->setTitle($rec["title"]);
591  $this->setContent($rec["content"]);
592  $this->setContextObjId((int) $rec["context_obj_id"]);
593  $this->setContextObjType($rec["context_obj_type"]);
594  $this->setContextSubObjId((int) $rec["context_sub_obj_id"]);
595  $this->setContextSubObjType($rec["context_sub_obj_type"]);
596  $this->setContentType($rec["content_type"]);
597  $this->setCreationDate($rec["creation_date"]);
598  $this->setUpdateDate($rec["update_date"]);
599  $this->setUserId($rec["user_id"]);
600  $this->setUpdateUserId($rec["update_user_id"]);
601  $this->setVisibility($rec["visibility"]);
602  $this->setContentLong($rec["content_long"]);
603  $this->setPriority($rec["priority"]);
604  $this->setContentIsLangVar($rec["content_is_lang_var"]);
605  $this->setContentTextIsLangVar((int) $rec["content_text_is_lang_var"]);
606  $this->setMobId($rec["mob_id"]);
607  $this->setPlaytime($rec["playtime"]);
608  $this->setMobPlayCounter($rec["mob_cnt_play"]);
609  $this->setMobDownloadCounter($rec["mob_cnt_download"]);
610  $this->setContentHtml($rec["content_html"]);
611  }
612 
616  public function create()
617  {
618  $ilDB = $this->db;
619 
620  // insert new record into db
621  $this->setId($ilDB->nextId("il_news_item"));
622  $ilDB->insert("il_news_item", array(
623  "id" => array("integer", $this->getId()),
624  "title" => array("text", $this->getTitle()),
625  "content" => array("clob", $this->getContent()),
626  "content_html" => array("integer", (int) $this->getContentHtml()),
627  "context_obj_id" => array("integer", (int) $this->getContextObjId()),
628  "context_obj_type" => array("text", $this->getContextObjType()),
629  "context_sub_obj_id" => array("integer", (int) $this->getContextSubObjId()),
630  "context_sub_obj_type" => array("text", $this->getContextSubObjType()),
631  "content_type" => array("text", $this->getContentType()),
632  "creation_date" => array("timestamp", ilUtil::now()),
633  "update_date" => array("timestamp", ilUtil::now()),
634  "user_id" => array("integer", $this->getUserId()),
635  "update_user_id" => array("integer", (int) $this->getUpdateUserId()),
636  "visibility" => array("text", $this->getVisibility()),
637  "content_long" => array("clob", $this->getContentLong()),
638  "priority" => array("integer", $this->getPriority()),
639  "content_is_lang_var" => array("integer", $this->getContentIsLangVar()),
640  "content_text_is_lang_var" => array("integer", (int) $this->getContentTextIsLangVar()),
641  "mob_id" => array("integer", $this->getMobId()),
642  "playtime" => array("text", $this->getPlaytime())
643  ));
644 
645 
646  $news_set = new ilSetting("news");
647  $max_items = $news_set->get("max_items");
648  if ($max_items <= 0) {
649  $max_items = 50;
650  }
651 
652  // limit number of news
653  if ($this->getLimitation()) {
654  // Determine how many rows should be deleted
655  $query = "SELECT count(*) cnt " .
656  "FROM il_news_item " .
657  "WHERE " .
658  "context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
659  " AND context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text") .
660  " AND context_sub_obj_id = " . $ilDB->quote($this->getContextSubObjId(), "integer") .
661  " AND " . $ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true) . " ";
662 
663  $set = $ilDB->query($query);
664  $rec = $ilDB->fetchAssoc($set);
665 
666  // if we have more records than allowed, delete them
667  if (($rec["cnt"] > $max_items) && $this->getContextObjId() > 0) {
668  $query = "SELECT * " .
669  "FROM il_news_item " .
670  "WHERE " .
671  "context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
672  " AND context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text") .
673  " AND context_sub_obj_id = " . $ilDB->quote($this->getContextSubObjId(), "integer") .
674  " AND " . $ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true) .
675  " ORDER BY creation_date ASC";
676 
677  $ilDB->setLimit($rec["cnt"] - $max_items);
678  $del_set = $ilDB->query($query);
679  while ($del_item = $ilDB->fetchAssoc($del_set)) {
680  $del_news = new ilNewsItem($del_item["id"]);
681  $del_news->delete();
682  }
683  }
684  }
685  }
686 
692  public function update($a_as_new = false)
693  {
694  $ilDB = $this->db;
695 
696  $fields = array(
697  "title" => array("text", $this->getTitle()),
698  "content" => array("clob", $this->getContent()),
699  "content_html" => array("integer", (int) $this->getContentHtml()),
700  "context_obj_id" => array("integer", $this->getContextObjId()),
701  "context_obj_type" => array("text", $this->getContextObjType()),
702  "context_sub_obj_id" => array("integer", $this->getContextSubObjId()),
703  "context_sub_obj_type" => array("text", $this->getContextSubObjType()),
704  "content_type" => array("text", $this->getContentType()),
705  "user_id" => array("integer", $this->getUserId()),
706  "update_user_id" => array("integer", (int) $this->getUpdateUserId()),
707  "visibility" => array("text", $this->getVisibility()),
708  "content_long" => array("clob", $this->getContentLong()),
709  "priority" => array("integer", $this->getPriority()),
710  "content_is_lang_var" => array("integer", $this->getContentIsLangVar()),
711  "content_text_is_lang_var" => array("integer", (int) $this->getContentTextIsLangVar()),
712  "mob_id" => array("integer", $this->getMobId()),
713  "mob_cnt_play" => array("integer", $this->getMobPlayCounter()),
714  "mob_cnt_download" => array("integer", $this->getMobDownloadCounter()),
715  "playtime" => array("text", $this->getPlaytime())
716  );
717 
718  $now = ilUtil::now();
719  if ($a_as_new) {
720  $fields["creation_date"] = array("timestamp", $now);
721  $fields["update_date"] = array("timestamp", $now);
722  } else {
723  $fields["update_date"] = array("timestamp", $now);
724  }
725 
726  $ilDB->update("il_news_item", $fields, array(
727  "id" => array("integer", $this->getId())
728  ));
729  }
730 
731 
735  public static function _getNewsItemsOfUser(
736  $a_user_id,
737  $a_only_public = false,
738  $a_prevent_aggregation = false,
739  $a_per = 0,
740  &$a_cnt = null
741  ) {
742  global $DIC;
743 
744  $ilAccess = $DIC->access();
745 
746  $news_item = new ilNewsItem();
747  $news_set = new ilSetting("news");
748 
749  $per = $a_per;
750 
751  include_once("./Services/News/classes/class.ilNewsSubscription.php");
752  include_once("./Services/Block/classes/class.ilBlockSetting.php");
753 
754  // this is currently not used
755  $ref_ids = ilNewsSubscription::_getSubscriptionsOfUser($a_user_id);
756 
757  if (ilObjUser::_lookupPref($a_user_id, "pd_items_news") != "n") {
758  // get all items of the personal desktop
759  $pd_items = ilObjUser::_lookupDesktopItems($a_user_id);
760  foreach ($pd_items as $item) {
761  if (!in_array($item["ref_id"], $ref_ids)) {
762  $ref_ids[] = $item["ref_id"];
763  }
764  }
765 
766  // get all memberships
767  include_once 'Services/Membership/classes/class.ilParticipants.php';
768  $crs_mbs = ilParticipants::_getMembershipByType($a_user_id, 'crs');
769  $grp_mbs = ilParticipants::_getMembershipByType($a_user_id, 'grp');
770  $items = array_merge($crs_mbs, $grp_mbs);
771  foreach ($items as $i) {
772  $item_references = ilObject::_getAllReferences($i);
773  if (is_array($item_references) && count($item_references)) {
774  foreach ($item_references as $ref_id) {
775  if (!in_array($ref_id, $ref_ids)) {
776  $ref_ids[] = $ref_id;
777  }
778  }
779  }
780  }
781  }
782 
783  $data = array();
784 
785  foreach ($ref_ids as $ref_id) {
786  if (!$a_only_public) {
787  // this loop should not cost too much performance
788  $acc = $ilAccess->checkAccessOfUser($a_user_id, "read", "", $ref_id);
789 
790  if (!$acc) {
791  continue;
792  }
793  }
794  if (ilNewsItem::getPrivateFeedId() != false) {
795  global $DIC;
796 
797  $rbacsystem = $DIC->rbac()->system();
798  $acc = $rbacsystem->checkAccessOfUser(ilNewsItem::getPrivateFeedId(), "read", $ref_id);
799 
800  if (!$acc) {
801  continue;
802  }
803  }
804 
805  $obj_id = ilObject::_lookupObjId($ref_id);
806  $obj_type = ilObject::_lookupType($obj_id);
807  $news = $news_item->getNewsForRefId(
808  $ref_id,
809  $a_only_public,
810  false,
811  $per,
812  $a_prevent_aggregation,
813  false,
814  false,
815  false,
816  $a_user_id
817  );
818 
819  // counter
820  if (!is_null($a_cnt)) {
821  $a_cnt[$ref_id] = count($news);
822  }
823 
825  }
826 
827  $data = ilUtil::sortArray($data, "creation_date", "desc", false, true);
828 
829  return $data;
830  }
831 
848  public function getNewsForRefId(
849  $a_ref_id,
850  $a_only_public = false,
851  $a_stopnesting = false,
852  $a_time_period = 0,
853  $a_prevent_aggregation = true,
854  $a_forum_group_sequences = false,
855  $a_no_auto_generated = false,
856  $a_ignore_date_filter = false,
857  $a_user_id = null,
858  $a_limit = 0,
859  $a_excluded = array()
860  ) {
861  $obj_id = ilObject::_lookupObjId($a_ref_id);
862  $obj_type = ilObject::_lookupType($obj_id);
863 
864  // get starting date
865  $starting_date = "";
866  if ($obj_type == "grp" || $obj_type == "crs" || $obj_type == "cat") {
867  include_once("./Services/Block/classes/class.ilBlockSetting.php");
868  $hide_news_per_date = ilBlockSetting::_lookup(
869  "news",
870  "hide_news_per_date",
871  0,
872  $obj_id
873  );
874  if ($hide_news_per_date && !$a_ignore_date_filter) {
875  $starting_date = ilBlockSetting::_lookup(
876  "news",
877  "hide_news_date",
878  0,
879  $obj_id
880  );
881  }
882  }
883 
884  if ($obj_type == "cat" && !$a_stopnesting) {
885  $news = $this->getAggregatedChildNewsData(
886  $a_ref_id,
887  $a_only_public,
888  $a_time_period,
889  $a_prevent_aggregation,
890  $starting_date,
891  $a_no_auto_generated
892  );
893  } elseif (($obj_type == "grp" || $obj_type == "crs") &&
894  !$a_stopnesting) {
895  $news = $this->getAggregatedNewsData(
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  $a_user_id,
903  $a_limit,
904  $a_excluded
905  );
906  } else {
907  $news_item = new ilNewsItem();
908  $news_item->setContextObjId($obj_id);
909  $news_item->setContextObjType($obj_type);
910  $news = $news_item->queryNewsForContext(
911  $a_only_public,
912  $a_time_period,
913  $starting_date,
914  $a_no_auto_generated
915  );
916  $unset = array();
917  foreach ($news as $k => $v) {
918  if (!$a_only_public || $v["visibility"] == NEWS_PUBLIC ||
919  ($v["priority"] == 0 &&
921  "news",
922  "public_notifications",
923  0,
924  $obj_id
925  ))) {
926  $news[$k]["ref_id"] = $a_ref_id;
927  } else {
928  $unset[] = $k;
929  }
930  }
931  foreach ($unset as $un) {
932  unset($news[$un]);
933  }
934  }
935 
936  if (!$a_prevent_aggregation) {
937  $news = $this->aggregateForums($news);
938  } elseif ($a_forum_group_sequences) {
939  $news = $this->aggregateForums($news, true);
940  }
941 
942  return $news;
943  }
944 
948  public function getAggregatedNewsData(
949  $a_ref_id,
950  $a_only_public = false,
951  $a_time_period = 0,
952  $a_prevent_aggregation = false,
953  $a_starting_date = "",
954  $a_no_auto_generated = false,
955  $a_user_id = null,
956  $a_limit = 0,
957  $a_exclude = array()
958  ) {
959  $tree = $this->tree;
960  $ilAccess = $this->access;
961  $ilObjDataCache = $this->obj_data_cache;
962 
963  // get news of parent object
964 
965  $data = array();
966 
967  // get subtree
968  $cur_node = $tree->getNodeData($a_ref_id);
969 
970  // do not check for lft (materialized path)
971  if ($cur_node) {
972  $nodes = (array) $tree->getSubTree($cur_node, true);
973  } else {
974  $nodes = array();
975  }
976 
977  // preload object data cache
978  $ref_ids = array();
979  $obj_ids = array();
980  foreach ($nodes as $node) {
981  $ref_ids[] = $node["child"];
982  $obj_ids[] = $node["obj_id"];
983  }
984 
985  $ilObjDataCache->preloadReferenceCache($ref_ids);
986  if (!$a_only_public) {
987  include_once "Services/Object/classes/class.ilObjectActivation.php";
989  }
990 
991  // no check, for which of the objects any news are available
992  $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $a_time_period, $a_starting_date);
993  //$news_obj_ids = $obj_ids;
994 
995  // get news for all subtree nodes
996  $contexts = array();
997  foreach ($nodes as $node) {
998  // only go on, if news are available
999  if (!in_array($node["obj_id"], $news_obj_ids)) {
1000  continue;
1001  }
1002 
1003  if (!$a_only_public) {
1004  if (!$a_user_id) {
1005  $acc = $ilAccess->checkAccess("read", "", $node["child"]);
1006  } else {
1007  $acc = $ilAccess->checkAccessOfUser(
1008  $a_user_id,
1009  "read",
1010  "",
1011  $node["child"]
1012  );
1013  }
1014  if (!$acc) {
1015  continue;
1016  }
1017  }
1018 
1019  $ref_id[$node["obj_id"]] = $node["child"];
1020  $contexts[] = array("obj_id" => $node["obj_id"],
1021  "obj_type" => $node["type"]);
1022  }
1023 
1024  // sort and return
1025  $news = $this->queryNewsForMultipleContexts(
1026  $contexts,
1027  $a_only_public,
1028  $a_time_period,
1029  $a_starting_date,
1030  $a_no_auto_generated,
1031  $a_user_id,
1032  $a_limit,
1033  $a_exclude
1034  );
1035 
1036  $to_del = array();
1037  foreach ($news as $k => $v) {
1038  $news[$k]["ref_id"] = $ref_id[$v["context_obj_id"]];
1039  }
1040 
1041  $data = ilNewsItem::mergeNews($data, $news);
1042  $data = ilUtil::sortArray($data, "creation_date", "desc", false, true);
1043 
1044  if (!$a_prevent_aggregation) {
1045  $data = $this->aggregateFiles($data, $a_ref_id);
1046  }
1047 
1048  return $data;
1049  }
1050 
1051  public function aggregateForums($news, $a_group_posting_sequence = false)
1052  {
1053  $to_del = array();
1054  $forums = array();
1055 
1056  // aggregate
1057  foreach ($news as $k => $v) {
1058  if ($a_group_posting_sequence && $last_aggregation_forum > 0 &&
1059  $last_aggregation_forum != $news[$k]["context_obj_id"]) {
1060  $forums[$last_aggregation_forum] = "";
1061  }
1062 
1063  if ($news[$k]["context_obj_type"] == "frm") {
1064  if ($forums[$news[$k]["context_obj_id"]] == "") {
1065  // $forums[forum_id] = news_id;
1066  $forums[$news[$k]["context_obj_id"]] = $k;
1067  $last_aggregation_forum = $news[$k]["context_obj_id"];
1068  } else {
1069  $to_del[] = $k;
1070  }
1071 
1072  $news[$k]["no_context_title"] = true;
1073 
1074  // aggregate every forum into it's "k" news
1075  $news[$forums[$news[$k]["context_obj_id"]]]["aggregation"][$k]
1076  = $news[$k];
1077  $news[$k]["agg_ref_id"]
1078  = $news[$k]["ref_id"];
1079  $news[$k]["content"] = "";
1080  $news[$k]["content_long"] = "";
1081  }
1082  }
1083 
1084  // delete double entries
1085  foreach ($to_del as $k) {
1086  unset($news[$k]);
1087  }
1088  //var_dump($news[14]["aggregation"]);
1089 
1090 
1091  return $news;
1092  }
1093 
1094  public function aggregateFiles($news, $a_ref_id)
1095  {
1096  $first_file = "";
1097  $to_del = array();
1098  foreach ($news as $k => $v) {
1099  // aggregate file related news
1100  if ($news[$k]["context_obj_type"] == "file") {
1101  if ($first_file == "") {
1102  $first_file = $k;
1103  } else {
1104  $to_del[] = $k;
1105  }
1106  $news[$first_file]["aggregation"][$k] = $news[$k];
1107  $news[$first_file]["agg_ref_id"] = $a_ref_id;
1108  $news[$first_file]["ref_id"] = $a_ref_id;
1109  }
1110  }
1111 
1112  foreach ($to_del as $v) {
1113  unset($news[$v]);
1114  }
1115 
1116  return $news;
1117  }
1118 
1119 
1124  $a_ref_id,
1125  $a_only_public = false,
1126  $a_time_period = 0,
1127  $a_prevent_aggregation = false,
1128  $a_starting_date = "",
1129  $a_no_auto_generated = false
1130  ) {
1131  $tree = $this->tree;
1132  $ilAccess = $this->access;
1133 
1134  // get news of parent object
1135  $data = $this->getNewsForRefId(
1136  $a_ref_id,
1137  $a_only_public,
1138  true,
1139  $a_time_period,
1140  true,
1141  false,
1142  false,
1143  $a_no_auto_generated
1144  );
1145  foreach ($data as $k => $v) {
1146  $data[$k]["ref_id"] = $a_ref_id;
1147  }
1148 
1149  // get childs
1150  $nodes = $tree->getChilds($a_ref_id);
1151 
1152  // no check, for which of the objects any news are available
1153  $obj_ids = array();
1154  foreach ($nodes as $node) {
1155  $obj_ids[] = $node["obj_id"];
1156  }
1157  $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $a_time_period, $a_starting_date);
1158  //$news_obj_ids = $obj_ids;
1159 
1160  // get news for all subtree nodes
1161  $contexts = array();
1162  foreach ($nodes as $node) {
1163  // only go on, if news are available
1164  if (!in_array($node["obj_id"], $news_obj_ids)) {
1165  continue;
1166  }
1167 
1168  if (!$a_only_public && !$ilAccess->checkAccess("read", "", $node["child"])) {
1169  continue;
1170  }
1171  $ref_id[$node["obj_id"]] = $node["child"];
1172  $contexts[] = array("obj_id" => $node["obj_id"],
1173  "obj_type" => $node["type"]);
1174  }
1175 
1176  $news = $this->queryNewsForMultipleContexts(
1177  $contexts,
1178  $a_only_public,
1179  $a_time_period,
1180  $a_starting_date,
1181  $a_no_auto_generated
1182  );
1183  foreach ($news as $k => $v) {
1184  $news[$k]["ref_id"] = $ref_id[$v["context_obj_id"]];
1185  }
1186  $data = ilNewsItem::mergeNews($data, $news);
1187 
1188  // sort and return
1189  $data = ilUtil::sortArray($data, "creation_date", "desc", false, true);
1190 
1191  if (!$a_prevent_aggregation) {
1192  $data = $this->aggregateFiles($data, $a_ref_id);
1193  }
1194 
1195  return $data;
1196  }
1197 
1201  public function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type = "")
1202  {
1203  $this->setContextObjId($a_obj_id);
1204  $this->setContextObjType($a_obj_type);
1205  $this->setContextSubObjId($a_sub_obj_id);
1206  $this->setContextSubObjType($a_sub_obj_type);
1207  }
1208 
1215  protected static function handleTimePeriod($a_time_period)
1216  {
1217  // time period is number of days
1218  if (is_numeric($a_time_period)) {
1219  if ($a_time_period > 0) {
1220  return date('Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
1221  }
1222  }
1223  // time period is datetime
1224  elseif (preg_match("/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/", $a_time_period)) {
1225  return $a_time_period;
1226  }
1227  // :TODO: what to return?
1228  }
1229 
1238  public function queryNewsForContext(
1239  $a_for_rss_use = false,
1240  $a_time_period = 0,
1241  $a_starting_date = "",
1242  $a_no_auto_generated = false,
1243  $a_oldest_first = false,
1244  $a_limit = 0
1245  ) {
1246  $ilDB = $this->db;
1247  $ilUser = $this->user;
1248  $lng = $this->lng;
1249 
1250  $and = "";
1251  if ($a_time_period > 0) {
1252  $limit_ts = self::handleTimePeriod($a_time_period);
1253  $and = " AND creation_date >= " . $ilDB->quote($limit_ts, "timestamp") . " ";
1254  }
1255 
1256  if ($a_starting_date != "") {
1257  $and.= " AND creation_date > " . $ilDB->quote($a_starting_date, "timestamp") . " ";
1258  }
1259 
1260  if ($a_no_auto_generated) {
1261  $and.= " AND priority = 1 AND content_type = " . $ilDB->quote("text", "text") . " ";
1262  }
1263 
1264  // this is changed with 4.1 (news table for lm pages)
1265  if ($this->getContextSubObjId() > 0) {
1266  $and.= " AND context_sub_obj_id = " . $ilDB->quote($this->getContextSubObjId(), "integer") .
1267  " AND context_sub_obj_type = " . $ilDB->quote($this->getContextSubObjType(), "text");
1268  }
1269 
1270  $ordering = ($a_oldest_first)
1271  ? " creation_date ASC, id ASC "
1272  : " creation_date DESC, id DESC ";
1273 
1274  if ($a_for_rss_use && ilNewsItem::getPrivateFeedId() == false) {
1275  $query = "SELECT * " .
1276  "FROM il_news_item " .
1277  " WHERE " .
1278  "context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
1279  " AND context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text") .
1280  $and .
1281  " ORDER BY " . $ordering;
1282  } elseif (ilNewsItem::getPrivateFeedId() != false) {
1283  $query = "SELECT il_news_item.* " .
1284  ", il_news_read.user_id user_read " .
1285  "FROM il_news_item LEFT JOIN il_news_read " .
1286  "ON il_news_item.id = il_news_read.news_id AND " .
1287  " il_news_read.user_id = " . $ilDB->quote(ilNewsItem::getPrivateFeedId(), "integer") .
1288  " WHERE " .
1289  "context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
1290  " AND context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text") .
1291  $and .
1292  " ORDER BY " . $ordering;
1293  } else {
1294  $query = "SELECT il_news_item.* " .
1295  ", il_news_read.user_id as user_read " .
1296  "FROM il_news_item LEFT JOIN il_news_read " .
1297  "ON il_news_item.id = il_news_read.news_id AND " .
1298  " il_news_read.user_id = " . $ilDB->quote($ilUser->getId(), "integer") .
1299  " WHERE " .
1300  "context_obj_id = " . $ilDB->quote($this->getContextObjId(), "integer") .
1301  " AND context_obj_type = " . $ilDB->quote($this->getContextObjType(), "text") .
1302  $and .
1303  " ORDER BY " . $ordering;
1304  }
1305  //echo $query;
1306  $set = $ilDB->query($query);
1307  $result = array();
1308  while ($rec = $ilDB->fetchAssoc($set)) {
1309  if ($a_limit > 0 && count($result) >= $a_limit) {
1310  continue;
1311  }
1312  if (!$a_for_rss_use || (ilNewsItem::getPrivateFeedId() != false) || ($rec["visibility"] == NEWS_PUBLIC ||
1313  ($rec["priority"] == 0 &&
1315  "news",
1316  "public_notifications",
1317  0,
1318  $rec["context_obj_id"]
1319  )))) {
1320  $result[$rec["id"]] = $rec;
1321  }
1322  }
1323 
1324  // do we get data for rss and may the time limit by an issue?
1325  // do a second query without time limit.
1326  // this is not very performant, but I do not have a better
1327  // idea. The keep_rss_min setting is currently (Jul 2012) only set
1328  // by mediacasts
1329  if ($a_time_period != "" && $a_for_rss_use) {
1330  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1331  $keep_rss_min = ilBlockSetting::_lookup(
1332  "news",
1333  "keep_rss_min",
1334  0,
1335  $this->getContextObjId()
1336  );
1337  if ($keep_rss_min > 0) {
1338  return $this->queryNewsForContext(
1339  true,
1340  0,
1341  $a_starting_date,
1342  $a_no_auto_generated,
1343  $a_oldest_first,
1344  $keep_rss_min
1345  );
1346  }
1347  }
1348 
1349  return $result;
1350  }
1351 
1359  public function checkNewsExistsForGroupCourse($a_ref_id, $a_time_period = 1)
1360  {
1361  $tree = $this->tree;
1362  $ilDB = $this->db;
1363 
1364  $all = array();
1365 
1366  if (!$tree->isDeleted($a_ref_id)) {
1367  // parse repository branch of group
1368  $nodes = array();
1369  $node = $tree->getNodeData($a_ref_id);
1370  foreach ($tree->getSubTree($node) as $child) {
1371  if ($child["type"] != "rolf") {
1372  $nodes[$child["obj_id"]] = $child["type"];
1373  }
1374  }
1375 
1376  $limit_ts = self::handleTimePeriod($a_time_period);
1377 
1378  // are there any news items for relevant objects and?
1379  $query = $ilDB->query("SELECT id,context_obj_id,context_obj_type" .
1380  " FROM il_news_item" .
1381  " WHERE " . $ilDB->in("context_obj_id", array_keys($nodes), false, "integer") .
1382  " AND creation_date >= " . $ilDB->quote($limit_ts, "timestamp"));
1383  while ($rec = $ilDB->fetchAssoc($query)) {
1384  if ($nodes[$rec["context_obj_id"]] == $rec["context_obj_type"]) {
1385  $all[] = $rec["id"];
1386  }
1387  }
1388  }
1389 
1390  return $all;
1391  }
1392 
1407  $a_contexts,
1408  $a_for_rss_use = false,
1409  $a_time_period = 0,
1410  $a_starting_date = "",
1411  $a_no_auto_generated = false,
1412  $a_user_id = null,
1413  $a_limit = 0,
1414  $a_exclude = array()
1415  ) {
1416  $ilDB = $this->db;
1417  $ilUser = $this->user;
1418  $lng = $this->lng;
1419  $ilCtrl = $this->ctrl;
1420 
1421  $and = "";
1422  if ($a_time_period > 0) {
1423  $limit_ts = self::handleTimePeriod($a_time_period);
1424  $and = " AND creation_date >= " . $ilDB->quote($limit_ts, "timestamp") . " ";
1425  }
1426 
1427  if ($a_starting_date != "") {
1428  $and.= " AND creation_date > " . $ilDB->quote($a_starting_date, "timestamp") . " ";
1429  }
1430 
1431  if ($a_no_auto_generated) {
1432  $and.= " AND priority = 1 AND content_type = " . $ilDB->quote("text", "text") . " ";
1433  }
1434 
1435  if ($a_limit > 0) {
1436  $ilDB->setLimit($a_limit, 0);
1437  }
1438 
1439  if (is_array($a_exclude) && count($a_exclude) > 0) {
1440  $and.= " AND " . $ilDB->in("id", $a_exclude, true, "integer") . " ";
1441  }
1442 
1443  $ids = array();
1444  $type = array();
1445 
1446  foreach ($a_contexts as $cont) {
1447  $ids[] = $cont["obj_id"];
1448  $type[$cont["obj_id"]] = $cont["obj_type"];
1449  }
1450 
1451  if ($a_for_rss_use && ilNewsItem::getPrivateFeedId() == false) {
1452  $query = "SELECT * " .
1453  "FROM il_news_item " .
1454  " WHERE " .
1455  $ilDB->in("context_obj_id", $ids, false, "integer") . " " .
1456  $and .
1457  " ORDER BY creation_date DESC ";
1458  } elseif (ilNewsItem::getPrivateFeedId() != false) {
1459  $query = "SELECT il_news_item.* " .
1460  ", il_news_read.user_id as user_read " .
1461  "FROM il_news_item LEFT JOIN il_news_read " .
1462  "ON il_news_item.id = il_news_read.news_id AND " .
1463  " il_news_read.user_id = " . $ilDB->quote(ilNewsItem::getPrivateFeedId(), "integer") .
1464  " WHERE " .
1465  $ilDB->in("context_obj_id", $ids, false, "integer") . " " .
1466  $and .
1467  " ORDER BY creation_date DESC ";
1468  } else {
1469  if ($a_user_id) {
1470  $user_id = $a_user_id;
1471  } else {
1472  $user_id = $ilUser->getId();
1473  }
1474  $query = "SELECT il_news_item.* " .
1475  ", il_news_read.user_id as user_read " .
1476  "FROM il_news_item LEFT JOIN il_news_read " .
1477  "ON il_news_item.id = il_news_read.news_id AND " .
1478  " il_news_read.user_id = " . $ilDB->quote($user_id, "integer") .
1479  " WHERE " .
1480  $ilDB->in("context_obj_id", $ids, false, "integer") . " " .
1481  $and .
1482  " ORDER BY creation_date DESC ";
1483  }
1484 
1485  $set = $ilDB->query($query);
1486  $result = array();
1487  while ($rec = $ilDB->fetchAssoc($set)) {
1488  if ($type[$rec["context_obj_id"]] == $rec["context_obj_type"]) {
1489  if (!$a_for_rss_use || ilNewsItem::getPrivateFeedId() != false || ($rec["visibility"] == NEWS_PUBLIC ||
1490  ($rec["priority"] == 0 &&
1492  "news",
1493  "public_notifications",
1494  0,
1495  $rec["context_obj_id"]
1496  )))) {
1497  $result[$rec["id"]] = $rec;
1498  }
1499  }
1500  }
1501 
1502  return $result;
1503  }
1504 
1505 
1509  public static function _setRead($a_user_id, $a_news_id)
1510  {
1511  global $DIC;
1512 
1513  $ilDB = $DIC->database();
1514  $ilAppEventHandler = $DIC["ilAppEventHandler"];
1515 
1516  $ilDB->replace(
1517  "il_news_read",
1518  array(
1519  "user_id" => array("integer", $a_user_id),
1520  "news_id" => array("integer", $a_news_id)
1521  ),
1522  array()
1523  );
1524 
1525  /*
1526  $ilDB->manipulate("DELETE FROM il_news_read WHERE ".
1527  "user_id = ".$ilDB->quote($a_user_id, "integer").
1528  " AND news_id = ".$ilDB->quote($a_news_id, "integer"));
1529  $ilDB->manipulate("INSERT INTO il_news_read (user_id, news_id) VALUES (".
1530  $ilDB->quote($a_user_id, "integer").",".
1531  $ilDB->quote($a_news_id, "integer").")");*/
1532 
1533  $ilAppEventHandler->raise(
1534  "Services/News",
1535  "readNews",
1536  array("user_id" => $a_user_id, "news_ids" => array($a_news_id))
1537  );
1538  }
1539 
1543  public static function _setUnread($a_user_id, $a_news_id)
1544  {
1545  global $DIC;
1546 
1547  $ilDB = $DIC->database();
1548  $ilAppEventHandler = $DIC["ilAppEventHandler"];
1549 
1550  $ilDB->manipulate("DELETE FROM il_news_read (user_id, news_id) VALUES (" .
1551  " WHERE user_id = " . $ilDB->quote($a_user_id, "integer") .
1552  " AND news_id = " . $ilDB->quote($a_news_id, "integer"));
1553 
1554  $ilAppEventHandler->raise(
1555  "Services/News",
1556  "unreadNews",
1557  array("user_id" => $a_user_id, "news_ids" => array($a_news_id))
1558  );
1559  }
1560 
1569  public static function mergeNews($n1, $n2)
1570  {
1571  foreach ($n2 as $id => $news) {
1572  $n1[$id] = $news;
1573  }
1574 
1575  return $n1;
1576  }
1577 
1583  public static function _getDefaultVisibilityForRefId($a_ref_id)
1584  {
1585  global $DIC;
1586 
1587  $tree = $DIC->repositoryTree();
1588  $ilSetting = $DIC->settings();
1589 
1590  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1591 
1592  $news_set = new ilSetting("news");
1593  $default_visibility = ($news_set->get("default_visibility") != "")
1594  ? $news_set->get("default_visibility")
1595  : "users";
1596 
1597  if ($tree->isInTree($a_ref_id)) {
1598  $path = $tree->getPathFull($a_ref_id);
1599 
1600  foreach ($path as $key => $row) {
1601  if (!in_array($row["type"], array("root", "cat","crs", "fold", "grp"))) {
1602  continue;
1603  }
1604 
1606  "news",
1607  "default_visibility",
1608  0,
1609  $row["obj_id"]
1610  );
1611 
1612  if ($visibility != "") {
1613  $default_visibility = $visibility;
1614  }
1615  }
1616  }
1617 
1618  return $default_visibility;
1619  }
1620 
1621 
1626  public function delete()
1627  {
1628  $ilDB = $this->db;
1629 
1630  // delete il_news_read entries
1631  $ilDB->manipulate("DELETE FROM il_news_read " .
1632  " WHERE news_id = " . $ilDB->quote($this->getId(), "integer"));
1633 
1634  // delete multimedia object
1635  $mob = $this->getMobId();
1636 
1637  // delete
1638  $query = "DELETE FROM il_news_item" .
1639  " WHERE id = " . $ilDB->quote($this->getId(), "integer");
1640  $ilDB->manipulate($query);
1641 
1642  // delete mob after news, to have a "mob usage" of 0
1643  if ($mob > 0 and ilObject::_exists($mob)) {
1644  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1645  $mob = new ilObjMediaObject($mob);
1646  $mob->delete();
1647  }
1648  }
1649 
1654  public static function deleteNewsOfContext(
1655  $a_context_obj_id,
1656  $a_context_obj_type,
1657  $a_context_sub_obj_id = 0,
1658  $a_context_sub_obj_type = ""
1659  ) {
1660  global $DIC;
1661 
1662  $ilDB = $DIC->database();
1663 
1664  if ($a_context_obj_id == 0 || $a_context_obj_type == "") {
1665  return [];
1666  }
1667 
1668  if ($a_context_sub_obj_id > 0) {
1669  $and = " AND context_sub_obj_id = " . $ilDB->quote($a_context_sub_obj_id, "integer") .
1670  " AND context_sub_obj_type = " . $ilDB->quote($a_context_sub_obj_type, "text");
1671  }
1672 
1673  // get news records
1674  $query = "SELECT * FROM il_news_item" .
1675  " WHERE context_obj_id = " . $ilDB->quote($a_context_obj_id, "integer") .
1676  " AND context_obj_type = " . $ilDB->quote($a_context_obj_type, "text") .
1677  $and;
1678 
1679  $news_set = $ilDB->query($query);
1680 
1681  while ($news = $ilDB->fetchAssoc($news_set)) {
1682  $news_obj = new ilNewsItem($news["id"]);
1683  $news_obj->delete();
1684  }
1685  }
1686 
1690  public static function _lookupTitle($a_news_id)
1691  {
1692  global $DIC;
1693 
1694  $ilDB = $DIC->database();
1695 
1696  $query = "SELECT title FROM il_news_item WHERE id = " .
1697  $ilDB->quote($a_news_id, "integer");
1698  $set = $ilDB->query($query);
1699  $rec = $ilDB->fetchAssoc($set);
1700  return $rec["title"];
1701  }
1702 
1706  public static function _lookupVisibility($a_news_id)
1707  {
1708  global $DIC;
1709 
1710  $ilDB = $DIC->database();
1711 
1712  $query = "SELECT visibility FROM il_news_item WHERE id = " .
1713  $ilDB->quote($a_news_id, "integer");
1714  $set = $ilDB->query($query);
1715  $rec = $ilDB->fetchAssoc($set);
1716 
1717  return $rec["visibility"];
1718  }
1719 
1723  public static function _lookupMobId($a_news_id)
1724  {
1725  global $DIC;
1726 
1727  $ilDB = $DIC->database();
1728 
1729  $query = "SELECT mob_id FROM il_news_item WHERE id = " .
1730  $ilDB->quote($a_news_id, "integer");
1731  $set = $ilDB->query($query);
1732  $rec = $ilDB->fetchAssoc($set);
1733  return $rec["mob_id"];
1734  }
1735 
1739  public static function filterObjIdsPerNews($a_obj_ids, $a_time_period = 0, $a_starting_date = "", $a_ending_date = '', $ignore_period = false)
1740  {
1741  global $DIC;
1742 
1743  $ilDB = $DIC->database();
1744 
1745  $and = "";
1746  if ($a_time_period > 0) {
1747  $limit_ts = self::handleTimePeriod($a_time_period);
1748  $and = " AND creation_date >= " . $ilDB->quote($limit_ts, "timestamp") . " ";
1749  }
1750 
1751  if ($a_starting_date != "") {
1752  $and.= " AND creation_date >= " . $ilDB->quote($a_starting_date, "timestamp");
1753  }
1754 
1755  $query = "SELECT DISTINCT(context_obj_id) AS obj_id FROM il_news_item" .
1756  " WHERE " . $ilDB->in("context_obj_id", $a_obj_ids, false, "integer") . " " . $and;
1757  //" WHERE context_obj_id IN (".implode(ilUtil::quoteArray($a_obj_ids),",").")".$and;
1758 
1759  $set = $ilDB->query($query);
1760  $objs = array();
1761  while ($rec = $ilDB->fetchAssoc($set)) {
1762  $objs[] = $rec["obj_id"];
1763  }
1764 
1765  return $objs;
1766  }
1767 
1771  public static function determineNewsTitle(
1772  $a_context_obj_type,
1773  $a_title,
1774  $a_content_is_lang_var,
1775  $a_agg_ref_id = 0,
1776  $a_aggregation = ""
1777  ) {
1778  global $DIC;
1779 
1780  $lng = $DIC->language();
1781 
1782  if ($a_agg_ref_id > 0) {
1783  $cnt = count($a_aggregation);
1784 
1785  // forums
1786  if ($a_context_obj_type == "frm") {
1787  if ($cnt > 1) {
1788  return sprintf($lng->txt("news_x_postings"), $cnt);
1789  } else {
1790  return $lng->txt("news_1_postings");
1791  }
1792  } else { // files
1793  $up_cnt = $cr_cnt = 0;
1794  foreach ($a_aggregation as $item) {
1795  if ($item["title"] == "file_updated") {
1796  $up_cnt++;
1797  } else {
1798  $cr_cnt++;
1799  }
1800  }
1801  $sep = "";
1802  if ($cr_cnt == 1) {
1803  $tit = $lng->txt("news_1_file_created");
1804  $sep = "<br />";
1805  } elseif ($cr_cnt > 1) {
1806  $tit = sprintf($lng->txt("news_x_files_created"), $cr_cnt);
1807  $sep = "<br />";
1808  }
1809  if ($up_cnt == 1) {
1810  $tit .= $sep . $lng->txt("news_1_file_updated");
1811  } elseif ($up_cnt > 1) {
1812  $tit .= $sep . sprintf($lng->txt("news_x_files_updated"), $up_cnt);
1813  }
1814  return $tit;
1815  }
1816  } else {
1817  if ($a_content_is_lang_var) {
1818  return $lng->txt($a_title);
1819  } else {
1820  return $a_title;
1821  }
1822  }
1823 
1824  return "";
1825  }
1826 
1830  public static function determineNewsContent($a_context_obj_type, $a_content, $a_is_lang_var)
1831  {
1832  global $DIC;
1833 
1834  $lng = $DIC->language();
1835 
1836  if ($a_is_lang_var) {
1837  $lng->loadLanguageModule($a_context_obj_type);
1838  return $lng->txt($a_content);
1839  } else {
1840  return $a_content;
1841  }
1842  }
1843 
1844 
1845 
1849  public static function getFirstNewsIdForContext(
1850  $a_context_obj_id,
1851  $a_context_obj_type,
1852  $a_context_sub_obj_id = "",
1853  $a_context_sub_obj_type = ""
1854  ) {
1855  global $DIC;
1856 
1857  $ilDB = $DIC->database();
1858 
1859  // Determine how many rows should be deleted
1860  $query = "SELECT * " .
1861  "FROM il_news_item " .
1862  "WHERE " .
1863  "context_obj_id = " . $ilDB->quote($a_context_obj_id, "integer") .
1864  " AND context_obj_type = " . $ilDB->quote($a_context_obj_type, "text") .
1865  " AND context_sub_obj_id = " . $ilDB->quote($a_context_sub_obj_id, "integer") .
1866  " AND " . $ilDB->equals("context_sub_obj_type", $a_context_sub_obj_type, "text", true);
1867 
1868  $set = $ilDB->query($query);
1869  $rec = $ilDB->fetchAssoc($set);
1870 
1871  return $rec["id"];
1872  }
1873 
1877  public static function getLastNewsIdForContext(
1878  $a_context_obj_id,
1879  $a_context_obj_type,
1880  $a_context_sub_obj_id = "",
1881  $a_context_sub_obj_type = "",
1882  $a_only_today = false
1883  ) {
1884  global $DIC;
1885 
1886  $ilDB = $DIC->database();
1887 
1888  // Determine how many rows should be deleted
1889  $query = "SELECT id, update_date " .
1890  "FROM il_news_item " .
1891  "WHERE " .
1892  "context_obj_id = " . $ilDB->quote($a_context_obj_id, "integer") .
1893  " AND context_obj_type = " . $ilDB->quote($a_context_obj_type, "text") .
1894  " AND context_sub_obj_id = " . $ilDB->quote($a_context_sub_obj_id, "integer") .
1895  " AND " . $ilDB->equals("context_sub_obj_type", $a_context_sub_obj_type, "text", true) .
1896  " ORDER BY update_date DESC";
1897 
1898  $ilDB->setLimit(1);
1899  $set = $ilDB->query($query);
1900  $rec = $ilDB->fetchAssoc($set);
1901 
1902  $id = (int) $rec["id"];
1903  if ($a_only_today) {
1904  $now = ilUtil::now();
1905  if (substr($now, 0, 10) != substr($rec["update_date"], 0, 10)) {
1906  $id = 0;
1907  }
1908  }
1909 
1910  return $id;
1911  }
1912 
1913 
1917  public static function _lookupMediaObjectUsages($a_mob_id)
1918  {
1919  global $DIC;
1920 
1921  $ilDB = $DIC->database();
1922 
1923  $query = "SELECT * " .
1924  "FROM il_news_item " .
1925  "WHERE " .
1926  " mob_id = " . $ilDB->quote($a_mob_id, "integer");
1927 
1928  $usages = array();
1929  $set = $ilDB->query($query);
1930  while ($rec = $ilDB->fetchAssoc($set)) {
1931  $usages[$rec["id"]] = array("type" => "news", "id" => $rec["id"]);
1932  }
1933 
1934  return $usages;
1935  }
1936 
1940  public static function _lookupContextObjId($a_news_id)
1941  {
1942  global $DIC;
1943 
1944  $ilDB = $DIC->database();
1945 
1946  $query = "SELECT * " .
1947  "FROM il_news_item " .
1948  "WHERE " .
1949  " id = " . $ilDB->quote($a_news_id, "integer");
1950  $set = $ilDB->query($query);
1951  $rec = $ilDB->fetchAssoc($set);
1952 
1953  return $rec["context_obj_id"];
1954  }
1955 
1956  public static function _lookupDefaultPDPeriod()
1957  {
1958  $news_set = new ilSetting("news");
1959  $per = $news_set->get("pd_period");
1960  if ($per == 0) {
1961  $per = 30;
1962  }
1963 
1964  return $per;
1965  }
1966 
1967  public static function _lookupUserPDPeriod($a_user_id)
1968  {
1969  $news_set = new ilSetting("news");
1970  $allow_shorter_periods = $news_set->get("allow_shorter_periods");
1971  $allow_longer_periods = $news_set->get("allow_longer_periods");
1972  $default_per = ilNewsItem::_lookupDefaultPDPeriod();
1973 
1974  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1975  $per = ilBlockSetting::_lookup(
1976  "pdnews",
1977  "news_pd_period",
1978  $a_user_id,
1979  0
1980  );
1981 
1982  // news period information
1983  if ($per <= 0 ||
1984  (!$allow_shorter_periods && ($per < $default_per)) ||
1985  (!$allow_longer_periods && ($per > $default_per))
1986  ) {
1987  $per = $default_per;
1988  }
1989 
1990  return $per;
1991  }
1992 
1993  public static function _lookupRSSPeriod()
1994  {
1995  $news_set = new ilSetting("news");
1996  $rss_period = $news_set->get("rss_period");
1997  if ($rss_period == 0) { // default to two weeks
1998  $rss_period = 14;
1999  }
2000  return $rss_period;
2001  }
2002  public static function setPrivateFeedId($a_userId)
2003  {
2004  ilNewsItem::$privFeedId = $a_userId;
2005  }
2006 
2007  public static function getPrivateFeedId()
2008  {
2009  return ilNewsItem::$privFeedId;
2010  }
2011 
2018  public function deliverMobFile($a_purpose = "Standard", $a_increase_download_cnt = false)
2019  {
2020  $mob = $this->getMobId();
2021  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
2022  $mob = new ilObjMediaObject($mob);
2023  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
2024 
2025  // check purpose
2026  if (!$mob->hasPurposeItem($a_purpose)) {
2027  return false;
2028  }
2029 
2030  $m_item = $mob->getMediaItem($a_purpose);
2031  if ($m_item->getLocationType() != "Reference") {
2032  $file = $mob_dir . "/" . $m_item->getLocation();
2033  if (file_exists($file) && is_file($file)) {
2034  if ($a_increase_download_cnt) {
2035  $this->increaseDownloadCounter();
2036  }
2037  ilUtil::deliverFile($file, $m_item->getLocation(), "", false, false, false);
2038  return true;
2039  } else {
2040  ilUtil::sendFailure("File not found!", true);
2041  return false;
2042  }
2043  } else {
2044  if ($a_increase_download_cnt) {
2045  $this->increaseDownloadCounter();
2046  }
2047  ilUtil::redirect($m_item->getLocation());
2048  }
2049  }
2050 
2057  public function increaseDownloadCounter()
2058  {
2059  $ilDB = $this->db;
2060 
2061  $cnt = $this->getMobDownloadCounter();
2062  $cnt++;
2063  $this->setMobDownloadCounter($cnt);
2064  $ilDB->manipulate(
2065  "UPDATE il_news_item SET " .
2066  " mob_cnt_download = " . $ilDB->quote($cnt, "integer") .
2067  " WHERE id = " . $ilDB->quote($this->getId(), "integer")
2068  );
2069  }
2070 
2077  public function increasePlayCounter()
2078  {
2079  $ilDB = $this->db;
2080 
2081  $cnt = $this->getMobPlayCounter();
2082  $cnt++;
2083  $this->setMobPlayCounter($cnt);
2084  $ilDB->manipulate(
2085  "UPDATE il_news_item SET " .
2086  " mob_cnt_play = " . $ilDB->quote($cnt, "integer") .
2087  " WHERE id = " . $ilDB->quote($this->getId(), "integer")
2088  );
2089  }
2090 
2097  public static function prepareNewsDataFromCache($a_cres)
2098  {
2099  global $DIC;
2100 
2101  $ilDB = $DIC->database();
2102 
2103  $data = $a_cres;
2104  $news_ids = array_keys($data);
2105  $set = $ilDB->query("SELECT id FROM il_news_item " .
2106  " WHERE " . $ilDB->in("id", $news_ids, false, "integer"));
2107  $existing_ids = array();
2108  while ($rec = $ilDB->fetchAssoc($set)) {
2109  $existing_ids[] = $rec["id"];
2110  }
2111  //var_dump($existing_ids);
2112  $existing_news = array();
2113  foreach ($data as $k => $v) {
2114  if (in_array($k, $existing_ids)) {
2115  $existing_news[$k] = $v;
2116  }
2117  }
2118 
2119  //var_dump($data);
2120  //var_dump($existing_news);
2121 
2122  return $existing_news;
2123  }
2124 }
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
getContentHtml()
Get content as html.
setContentTextIsLangVar($a_val=0)
Set content text ist lang var.
setContext($a_obj_id, $a_obj_type, $a_sub_obj_id=0, $a_sub_obj_type="")
Convenient function to set the whole context information.
getUserId()
Get UserId.
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.
static _lookupRSSPeriod()
getMobId()
Get MobId.
setVisibility($a_visibility="users")
Set Visibility.
$result
$type
setContextSubObjId($a_context_sub_obj_id)
Set ContextSubObjId.
global $DIC
Definition: saml.php:7
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
static _setUnread($a_user_id, $a_news_id)
Set item unread.
static handleTimePeriod($a_time_period)
Convert time period for DB-queries.
setContextSubObjType($a_context_sub_obj_type)
Set ContextSubObjType.
getContentType()
Get ContentType.
increaseDownloadCounter()
Increase download counter.
static _lookupUserPDPeriod($a_user_id)
getPriority()
Get Priority.
static _getMembershipByType($a_usr_id, $a_type, $a_only_member_role=false)
get membership by type Get course or group membership
setCreationDate($a_creation_date)
Set CreationDate.
getPlaytime()
Get Playtime.
read()
Read item from database.
static _lookupVisibility($a_news_id)
Lookup News Visibility.
setTitle($a_title)
Set Title.
__construct($a_id=0)
Constructor.
static mergeNews($n1, $n2)
Merges two sets of news.
static prepareNewsDataFromCache($a_cres)
Prepare news data from cache.
getCreationDate()
Get CreationDate.
getContentTextIsLangVar()
Get content text ist lang var.
getContentLong()
Get ContentLong.
getContextObjType()
Get ContextObjType.
static now()
Return current timestamp in Y-m-d H:i:s format.
setPriority($a_priority=1)
Set Priority.
user()
Definition: user.php:4
getContextSubObjType()
Get ContextSubObjType.
static _getAllReferences($a_id)
get all reference ids of object
static _getDirectory($a_mob_id)
get directory for files of media object (static)
getMobDownloadCounter()
Get mob download counter.
getContent()
Get Content.
global $ilCtrl
Definition: ilias.php:18
static _lookupTitle($a_news_id)
Lookup News Title.
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.
setContentIsLangVar($a_content_is_lang_var=0)
Set ContentIsLangVar.
setContent($a_content)
Set Content.
static _lookupMobId($a_news_id)
Lookup mob id.
getContentIsLangVar()
Get ContentIsLangVar.
static _getSubscriptionsOfUser($a_user_id)
Get subscriptions of user.
const NEWS_PUBLIC
setContextObjId($a_context_obj_id)
Set ContextObjId.
setUpdateUserId($a_val)
Set update user 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.
static _lookupMediaObjectUsages($a_mob_id)
Lookup media object usage(s)
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.
$a_content
Definition: workflow.php:93
static determineNewsContent($a_context_obj_type, $a_content, $a_is_lang_var)
Determine new content.
aggregateForums($news, $a_group_posting_sequence=false)
static _setRead($a_user_id, $a_news_id)
Set item read.
static $privFeedId
getId()
Get Id.
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 _lookupObjId($a_id)
setLimitation($a_limitation)
Set Limitation for number of items.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
static _lookup($a_type, $a_setting, $a_user=0, $a_block_id=0)
Lookup setting from database.
setMobDownloadCounter($a_val)
Set mob download counter.
getUpdateDate()
Get UpdateDate.
$ilUser
Definition: imgupload.php:18
deliverMobFile($a_purpose="Standard", $a_increase_download_cnt=false)
Deliver mob file.
Class ilObjMediaObject.
$query
static preloadData(array $a_ref_ids)
Preload data to internal cache.
update($a_as_new=false)
Update item in database.
setUserId($a_user_id)
Set UserId.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
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.
getLimitation()
Get Limitation for number of items.
getContextSubObjId()
Get ContextSubObjId.
getVisibility()
Get Visibility.
setContentType($a_content_type="text")
Set ContentType.
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.
getMobPlayCounter()
Get mob play counter.
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.
static _lookupDesktopItems($user_id, $a_types="")
get all desktop items of user and specified type
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.
static getPrivateFeedId()
global $ilSetting
Definition: privfeed.php:17
static _lookupPref($a_usr_id, $a_keyword)
setContentHtml($a_val)
Is content HTML (tiny used?)
global $ilDB
setMobId($a_mob_id)
Set MobId.
setContentLong($a_content_long)
Set ContentLong.
static _getDefaultVisibilityForRefId($a_ref_id)
Get default visibility for reference id.
static _lookupContextObjId($a_news_id)
Context Object ID.
$i
Definition: disco.tpl.php:19
setContextObjType($a_context_obj_type)
Set ContextObjType.
static filterObjIdsPerNews($a_obj_ids, $a_time_period=0, $a_starting_date="", $a_ending_date='', $ignore_period=false)
Checks whether news are available for.
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.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
checkNewsExistsForGroupCourse($a_ref_id, $a_time_period=1)
setPlaytime($a_playtime)
Set Playtime.
static redirect($a_script)
setUpdateDate($a_update_date)
Set UpdateDate.
create()
Create.
setId($a_id)
Set Id.
$key
Definition: croninfo.php:18
getTitle()
Get Title.
getUpdateUserId()
Get update user id.
static _lookupDefaultPDPeriod()
setMobPlayCounter($a_val)
Set mob play counter.
increasePlayCounter()
Increase play counter.
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static setPrivateFeedId($a_userId)
aggregateFiles($news, $a_ref_id)
getContextObjId()
Get ContextObjId.