public function run() { global $lng, $ilDB; $status = ilCronJobResult::STATUS_NO_ACTION; $status_details = null; $setting = new ilSetting("cron"); $last_run = $setting->get(get_class($this)); // #10284 - we already did send today, do nothing if ($last_run == date("Y-m-d")) { // #14005 $status_details = "Did already run today."; } else { // gather objects and participants with notification setting $objects = array(); $set = $ilDB->query("SELECT usr_id,keyword FROM usr_pref" . " WHERE " . $ilDB->like("keyword", "text", "grpcrs_ntf_%") . " AND value = " . $ilDB->quote("1", "text")); while ($row = $ilDB->fetchAssoc($set)) { $ref_id = substr($row["keyword"], 11); $type = ilObject::_lookupType($ref_id, true); if ($type) { $objects[$type][$ref_id][] = $row["usr_id"]; } } $counter = 0; if (sizeof($objects)) { $old_lng = $lng; include_once "Services/News/classes/class.ilNewsItem.php"; foreach ($objects as $type => $ref_ids) { // type is not needed for now foreach ($ref_ids as $ref_id => $user_ids) { // gather news per object $news_item = new ilNewsItem(); if ($news_item->checkNewsExistsForGroupCourse($ref_id)) { foreach ($user_ids as $user_id) { // gather news for user $user_news = $news_item->getNewsForRefId($ref_id, false, false, 1, false, false, false, false, $user_id); if ($user_news) { $this->sendMail($user_id, $ref_id, $user_news); $counter++; } } } } } $lng = $old_lng; } // save last run $setting->set(get_class($this), date("Y-m-d")); if ($counter) { $status = ilCronJobResult::STATUS_OK; } } $result = new ilCronJobResult(); $result->setStatus($status); if ($status_details) { $result->setMessage($status_details); } return $result; }
public function sendNotifications() { global $ilDB, $lng; $setting = new ilSetting("cron"); $last_run = $setting->get(get_class($this)); // #10284 - we already did send today, do nothing if ($last_run == date("Y-m-d")) { return; } // gather objects and participants with notification setting $objects = array(); $set = $ilDB->query("SELECT usr_id,keyword FROM usr_pref" . " WHERE " . $ilDB->like("keyword", "text", "grpcrs_ntf_%") . " AND value = " . $ilDB->quote("1", "text")); while ($row = $ilDB->fetchAssoc($set)) { $ref_id = substr($row["keyword"], 11); $type = ilObject::_lookupType($ref_id, true); if ($type) { $objects[$type][$ref_id][] = $row["usr_id"]; } } if (sizeof($objects)) { $old_lng = $lng; include_once "Services/News/classes/class.ilNewsItem.php"; foreach ($objects as $type => $ref_ids) { // type is not needed for now foreach ($ref_ids as $ref_id => $user_ids) { // gather news per object $news_item = new ilNewsItem(); if ($news_item->checkNewsExistsForGroupCourse($ref_id)) { foreach ($user_ids as $user_id) { // gather news for user $user_news = $news_item->getNewsForRefId($ref_id, false, false, 1, false, false, false, false, $user_id); if ($user_news) { $this->sendMail($user_id, $ref_id, $user_news); } } } } } $lng = $old_lng; } // save last run $setting->set(get_class($this), date("Y-m-d")); return true; }
/** * TABLE NewsForContext: Get table HTML. * */ public function getNewsForContextTable() { global $lng; $news_item = new ilNewsItem(); $news_item->setContextObjId($this->getContextObjId()); $news_item->setContextObjType($this->getContextObjType()); $news_item->setContextSubObjId($this->getContextSubObjId()); $news_item->setContextSubObjType($this->getContextSubObjType()); $perm_ref_id = 0; if (in_array($this->getContextObjType(), array("cat", "grp", "crs", "root"))) { $data = $news_item->getNewsForRefId($_GET["ref_id"], false, false, 0, true, false, true, true); } else { $perm_ref_id = $_GET["ref_id"]; if ($this->getContextSubObjId() > 0) { $data = $news_item->queryNewsForContext(false, 0, "", true, true); } else { $data = $news_item->queryNewsForContext(); } } include_once "Services/News/classes/class.ilNewsForContextTableGUI.php"; $table_gui = new ilNewsForContextTableGUI($this, "getNewsForContextTable", $perm_ref_id); $table_gui->setTitle($lng->txt("news_table_news_for_context")); $table_gui->setRowTemplate("tpl.table_row_news_for_context.html", "Services/News"); $table_gui->setData($data); $table_gui->setDefaultOrderField("creation_date"); $table_gui->setDefaultOrderDirection("desc"); $table_gui->addMultiCommand("confirmDeletionNewsItems", $lng->txt("delete")); $table_gui->setTitle($lng->txt("news"), "icon_news.png", $lng->txt("news")); $table_gui->setSelectAllCheckbox("news_id"); return $table_gui->getHTML(); }
function view() { global $ilUser, $lng, $tpl, $ilCtrl; $ref_ids = array(); $obj_ids = array(); $pd_items = $ilUser->getDesktopItems(); foreach ($pd_items as $item) { $ref_ids[] = $item["ref_id"]; $obj_ids[] = $item["obj_id"]; } $sel_ref_id = $_GET["news_ref_id"] > 0 ? $_GET["news_ref_id"] : $ilUser->getPref("news_sel_ref_id"); include_once "./Services/News/classes/class.ilNewsItem.php"; $per = $_SESSION["news_pd_news_per"] != "" ? $_SESSION["news_pd_news_per"] : ilNewsItem::_lookupUserPDPeriod($ilUser->getId()); $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $per); // related objects (contexts) of news $contexts[0] = $lng->txt("news_all_items"); $conts = array(); $sel_has_news = false; foreach ($ref_ids as $ref_id) { $obj_id = ilObject::_lookupObjId($ref_id); $title = ilObject::_lookupTitle($obj_id); $conts[$ref_id] = $title; if ($sel_ref_id == $ref_id) { $sel_has_news = true; } } $cnt = array(); $nitem = new ilNewsItem(); $news_items = $nitem->_getNewsItemsOfUser($ilUser->getId(), false, true, $per, $cnt); // reset selected news ref id, if no news are given for id if (!$sel_has_news) { $sel_ref_id = ""; } asort($conts); foreach ($conts as $ref_id => $title) { $contexts[$ref_id] = $title . " (" . (int) $cnt[$ref_id] . ")"; } if ($sel_ref_id > 0) { $obj_id = ilObject::_lookupObjId($sel_ref_id); $obj_type = ilObject::_lookupType($obj_id); $nitem->setContextObjId($obj_id); $nitem->setContextObjType($obj_type); $news_items = $nitem->getNewsForRefId($sel_ref_id, false, false, $per, true); } include_once "./Services/News/classes/class.ilPDNewsTableGUI.php"; $pd_news_table = new ilPDNewsTableGUI($this, "view", $contexts, $sel_ref_id); $pd_news_table->setData($news_items); $pd_news_table->setNoEntriesText($lng->txt("news_no_news_items")); $tpl->setContent($pd_news_table->getHTML()); }
/** * Get news for context */ function getNewsData() { global $ilCtrl, $ilUser; include_once "./Services/News/classes/class.ilNewsCache.php"; $this->acache = new ilNewsCache(); /* $cres = $this->acache->getEntry($ilUser->getId().":".$_GET["ref_id"]); if ($this->acache->getLastAccessStatus() == "hit" && false) { $news_data = unserialize($cres); } else {*/ $news_item = new ilNewsItem(); $news_item->setContextObjId($ilCtrl->getContextObjId()); $news_item->setContextObjType($ilCtrl->getContextObjType()); // workaround, better: reduce constructor and introduce //$prevent_aggregation = $this->getProperty("prevent_aggregation"); $prevent_aggregation = true; if ($ilCtrl->getContextObjType() != "frm") { $forum_grouping = true; } else { $forum_grouping = false; } $news_data = $news_item->getNewsForRefId($_GET["ref_id"], false, false, 0, $prevent_aggregation, $forum_grouping); $this->acache->storeEntry($ilUser->getId() . ":" . $_GET["ref_id"], serialize($news_data)); // } //var_dump($news_data); return $news_data; }
/** * Get all news items for a user. */ static function _getNewsItemsOfUser($a_user_id, $a_only_public = false, $a_prevent_aggregation = false, $a_per = 0, &$a_cnt = NULL) { global $ilAccess; $news_item = new ilNewsItem(); $news_set = new ilSetting("news"); $per = $a_per; include_once "./Services/News/classes/class.ilNewsSubscription.php"; include_once "./Services/Block/classes/class.ilBlockSetting.php"; // this is currently not used $ref_ids = ilNewsSubscription::_getSubscriptionsOfUser($a_user_id); if (ilObjUser::_lookupPref($a_user_id, "pd_items_news") != "n") { // get all items of the personal desktop $pd_items = ilObjUser::_lookupDesktopItems($a_user_id); foreach ($pd_items as $item) { if (!in_array($item["ref_id"], $ref_ids)) { $ref_ids[] = $item["ref_id"]; } } // get all memberships include_once 'Services/Membership/classes/class.ilParticipants.php'; $crs_mbs = ilParticipants::_getMembershipByType($a_user_id, 'crs'); $grp_mbs = ilParticipants::_getMembershipByType($a_user_id, 'grp'); $items = array_merge($crs_mbs, $grp_mbs); foreach ($items as $i) { $item_references = ilObject::_getAllReferences($i); if (is_array($item_references) && count($item_references)) { foreach ($item_references as $ref_id) { if (!in_array($ref_id, $ref_ids)) { $ref_ids[] = $ref_id; } } } } } $data = array(); foreach ($ref_ids as $ref_id) { if (!$a_only_public) { // this loop should not cost too much performance $acc = $ilAccess->checkAccessOfUser($a_user_id, "read", "", $ref_id); if (!$acc) { continue; } } if (ilNewsItem::getPrivateFeedId() != false) { global $rbacsystem; $acc = $rbacsystem->checkAccessOfUser(ilNewsItem::getPrivateFeedId(), "read", $ref_id); if (!$acc) { continue; } } $obj_id = ilObject::_lookupObjId($ref_id); $obj_type = ilObject::_lookupType($obj_id); $news = $news_item->getNewsForRefId($ref_id, $a_only_public, false, $per, $a_prevent_aggregation, false, false, false, $a_user_id); // counter if (!is_null($a_cnt)) { $a_cnt[$ref_id] = count($news); } $data = ilNewsItem::mergeNews($data, $news); } $data = ilUtil::sortArray($data, "creation_date", "desc", false, true); return $data; }
function ilObjectFeedWriter($a_ref_id, $a_userid = false, $a_purpose = false) { global $ilSetting, $lng; parent::ilFeedWriter(); if ($a_ref_id <= 0) { return; } include_once "./Services/Block/classes/class.ilBlockSetting.php"; $news_set = new ilSetting("news"); if (!$news_set->get("enable_rss_for_internal")) { return; } $obj_id = ilObject::_lookupObjId($a_ref_id); $obj_type = ilObject::_lookupType($obj_id); $obj_title = ilObject::_lookupTitle($obj_id); if (!ilBlockSetting::_lookup("news", "public_feed", 0, $obj_id)) { return; } if ($ilSetting->get('short_inst_name') != "") { $this->setChannelTitle($ilSetting->get('short_inst_name') . " - " . $this->prepareStr($loc . $obj_title)); } else { $this->setChannelTitle("ILIAS" . " - " . $this->prepareStr($loc . $obj_title . ($a_purpose ? " - " . $a_purpose : ""))); } $this->setChannelAbout(ILIAS_HTTP_PATH); $this->setChannelLink(ILIAS_HTTP_PATH); // not nice, to do: general solution if ($obj_type == "mcst") { include_once "./Modules/MediaCast/classes/class.ilObjMediaCastAccess.php"; if (!ilObjMediaCastAccess::_lookupOnline($obj_id)) { $lng->loadLanguageModule("mcst"); $feed_item = new ilFeedItem(); $feed_item->setTitle($lng->txt("mcst_media_cast_not_online")); $feed_item->setDescription($lng->txt("mcst_media_cast_not_online_text")); $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID . "&target=" . $item["context_obj_type"]); $this->addItem($feed_item); return; } } include_once "./Services/Locator/classes/class.ilLocatorGUI.php"; $cont_loc = new ilLocatorGUI(); $cont_loc->addContextItems($a_ref_id, true); $cont_loc->setTextOnly(true); $loc = $cont_loc->getTextVersion(); if (trim($loc) != "") { $loc = " [" . $loc . "] "; } $rss_period = ilNewsItem::_lookupRSSPeriod(); ilNewsItem::setPrivateFeedId($a_userid); $news_item = new ilNewsItem(); $news_item->setContextObjId($obj_id); $news_item->setContextObjType($obj_type); $items = $news_item->getNewsForRefId($a_ref_id, true, false, $rss_period, true); if ($a_purpose) { include_once "./Services/MediaObjects/classes/class.ilMediaItem.php"; } $i = 0; foreach ($items as $item) { $i++; if ($a_purpose != false && $obj_type == "mcst") { $mob = ilMediaItem::_getMediaItemsOfMObId($item[mob_id], $a_purpose); if ($mob == false) { continue; } } $obj_title = ilObject::_lookupTitle($item["context_obj_id"]); $feed_item = new ilFeedItem(); $title = ilNewsItem::determineNewsTitle($item["context_obj_type"], $item["title"], $item["content_is_lang_var"], $item["agg_ref_id"], $item["aggregation"]); // path $cont_loc = new ilLocatorGUI(); $cont_loc->addContextItems($item["ref_id"], true, $a_ref_id); $cont_loc->setTextOnly(true); $loc = $cont_loc->getHTML(); if (trim($loc) != "") { $loc = "[" . $loc . "]"; } if ($news_set->get("rss_title_format") == "news_obj") { $sep = trim($this->prepareStr($loc)) == "" ? "" : " "; $feed_item->setTitle($this->prepareStr($title) . " (" . $this->prepareStr($loc) . $sep . $this->prepareStr($obj_title) . ")"); } else { $feed_item->setTitle($this->prepareStr($loc) . " " . $this->prepareStr($obj_title) . ": " . $this->prepareStr($title)); } $feed_item->setDescription($this->prepareStr(nl2br(ilNewsItem::determineNewsContent($item["context_obj_type"], $item["content"], $item["content_text_is_lang_var"])))); // lm hack, not nice if (in_array($item["context_obj_type"], array("dbk", "lm")) && $item["context_sub_obj_type"] == "pg" && $item["context_sub_obj_id"] > 0) { $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID . "&target=pg_" . $item["context_sub_obj_id"] . "_" . $item["ref_id"]); } else { if ($item["context_obj_type"] == "wiki" && $item["context_sub_obj_type"] == "wpg" && $item["context_sub_obj_id"] > 0) { include_once "./Modules/Wiki/classes/class.ilWikiPage.php"; $wptitle = ilWikiPage::lookupTitle($item["context_sub_obj_id"]); $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID . "&target=" . $item["context_obj_type"] . "_" . $item["ref_id"] . "_" . $wptitle); } else { if (in_array($item["context_obj_type"], array("frm")) && $item["context_sub_obj_type"] == "pos" && $item["context_sub_obj_id"] > 0) { // frm hack, not nice include_once "./Modules/Forum/classes/class.ilObjForumAccess.php"; $thread_id = ilObjForumAccess::_getThreadForPosting($item["context_sub_obj_id"]); if ($thread_id > 0) { $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID . "&target=" . $item["context_obj_type"] . "_" . $item["ref_id"] . "_" . $thread_id . "_" . $item["context_sub_obj_id"]); } else { $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID . "&target=" . $item["context_obj_type"] . "_" . $item["ref_id"]); } } else { $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID . "&target=" . $item["context_obj_type"] . "_" . $item["ref_id"]); //echo "<br>".ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID. // "&target=".$item["context_obj_type"]."_".$item["ref_id"]; } } } $feed_item->setAbout($feed_item->getLink() . "&il_about_feed=" . $item["id"]); $feed_item->setDate($item["creation_date"]); // Enclosure if ($item["content_type"] == NEWS_AUDIO && $item["mob_id"] > 0 && ilObject::_exists($item["mob_id"])) { $go_on = true; if ($obj_type == "mcst") { include_once "./Modules/MediaCast/classes/class.ilObjMediaCastAccess.php"; if (!ilObjMediaCastAccess::_lookupPublicFiles($obj_id)) { $go_on = false; } } if ($go_on) { include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; $url = ilObjMediaObject::_lookupItemPath($item["mob_id"], true, true, $mob["purpose"]); $file = ilObjMediaObject::_lookupItemPath($item["mob_id"], false, false, $mob["purpose"]); if (is_file($file)) { $size = filesize($file); } $feed_item->setEnclosureUrl($url); $feed_item->setEnclosureType(isset($mob["format"]) ? $mob["format"] : "audio/mpeg"); $feed_item->setEnclosureLength($size); } } $this->addItem($feed_item); } }