ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
30  protected $id;
31  protected $title;
32  protected $content;
36  protected $content_html;
37  protected $context_obj_id;
38  protected $context_obj_type;
41  protected $content_type = "text";
42  protected $creation_date;
43  protected $update_date;
44  protected $user_id;
48  protected $update_user_id;
49  protected $visibility = "users";
50  protected $content_long;
51  protected $priority = 1;
52  protected $content_is_lang_var = 0;
53  protected $mob_id;
54  protected $playtime;
55 
56  private static $privFeedId = false;
57  private $limitation;
58 
64  public function __construct($a_id = 0)
65  {
66  if ($a_id > 0)
67  {
68  $this->setId($a_id);
69  $this->read();
70  }
71  $this->limitation = true;
72  }
73 
79  public function setId($a_id)
80  {
81  $this->id = $a_id;
82  }
83 
89  public function getId()
90  {
91  return $this->id;
92  }
93 
99  public function setTitle($a_title)
100  {
101  $this->title = $a_title;
102  }
103 
109  public function getTitle()
110  {
111  return $this->title;
112  }
113 
119  public function setContent($a_content)
120  {
121  $this->content = $a_content;
122  }
123 
129  public function getContent()
130  {
131  return $this->content;
132  }
133 
139  public function setContextObjId($a_context_obj_id)
140  {
141  $this->context_obj_id = $a_context_obj_id;
142  }
143 
149  public function getContextObjId()
150  {
151  return $this->context_obj_id;
152  }
153 
159  public function setContextObjType($a_context_obj_type)
160  {
161  $this->context_obj_type = $a_context_obj_type;
162  }
163 
169  public function getContextObjType()
170  {
172  }
173 
179  public function setContextSubObjId($a_context_sub_obj_id)
180  {
181  $this->context_sub_obj_id = $a_context_sub_obj_id;
182  }
183 
189  public function getContextSubObjId()
190  {
192  }
193 
199  public function setContextSubObjType($a_context_sub_obj_type)
200  {
201  $this->context_sub_obj_type = $a_context_sub_obj_type;
202  }
203 
209  public function getContextSubObjType()
210  {
212  }
213 
219  public function setContentType($a_content_type = "text")
220  {
221  $this->content_type = $a_content_type;
222  }
223 
229  public function getContentType()
230  {
231  return $this->content_type;
232  }
233 
239  public function setCreationDate($a_creation_date)
240  {
241  $this->creation_date = $a_creation_date;
242  }
243 
249  public function getCreationDate()
250  {
251  return $this->creation_date;
252  }
253 
259  public function setUpdateDate($a_update_date)
260  {
261  $this->update_date = $a_update_date;
262  }
263 
269  public function getUpdateDate()
270  {
271  return $this->update_date;
272  }
273 
279  public function setUserId($a_user_id)
280  {
281  $this->user_id = $a_user_id;
282  }
283 
289  public function getUserId()
290  {
291  return $this->user_id;
292  }
293 
299  function setUpdateUserId($a_val)
300  {
301  $this->update_user_id = $a_val;
302  }
303 
309  function getUpdateUserId()
310  {
311  return $this->update_user_id;
312  }
313 
319  public function setVisibility($a_visibility = "users")
320  {
321  $this->visibility = $a_visibility;
322  }
323 
329  public function getVisibility()
330  {
331  return $this->visibility;
332  }
333 
339  public function setContentLong($a_content_long)
340  {
341  $this->content_long = $a_content_long;
342  }
343 
349  public function getContentLong()
350  {
351  return $this->content_long;
352  }
353 
359  public function setPriority($a_priority = 1)
360  {
361  $this->priority = $a_priority;
362  }
363 
369  public function getPriority()
370  {
371  return $this->priority;
372  }
373 
379  public function setContentIsLangVar($a_content_is_lang_var = 0)
380  {
381  $this->content_is_lang_var = $a_content_is_lang_var;
382  }
383 
389  public function getContentIsLangVar()
390  {
392  }
393 
399  public function setMobId($a_mob_id)
400  {
401  $this->mob_id = $a_mob_id;
402  }
403 
409  public function getMobId()
410  {
411  return $this->mob_id;
412  }
413 
419  public function setPlaytime($a_playtime)
420  {
421  $this->playtime = $a_playtime;
422  }
423 
429  public function getPlaytime()
430  {
431  return $this->playtime;
432  }
433 
434 
440  function setLimitation($a_limitation)
441  {
442  $this->limitation = $a_limitation;
443  }
444 
450  function getLimitation()
451  {
452  return $this->limitation;
453  }
454 
460  public function setContentTextIsLangVar($a_val = 0)
461  {
462  $this->content_text_is_lang_var = $a_val;
463  }
464 
470  public function getContentTextIsLangVar()
471  {
472  return $this->content_text_is_lang_var;
473  }
474 
480  function setMobPlayCounter($a_val)
481  {
482  $this->mob_cnt_play = $a_val;
483  }
484 
490  function getMobPlayCounter()
491  {
492  return $this->mob_cnt_play;
493  }
494 
500  function setMobDownloadCounter($a_val)
501  {
502  $this->mob_cnt_download = $a_val;
503  }
504 
511  {
512  return $this->mob_cnt_download;
513  }
514 
520  function setContentHtml($a_val)
521  {
522  $this->content_html = $a_val;
523  }
524 
530  function getContentHtml()
531  {
532  return $this->content_html;
533  }
534 
538  public function read()
539  {
540  global $ilDB;
541 
542  $query = "SELECT * FROM il_news_item WHERE id = ".
543  $ilDB->quote($this->getId(), "integer");
544  $set = $ilDB->query($query);
545  $rec = $ilDB->fetchAssoc($set);
546 
547  $this->setTitle($rec["title"]);
548  $this->setContent($rec["content"]);
549  $this->setContextObjId((int) $rec["context_obj_id"]);
550  $this->setContextObjType($rec["context_obj_type"]);
551  $this->setContextSubObjId((int) $rec["context_sub_obj_id"]);
552  $this->setContextSubObjType($rec["context_sub_obj_type"]);
553  $this->setContentType($rec["content_type"]);
554  $this->setCreationDate($rec["creation_date"]);
555  $this->setUpdateDate($rec["update_date"]);
556  $this->setUserId($rec["user_id"]);
557  $this->setUpdateUserId($rec["update_user_id"]);
558  $this->setVisibility($rec["visibility"]);
559  $this->setContentLong($rec["content_long"]);
560  $this->setPriority($rec["priority"]);
561  $this->setContentIsLangVar($rec["content_is_lang_var"]);
562  $this->setContentTextIsLangVar((int) $rec["content_text_is_lang_var"]);
563  $this->setMobId($rec["mob_id"]);
564  $this->setPlaytime($rec["playtime"]);
565  $this->setMobPlayCounter($rec["mob_cnt_play"]);
566  $this->setMobDownloadCounter($rec["mob_cnt_download"]);
567  $this->setContentHtml($rec["content_html"]);
568 
569  }
570 
574  function create()
575  {
576  global $ilDB;
577 
578  // insert new record into db
579  $this->setId($ilDB->nextId("il_news_item"));
580  $ilDB->insert("il_news_item", array(
581  "id" => array("integer", $this->getId()),
582  "title" => array("text", $this->getTitle()),
583  "content" => array("clob", $this->getContent()),
584  "content_html" => array("integer", (int) $this->getContentHtml()),
585  "context_obj_id" => array("integer", (int) $this->getContextObjId()),
586  "context_obj_type" => array("text", $this->getContextObjType()),
587  "context_sub_obj_id" => array("integer", (int) $this->getContextSubObjId()),
588  "context_sub_obj_type" => array("text", $this->getContextSubObjType()),
589  "content_type" => array("text", $this->getContentType()),
590  "creation_date" => array("timestamp", ilUtil::now()),
591  "update_date" => array("timestamp", ilUtil::now()),
592  "user_id" => array("integer", $this->getUserId()),
593  "update_user_id" => array("integer", (int) $this->getUpdateUserId()),
594  "visibility" => array("text", $this->getVisibility()),
595  "content_long" => array("clob", $this->getContentLong()),
596  "priority" => array("integer", $this->getPriority()),
597  "content_is_lang_var" => array("integer", $this->getContentIsLangVar()),
598  "content_text_is_lang_var" => array("integer", (int) $this->getContentTextIsLangVar()),
599  "mob_id" => array("integer", $this->getMobId()),
600  "playtime" => array("text", $this->getPlaytime())
601  ));
602 
603 
604  $news_set = new ilSetting("news");
605  $max_items = $news_set->get("max_items");
606  if ($max_items <= 0)
607  {
608  $max_items = 50;
609  }
610 
611  // limit number of news
612  if ($this->getLimitation())
613  {
614  // Determine how many rows should be deleted
615  $query = "SELECT count(*) cnt ".
616  "FROM il_news_item ".
617  "WHERE ".
618  "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
619  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
620  " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId(), "integer").
621  " AND ".$ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true)." ";
622 
623  $set = $ilDB->query($query);
624  $rec = $ilDB->fetchAssoc($set);
625 
626  // if we have more records than allowed, delete them
627  if (($rec["cnt"] > $max_items) && $this->getContextObjId() > 0)
628  {
629  $query = "SELECT * ".
630  "FROM il_news_item ".
631  "WHERE ".
632  "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
633  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
634  " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId(), "integer").
635  " AND ".$ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true).
636  " ORDER BY creation_date ASC";
637 
638  $ilDB->setLimit($rec["cnt"] - $max_items);
639  $del_set = $ilDB->query($query);
640  while ($del_item = $ilDB->fetchAssoc($del_set))
641  {
642  $del_news = new ilNewsItem($del_item["id"]);
643  $del_news->delete();
644  }
645  }
646  }
647  }
648 
654  public function update($a_as_new = false)
655  {
656  global $ilDB;
657 
658  $fields = array(
659  "title" => array("text", $this->getTitle()),
660  "content" => array("clob", $this->getContent()),
661  "content_html" => array("integer", (int) $this->getContentHtml()),
662  "context_obj_id" => array("integer", $this->getContextObjId()),
663  "context_obj_type" => array("text", $this->getContextObjType()),
664  "context_sub_obj_id" => array("integer", $this->getContextSubObjId()),
665  "context_sub_obj_type" => array("text", $this->getContextSubObjType()),
666  "content_type" => array("text", $this->getContentType()),
667  "user_id" => array("integer", $this->getUserId()),
668  "update_user_id" => array("integer", (int) $this->getUpdateUserId()),
669  "visibility" => array("text", $this->getVisibility()),
670  "content_long" => array("clob", $this->getContentLong()),
671  "priority" => array("integer", $this->getPriority()),
672  "content_is_lang_var" => array("integer", $this->getContentIsLangVar()),
673  "content_text_is_lang_var" => array("integer", (int) $this->getContentTextIsLangVar()),
674  "mob_id" => array("integer", $this->getMobId()),
675  "mob_cnt_play" => array("integer", $this->getMobPlayCounter()),
676  "mob_cnt_download" => array("integer", $this->getMobDownloadCounter()),
677  "playtime" => array("text", $this->getPlaytime())
678  );
679 
680  $now = ilUtil::now();
681  if ($a_as_new)
682  {
683  $fields["creation_date"] = array("timestamp", $now);
684  $fields["update_date"] = array("timestamp", $now);
685  }
686  else
687  {
688  $fields["update_date"] = array("timestamp", $now);
689  }
690 
691  $ilDB->update("il_news_item", $fields, array(
692  "id" => array("integer", $this->getId())
693  ));
694 
695  }
696 
697 
701  static function _getNewsItemsOfUser($a_user_id, $a_only_public = false,
702  $a_prevent_aggregation = false, $a_per = 0, &$a_cnt = NULL)
703  {
704  global $ilAccess;
705 
706  $news_item = new ilNewsItem();
707  $news_set = new ilSetting("news");
708 
709  $per = $a_per;
710 
711  include_once("./Services/News/classes/class.ilNewsSubscription.php");
712  include_once("./Services/Block/classes/class.ilBlockSetting.php");
713 
714  // this is currently not used
715  $ref_ids = ilNewsSubscription::_getSubscriptionsOfUser($a_user_id);
716 
717  if (ilObjUser::_lookupPref($a_user_id, "pd_items_news") != "n")
718  {
719  // get all items of the personal desktop
720  $pd_items = ilObjUser::_lookupDesktopItems($a_user_id);
721  foreach($pd_items as $item)
722  {
723  if (!in_array($item["ref_id"], $ref_ids))
724  {
725  $ref_ids[] = $item["ref_id"];
726  }
727  }
728 
729  // get all memberships
730  include_once 'Services/Membership/classes/class.ilParticipants.php';
731  $crs_mbs = ilParticipants::_getMembershipByType($a_user_id, 'crs');
732  $grp_mbs = ilParticipants::_getMembershipByType($a_user_id, 'grp');
733  $items = array_merge($crs_mbs, $grp_mbs);
734  foreach($items as $i)
735  {
736  $item_references = ilObject::_getAllReferences($i);
737  if(is_array($item_references) && count($item_references))
738  {
739  foreach($item_references as $ref_id)
740  {
741  if (!in_array($ref_id, $ref_ids))
742  {
743  $ref_ids[] = $ref_id;
744  }
745  }
746  }
747  }
748  }
749 
750  $data = array();
751 
752  foreach($ref_ids as $ref_id)
753  {
754  if (!$a_only_public)
755  {
756  // this loop should not cost too much performance
757  $acc = $ilAccess->checkAccessOfUser($a_user_id, "read", "", $ref_id);
758 
759  if (!$acc)
760  {
761  continue;
762  }
763  }
764  if (ilNewsItem::getPrivateFeedId() != false) {
765  global $rbacsystem;
766  $acc = $rbacsystem->checkAccessOfUser(ilNewsItem::getPrivateFeedId(),"read", $ref_id);
767 
768  if (!$acc)
769  {
770  continue;
771  }
772  }
773 
774  $obj_id = ilObject::_lookupObjId($ref_id);
775  $obj_type = ilObject::_lookupType($obj_id);
776  $news = $news_item->getNewsForRefId($ref_id, $a_only_public, false,
777  $per, $a_prevent_aggregation, false, false, false, $a_user_id);
778 
779  // counter
780  if (!is_null($a_cnt))
781  {
782  $a_cnt[$ref_id] = count($news);
783  }
784 
786  }
787 
788  $data = ilUtil::sortArray($data, "creation_date", "desc", false, true);
789 
790  return $data;
791  }
792 
809  function getNewsForRefId($a_ref_id, $a_only_public = false, $a_stopnesting = false,
810  $a_time_period = 0, $a_prevent_aggregation = true, $a_forum_group_sequences = false,
811  $a_no_auto_generated = false, $a_ignore_date_filter = false, $a_user_id = null, $a_limit = 0, $a_excluded = array())
812  {
813  $obj_id = ilObject::_lookupObjId($a_ref_id);
814  $obj_type = ilObject::_lookupType($obj_id);
815 
816  // get starting date
817  $starting_date = "";
818  if ($obj_type == "grp" || $obj_type == "crs" || $obj_type == "cat")
819  {
820  include_once("./Services/Block/classes/class.ilBlockSetting.php");
821  $hide_news_per_date = ilBlockSetting::_lookup("news", "hide_news_per_date",
822  0, $obj_id);
823  if ($hide_news_per_date && !$a_ignore_date_filter)
824  {
825  $starting_date = ilBlockSetting::_lookup("news", "hide_news_date",
826  0, $obj_id);
827  }
828  }
829 
830  if ($obj_type == "cat" && !$a_stopnesting)
831  {
832  $news = $this->getAggregatedChildNewsData($a_ref_id, $a_only_public, $a_time_period,
833  $a_prevent_aggregation, $starting_date, $a_no_auto_generated);
834  }
835  else if (($obj_type == "grp" || $obj_type == "crs") &&
836  !$a_stopnesting)
837  {
838  $news = $this->getAggregatedNewsData($a_ref_id, $a_only_public, $a_time_period,
839  $a_prevent_aggregation, $starting_date, $a_no_auto_generated, $a_user_id, $a_limit, $a_excluded);
840  }
841  else
842  {
843  $news_item = new ilNewsItem();
844  $news_item->setContextObjId($obj_id);
845  $news_item->setContextObjType($obj_type);
846  $news = $news_item->queryNewsForContext($a_only_public, $a_time_period,
847  $starting_date, $a_no_auto_generated);
848  $unset = array();
849  foreach ($news as $k => $v)
850  {
851  if (!$a_only_public || $v["visibility"] == NEWS_PUBLIC ||
852  ($v["priority"] == 0 &&
853  ilBlockSetting::_lookup("news", "public_notifications",
854  0, $obj_id)))
855  {
856  $news[$k]["ref_id"] = $a_ref_id;
857  }
858  else
859  {
860  $unset[] = $k;
861  }
862  }
863  foreach ($unset as $un)
864  {
865  unset($news[$un]);
866  }
867  }
868 
869  if (!$a_prevent_aggregation)
870  {
871  $news = $this->aggregateForums($news);
872  }
873  else if ($a_forum_group_sequences)
874  {
875  $news = $this->aggregateForums($news, true);
876  }
877 
878  return $news;
879  }
880 
884  function getAggregatedNewsData($a_ref_id, $a_only_public = false, $a_time_period = 0,
885  $a_prevent_aggregation = false, $a_starting_date = "", $a_no_auto_generated = false,
886  $a_user_id = null, $a_limit = 0, $a_exclude = array())
887  {
888  global $tree, $ilAccess, $ilObjDataCache;
889 
890  // get news of parent object
891 
892  $data = array();
893 
894  // get subtree
895  $cur_node = $tree->getNodeData($a_ref_id);
896 
897  // do not check for lft (materialized path)
898  if($cur_node)
899  {
900  $nodes = (array) $tree->getSubTree($cur_node,true);
901  }
902  else
903  {
904  $nodes = array();
905  }
906 
907  // preload object data cache
908  $ref_ids = array();
909  $obj_ids = array();
910  foreach($nodes as $node)
911  {
912  $ref_ids[] = $node["child"];
913  $obj_ids[] = $node["obj_id"];
914  }
915 
916  $ilObjDataCache->preloadReferenceCache($ref_ids);
917  if (!$a_only_public)
918  {
919  include_once "Services/Object/classes/class.ilObjectActivation.php";
921  }
922 
923  // no check, for which of the objects any news are available
924  $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $a_time_period, $a_starting_date);
925  //$news_obj_ids = $obj_ids;
926 
927  // get news for all subtree nodes
928  $contexts = array();
929  foreach($nodes as $node)
930  {
931  // only go on, if news are available
932  if (!in_array($node["obj_id"], $news_obj_ids))
933  {
934  continue;
935  }
936 
937  if (!$a_only_public)
938  {
939  if(!$a_user_id)
940  {
941  $acc = $ilAccess->checkAccess("read", "", $node["child"]);
942  }
943  else
944  {
945  $acc = $ilAccess->checkAccessOfUser($a_user_id, "read", "",
946  $node["child"]);
947  }
948  if (!$acc)
949  {
950  continue;
951  }
952  }
953 
954  $ref_id[$node["obj_id"]] = $node["child"];
955  $contexts[] = array("obj_id" => $node["obj_id"],
956  "obj_type" => $node["type"]);
957  }
958 
959  // sort and return
960  $news = $this->queryNewsForMultipleContexts($contexts, $a_only_public, $a_time_period,
961  $a_starting_date, $a_no_auto_generated, $a_user_id, $a_limit, $a_exclude);
962 
963  $to_del = array();
964  foreach ($news as $k => $v)
965  {
966  $news[$k]["ref_id"] = $ref_id[$v["context_obj_id"]];
967  }
968 
970  $data = ilUtil::sortArray($data, "creation_date", "desc", false, true);
971 
972  if (!$a_prevent_aggregation)
973  {
974  $data = $this->aggregateFiles($data, $a_ref_id);
975  }
976 
977  return $data;
978  }
979 
980  function aggregateForums($news, $a_group_posting_sequence = false)
981  {
982  $to_del = array();
983  $forums = array();
984 
985  // aggregate
986  foreach ($news as $k => $v)
987  {
988  if ($a_group_posting_sequence && $last_aggregation_forum > 0 &&
989  $last_aggregation_forum != $news[$k]["context_obj_id"])
990  {
991  $forums[$last_aggregation_forum] = "";
992  }
993 
994  if ($news[$k]["context_obj_type"] == "frm")
995  {
996  if ($forums[$news[$k]["context_obj_id"]] == "")
997  {
998  // $forums[forum_id] = news_id;
999  $forums[$news[$k]["context_obj_id"]] = $k;
1000  $last_aggregation_forum = $news[$k]["context_obj_id"];
1001  }
1002  else
1003  {
1004  $to_del[] = $k;
1005  }
1006 
1007  $news[$k]["no_context_title"] = true;
1008 
1009  // aggregate every forum into it's "k" news
1010  $news[$forums[$news[$k]["context_obj_id"]]]["aggregation"][$k]
1011  = $news[$k];
1012  $news[$k]["agg_ref_id"]
1013  = $news[$k]["ref_id"];
1014  $news[$k]["content"] = "";
1015  $news[$k]["content_long"] = "";
1016  }
1017  }
1018 
1019  // delete double entries
1020  foreach($to_del as $k)
1021  {
1022  unset($news[$k]);
1023  }
1024 //var_dump($news[14]["aggregation"]);
1025 
1026 
1027  return $news;
1028  }
1029 
1030  function aggregateFiles($news, $a_ref_id)
1031  {
1032  $first_file = "";
1033  $to_del = array();
1034  foreach ($news as $k => $v)
1035  {
1036  // aggregate file related news
1037  if ($news[$k]["context_obj_type"] == "file")
1038  {
1039  if ($first_file == "")
1040  {
1041  $first_file = $k;
1042  }
1043  else
1044  {
1045  $to_del[] = $k;
1046  }
1047  $news[$first_file]["aggregation"][$k] = $news[$k];
1048  $news[$first_file]["agg_ref_id"] = $a_ref_id;
1049  $news[$first_file]["ref_id"] = $a_ref_id;
1050  }
1051  }
1052 
1053  foreach($to_del as $v)
1054  {
1055  unset($news[$v]);
1056  }
1057 
1058  return $news;
1059  }
1060 
1061 
1065  function getAggregatedChildNewsData($a_ref_id, $a_only_public = false,
1066  $a_time_period = 0, $a_prevent_aggregation = false, $a_starting_date = "",
1067  $a_no_auto_generated = false)
1068  {
1069  global $tree, $ilAccess;
1070 
1071  // get news of parent object
1072  $data = $this->getNewsForRefId($a_ref_id, $a_only_public, true, $a_time_period,
1073  true, false, false, $a_no_auto_generated);
1074  foreach ($data as $k => $v)
1075  {
1076  $data[$k]["ref_id"] = $a_ref_id;
1077  }
1078 
1079  // get childs
1080  $nodes = $tree->getChilds($a_ref_id);
1081 
1082  // no check, for which of the objects any news are available
1083  $obj_ids = array();
1084  foreach($nodes as $node)
1085  {
1086  $obj_ids[] = $node["obj_id"];
1087  }
1088  $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $a_time_period, $a_starting_date);
1089  //$news_obj_ids = $obj_ids;
1090 
1091  // get news for all subtree nodes
1092  $contexts = array();
1093  foreach($nodes as $node)
1094  {
1095  // only go on, if news are available
1096  if (!in_array($node["obj_id"], $news_obj_ids))
1097  {
1098  continue;
1099  }
1100 
1101  if (!$a_only_public && !$ilAccess->checkAccess("read", "", $node["child"]))
1102  {
1103  continue;
1104  }
1105  $ref_id[$node["obj_id"]] = $node["child"];
1106  $contexts[] = array("obj_id" => $node["obj_id"],
1107  "obj_type" => $node["type"]);
1108  }
1109 
1110  $news = $this->queryNewsForMultipleContexts($contexts, $a_only_public, $a_time_period,
1111  $a_starting_date, $a_no_auto_generated);
1112  foreach ($news as $k => $v)
1113  {
1114  $news[$k]["ref_id"] = $ref_id[$v["context_obj_id"]];
1115  }
1116  $data = ilNewsItem::mergeNews($data, $news);
1117 
1118  // sort and return
1119  $data = ilUtil::sortArray($data, "creation_date", "desc", false, true);
1120 
1121  if (!$a_prevent_aggregation)
1122  {
1123  $data = $this->aggregateFiles($data, $a_ref_id);
1124  }
1125 
1126  return $data;
1127  }
1128 
1132  function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type = "")
1133  {
1134  $this->setContextObjId($a_obj_id);
1135  $this->setContextObjType($a_obj_type);
1136  $this->setContextSubObjId($a_sub_obj_id);
1137  $this->setContextSubObjType($a_sub_obj_type);
1138  }
1139 
1146  protected static function handleTimePeriod($a_time_period)
1147  {
1148  // time period is number of days
1149  if(is_numeric($a_time_period))
1150  {
1151  if($a_time_period > 0)
1152  {
1153  return date('Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
1154  }
1155  }
1156  // time period is datetime
1157  else if(preg_match("/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/", $a_time_period))
1158  {
1159  return $a_time_period;
1160  }
1161  // :TODO: what to return?
1162  }
1163 
1172  public function queryNewsForContext($a_for_rss_use = false, $a_time_period = 0,
1173  $a_starting_date = "", $a_no_auto_generated = false, $a_oldest_first = false, $a_limit = 0)
1174  {
1175  global $ilDB, $ilUser, $lng;
1176 
1177  $and = "";
1178  if ($a_time_period > 0)
1179  {
1180  $limit_ts = self::handleTimePeriod($a_time_period);
1181  $and = " AND creation_date >= ".$ilDB->quote($limit_ts, "timestamp")." ";
1182  }
1183 
1184  if ($a_starting_date != "")
1185  {
1186  $and.= " AND creation_date > ".$ilDB->quote($a_starting_date, "timestamp")." ";
1187  }
1188 
1189  if ($a_no_auto_generated)
1190  {
1191  $and.= " AND priority = 1 AND content_type = ".$ilDB->quote("text", "text")." ";
1192  }
1193 
1194  // this is changed with 4.1 (news table for lm pages)
1195  if ($this->getContextSubObjId() > 0)
1196  {
1197  $and.= " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId(), "integer").
1198  " AND context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType(), "text");
1199  }
1200 
1201  $ordering = ($a_oldest_first)
1202  ? " creation_date ASC, id ASC "
1203  : " creation_date DESC, id DESC ";
1204 
1205  if ($a_for_rss_use && ilNewsItem::getPrivateFeedId() == false)
1206  {
1207  $query = "SELECT * ".
1208  "FROM il_news_item ".
1209  " WHERE ".
1210  "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
1211  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
1212  $and.
1213  " ORDER BY ".$ordering;
1214  }
1215  elseif (ilNewsItem::getPrivateFeedId() != false)
1216  {
1217  $query = "SELECT il_news_item.* ".
1218  ", il_news_read.user_id user_read ".
1219  "FROM il_news_item LEFT JOIN il_news_read ".
1220  "ON il_news_item.id = il_news_read.news_id AND ".
1221  " il_news_read.user_id = ".$ilDB->quote(ilNewsItem::getPrivateFeedId(), "integer").
1222  " WHERE ".
1223  "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
1224  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
1225  $and.
1226  " ORDER BY ".$ordering;
1227  }
1228  else
1229  {
1230  $query = "SELECT il_news_item.* ".
1231  ", il_news_read.user_id as user_read ".
1232  "FROM il_news_item LEFT JOIN il_news_read ".
1233  "ON il_news_item.id = il_news_read.news_id AND ".
1234  " il_news_read.user_id = ".$ilDB->quote($ilUser->getId(), "integer").
1235  " WHERE ".
1236  "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
1237  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
1238  $and.
1239  " ORDER BY ".$ordering;
1240  }
1241 //echo $query;
1242  $set = $ilDB->query($query);
1243  $result = array();
1244  while($rec = $ilDB->fetchAssoc($set))
1245  {
1246  if ($a_limit > 0 && count($result) >= $a_limit)
1247  {
1248  continue;
1249  }
1250  if (!$a_for_rss_use || (ilNewsItem::getPrivateFeedId() != false) || ($rec["visibility"] == NEWS_PUBLIC ||
1251  ($rec["priority"] == 0 &&
1252  ilBlockSetting::_lookup("news", "public_notifications",
1253  0, $rec["context_obj_id"]))))
1254  {
1255  $result[$rec["id"]] = $rec;
1256  }
1257  }
1258 
1259  // do we get data for rss and may the time limit by an issue?
1260  // do a second query without time limit.
1261  // this is not very performant, but I do not have a better
1262  // idea. The keep_rss_min setting is currently (Jul 2012) only set
1263  // by mediacasts
1264  if ($a_time_period != "" && $a_for_rss_use)
1265  {
1266  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1267  $keep_rss_min = ilBlockSetting::_lookup("news", "keep_rss_min",
1268  0, $this->getContextObjId());
1269  if ($keep_rss_min > 0)
1270  {
1271  return $this->queryNewsForContext(true, 0,
1272  $a_starting_date, $a_no_auto_generated, $a_oldest_first, $keep_rss_min);
1273  }
1274  }
1275 
1276  return $result;
1277 
1278  }
1279 
1287  public function checkNewsExistsForGroupCourse($a_ref_id, $a_time_period = 1)
1288  {
1289  global $tree, $ilDB;
1290 
1291  $all = array();
1292 
1293  if(!$tree->isDeleted($a_ref_id))
1294  {
1295  // parse repository branch of group
1296  $nodes = array();
1297  $node = $tree->getNodeData($a_ref_id);
1298  foreach($tree->getSubTree($node) as $child)
1299  {
1300  if($child["type"] != "rolf")
1301  {
1302  $nodes[$child["obj_id"]] = $child["type"];
1303  }
1304  }
1305 
1306  $limit_ts = self::handleTimePeriod($a_time_period);
1307 
1308  // are there any news items for relevant objects and?
1309  $query = $ilDB->query("SELECT id,context_obj_id,context_obj_type".
1310  " FROM il_news_item".
1311  " WHERE ".$ilDB->in("context_obj_id", array_keys($nodes), false, "integer").
1312  " AND creation_date >= ".$ilDB->quote($limit_ts, "timestamp"));
1313  while($rec = $ilDB->fetchAssoc($query))
1314  {
1315  if ($nodes[$rec["context_obj_id"]] == $rec["context_obj_type"])
1316  {
1317  $all[] = $rec["id"];
1318  }
1319  }
1320  }
1321 
1322  return $all;
1323  }
1324 
1338  public function queryNewsForMultipleContexts($a_contexts, $a_for_rss_use = false,
1339  $a_time_period = 0, $a_starting_date = "", $a_no_auto_generated = false,
1340  $a_user_id = null, $a_limit = 0, $a_exclude = array())
1341  {
1342  global $ilDB, $ilUser, $lng, $ilCtrl;
1343 
1344  $and = "";
1345  if ($a_time_period > 0)
1346  {
1347  $limit_ts = self::handleTimePeriod($a_time_period);
1348  $and = " AND creation_date >= ".$ilDB->quote($limit_ts, "timestamp")." ";
1349  }
1350 
1351  if ($a_starting_date != "")
1352  {
1353  $and.= " AND creation_date > ".$ilDB->quote($a_starting_date, "timestamp")." ";
1354  }
1355 
1356  if ($a_no_auto_generated)
1357  {
1358  $and.= " AND priority = 1 AND content_type = ".$ilDB->quote("text", "text")." ";
1359  }
1360 
1361  if ($a_limit > 0)
1362  {
1363  $ilDB->setLimit($a_limit, 0);
1364  }
1365 
1366  if (is_array($a_exclude) && count($a_exclude) > 0)
1367  {
1368  $and.= " AND ".$ilDB->in("id", $a_exclude, true, "integer")." ";
1369  }
1370 
1371  $ids = array();
1372  $type = array();
1373 
1374  foreach($a_contexts as $cont)
1375  {
1376  $ids[] = $cont["obj_id"];
1377  $type[$cont["obj_id"]] = $cont["obj_type"];
1378  }
1379 
1380  if ($a_for_rss_use && ilNewsItem::getPrivateFeedId() == false)
1381  {
1382  $query = "SELECT * ".
1383  "FROM il_news_item ".
1384  " WHERE ".
1385  $ilDB->in("context_obj_id", $ids, false, "integer")." ".
1386  $and.
1387  " ORDER BY creation_date DESC ";
1388  }
1389  elseif (ilNewsItem::getPrivateFeedId() != false)
1390  {
1391  $query = "SELECT il_news_item.* ".
1392  ", il_news_read.user_id as user_read ".
1393  "FROM il_news_item LEFT JOIN il_news_read ".
1394  "ON il_news_item.id = il_news_read.news_id AND ".
1395  " il_news_read.user_id = ".$ilDB->quote(ilNewsItem::getPrivateFeedId(), "integer").
1396  " WHERE ".
1397  $ilDB->in("context_obj_id", $ids, false, "integer")." ".
1398  $and.
1399  " ORDER BY creation_date DESC ";
1400  }
1401  else
1402  {
1403  if($a_user_id)
1404  {
1405  $user_id = $a_user_id;
1406  }
1407  else
1408  {
1409  $user_id = $ilUser->getId();
1410  }
1411  $query = "SELECT il_news_item.* ".
1412  ", il_news_read.user_id as user_read ".
1413  "FROM il_news_item LEFT JOIN il_news_read ".
1414  "ON il_news_item.id = il_news_read.news_id AND ".
1415  " il_news_read.user_id = ".$ilDB->quote($user_id, "integer").
1416  " WHERE ".
1417  $ilDB->in("context_obj_id", $ids, false, "integer")." ".
1418  $and.
1419  " ORDER BY creation_date DESC ";
1420  }
1421 
1422  $set = $ilDB->query($query);
1423  $result = array();
1424  while($rec = $ilDB->fetchAssoc($set))
1425  {
1426  if ($type[$rec["context_obj_id"]] == $rec["context_obj_type"])
1427  {
1428  if (!$a_for_rss_use || ilNewsItem::getPrivateFeedId() != false || ($rec["visibility"] == NEWS_PUBLIC ||
1429  ($rec["priority"] == 0 &&
1430  ilBlockSetting::_lookup("news", "public_notifications",
1431  0, $rec["context_obj_id"]))))
1432  {
1433  $result[$rec["id"]] = $rec;
1434  }
1435  }
1436  }
1437 
1438  return $result;
1439 
1440  }
1441 
1442 
1446  static function _setRead($a_user_id, $a_news_id)
1447  {
1448  global $ilDB, $ilAppEventHandler;
1449 
1450  $ilDB->replace("il_news_read",
1451  array(
1452  "user_id" => array("integer", $a_user_id),
1453  "news_id" => array("integer", $a_news_id)
1454  ),
1455  array()
1456  );
1457 
1458  /*
1459  $ilDB->manipulate("DELETE FROM il_news_read WHERE ".
1460  "user_id = ".$ilDB->quote($a_user_id, "integer").
1461  " AND news_id = ".$ilDB->quote($a_news_id, "integer"));
1462  $ilDB->manipulate("INSERT INTO il_news_read (user_id, news_id) VALUES (".
1463  $ilDB->quote($a_user_id, "integer").",".
1464  $ilDB->quote($a_news_id, "integer").")");*/
1465 
1466  $ilAppEventHandler->raise("Services/News", "readNews",
1467  array("user_id" => $a_user_id, "news_ids" => array($a_news_id)));
1468  }
1469 
1473  static function _setUnread($a_user_id, $a_news_id)
1474  {
1475  global $ilDB, $ilAppEventHandler;
1476 
1477  $ilDB->manipulate("DELETE FROM il_news_read (user_id, news_id) VALUES (".
1478  " WHERE user_id = ".$ilDB->quote($a_user_id, "integer").
1479  " AND news_id = ".$ilDB->quote($a_news_id, "integer"));
1480 
1481  $ilAppEventHandler->raise("Services/News", "unreadNews",
1482  array("user_id" => $a_user_id, "news_ids" => array($a_news_id)));
1483  }
1484 
1493  static function mergeNews($n1, $n2)
1494  {
1495  foreach($n2 as $id => $news)
1496  {
1497  $n1[$id] = $news;
1498  }
1499 
1500  return $n1;
1501  }
1502 
1508  static function _getDefaultVisibilityForRefId($a_ref_id)
1509  {
1510  global $tree, $ilSetting;
1511 
1512  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1513 
1514  $news_set = new ilSetting("news");
1515  $default_visibility = ($news_set->get("default_visibility") != "")
1516  ? $news_set->get("default_visibility")
1517  : "users";
1518 
1519  if ($tree->isInTree($a_ref_id))
1520  {
1521  $path = $tree->getPathFull($a_ref_id);
1522 
1523  foreach ($path as $key => $row)
1524  {
1525  if (!in_array($row["type"], array("root", "cat","crs", "fold", "grp")))
1526  {
1527  continue;
1528  }
1529 
1530  $visibility = ilBlockSetting::_lookup("news", "default_visibility",
1531  0, $row["obj_id"]);
1532 
1533  if ($visibility != "")
1534  {
1535  $default_visibility = $visibility;
1536  }
1537  }
1538  }
1539 
1540  return $default_visibility;
1541  }
1542 
1543 
1548  public function delete()
1549  {
1550  global $ilDB;
1551 
1552  // delete il_news_read entries
1553  $ilDB->manipulate("DELETE FROM il_news_read ".
1554  " WHERE news_id = ".$ilDB->quote($this->getId(), "integer"));
1555 
1556  // delete multimedia object
1557  $mob = $this->getMobId();
1558 
1559  // delete
1560  $query = "DELETE FROM il_news_item".
1561  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
1562  $ilDB->manipulate($query);
1563 
1564  // delete mob after news, to have a "mob usage" of 0
1565  if ($mob > 0 and ilObject::_exists($mob))
1566  {
1567  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1568  $mob = new ilObjMediaObject($mob);
1569  $mob->delete();
1570  }
1571  }
1572 
1577  static public function deleteNewsOfContext($a_context_obj_id,
1578  $a_context_obj_type, $a_context_sub_obj_id = 0, $a_context_sub_obj_type = "")
1579  {
1580  global $ilDB;
1581 
1582  if ($a_context_obj_id == 0 || $a_context_obj_type == "")
1583  {
1584  return;
1585  }
1586 
1587  if ($a_context_sub_obj_id > 0)
1588  {
1589  $and = " AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id, "integer").
1590  " AND context_sub_obj_type = ".$ilDB->quote($a_context_sub_obj_type, "text");
1591  }
1592 
1593  // get news records
1594  $query = "SELECT * FROM il_news_item".
1595  " WHERE context_obj_id = ".$ilDB->quote($a_context_obj_id, "integer").
1596  " AND context_obj_type = ".$ilDB->quote($a_context_obj_type, "text").
1597  $and;
1598 
1599  $news_set = $ilDB->query($query);
1600 
1601  while ($news = $ilDB->fetchAssoc($news_set))
1602  {
1603  $news_obj = new ilNewsItem($news["id"]);
1604  $news_obj->delete();
1605  }
1606  }
1607 
1611  static function _lookupTitle($a_news_id)
1612  {
1613  global $ilDB;
1614 
1615  $query = "SELECT title FROM il_news_item WHERE id = ".
1616  $ilDB->quote($a_news_id, "integer");
1617  $set = $ilDB->query($query);
1618  $rec = $ilDB->fetchAssoc($set);
1619  return $rec["title"];
1620  }
1621 
1625  static function _lookupVisibility($a_news_id)
1626  {
1627  global $ilDB;
1628 
1629  $query = "SELECT visibility FROM il_news_item WHERE id = ".
1630  $ilDB->quote($a_news_id, "integer");
1631  $set = $ilDB->query($query);
1632  $rec = $ilDB->fetchAssoc($set);
1633 
1634  return $rec["visibility"];
1635  }
1636 
1640  static function _lookupMobId($a_news_id)
1641  {
1642  global $ilDB;
1643 
1644  $query = "SELECT mob_id FROM il_news_item WHERE id = ".
1645  $ilDB->quote($a_news_id, "integer");
1646  $set = $ilDB->query($query);
1647  $rec = $ilDB->fetchAssoc($set);
1648  return $rec["mob_id"];
1649  }
1650 
1654  static function filterObjIdsPerNews($a_obj_ids, $a_time_period = 0, $a_starting_date = "",$a_ending_date = '', $ignore_period = false)
1655  {
1656  global $ilDB;
1657 
1658  $and = "";
1659  if ($a_time_period > 0)
1660  {
1661  $limit_ts = self::handleTimePeriod($a_time_period);
1662  $and = " AND creation_date >= ".$ilDB->quote($limit_ts, "timestamp")." ";
1663  }
1664 
1665  if ($a_starting_date != "")
1666  {
1667  $and.= " AND creation_date >= ".$ilDB->quote($a_starting_date, "timestamp");
1668  }
1669 
1670  $query = "SELECT DISTINCT(context_obj_id) AS obj_id FROM il_news_item".
1671  " WHERE ".$ilDB->in("context_obj_id", $a_obj_ids, false, "integer")." ".$and;
1672  //" WHERE context_obj_id IN (".implode(ilUtil::quoteArray($a_obj_ids),",").")".$and;
1673 
1674  $set = $ilDB->query($query);
1675  $objs = array();
1676  while($rec = $ilDB->fetchAssoc($set))
1677  {
1678  $objs[] = $rec["obj_id"];
1679  }
1680 
1681  return $objs;
1682  }
1683 
1687  static function determineNewsTitle($a_context_obj_type, $a_title, $a_content_is_lang_var,
1688  $a_agg_ref_id = 0, $a_aggregation = "")
1689  {
1690  global $lng;
1691 
1692  if ($a_agg_ref_id > 0)
1693  {
1694  $cnt = count($a_aggregation);
1695 
1696  // forums
1697  if ($a_context_obj_type == "frm")
1698  {
1699  if ($cnt > 1)
1700  {
1701  return sprintf($lng->txt("news_x_postings"), $cnt);
1702  }
1703  else
1704  {
1705  return $lng->txt("news_1_postings");
1706  }
1707  }
1708  else // files
1709  {
1710  $up_cnt = $cr_cnt = 0;
1711  foreach($a_aggregation as $item)
1712  {
1713  if ($item["title"] == "file_updated")
1714  {
1715  $up_cnt++;
1716  }
1717  else
1718  {
1719  $cr_cnt++;
1720  }
1721  }
1722  $sep = "";
1723  if ($cr_cnt == 1)
1724  {
1725  $tit = $lng->txt("news_1_file_created");
1726  $sep = "<br />";
1727  }
1728  else if ($cr_cnt > 1)
1729  {
1730  $tit = sprintf($lng->txt("news_x_files_created"), $cr_cnt);
1731  $sep = "<br />";
1732  }
1733  if ($up_cnt == 1)
1734  {
1735  $tit .= $sep.$lng->txt("news_1_file_updated");
1736  }
1737  else if ($up_cnt > 1)
1738  {
1739  $tit .= $sep.sprintf($lng->txt("news_x_files_updated"), $up_cnt);
1740  }
1741  return $tit;
1742  }
1743  }
1744  else
1745  {
1746  if ($a_content_is_lang_var)
1747  {
1748  return $lng->txt($a_title);
1749  }
1750  else
1751  {
1752  return $a_title;
1753  }
1754  }
1755 
1756  return "";
1757  }
1758 
1762  static function determineNewsContent($a_context_obj_type, $a_content, $a_is_lang_var)
1763  {
1764  global $lng;
1765 
1766  if ($a_is_lang_var)
1767  {
1768  $lng->loadLanguageModule($a_context_obj_type);
1769  return $lng->txt($a_content);
1770  }
1771  else
1772  {
1773  return $a_content;
1774  }
1775  }
1776 
1777 
1778 
1782  static function getFirstNewsIdForContext($a_context_obj_id,
1783  $a_context_obj_type, $a_context_sub_obj_id = "", $a_context_sub_obj_type = "")
1784  {
1785  global $ilDB;
1786 
1787  // Determine how many rows should be deleted
1788  $query = "SELECT * ".
1789  "FROM il_news_item ".
1790  "WHERE ".
1791  "context_obj_id = ".$ilDB->quote($a_context_obj_id, "integer").
1792  " AND context_obj_type = ".$ilDB->quote($a_context_obj_type, "text").
1793  " AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id, "integer").
1794  " AND ".$ilDB->equals("context_sub_obj_type", $a_context_sub_obj_type, "text", true);
1795 
1796  $set = $ilDB->query($query);
1797  $rec = $ilDB->fetchAssoc($set);
1798 
1799  return $rec["id"];
1800  }
1801 
1805  static function getLastNewsIdForContext($a_context_obj_id,
1806  $a_context_obj_type, $a_context_sub_obj_id = "", $a_context_sub_obj_type = "",
1807  $a_only_today = false)
1808  {
1809  global $ilDB;
1810 
1811  // Determine how many rows should be deleted
1812  $query = "SELECT id, update_date ".
1813  "FROM il_news_item ".
1814  "WHERE ".
1815  "context_obj_id = ".$ilDB->quote($a_context_obj_id, "integer").
1816  " AND context_obj_type = ".$ilDB->quote($a_context_obj_type, "text").
1817  " AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id, "integer").
1818  " AND ".$ilDB->equals("context_sub_obj_type", $a_context_sub_obj_type, "text", true).
1819  " ORDER BY update_date DESC";
1820 
1821  $ilDB->setLimit(1);
1822  $set = $ilDB->query($query);
1823  $rec = $ilDB->fetchAssoc($set);
1824 
1825  $id = (int) $rec["id"];
1826  if ($a_only_today)
1827  {
1828  $now = ilUtil::now();
1829  if (substr($now, 0, 10) != substr($rec["update_date"], 0, 10))
1830  {
1831  $id = 0;
1832  }
1833  }
1834 
1835  return $id;
1836  }
1837 
1838 
1842  static function _lookupMediaObjectUsages($a_mob_id)
1843  {
1844  global $ilDB;
1845 
1846  $query = "SELECT * ".
1847  "FROM il_news_item ".
1848  "WHERE ".
1849  " mob_id = ".$ilDB->quote($a_mob_id, "integer");
1850 
1851  $usages = array();
1852  $set = $ilDB->query($query);
1853  while ($rec = $ilDB->fetchAssoc($set))
1854  {
1855  $usages[$rec["id"]] = array("type" => "news", "id" => $rec["id"]);
1856  }
1857 
1858  return $usages;
1859  }
1860 
1864  static function _lookupContextObjId($a_news_id)
1865  {
1866  global $ilDB;
1867 
1868  $query = "SELECT * ".
1869  "FROM il_news_item ".
1870  "WHERE ".
1871  " id = ".$ilDB->quote($a_news_id, "integer");
1872  $set = $ilDB->query($query);
1873  $rec = $ilDB->fetchAssoc($set);
1874 
1875  return $rec["context_obj_id"];
1876  }
1877 
1878  static function _lookupDefaultPDPeriod()
1879  {
1880  $news_set = new ilSetting("news");
1881  $per = $news_set->get("pd_period");
1882  if ($per == 0)
1883  {
1884  $per = 30;
1885  }
1886 
1887  return $per;
1888  }
1889 
1890  static function _lookupUserPDPeriod($a_user_id)
1891  {
1892  $news_set = new ilSetting("news");
1893  $allow_shorter_periods = $news_set->get("allow_shorter_periods");
1894  $allow_longer_periods = $news_set->get("allow_longer_periods");
1895  $default_per = ilNewsItem::_lookupDefaultPDPeriod();
1896 
1897  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1898  $per = ilBlockSetting::_lookup("pdnews", "news_pd_period",
1899  $a_user_id, 0);
1900 
1901  // news period information
1902  if ($per <= 0 ||
1903  (!$allow_shorter_periods && ($per < $default_per)) ||
1904  (!$allow_longer_periods && ($per > $default_per))
1905  )
1906  {
1907  $per = $default_per;
1908  }
1909 
1910  return $per;
1911  }
1912 
1913  static function _lookupRSSPeriod()
1914  {
1915  $news_set = new ilSetting("news");
1916  $rss_period = $news_set->get("rss_period");
1917  if ($rss_period == 0) // default to two weeks
1918  {
1919  $rss_period = 14;
1920  }
1921  return $rss_period;
1922  }
1923  static function setPrivateFeedId ($a_userId)
1924  {
1925  ilNewsItem::$privFeedId = $a_userId;
1926  }
1927 
1928  static function getPrivateFeedId () {
1929 
1930  return ilNewsItem::$privFeedId;
1931  }
1932 
1939  function deliverMobFile($a_purpose = "Standard", $a_increase_download_cnt = false)
1940  {
1941  $mob = $this->getMobId();
1942  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1943  $mob = new ilObjMediaObject($mob);
1944  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
1945 
1946  // check purpose
1947  if (!$mob->hasPurposeItem($a_purpose))
1948  {
1949  return false;
1950  }
1951 
1952  $m_item = $mob->getMediaItem($a_purpose);
1953  if ($m_item->getLocationType() != "Reference")
1954  {
1955  $file = $mob_dir."/".$m_item->getLocation();
1956  if (file_exists($file) && is_file($file))
1957  {
1958  if ($a_increase_download_cnt)
1959  {
1960  $this->increaseDownloadCounter();
1961  }
1962  ilUtil::deliverFile($file, $m_item->getLocation(), "", false, false, false);
1963  return true;
1964  }
1965  else
1966  {
1967  ilUtil::sendFailure("File not found!",true);
1968  return false;
1969  }
1970  }
1971  else
1972  {
1973  if ($a_increase_download_cnt)
1974  {
1975  $this->increaseDownloadCounter();
1976  }
1977  ilUtil::redirect($m_item->getLocation());
1978  }
1979  }
1980 
1988  {
1989  global $ilDB;
1990 
1991  $cnt = $this->getMobDownloadCounter();
1992  $cnt++;
1993  $this->setMobDownloadCounter($cnt);
1994  $ilDB->manipulate("UPDATE il_news_item SET ".
1995  " mob_cnt_download = ".$ilDB->quote($cnt, "integer").
1996  " WHERE id = ".$ilDB->quote($this->getId(), "integer")
1997  );
1998  }
1999 
2007  {
2008  global $ilDB;
2009 
2010  $cnt = $this->getMobPlayCounter();
2011  $cnt++;
2012  $this->setMobPlayCounter($cnt);
2013  $ilDB->manipulate("UPDATE il_news_item SET ".
2014  " mob_cnt_play = ".$ilDB->quote($cnt, "integer").
2015  " WHERE id = ".$ilDB->quote($this->getId(), "integer")
2016  );
2017  }
2018 
2025  static function prepareNewsDataFromCache($a_cres)
2026  {
2027  global $ilDB;
2028 
2029  $data = $a_cres;
2030  $news_ids = array_keys($data);
2031  $set = $ilDB->query("SELECT id FROM il_news_item ".
2032  " WHERE ".$ilDB->in("id", $news_ids, false, "integer"));
2033  $existing_ids = array();
2034  while ($rec = $ilDB->fetchAssoc($set))
2035  {
2036  $existing_ids[] = $rec["id"];
2037  }
2038  //var_dump($existing_ids);
2039  $existing_news = array();
2040  foreach ($data as $k => $v)
2041  {
2042  if (in_array($k, $existing_ids))
2043  {
2044  $existing_news[$k] = $v;
2045  }
2046  }
2047 
2048  //var_dump($data);
2049  //var_dump($existing_news);
2050 
2051  return $existing_news;
2052  }
2053 
2054 }
2055 ?>
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.
getContentHtml()
Get content as html.
ILIAS Setting Class.
setContentTextIsLangVar($a_val=0)
Set content text ist lang var.
$path
Definition: aliased.php:25
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.
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 _lookupRSSPeriod()
getMobId()
Get MobId.
setVisibility($a_visibility="users")
Set Visibility.
$result
setContextSubObjId($a_context_sub_obj_id)
Set ContextSubObjId.
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
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 _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.
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.
setTitle($a_title)
Set Title.
__construct($a_id=0)
Constructor.
static mergeNews($n1, $n2)
Merges two sets of news.
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.
static prepareNewsDataFromCache($a_cres)
Prepare news data from cache.
getCreationDate()
Get CreationDate.
getContentTextIsLangVar()
Get content text ist lang var.
getContentLong()
Get ContentLong.
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
getContextObjType()
Get ContextObjType.
static now()
Return current timestamp in Y-m-d H:i:s format.
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.
setPriority($a_priority=1)
Set Priority.
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.
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.
setContentIsLangVar($a_content_is_lang_var=0)
Set ContentIsLangVar.
setContent($a_content)
Set Content.
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.
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 _lookupMediaObjectUsages($a_mob_id)
Lookup media object usage(s)
$a_content
Definition: workflow.php:94
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.
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.
static preloadData(array $a_ref_ids)
Preload data to internal cache.
update($a_as_new=false)
Update item in database.
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
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.
getLimitation()
Get Limitation for number of items.
getContextSubObjId()
Get ContextSubObjId.
getVisibility()
Get Visibility.
setContentType($a_content_type="text")
Set ContentType.
getMobPlayCounter()
Get mob play counter.
static _lookupDesktopItems($user_id, $a_types="")
get all desktop items of user and specified type
static getPrivateFeedId()
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.
$ref_id
Definition: sahs_server.php:39
global $ilSetting
Definition: privfeed.php:17
static _lookupPref($a_usr_id, $a_keyword)
global $lng
Definition: privfeed.php:17
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.
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.
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)
http redirect to other script
setUpdateDate($a_update_date)
Set UpdateDate.
create()
Create.
setId($a_id)
Set Id.
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.
getTitle()
Get Title.
getUpdateUserId()
Get update user id.
static _lookupDefaultPDPeriod()
setMobPlayCounter($a_val)
Set mob play counter.
increasePlayCounter()
Increase play counter.
static setPrivateFeedId($a_userId)
aggregateFiles($news, $a_ref_id)
getContextObjId()
Get ContextObjId.