ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilNewsItem.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 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 include_once("./Services/News/classes/class.ilNewsItemGen.php");
9 
22 {
23 
24  private static $privFeedId = false;
25  private $limitation;
26 
32  public function __construct($a_id = 0)
33  {
34  parent::__construct($a_id);
35  $this->limitation = true;
36  }
37 
38 
44  function setLimitation($a_limitation)
45  {
46  $this->limitation = $a_limitation;
47  }
48 
54  function getLimitation()
55  {
56  return $this->limitation;
57  }
58 
62  function create()
63  {
64  global $ilDB;
65 
67 
68  $news_set = new ilSetting("news");
69  $max_items = $news_set->get("max_items");
70  if ($max_items <= 0)
71  {
72  $max_items = 50;
73  }
74 
75  // limit number of news
76  if ($this->getLimitation())
77  {
78  // Determine how many rows should be deleted
79  $query = "SELECT count(*) cnt ".
80  "FROM il_news_item ".
81  "WHERE ".
82  "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
83  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
84  " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId(), "integer").
85  " AND ".$ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true)." ";
86 
87  $set = $ilDB->query($query);
88  $rec = $ilDB->fetchAssoc($set);
89 
90  // if we have more records than allowed, delete them
91  if (($rec["cnt"] > $max_items) && $this->getContextObjId() > 0)
92  {
93  $query = "SELECT * ".
94  "FROM il_news_item ".
95  "WHERE ".
96  "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
97  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
98  " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId(), "integer").
99  " AND ".$ilDB->equals("context_sub_obj_type", $this->getContextSubObjType(), "text", true).
100  " ORDER BY creation_date ASC";
101 
102  $ilDB->setLimit($rec["cnt"] - $max_items);
103  $del_set = $ilDB->query($query);
104  while ($del_item = $ilDB->fetchAssoc($del_set))
105  {
106  $del_news = new ilNewsItem($del_item["id"]);
107  $del_news->delete();
108  }
109  }
110  }
111  }
112 
116  static function _getNewsItemsOfUser($a_user_id, $a_only_public = false,
117  $a_prevent_aggregation = false, $a_per = 0, &$a_cnt = NULL)
118  {
119  global $ilAccess, $ilUser;
120 
121  $news_item = new ilNewsItem();
122  $news_set = new ilSetting("news");
123 
124  $per = $a_per;
125 
126  include_once("./Services/News/classes/class.ilNewsSubscription.php");
127  include_once("./Services/Block/classes/class.ilBlockSetting.php");
128 
129  // this is currently not used
130  $ref_ids = ilNewsSubscription::_getSubscriptionsOfUser($a_user_id);
131 
132  if (ilObjUser::_lookupPref($a_user_id, "pd_items_news") != "n")
133  {
134  // this should be the case for all users
135  $pd_items = ilObjUser::_lookupDesktopItems($a_user_id);
136  foreach($pd_items as $item)
137  {
138  if (!in_array($item["ref_id"], $ref_ids))
139  {
140  $ref_ids[] = $item["ref_id"];
141  }
142  }
143  }
144 
145  $data = array();
146 
147  foreach($ref_ids as $ref_id)
148  {
149  if (!$a_only_public)
150  {
151  // this loop should not cost too much performance
152  $acc = $ilAccess->checkAccess("read", "", $ref_id);
153 
154  if (!$acc)
155  {
156  continue;
157  }
158  }
159  if (ilNewsItem::getPrivateFeedId() != false) {
160  global $rbacsystem;
161  $acc = $rbacsystem->checkAccessOfUser(ilNewsItem::getPrivateFeedId(),"read", $ref_id);
162 
163  if (!$acc)
164  {
165  continue;
166  }
167  }
168 
169  $obj_id = ilObject::_lookupObjId($ref_id);
170  $obj_type = ilObject::_lookupType($obj_id);
171  $news = $news_item->getNewsForRefId($ref_id, $a_only_public, false,
172  $per, $a_prevent_aggregation);
173 
174  // counter
175  if (!is_null($a_cnt))
176  {
177  $a_cnt[$ref_id] = count($news);
178  }
179 
181  }
182 
183  $data = ilUtil::sortArray($data, "creation_date", "desc", false, true);
184 
185  return $data;
186  }
187 
191  function getNewsForRefId($a_ref_id, $a_only_public = false, $a_stopnesting = false,
192  $a_time_period = 0, $a_prevent_aggregation = true, $a_forum_group_sequences = false,
193  $a_no_auto_generated = false, $a_ignore_date_filter = false)
194  {
195  $obj_id = ilObject::_lookupObjId($a_ref_id);
196  $obj_type = ilObject::_lookupType($obj_id);
197 
198  // get starting date
199  $starting_date = "";
200  if ($obj_type == "grp" || $obj_type == "crs" || $obj_type == "cat")
201  {
202  include_once("./Services/Block/classes/class.ilBlockSetting.php");
203  $hide_news_per_date = ilBlockSetting::_lookup("news", "hide_news_per_date",
204  0, $obj_id);
205  if ($hide_news_per_date && !$a_ignore_date_filter)
206  {
207  $starting_date = ilBlockSetting::_lookup("news", "hide_news_date",
208  0, $obj_id);
209  }
210  }
211 
212  if ($obj_type == "cat" && !$a_stopnesting)
213  {
214  $news = $this->getAggregatedChildNewsData($a_ref_id, $a_only_public, $a_time_period,
215  $a_prevent_aggregation, $starting_date, $a_no_auto_generated);
216  }
217  else if (($obj_type == "grp" || $obj_type == "crs") &&
218  !$a_stopnesting)
219  {
220  $news = $this->getAggregatedNewsData($a_ref_id, $a_only_public, $a_time_period,
221  $a_prevent_aggregation, $starting_date, $a_no_auto_generated);
222  }
223  else
224  {
225  $news_item = new ilNewsItem();
226  $news_item->setContextObjId($obj_id);
227  $news_item->setContextObjType($obj_type);
228  $news = $news_item->queryNewsForContext($a_only_public, $a_time_period,
229  $starting_date, $a_no_auto_generated);
230  $unset = array();
231  foreach ($news as $k => $v)
232  {
233  if (!$a_only_public || $v["visibility"] == NEWS_PUBLIC ||
234  ($v["priority"] == 0 &&
235  ilBlockSetting::_lookup("news", "public_notifications",
236  0, $obj_id)))
237  {
238  $news[$k]["ref_id"] = $a_ref_id;
239  }
240  else
241  {
242  $unset[] = $k;
243  }
244  }
245  foreach ($unset as $un)
246  {
247  unset($news[$un]);
248  }
249  }
250 
251  return $news;
252  }
253 
257  function getAggregatedNewsData($a_ref_id, $a_only_public = false, $a_time_period = 0,
258  $a_prevent_aggregation = false, $a_starting_date = "", $a_no_auto_generated = false)
259  {
260  global $tree, $ilAccess, $ilObjDataCache;
261 
262  // get news of parent object
263 
264  $data = array();
265 
266  // get subtree
267  $cur_node = $tree->getNodeData($a_ref_id);
268 
269  if ($cur_node["lft"] != "") // should never be empty
270  {
271  $nodes = $tree->getSubTree($cur_node, true);
272  }
273  else
274  {
275  $nodes = array();
276  }
277 
278  // preload object data cache
279  $ref_ids = array();
280  $obj_ids = array();
281  foreach($nodes as $node)
282  {
283  $ref_ids[] = $node["child"];
284  $obj_ids[] = $node["obj_id"];
285  }
286 
287  $ilObjDataCache->preloadReferenceCache($ref_ids);
288  if (!$a_only_public)
289  {
290  $ilAccess->preloadActivationTimes($ref_ids);
291  }
292 
293  // no check, for which of the objects any news are available
294  $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $a_time_period, $a_starting_date);
295  //$news_obj_ids = $obj_ids;
296 
297  // get news for all subtree nodes
298  $contexts = array();
299  foreach($nodes as $node)
300  {
301  // only go on, if news are available
302  if (!in_array($node["obj_id"], $news_obj_ids))
303  {
304  continue;
305  }
306 
307  if (!$a_only_public)
308  {
309  $acc = $ilAccess->checkAccess("read", "", $node["child"]);
310 
311  if (!$acc)
312  {
313  continue;
314  }
315  }
316 
317  $ref_id[$node["obj_id"]] = $node["child"];
318  $contexts[] = array("obj_id" => $node["obj_id"],
319  "obj_type" => $node["type"]);
320  }
321 
322  // sort and return
323  $news = $this->queryNewsForMultipleContexts($contexts, $a_only_public, $a_time_period,
324  $a_starting_date, $a_no_auto_generated);
325 
326  $to_del = array();
327  foreach ($news as $k => $v)
328  {
329  $news[$k]["ref_id"] = $ref_id[$v["context_obj_id"]];
330  }
331 
333  $data = ilUtil::sortArray($data, "creation_date", "desc", false, true);
334 
335  if (!$a_prevent_aggregation)
336  {
337  $data = $this->aggregateFiles($data, $a_ref_id);
338  }
339 
340  return $data;
341  }
342 
343  function aggregateFiles($news, $a_ref_id)
344  {
345  $first_file = "";
346  $to_del = array();
347  foreach ($news as $k => $v)
348  {
349  // aggregate file related news
350  if ($news[$k]["context_obj_type"] == "file")
351  {
352  if ($first_file == "")
353  {
354  $first_file = $k;
355  }
356  else
357  {
358  $to_del[] = $k;
359  }
360  $news[$first_file]["aggregation"][$k] = $news[$k];
361  $news[$first_file]["agg_ref_id"] = $a_ref_id;
362  $news[$first_file]["ref_id"] = $a_ref_id;
363  }
364  }
365 
366  foreach($to_del as $v)
367  {
368  unset($news[$v]);
369  }
370 
371  return $news;
372  }
373 
374 
378  function getAggregatedChildNewsData($a_ref_id, $a_only_public = false,
379  $a_time_period = 0, $a_prevent_aggregation = false, $a_starting_date = "",
380  $a_no_auto_generated = false)
381  {
382  global $tree, $ilAccess;
383 
384  // get news of parent object
385  $data = $this->getNewsForRefId($a_ref_id, $a_only_public, true, $a_time_period,
386  true, false, false, $a_no_auto_generated);
387  foreach ($data as $k => $v)
388  {
389  $data[$k]["ref_id"] = $a_ref_id;
390  }
391 
392  // get childs
393  $nodes = $tree->getChilds($a_ref_id);
394 
395  // no check, for which of the objects any news are available
396  $obj_ids = array();
397  foreach($nodes as $node)
398  {
399  $obj_ids[] = $node["obj_id"];
400  }
401  $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $a_time_period, $a_starting_date);
402  //$news_obj_ids = $obj_ids;
403 
404  // get news for all subtree nodes
405  $contexts = array();
406  foreach($nodes as $node)
407  {
408  // only go on, if news are available
409  if (!in_array($node["obj_id"], $news_obj_ids))
410  {
411  continue;
412  }
413 
414  if (!$a_only_public && !$ilAccess->checkAccess("read", "", $node["child"]))
415  {
416  continue;
417  }
418  $ref_id[$node["obj_id"]] = $node["child"];
419  $contexts[] = array("obj_id" => $node["obj_id"],
420  "obj_type" => $node["type"]);
421  }
422 
423  $news = $this->queryNewsForMultipleContexts($contexts, $a_only_public, $a_time_period,
424  $a_starting_date, $a_no_auto_generated);
425  foreach ($news as $k => $v)
426  {
427  $news[$k]["ref_id"] = $ref_id[$v["context_obj_id"]];
428  }
430 
431  // sort and return
432  $data = ilUtil::sortArray($data, "creation_date", "desc", false, true);
433 
434  if (!$a_prevent_aggregation)
435  {
436  $data = $this->aggregateFiles($data, $a_ref_id);
437  }
438 
439  return $data;
440  }
441 
445  function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type = "")
446  {
447  $this->setContextObjId($a_obj_id);
448  $this->setContextObjType($a_obj_type);
449  $this->setContextSubObjId($a_sub_obj_id);
450  $this->setContextSubObjType($a_sub_obj_type);
451  }
452 
461  public function queryNewsForContext($a_for_rss_use = false, $a_time_period = 0,
462  $a_starting_date = "", $a_no_auto_generated = false, $a_oldest_first = false)
463  {
464  global $ilDB, $ilUser, $lng;
465 
466  $and = "";
467  if ($a_time_period > 0)
468  {
469  $limit_ts = date('Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
470  $and = " AND creation_date >= ".$ilDB->quote($limit_ts, "timestamp")." ";
471  }
472 
473  if ($a_starting_date != "")
474  {
475  $and.= " AND creation_date > ".$ilDB->quote($a_starting_date, "timestamp")." ";
476  }
477 
478  if ($a_no_auto_generated)
479  {
480  $and.= " AND priority = 1 AND content_type = ".$ilDB->quote("text", "text")." ";
481  }
482 
483  // this is changed with 4.1 (news table for lm pages)
484  if ($this->getContextSubObjId() > 0)
485  {
486  $and.= " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId(), "integer").
487  " AND context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType(), "text");
488  }
489 
490  $ordering = ($a_oldest_first)
491  ? " creation_date ASC, id ASC "
492  : " creation_date DESC, id DESC ";
493 
494  if ($a_for_rss_use && ilNewsItem::getPrivateFeedId() == false)
495  {
496  $query = "SELECT * ".
497  "FROM il_news_item ".
498  " WHERE ".
499  "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
500  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
501  $and.
502  " ORDER BY ".$ordering;
503  }
504  elseif (ilNewsItem::getPrivateFeedId() != false)
505  {
506  $query = "SELECT il_news_item.* ".
507  ", il_news_read.user_id user_read ".
508  "FROM il_news_item LEFT JOIN il_news_read ".
509  "ON il_news_item.id = il_news_read.news_id AND ".
510  " il_news_read.user_id = ".$ilDB->quote(ilNewsItem::getPrivateFeedId(), "integer").
511  " WHERE ".
512  "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
513  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
514  $and.
515  " ORDER BY ".$ordering;
516  }
517  else
518  {
519  $query = "SELECT il_news_item.* ".
520  ", il_news_read.user_id as user_read ".
521  "FROM il_news_item LEFT JOIN il_news_read ".
522  "ON il_news_item.id = il_news_read.news_id AND ".
523  " il_news_read.user_id = ".$ilDB->quote($ilUser->getId(), "integer").
524  " WHERE ".
525  "context_obj_id = ".$ilDB->quote($this->getContextObjId(), "integer").
526  " AND context_obj_type = ".$ilDB->quote($this->getContextObjType(), "text").
527  $and.
528  " ORDER BY ".$ordering;
529  }
530 //echo $query;
531  $set = $ilDB->query($query);
532  $result = array();
533  while($rec = $ilDB->fetchAssoc($set))
534  {
535  if (!$a_for_rss_use || (ilNewsItem::getPrivateFeedId() != false) || ($rec["visibility"] == NEWS_PUBLIC ||
536  ($rec["priority"] == 0 &&
537  ilBlockSetting::_lookup("news", "public_notifications",
538  0, $rec["context_obj_id"]))))
539  {
540  $result[$rec["id"]] = $rec;
541  }
542  }
543 
544  return $result;
545 
546  }
547 
553  public function queryNewsForMultipleContexts($a_contexts, $a_for_rss_use = false,
554  $a_time_period = 0, $a_starting_date = "", $a_no_auto_generated = false)
555  {
556  global $ilDB, $ilUser, $lng, $ilCtrl;
557 
558  $and = "";
559  if ($a_time_period > 0)
560  {
561  $limit_ts = date('Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
562  $and = " AND creation_date >= ".$ilDB->quote($limit_ts, "timestamp")." ";
563  }
564 
565  if ($a_starting_date != "")
566  {
567  $and.= " AND creation_date > ".$ilDB->quote($a_starting_date, "timestamp")." ";
568  }
569 
570  if ($a_no_auto_generated)
571  {
572  $and.= " AND priority = 1 AND content_type = ".$ilDB->quote("text", "text")." ";
573  }
574 
575  $ids = array();
576  $type = array();
577  foreach($a_contexts as $cont)
578  {
579  $ids[] = $cont["obj_id"];
580  $type[$cont["obj_id"]] = $cont["obj_type"];
581  }
582 
583  if ($a_for_rss_use && ilNewsItem::getPrivateFeedId() == false)
584  {
585  $query = "SELECT * ".
586  "FROM il_news_item ".
587  " WHERE ".
588  $ilDB->in("context_obj_id", $ids, false, "integer")." ".
589  $and.
590  " ORDER BY creation_date DESC ";
591  }
592  elseif (ilNewsItem::getPrivateFeedId() != false)
593  {
594  $query = "SELECT il_news_item.* ".
595  ", il_news_read.user_id as user_read ".
596  "FROM il_news_item LEFT JOIN il_news_read ".
597  "ON il_news_item.id = il_news_read.news_id AND ".
598  " il_news_read.user_id = ".$ilDB->quote(ilNewsItem::getPrivateFeedId(), "integer").
599  " WHERE ".
600  $ilDB->in("context_obj_id", $ids, false, "integer")." ".
601  $and.
602  " ORDER BY creation_date DESC ";
603  }
604  else
605  {
606  $query = "SELECT il_news_item.* ".
607  ", il_news_read.user_id as user_read ".
608  "FROM il_news_item LEFT JOIN il_news_read ".
609  "ON il_news_item.id = il_news_read.news_id AND ".
610  " il_news_read.user_id = ".$ilDB->quote($ilUser->getId(), "integer").
611  " WHERE ".
612  $ilDB->in("context_obj_id", $ids, false, "integer")." ".
613  $and.
614  " ORDER BY creation_date DESC ";
615  }
616 
617  $set = $ilDB->query($query);
618  $result = array();
619  while($rec = $ilDB->fetchAssoc($set))
620  {
621  if ($type[$rec["context_obj_id"]] == $rec["context_obj_type"])
622  {
623  if (!$a_for_rss_use || ilNewsItem::getPrivateFeedId() != false || ($rec["visibility"] == NEWS_PUBLIC ||
624  ($rec["priority"] == 0 &&
625  ilBlockSetting::_lookup("news", "public_notifications",
626  0, $rec["context_obj_id"]))))
627  {
628  $result[$rec["id"]] = $rec;
629  }
630  }
631  }
632 
633  return $result;
634 
635  }
636 
637 
641  function _setRead($a_user_id, $a_news_id)
642  {
643  global $ilDB, $ilAppEventHandler;
644 
645  $ilDB->manipulate("DELETE FROM il_news_read WHERE ".
646  "user_id = ".$ilDB->quote($a_user_id, "integer").
647  " AND news_id = ".$ilDB->quote($a_news_id, "integer"));
648  $ilDB->manipulate("INSERT INTO il_news_read (user_id, news_id) VALUES (".
649  $ilDB->quote($a_user_id, "integer").",".
650  $ilDB->quote($a_news_id, "integer").")");
651 
652  $ilAppEventHandler->raise("Services/News", "readNews",
653  array("user_id" => $a_user_id, "news_ids" => array($a_news_id)));
654  }
655 
659  function _setUnread($a_user_id, $a_news_id)
660  {
661  global $ilDB, $ilAppEventHandler;
662 
663  $ilDB->manipulate("DELETE FROM il_news_read (user_id, news_id) VALUES (".
664  " WHERE user_id = ".$ilDB->quote($a_user_id, "integer").
665  " AND news_id = ".$ilDB->quote($a_news_id, "integer"));
666 
667  $ilAppEventHandler->raise("Services/News", "unreadNews",
668  array("user_id" => $a_user_id, "news_ids" => array($a_news_id)));
669  }
670 
679  function mergeNews($n1, $n2)
680  {
681  foreach($n2 as $id => $news)
682  {
683  $n1[$id] = $news;
684  }
685 
686  return $n1;
687  }
688 
694  static function _getDefaultVisibilityForRefId($a_ref_id)
695  {
696  global $tree, $ilSetting;
697 
698  include_once("./Services/Block/classes/class.ilBlockSetting.php");
699 
700  $news_set = new ilSetting("news");
701  $default_visibility = ($news_set->get("default_visibility") != "")
702  ? $news_set->get("default_visibility")
703  : "users";
704 
705  if ($tree->isInTree($a_ref_id))
706  {
707  $path = $tree->getPathFull($a_ref_id);
708 
709  foreach ($path as $key => $row)
710  {
711  if (!in_array($row["type"], array("root", "cat","crs", "fold", "grp", "icrs")))
712  {
713  continue;
714  }
715 
716  $visibility = ilBlockSetting::_lookup("news", "default_visibility",
717  0, $row["obj_id"]);
718 
719  if ($visibility != "")
720  {
721  $default_visibility = $visibility;
722  }
723  }
724  }
725 
726  return $default_visibility;
727  }
728 
729 
734  public function delete()
735  {
736  global $ilDB;
737 
738  // delete il_news_read entries
739  $ilDB->manipulate("DELETE FROM il_news_read ".
740  " WHERE news_id = ".$ilDB->quote($this->getId(), "integer"));
741 
742  // delete multimedia object
743  $mob = $this->getMobId();
744 
745  // delete
746  parent::delete();
747 
748  // delete mob after news, to have a "mob usage" of 0
749  if ($mob > 0 and ilObject::_exists($mob))
750  {
751  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
752  $mob = new ilObjMediaObject($mob);
753  $mob->delete();
754  }
755  }
756 
761  static public function deleteNewsOfContext($a_context_obj_id,
762  $a_context_obj_type, $a_context_sub_obj_id = 0, $a_context_sub_obj_type = "")
763  {
764  global $ilDB;
765 
766  if ($a_context_obj_id == 0 || $a_context_obj_type == "")
767  {
768  return;
769  }
770 
771  if ($a_context_sub_obj_id > 0)
772  {
773  $and = " AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id, "integer").
774  " AND context_sub_obj_type = ".$ilDB->quote($a_context_sub_obj_type, "text");
775  }
776 
777  // get news records
778  $query = "SELECT * FROM il_news_item".
779  " WHERE context_obj_id = ".$ilDB->quote($a_context_obj_id, "integer").
780  " AND context_obj_type = ".$ilDB->quote($a_context_obj_type, "text").
781  $and;
782 
783  $news_set = $ilDB->query($query);
784 
785  while ($news = $ilDB->fetchAssoc($news_set))
786  {
787  $news_obj = new ilNewsItem($news["id"]);
788  $news_obj->delete();
789  }
790  }
791 
795  static function _lookupTitle($a_news_id)
796  {
797  global $ilDB;
798 
799  $query = "SELECT title FROM il_news_item WHERE id = ".
800  $ilDB->quote($a_news_id, "integer");
801  $set = $ilDB->query($query);
802  $rec = $ilDB->fetchAssoc($set);
803  return $rec["title"];
804  }
805 
809  static function _lookupVisibility($a_news_id)
810  {
811  global $ilDB;
812 
813  $query = "SELECT visibility FROM il_news_item WHERE id = ".
814  $ilDB->quote($a_news_id, "integer");
815  $set = $ilDB->query($query);
816  $rec = $ilDB->fetchAssoc($set);
817 
818  return $rec["visibility"];
819  }
820 
824  static function _lookupMobId($a_news_id)
825  {
826  global $ilDB;
827 
828  $query = "SELECT mob_id FROM il_news_item WHERE id = ".
829  $ilDB->quote($a_news_id, "integer");
830  $set = $ilDB->query($query);
831  $rec = $ilDB->fetchAssoc($set);
832  return $rec["mob_id"];
833  }
834 
838  static function filterObjIdsPerNews($a_obj_ids, $a_time_period = 0, $a_starting_date = "",$a_ending_date = '', $ignore_period = false)
839  {
840  global $ilDB;
841 
842  $and = "";
843  if ($a_time_period > 0)
844  {
845  $limit_ts = date('Y-m-d H:i:s', time() - ($a_time_period * 24 * 60 * 60));
846  $and = " AND creation_date >= ".$ilDB->quote($limit_ts, "timestamp")." ";
847  }
848 
849  if ($a_starting_date != "")
850  {
851  $and.= " AND creation_date >= ".$ilDB->quote($a_starting_date, "timestamp");
852  }
853 
854  $query = "SELECT DISTINCT(context_obj_id) AS obj_id FROM il_news_item".
855  " WHERE ".$ilDB->in("context_obj_id", $a_obj_ids, false, "integer")." ".$and;
856  //" WHERE context_obj_id IN (".implode(ilUtil::quoteArray($a_obj_ids),",").")".$and;
857 
858  $set = $ilDB->query($query);
859  $objs = array();
860  while($rec = $ilDB->fetchAssoc($set))
861  {
862  $objs[] = $rec["obj_id"];
863  }
864 
865  return $objs;
866  }
867 
871  static function determineNewsTitle($a_context_obj_type, $a_title, $a_content_is_lang_var,
872  $a_agg_ref_id = 0, $a_aggregation = "")
873  {
874  global $lng;
875 
876  if ($a_agg_ref_id > 0)
877  {
878  $cnt = count($a_aggregation);
879 
880  $up_cnt = $cr_cnt = 0;
881  foreach($a_aggregation as $item)
882  {
883  if ($item["title"] == "file_updated")
884  {
885  $up_cnt++;
886  }
887  else
888  {
889  $cr_cnt++;
890  }
891  }
892  $sep = "";
893  if ($cr_cnt == 1)
894  {
895  $tit = $lng->txt("news_1_file_created");
896  $sep = "<br />";
897  }
898  else if ($cr_cnt > 1)
899  {
900  $tit = sprintf($lng->txt("news_x_files_created"), $cr_cnt);
901  $sep = "<br />";
902  }
903  if ($up_cnt == 1)
904  {
905  $tit .= $sep.$lng->txt("news_1_file_updated");
906  }
907  else if ($up_cnt > 1)
908  {
909  $tit .= $sep.sprintf($lng->txt("news_x_files_updated"), $up_cnt);
910  }
911  return $tit;
912  }
913  else
914  {
915  if ($a_content_is_lang_var)
916  {
917  return $lng->txt($a_title);
918  }
919  else
920  {
921  return $a_title;
922  }
923  }
924 
925  return "";
926  }
927 
928 
932  static function getFirstNewsIdForContext($a_context_obj_id,
933  $a_context_obj_type, $a_context_sub_obj_id = "", $a_context_sub_obj_type = "")
934  {
935  global $ilDB;
936 
937  // Determine how many rows should be deleted
938  $query = "SELECT * ".
939  "FROM il_news_item ".
940  "WHERE ".
941  "context_obj_id = ".$ilDB->quote($a_context_obj_id, "integer").
942  " AND context_obj_type = ".$ilDB->quote($a_context_obj_type, "text").
943  " AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id, "integer").
944  " AND ".$ilDB->equals("context_sub_obj_type", $a_context_sub_obj_type, "text", true);
945 
946  $set = $ilDB->query($query);
947  $rec = $ilDB->fetchAssoc($set);
948 
949  return $rec["id"];
950  }
951 
955  static function _lookupMediaObjectUsages($a_mob_id)
956  {
957  global $ilDB;
958 
959  $query = "SELECT * ".
960  "FROM il_news_item ".
961  "WHERE ".
962  " mob_id = ".$ilDB->quote($a_mob_id, "integer");
963 
964  $usages = array();
965  $set = $ilDB->query($query);
966  while ($rec = $ilDB->fetchAssoc($set))
967  {
968  $usages[$rec["id"]] = array("type" => "news", "id" => $rec["id"]);
969  }
970 
971  return $usages;
972  }
973 
977  static function _lookupContextObjId($a_news_id)
978  {
979  global $ilDB;
980 
981  $query = "SELECT * ".
982  "FROM il_news_item ".
983  "WHERE ".
984  " id = ".$ilDB->quote($a_news_id, "integer");
985  $set = $ilDB->query($query);
986  $rec = $ilDB->fetchAssoc($set);
987 
988  return $rec["context_obj_id"];
989  }
990 
992  {
993  $news_set = new ilSetting("news");
994  $per = $news_set->get("pd_period");
995  if ($per == 0)
996  {
997  $per = 30;
998  }
999 
1000  return $per;
1001  }
1002 
1003  function _lookupUserPDPeriod($a_user_id)
1004  {
1005  global $ilSetting;
1006 
1007  $news_set = new ilSetting("news");
1008  $allow_shorter_periods = $news_set->get("allow_shorter_periods");
1009  $allow_longer_periods = $news_set->get("allow_longer_periods");
1010  $default_per = ilNewsItem::_lookupDefaultPDPeriod();
1011 
1012  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1013  $per = ilBlockSetting::_lookup("pdnews", "news_pd_period",
1014  $a_user_id, 0);
1015 
1016  // news period information
1017  if ($per <= 0 ||
1018  (!$allow_shorter_periods && ($per < $default_per)) ||
1019  (!$allow_longer_periods && ($per > $default_per))
1020  )
1021  {
1022  $per = $default_per;
1023  }
1024 
1025  return $per;
1026  }
1027 
1028  function _lookupRSSPeriod()
1029  {
1030  $news_set = new ilSetting("news");
1031  $rss_period = $news_set->get("rss_period");
1032  if ($rss_period == 0) // default to two weeks
1033  {
1034  $rss_period = 14;
1035  }
1036  return $rss_period;
1037  }
1038  function setPrivateFeedId ($a_userId)
1039  {
1040  ilNewsItem::$privFeedId = $a_userId;
1041  }
1042 
1043  function getPrivateFeedId () {
1044 
1045  return ilNewsItem::$privFeedId;
1046  }
1047 }
1048 ?>