/** * Query News for multiple Contexts * * @param array $a_contexts array of array("obj_id", "obj_type") */ public function queryNewsForMultipleContexts($a_contexts, $a_for_rss_use = false, $a_time_period = 0, $a_starting_date = "", $a_no_auto_generated = false, $a_user_id = null) { global $ilDB, $ilUser, $lng, $ilCtrl; $and = ""; if ($a_time_period > 0) { $limit_ts = date('Y-m-d H:i:s', time() - $a_time_period * 24 * 60 * 60); $and = " AND creation_date >= " . $ilDB->quote($limit_ts, "timestamp") . " "; } if ($a_starting_date != "") { $and .= " AND creation_date > " . $ilDB->quote($a_starting_date, "timestamp") . " "; } if ($a_no_auto_generated) { $and .= " AND priority = 1 AND content_type = " . $ilDB->quote("text", "text") . " "; } $ids = array(); $type = array(); foreach ($a_contexts as $cont) { $ids[] = $cont["obj_id"]; $type[$cont["obj_id"]] = $cont["obj_type"]; } if ($a_for_rss_use && ilNewsItem::getPrivateFeedId() == false) { $query = "SELECT * " . "FROM il_news_item " . " WHERE " . $ilDB->in("context_obj_id", $ids, false, "integer") . " " . $and . " ORDER BY creation_date DESC "; } elseif (ilNewsItem::getPrivateFeedId() != false) { $query = "SELECT il_news_item.* " . ", il_news_read.user_id as user_read " . "FROM il_news_item LEFT JOIN il_news_read " . "ON il_news_item.id = il_news_read.news_id AND " . " il_news_read.user_id = " . $ilDB->quote(ilNewsItem::getPrivateFeedId(), "integer") . " WHERE " . $ilDB->in("context_obj_id", $ids, false, "integer") . " " . $and . " ORDER BY creation_date DESC "; } else { if ($a_user_id) { $user_id = $a_user_id; } else { $user_id = $ilUser->getId(); } $query = "SELECT il_news_item.* " . ", il_news_read.user_id as user_read " . "FROM il_news_item LEFT JOIN il_news_read " . "ON il_news_item.id = il_news_read.news_id AND " . " il_news_read.user_id = " . $ilDB->quote($user_id, "integer") . " WHERE " . $ilDB->in("context_obj_id", $ids, false, "integer") . " " . $and . " ORDER BY creation_date DESC "; } $set = $ilDB->query($query); $result = array(); while ($rec = $ilDB->fetchAssoc($set)) { if ($type[$rec["context_obj_id"]] == $rec["context_obj_type"]) { if (!$a_for_rss_use || ilNewsItem::getPrivateFeedId() != false || ($rec["visibility"] == NEWS_PUBLIC || $rec["priority"] == 0 && ilBlockSetting::_lookup("news", "public_notifications", 0, $rec["context_obj_id"]))) { $result[$rec["id"]] = $rec; } } } return $result; }