00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 define("NEWS_NOTICE", 0);
00025 define("NEWS_MESSAGE", 1);
00026 define("NEWS_WARNING", 2);
00027
00028 include_once("./Services/News/classes/class.ilNewsItemGen.php");
00029
00042 class ilNewsItem extends ilNewsItemGen
00043 {
00044 private $limitation;
00045
00051 public function __construct($a_id = 0)
00052 {
00053 parent::__construct($a_id);
00054 $this->limitation = true;
00055 }
00056
00057
00063 function setLimitation($a_limitation)
00064 {
00065 $this->limitation = $a_limitation;
00066 }
00067
00073 function getLimitation()
00074 {
00075 return $this->limitation;
00076 }
00077
00081 function create()
00082 {
00083 global $ilDB;
00084
00085 parent::create();
00086
00087 $news_set = new ilSetting("news");
00088 $max_items = $news_set->get("max_items");
00089 if ($max_items <= 0)
00090 {
00091 $max_items = 50;
00092 }
00093
00094
00095 if ($this->getLimitation())
00096 {
00097
00098 $query = "SELECT count(*) AS cnt ".
00099 "FROM il_news_item ".
00100 "WHERE ".
00101 "context_obj_id = ".$ilDB->quote($this->getContextObjId()).
00102 " AND context_obj_type = ".$ilDB->quote($this->getContextObjType()).
00103 " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId()).
00104 " AND context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType());
00105
00106 $set = $ilDB->query($query);
00107 $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00108
00109
00110 if (($rec["cnt"] > $max_items) && $this->getContextObjId() > 0)
00111 {
00112 $query = "SELECT * ".
00113 "FROM il_news_item ".
00114 "WHERE ".
00115 "context_obj_id = ".$ilDB->quote($this->getContextObjId()).
00116 " AND context_obj_type = ".$ilDB->quote($this->getContextObjType()).
00117 " AND context_sub_obj_id = ".$ilDB->quote($this->getContextSubObjId()).
00118 " AND context_sub_obj_type = ".$ilDB->quote($this->getContextSubObjType()).
00119 " ORDER BY creation_date ASC".
00120 " LIMIT ".($rec["cnt"] - $max_items);
00121
00122 $del_set = $ilDB->query($query);
00123 while ($del_item = $del_set->fetchRow(DB_FETCHMODE_ASSOC))
00124 {
00125 $del_news = new ilNewsItem($del_item["id"]);
00126 $del_news->delete();
00127 }
00128 }
00129 }
00130 }
00131
00135 static function _getNewsItemsOfUser($a_user_id, $a_only_public = false,
00136 $a_prevent_aggregation = false, $a_per = 0, &$a_cnt = NULL)
00137 {
00138 global $ilAccess, $ilUser, $ilBench;
00139
00140 $ilBench->start("News", "getNewsItemsOfUser");
00141
00142 $news_item = new ilNewsItem();
00143 $news_set = new ilSetting("news");
00144
00145 $per = $a_per;
00146
00147 include_once("./Services/News/classes/class.ilNewsSubscription.php");
00148 include_once("./Services/Block/classes/class.ilBlockSetting.php");
00149
00150
00151 $ilBench->start("News", "getNewsItemsOfUser_getRefIds");
00152 $ref_ids = ilNewsSubscription::_getSubscriptionsOfUser($a_user_id);
00153
00154 if (ilObjUser::_lookupPref($a_user_id, "pd_items_news") != "n")
00155 {
00156
00157 $pd_items = ilObjUser::_lookupDesktopItems($a_user_id);
00158 foreach($pd_items as $item)
00159 {
00160 if (!in_array($item["ref_id"], $ref_ids))
00161 {
00162 $ref_ids[] = $item["ref_id"];
00163 }
00164 }
00165 }
00166 $ilBench->stop("News", "getNewsItemsOfUser_getRefIds");
00167
00168 $data = array();
00169
00170 foreach($ref_ids as $ref_id)
00171 {
00172 $ilBench->start("News", "getNewsForRefId");
00173 if (!$a_only_public)
00174 {
00175
00176 $ilBench->start("News", "getAggregatedNewsData_getContexts_checkAccess");
00177 $acc = $ilAccess->checkAccess("read", "", $ref_id);
00178 $ilBench->stop("News", "getAggregatedNewsData_getContexts_checkAccess");
00179
00180 if (!$acc)
00181 {
00182 continue;
00183 }
00184 }
00185
00186 $ilBench->start("News", "getNewsForRefId_getNews");
00187 $obj_id = ilObject::_lookupObjId($ref_id);
00188 $obj_type = ilObject::_lookupType($obj_id);
00189 $news = $news_item->getNewsForRefId($ref_id, $a_only_public, false,
00190 $per, $a_prevent_aggregation);
00191 $ilBench->stop("News", "getNewsForRefId_getNews");
00192
00193
00194 if (!is_null($a_cnt))
00195 {
00196 $a_cnt[$ref_id] = count($news);
00197 }
00198
00199 $ilBench->start("News", "getNewsForRefId_mergeNews");
00200 $data = ilNewsItem::mergeNews($data, $news);
00201 $ilBench->stop("News", "getNewsForRefId_mergeNews");
00202
00203 $ilBench->stop("News", "getNewsForRefId");
00204 }
00205
00206 $data = ilUtil::sortArray($data, "creation_date", "desc", false, true);
00207
00208 $ilBench->stop("News", "getNewsItemsOfUser");
00209
00210
00211 return $data;
00212 }
00213
00217 function getNewsForRefId($a_ref_id, $a_only_public = false, $a_stopnesting = false,
00218 $a_time_period = 0, $a_prevent_aggregation = true, $a_forum_group_sequences = false)
00219 {
00220 $obj_id = ilObject::_lookupObjId($a_ref_id);
00221 $obj_type = ilObject::_lookupType($obj_id);
00222
00223
00224 $starting_date = "";
00225 if ($obj_type == "grp" || $obj_type == "crs" || $obj_type == "cat")
00226 {
00227 include_once("./Services/Block/classes/class.ilBlockSetting.php");
00228 $hide_news_per_date = ilBlockSetting::_lookup("news", "hide_news_per_date",
00229 0, $obj_id);
00230 if ($hide_news_per_date)
00231 {
00232 $starting_date = ilBlockSetting::_lookup("news", "hide_news_date",
00233 0, $obj_id);
00234 }
00235 }
00236
00237 if ($obj_type == "cat" && !$a_stopnesting)
00238 {
00239 $news = $this->getAggregatedChildNewsData($a_ref_id, $a_only_public, $a_time_period,
00240 $a_prevent_aggregation, $starting_date);
00241 }
00242 else if (($obj_type == "grp" || $obj_type == "crs") &&
00243 !$a_stopnesting)
00244 {
00245 $news = $this->getAggregatedNewsData($a_ref_id, $a_only_public, $a_time_period,
00246 $a_prevent_aggregation, $starting_date);
00247 }
00248 else
00249 {
00250 $news_item = new ilNewsItem();
00251 $news_item->setContextObjId($obj_id);
00252 $news_item->setContextObjType($obj_type);
00253 $news = $news_item->queryNewsForContext($a_only_public, $a_time_period,
00254 $starting_date);
00255 $unset = array();
00256 foreach ($news as $k => $v)
00257 {
00258 if (!$a_only_public || $v["visibility"] == NEWS_PUBLIC ||
00259 ($v["priority"] == 0 &&
00260 ilBlockSetting::_lookup("news", "public_notifications",
00261 0, $obj_id)))
00262 {
00263 $news[$k]["ref_id"] = $a_ref_id;
00264 }
00265 else
00266 {
00267 $unset[] = $k;
00268 }
00269 }
00270 foreach ($unset as $un)
00271 {
00272 unset($news[$un]);
00273 }
00274 }
00275
00276 if (!$a_prevent_aggregation)
00277 {
00278 $news = $this->aggregateForums($news);
00279 }
00280 else if ($a_forum_group_sequences)
00281 {
00282 $news = $this->aggregateForums($news, true);
00283 }
00284
00285 return $news;
00286 }
00287
00291 function getAggregatedNewsData($a_ref_id, $a_only_public = false, $a_time_period = 0,
00292 $a_prevent_aggregation = false, $a_starting_date = "")
00293 {
00294 global $tree, $ilAccess, $ilBench, $ilObjDataCache;
00295
00296 $ilBench->start("News", "getAggregatedNewsData");
00297
00298
00299
00300 $data = array();
00301
00302
00303 $ilBench->start("News", "getAggregatedNewsData_getSubTree");
00304 $cur_node = $tree->getNodeData($a_ref_id);
00305
00306 if ($cur_node["lft"] != "")
00307 {
00308 $nodes = $tree->getSubTree($cur_node, true);
00309 }
00310 else
00311 {
00312 $nodes = array();
00313 }
00314
00315
00316 $ref_ids = array();
00317 $obj_ids = array();
00318 foreach($nodes as $node)
00319 {
00320 $ref_ids[] = $node["child"];
00321 $obj_ids[] = $node["obj_id"];
00322 }
00323
00324 $ilObjDataCache->preloadReferenceCache($ref_ids);
00325 if (!$a_only_public)
00326 {
00327 $ilAccess->preloadActivationTimes($ref_ids);
00328 }
00329 $ilBench->stop("News", "getAggregatedNewsData_getSubTree");
00330
00331
00332 $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $a_time_period);
00333
00334
00335
00336 $ilBench->start("News", "getAggregatedNewsData_getContexts");
00337 $contexts = array();
00338 foreach($nodes as $node)
00339 {
00340
00341 if (!in_array($node["obj_id"], $news_obj_ids))
00342 {
00343 continue;
00344 }
00345
00346 if (!$a_only_public)
00347 {
00348 $ilBench->start("News", "getAggregatedNewsData_getContexts_checkAccess");
00349 $acc = $ilAccess->checkAccess("read", "", $node["child"]);
00350 $ilBench->stop("News", "getAggregatedNewsData_getContexts_checkAccess");
00351
00352 if (!$acc)
00353 {
00354 continue;
00355 }
00356 }
00357
00358 $ref_id[$node["obj_id"]] = $node["child"];
00359 $contexts[] = array("obj_id" => $node["obj_id"],
00360 "obj_type" => $node["type"]);
00361 }
00362 $ilBench->stop("News", "getAggregatedNewsData_getContexts");
00363
00364
00365 $news = $this->queryNewsForMultipleContexts($contexts, $a_only_public, $a_time_period,
00366 $a_starting_date);
00367
00368 $ilBench->start("News", "getAggregatedNewsData_mergeAndSort");
00369
00370 $to_del = array();
00371 foreach ($news as $k => $v)
00372 {
00373 $news[$k]["ref_id"] = $ref_id[$v["context_obj_id"]];
00374 }
00375
00376 $data = ilNewsItem::mergeNews($data, $news);
00377 $data = ilUtil::sortArray($data, "creation_date", "desc", false, true);
00378
00379 if (!$a_prevent_aggregation)
00380 {
00381 $data = $this->aggregateFiles($data, $a_ref_id);
00382 }
00383
00384
00385
00386 $ilBench->stop("News", "getAggregatedNewsData_mergeAndSort");
00387 $ilBench->stop("News", "getAggregatedNewsData");
00388
00389 return $data;
00390 }
00391
00392 function aggregateForums($news, $a_group_posting_sequence = false)
00393 {
00394 $to_del = array();
00395 $forums = array();
00396
00397
00398 foreach ($news as $k => $v)
00399 {
00400 if ($a_group_posting_sequence && $last_aggregation_forum > 0 &&
00401 $last_aggregation_forum != $news[$k]["context_obj_id"])
00402 {
00403 $forums[$last_aggregation_forum] = "";
00404 }
00405
00406 if ($news[$k]["context_obj_type"] == "frm")
00407 {
00408 if ($forums[$news[$k]["context_obj_id"]] == "")
00409 {
00410
00411 $forums[$news[$k]["context_obj_id"]] = $k;
00412 $last_aggregation_forum = $news[$k]["context_obj_id"];
00413 }
00414 else
00415 {
00416 $to_del[] = $k;
00417 }
00418
00419 $news[$k]["no_context_title"] = true;
00420
00421
00422 $news[$forums[$news[$k]["context_obj_id"]]]["aggregation"][$k]
00423 = $news[$k];
00424 $news[$k]["agg_ref_id"]
00425 = $news[$k]["ref_id"];
00426 $news[$k]["content"] = "";
00427 $news[$k]["content_long"] = "";
00428 }
00429 }
00430
00431
00432 foreach($to_del as $k)
00433 {
00434 unset($news[$k]);
00435 }
00436
00437
00438
00439 return $news;
00440 }
00441
00442 function aggregateFiles($news, $a_ref_id)
00443 {
00444 $first_file = "";
00445 $to_del = array();
00446 foreach ($news as $k => $v)
00447 {
00448
00449 if ($news[$k]["context_obj_type"] == "file")
00450 {
00451 if ($first_file == "")
00452 {
00453 $first_file = $k;
00454 }
00455 else
00456 {
00457 $to_del[] = $k;
00458 }
00459 $news[$first_file]["aggregation"][$k] = $news[$k];
00460 $news[$first_file]["agg_ref_id"] = $a_ref_id;
00461 $news[$first_file]["ref_id"] = $a_ref_id;
00462 }
00463 }
00464
00465 foreach($to_del as $v)
00466 {
00467 unset($news[$v]);
00468 }
00469
00470 return $news;
00471 }
00472
00473
00477 function getAggregatedChildNewsData($a_ref_id, $a_only_public = false,
00478 $a_time_period = 0, $a_prevent_aggregation = false, $a_starting_date = "")
00479 {
00480 global $tree, $ilAccess, $ilBench;
00481
00482 $ilBench->start("News", "getAggregatedChildNewsData");
00483
00484
00485 $data = $this->getNewsForRefId($a_ref_id, $a_only_public, true, $a_time_period);
00486 foreach ($data as $k => $v)
00487 {
00488 $data[$k]["ref_id"] = $a_ref_id;
00489 }
00490
00491
00492 $nodes = $tree->getChilds($a_ref_id);
00493
00494
00495 $obj_ids = array();
00496 foreach($nodes as $node)
00497 {
00498 $obj_ids[] = $node["obj_id"];
00499 }
00500 $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $a_time_period);
00501
00502
00503
00504 $contexts = array();
00505 foreach($nodes as $node)
00506 {
00507
00508 if (!in_array($node["obj_id"], $news_obj_ids))
00509 {
00510 continue;
00511 }
00512
00513 if (!$a_only_public && !$ilAccess->checkAccess("read", "", $node["child"]))
00514 {
00515 continue;
00516 }
00517 $ref_id[$node["obj_id"]] = $node["child"];
00518 $contexts[] = array("obj_id" => $node["obj_id"],
00519 "obj_type" => $node["type"]);
00520 }
00521
00522 $news = $this->queryNewsForMultipleContexts($contexts, $a_only_public, $a_time_period,
00523 $a_starting_date);
00524 foreach ($news as $k => $v)
00525 {
00526 $news[$k]["ref_id"] = $ref_id[$v["context_obj_id"]];
00527 }
00528 $data = ilNewsItem::mergeNews($data, $news);
00529
00530
00531 $data = ilUtil::sortArray($data, "creation_date", "desc", false, true);
00532
00533 if (!$a_prevent_aggregation)
00534 {
00535 $data = $this->aggregateFiles($data, $a_ref_id);
00536 }
00537
00538 $ilBench->stop("News", "getAggregatedChildNewsData");
00539
00540 return $data;
00541 }
00542
00546 function setContext($a_obj_id, $a_obj_type, $a_sub_obj_id = 0, $a_sub_obj_type = "")
00547 {
00548 $this->setContextObjId($a_obj_id);
00549 $this->setContextObjType($a_obj_type);
00550 $this->setContextSubObjId($a_sub_obj_id);
00551 $this->setContextSubObjType($a_sub_obj_type);
00552 }
00553
00558 public function queryNewsForContext($a_for_rss_use = false, $a_time_period = 0,
00559 $a_starting_date = "")
00560 {
00561 global $ilDB, $ilUser;
00562
00563 $and = ($a_time_period > 0)
00564 ? " AND (TO_DAYS(now()) - TO_DAYS(creation_date)) <= ".((int)$a_time_period)
00565 : "";
00566
00567 if ($a_starting_date != "")
00568 {
00569 $and.= " AND creation_date > ".$ilDB->quote($a_starting_date)." ";
00570 }
00571
00572 if ($a_for_rss_use)
00573 {
00574 $query = "SELECT * ".
00575 "FROM il_news_item ".
00576 " WHERE ".
00577 "context_obj_id = ".$ilDB->quote($this->getContextObjId()).
00578 " AND context_obj_type = ".$ilDB->quote($this->getContextObjType()).
00579 $and.
00580 " ORDER BY creation_date DESC ";
00581 }
00582 else
00583 {
00584 $query = "SELECT il_news_item.* ".
00585 ", il_news_read.user_id as user_read ".
00586 "FROM il_news_item LEFT JOIN il_news_read ".
00587 "ON il_news_item.id = il_news_read.news_id AND ".
00588 " il_news_read.user_id = ".$ilDB->quote($ilUser->getId()).
00589 " WHERE ".
00590 "context_obj_id = ".$ilDB->quote($this->getContextObjId()).
00591 " AND context_obj_type = ".$ilDB->quote($this->getContextObjType()).
00592 $and.
00593 " ORDER BY creation_date DESC ";
00594 }
00595
00596 $set = $ilDB->query($query);
00597 $result = array();
00598 while($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00599 {
00600 if (!$a_for_rss_use || ($rec["visibility"] == NEWS_PUBLIC ||
00601 ($rec["priority"] == 0 &&
00602 ilBlockSetting::_lookup("news", "public_notifications",
00603 0, $rec["context_obj_id"]))))
00604 {
00605 $result[$rec["id"]] = $rec;
00606 }
00607 }
00608
00609 return $result;
00610
00611 }
00612
00618 public function queryNewsForMultipleContexts($a_contexts, $a_for_rss_use = false,
00619 $a_time_period = 0, $a_starting_date = "")
00620 {
00621 global $ilDB, $ilUser, $ilBench;
00622
00623 $ilBench->start("News", "queryNewsForMultipleContexts");
00624
00625 $and = ($a_time_period > 0)
00626 ? " AND (TO_DAYS(now()) - TO_DAYS(creation_date)) <= ".((int)$a_time_period)
00627 : "";
00628
00629 if ($a_starting_date != "")
00630 {
00631 $and.= " AND creation_date > ".$ilDB->quote($a_starting_date)." ";
00632 }
00633
00634 $ids = array();
00635 $type = array();
00636 foreach($a_contexts as $cont)
00637 {
00638 $ids[] = $cont["obj_id"];
00639 $type[$cont["obj_id"]] = $cont["obj_type"];
00640 }
00641
00642 if ($a_for_rss_use)
00643 {
00644 $query = "SELECT * ".
00645 "FROM il_news_item ".
00646 " WHERE ".
00647 "context_obj_id IN (".implode(",",ilUtil::quoteArray($ids)).") ".
00648 $and.
00649 " ORDER BY creation_date DESC ";
00650 }
00651 else
00652 {
00653 $query = "SELECT il_news_item.* ".
00654 ", il_news_read.user_id as user_read ".
00655 "FROM il_news_item LEFT JOIN il_news_read ".
00656 "ON il_news_item.id = il_news_read.news_id AND ".
00657 " il_news_read.user_id = ".$ilDB->quote($ilUser->getId()).
00658 " WHERE ".
00659 "context_obj_id IN (".implode(",",ilUtil::quoteArray($ids)).") ".
00660 $and.
00661 " ORDER BY creation_date DESC ";
00662 }
00663
00664 $set = $ilDB->query($query);
00665 $result = array();
00666 while($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00667 {
00668 if ($type[$rec["context_obj_id"]] == $rec["context_obj_type"])
00669 {
00670 if (!$a_for_rss_use || ($rec["visibility"] == NEWS_PUBLIC ||
00671 ($rec["priority"] == 0 &&
00672 ilBlockSetting::_lookup("news", "public_notifications",
00673 0, $rec["context_obj_id"]))))
00674 {
00675 $result[$rec["id"]] = $rec;
00676 }
00677 }
00678 }
00679
00680 $ilBench->stop("News", "queryNewsForMultipleContexts");
00681
00682 return $result;
00683
00684 }
00685
00686
00690 function _setRead($a_user_id, $a_news_id)
00691 {
00692 global $ilDB, $ilAppEventHandler;
00693
00694 $q = "REPLACE INTO il_news_read (user_id, news_id) VALUES (".
00695 $ilDB->quote($a_user_id).",".$ilDB->quote($a_news_id).")";
00696 $ilDB->query($q);
00697
00698 $ilAppEventHandler->raise("Services/News", "readNews",
00699 array("user_id" => $a_user_id, "news_ids" => array($a_news_id)));
00700 }
00701
00705 function _setUnread($a_user_id, $a_news_id)
00706 {
00707 global $ilDB, $ilAppEventHandler;
00708
00709 $q = "DELETE FROM il_news_read (user_id, news_id) VALUES (".
00710 " WHERE user_id = ".$ilDB->quote($a_user_id).
00711 " AND news_id = ".$ilDB->quote($a_news_id);
00712 $ilDB->query($q);
00713
00714 $ilAppEventHandler->raise("Services/News", "unreadNews",
00715 array("user_id" => $a_user_id, "news_ids" => array($a_news_id)));
00716 }
00717
00726 function mergeNews($n1, $n2)
00727 {
00728 foreach($n2 as $id => $news)
00729 {
00730 $n1[$id] = $news;
00731 }
00732
00733 return $n1;
00734 }
00735
00741 static function _getDefaultVisibilityForRefId($a_ref_id)
00742 {
00743 global $tree, $ilSetting;
00744
00745 include_once("./Services/Block/classes/class.ilBlockSetting.php");
00746
00747 $news_set = new ilSetting("news");
00748 $default_visibility = ($news_set->get("default_visibility") != "")
00749 ? $news_set->get("default_visibility")
00750 : "users";
00751
00752 if ($tree->isInTree($a_ref_id))
00753 {
00754 $path = $tree->getPathFull($a_ref_id);
00755
00756 foreach ($path as $key => $row)
00757 {
00758 if (!in_array($row["type"], array("root", "cat","crs", "fold", "grp", "icrs")))
00759 {
00760 continue;
00761 }
00762
00763 $visibility = ilBlockSetting::_lookup("news", "default_visibility",
00764 0, $row["obj_id"]);
00765
00766 if ($visibility != "")
00767 {
00768 $default_visibility = $visibility;
00769 }
00770 }
00771 }
00772
00773 return $default_visibility;
00774 }
00775
00776
00781 public function delete()
00782 {
00783 global $ilDB;
00784
00785
00786 $query = "DELETE FROM il_news_read ".
00787 " WHERE news_id = ".$ilDB->quote($this->getId());
00788 $ilDB->query($query);
00789
00790
00791 $mob = $this->getMobId();
00792
00793
00794 parent::delete();
00795
00796
00797 if ($mob > 0 and ilObject::_exists($mob))
00798 {
00799 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
00800 $mob = new ilObjMediaObject($mob);
00801 $mob->delete();
00802 }
00803 }
00804
00809 public function deleteNewsOfContext($a_context_obj_id,
00810 $a_context_obj_type)
00811 {
00812 global $ilDB;
00813
00814 if ($a_context_obj_id == 0 || $a_context_obj_type == "")
00815 {
00816 return;
00817 }
00818
00819
00820 $query = "SELECT * FROM il_news_item".
00821 " WHERE context_obj_id = ".$ilDB->quote($a_context_obj_id).
00822 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type);
00823
00824 $news_set = $ilDB->query($query);
00825
00826 while ($news = $news_set->fetchRow(DB_FETCHMODE_ASSOC))
00827 {
00828 $news_obj = new ilNewsItem($news["id"]);
00829 $news_obj->delete();
00830 }
00831 }
00832
00836 static function _lookupTitle($a_news_id)
00837 {
00838 global $ilDB;
00839
00840 $query = "SELECT title FROM il_news_item WHERE id = ".
00841 $ilDB->quote($a_news_id);
00842 $set = $ilDB->query($query);
00843 $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00844 return $rec["title"];
00845 }
00846
00850 static function _lookupVisibility($a_news_id)
00851 {
00852 global $ilDB;
00853
00854 $query = "SELECT visibility FROM il_news_item WHERE id = ".
00855 $ilDB->quote($a_news_id);
00856 $set = $ilDB->query($query);
00857 $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00858
00859 return $rec["visibility"];
00860 }
00861
00865 static function filterObjIdsPerNews($a_obj_ids, $a_time_period = 0)
00866 {
00867 global $ilDB;
00868
00869 $and = ($a_time_period > 0)
00870 ? " AND (TO_DAYS(now()) - TO_DAYS(creation_date)) <= ".((int)$a_time_period)
00871 : "";
00872
00873 $query = "SELECT DISTINCT(context_obj_id) AS obj_id FROM il_news_item".
00874 " WHERE context_obj_id IN (".implode(ilUtil::quoteArray($a_obj_ids),",").")".$and;
00875
00876 $set = $ilDB->query($query);
00877 $objs = array();
00878 while($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00879 {
00880 $objs[] = $rec["obj_id"];
00881 }
00882 return $objs;
00883 }
00884
00888 static function determineNewsTitle($a_context_obj_type, $a_title, $a_content_is_lang_var,
00889 $a_agg_ref_id = 0, $a_aggregation = "")
00890 {
00891 global $lng;
00892
00893 if ($a_agg_ref_id > 0)
00894 {
00895 $cnt = count($a_aggregation);
00896
00897
00898 if ($a_context_obj_type == "frm")
00899 {
00900 if ($cnt > 1)
00901 {
00902 return sprintf($lng->txt("news_x_postings"), $cnt);
00903 }
00904 else
00905 {
00906 return $lng->txt("news_1_postings");
00907 }
00908 }
00909 else
00910 {
00911 $up_cnt = $cr_cnt = 0;
00912 foreach($a_aggregation as $item)
00913 {
00914 if ($item["title"] == "file_updated")
00915 {
00916 $up_cnt++;
00917 }
00918 else
00919 {
00920 $cr_cnt++;
00921 }
00922 }
00923 $sep = "";
00924 if ($cr_cnt == 1)
00925 {
00926 $tit = $lng->txt("news_1_file_created");
00927 $sep = "<br />";
00928 }
00929 else if ($cr_cnt > 1)
00930 {
00931 $tit = sprintf($lng->txt("news_x_files_created"), $cr_cnt);
00932 $sep = "<br />";
00933 }
00934 if ($up_cnt == 1)
00935 {
00936 $tit .= $sep.$lng->txt("news_1_file_updated");
00937 }
00938 else if ($up_cnt > 1)
00939 {
00940 $tit .= $sep.sprintf($lng->txt("news_x_files_updated"), $up_cnt);
00941 }
00942 return $tit;
00943 }
00944 }
00945 else
00946 {
00947 if ($a_content_is_lang_var)
00948 {
00949 return $lng->txt($a_title);
00950 }
00951 else
00952 {
00953 return $a_title;
00954 }
00955 }
00956
00957 return "";
00958 }
00959
00960
00964 static function getFirstNewsIdForContext($a_context_obj_id,
00965 $a_context_obj_type, $a_context_sub_obj_id = "", $a_context_sub_obj_type = "")
00966 {
00967 global $ilDB;
00968
00969
00970 $query = "SELECT * ".
00971 "FROM il_news_item ".
00972 "WHERE ".
00973 "context_obj_id = ".$ilDB->quote($a_context_obj_id).
00974 " AND context_obj_type = ".$ilDB->quote($a_context_obj_type).
00975 " AND context_sub_obj_id = ".$ilDB->quote($a_context_sub_obj_id).
00976 " AND context_sub_obj_type = ".$ilDB->quote($a_context_sub_obj_type);
00977
00978 $set = $ilDB->query($query);
00979 $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00980
00981 return $rec["id"];
00982 }
00983
00987 static function _lookupMediaObjectUsages($a_mob_id)
00988 {
00989 global $ilDB;
00990
00991 $query = "SELECT * ".
00992 "FROM il_news_item ".
00993 "WHERE ".
00994 " mob_id = ".$ilDB->quote($a_mob_id);
00995
00996 $usages = array();
00997 $set = $ilDB->query($query);
00998 while ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00999 {
01000 $usages[$rec["id"]] = array("type" => "news", "id" => $rec["id"]);
01001 }
01002
01003 return $usages;
01004 }
01005
01009 static function _lookupContextObjId($a_news_id)
01010 {
01011 global $ilDB;
01012
01013 $query = "SELECT * ".
01014 "FROM il_news_item ".
01015 "WHERE ".
01016 " id = ".$ilDB->quote($a_news_id);
01017 $set = $ilDB->query($query);
01018 $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
01019
01020 return $rec["context_obj_id"];
01021 }
01022
01023 function _lookupDefaultPDPeriod()
01024 {
01025 $news_set = new ilSetting("news");
01026 $per = $news_set->get("pd_period");
01027 if ($per == 0)
01028 {
01029 $per = 30;
01030 }
01031
01032 return $per;
01033 }
01034
01035 function _lookupUserPDPeriod($a_user_id)
01036 {
01037 global $ilSetting;
01038
01039 $news_set = new ilSetting("news");
01040 $allow_shorter_periods = $news_set->get("allow_shorter_periods");
01041 $allow_longer_periods = $news_set->get("allow_longer_periods");
01042 $default_per = ilNewsItem::_lookupDefaultPDPeriod();
01043
01044 include_once("./Services/Block/classes/class.ilBlockSetting.php");
01045 $per = ilBlockSetting::_lookup("pdnews", "news_pd_period",
01046 $a_user_id, 0);
01047
01048
01049 if ($per <= 0 ||
01050 (!$allow_shorter_periods && ($per < $default_per)) ||
01051 (!$allow_longer_periods && ($per > $default_per))
01052 )
01053 {
01054 $per = $default_per;
01055 }
01056
01057 return $per;
01058 }
01059
01060 function _lookupRSSPeriod()
01061 {
01062 $news_set = new ilSetting("news");
01063 $rss_period = $news_set->get("rss_period");
01064 if ($rss_period == 0)
01065 {
01066 $rss_period = 14;
01067 }
01068 return $rss_period;
01069 }
01070 }
01071 ?>