/**
  * 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;
 }
 /**
  * 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();
 }
示例#3
0
    /**
     * Moves all posts within the current thread to a new forum
     * 
     * @param    integer 	$old_obj_id object id of the current forum
     * @param    integer 	$old_pk		primary key of old forum
     * @param    integer 	$new_obj_id	object id of the new forum
     * @param    integer 	$new_pk		primary key of new forum
     * @return	integer 	number of afffected rows by updating posts
     * @access	public
     */
    public function movePosts($old_obj_id, $old_pk, $new_obj_id, $new_pk)
    {
        global $ilDB;
        if ($this->id) {
            $nodes = $this->getAllPosts();
            if (is_array($nodes)) {
                // Move attachments
                foreach ($nodes as $node) {
                    $file_obj = new ilFileDataForum((int) $old_obj_id, (int) $node->pos_pk);
                    $file_obj->moveFilesOfPost((int) $new_obj_id);
                    unset($file_obj);
                }
            }
            $this->db->lockTables(array(0 => array('name' => 'frm_user_read', 'type' => ilDB::LOCK_WRITE), 1 => array('name' => 'frm_thread_access', 'type' => ilDB::LOCK_WRITE)));
            $this->db->manipulateF('
				DELETE FROM frm_user_read
				WHERE obj_id = %s AND thread_id =%s', array('integer', 'integer'), array($new_obj_id, $this->id));
            $this->db->manipulateF('
				UPDATE frm_user_read
				SET obj_id = %s
				WHERE thread_id = %s', array('integer', 'integer'), array($new_obj_id, $this->id));
            $this->db->manipulateF('
				DELETE FROM frm_thread_access
				WHERE obj_id = %s AND thread_id =%s', array('integer', 'integer'), array($new_obj_id, $this->id));
            $this->db->manipulateF('
				UPDATE frm_thread_access
				SET obj_id = %s
				WHERE thread_id =%s', array('integer', 'integer'), array($new_obj_id, $this->id));
            $this->db->unlockTables();
            $this->db->manipulateF('
				UPDATE frm_posts
				SET pos_top_fk = %s
				WHERE pos_thr_fk = %s', array('integer', 'integer'), array($new_pk, $this->id));
            // update all related news
            $posts = $ilDB->queryf('
				SELECT * FROM frm_posts WHERE pos_thr_fk = %s', array('integer'), array($this->id));
            $old_obj_id = ilForum::_lookupObjIdForForumId($old_pk);
            $new_obj_id = ilForum::_lookupObjIdForForumId($new_pk);
            while ($post = $posts->fetchRow(DB_FETCHMODE_ASSOC)) {
                include_once "./Services/News/classes/class.ilNewsItem.php";
                $news_id = ilNewsItem::getFirstNewsIdForContext($old_obj_id, "frm", $post["pos_pk"], "pos");
                $news_item = new ilNewsItem($news_id);
                $news_item->setContextObjId($new_obj_id);
                $news_item->update();
                //echo "<br>-".$post["pos_pk"]."-".$old_obj_id."-".$new_obj_id."-";
            }
            return count($nodes);
        }
        return 0;
    }
 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());
 }
示例#5
0
 /**
  * Get News For Ref Id.
  *
  * $a_user_id does only work for groups and courses so far
  */
 function 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)
 {
     $obj_id = ilObject::_lookupObjId($a_ref_id);
     $obj_type = ilObject::_lookupType($obj_id);
     // get starting date
     $starting_date = "";
     if ($obj_type == "grp" || $obj_type == "crs" || $obj_type == "cat") {
         include_once "./Services/Block/classes/class.ilBlockSetting.php";
         $hide_news_per_date = ilBlockSetting::_lookup("news", "hide_news_per_date", 0, $obj_id);
         if ($hide_news_per_date && !$a_ignore_date_filter) {
             $starting_date = ilBlockSetting::_lookup("news", "hide_news_date", 0, $obj_id);
         }
     }
     if ($obj_type == "cat" && !$a_stopnesting) {
         $news = $this->getAggregatedChildNewsData($a_ref_id, $a_only_public, $a_time_period, $a_prevent_aggregation, $starting_date, $a_no_auto_generated);
     } else {
         if (($obj_type == "grp" || $obj_type == "crs") && !$a_stopnesting) {
             $news = $this->getAggregatedNewsData($a_ref_id, $a_only_public, $a_time_period, $a_prevent_aggregation, $starting_date, $a_no_auto_generated, $a_user_id);
         } else {
             $news_item = new ilNewsItem();
             $news_item->setContextObjId($obj_id);
             $news_item->setContextObjType($obj_type);
             $news = $news_item->queryNewsForContext($a_only_public, $a_time_period, $starting_date, $a_no_auto_generated);
             $unset = array();
             foreach ($news as $k => $v) {
                 if (!$a_only_public || $v["visibility"] == NEWS_PUBLIC || $v["priority"] == 0 && ilBlockSetting::_lookup("news", "public_notifications", 0, $obj_id)) {
                     $news[$k]["ref_id"] = $a_ref_id;
                 } else {
                     $unset[] = $k;
                 }
             }
             foreach ($unset as $un) {
                 unset($news[$un]);
             }
         }
     }
     if (!$a_prevent_aggregation) {
         $news = $this->aggregateForums($news);
     } else {
         if ($a_forum_group_sequences) {
             $news = $this->aggregateForums($news, true);
         }
     }
     return $news;
 }
 /**
  * Save new cast item
  */
 function saveCastItemObject()
 {
     global $tpl, $ilCtrl, $ilUser, $lng, $ilTabs;
     $this->checkPermission("write");
     $ilTabs->activateTab("edit_content");
     $this->initAddCastItemForm();
     if ($_POST["url_Standard"] == "" && !$_FILES['file_Standard']['tmp_name']) {
         ilUtil::sendFailure($lng->txt("msg_input_either_file_or_url"));
         $this->populateFormFromPost();
     } else {
         if ($this->form_gui->checkInput()) {
             // create dummy object in db (we need an id)
             include_once "./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php";
             $mob = new ilObjMediaObject();
             $mob->create();
             //handle standard purpose
             $file = $this->createMediaItemForPurpose($mob, "Standard");
             // set title and description
             // set title to basename of file if left empty
             $title = $this->form_gui->getInput("title") != "" ? $this->form_gui->getInput("title") : basename($file);
             $description = $this->form_gui->getInput("description");
             $mob->setTitle($title);
             $mob->setDescription($description);
             // save preview pic
             $prevpic = $this->form_gui->getInput("preview_pic");
             if ($prevpic["size"] > 0) {
                 $mob->uploadVideoPreviewPic($prevpic);
             }
             // determine duration for standard purpose
             $duration = $this->getDuration($file);
             // handle other purposes
             foreach ($this->additionalPurposes as $purpose) {
                 // check if some purpose has been uploaded
                 $file_gui = $this->form_gui->getInput("file_" . $purpose);
                 $url_gui = $this->form_gui->getInput("url_" . $purpose);
                 if ($url_gui || $file_gui["size"] > 0) {
                     $this->createMediaItemForPurpose($mob, $purpose);
                 }
             }
             $mob->update();
             if ($prevpic["size"] == 0) {
                 // re-read media object
                 $mob = new ilObjMediaObject($mob->getId());
                 $mob->generatePreviewPic(320, 240);
             }
             //
             // @todo: save usage
             //
             $news_set = new ilSetting("news");
             $enable_internal_rss = $news_set->get("enable_rss_for_internal");
             // create new media cast item
             include_once "./Services/News/classes/class.ilNewsItem.php";
             $mc_item = new ilNewsItem();
             $mc_item->setMobId($mob->getId());
             $mc_item->setContentType(NEWS_AUDIO);
             $mc_item->setContextObjId($this->object->getId());
             $mc_item->setContextObjType($this->object->getType());
             $mc_item->setUserId($ilUser->getId());
             $mc_item->setPlaytime($duration);
             $mc_item->setTitle($title);
             $mc_item->setContent($description);
             $mc_item->setLimitation(false);
             if ($enable_internal_rss) {
                 $mc_item->setVisibility($this->form_gui->getInput("visibility"));
             } else {
                 $mc_item->setVisibility("users");
             }
             $mc_item->create();
             $ilCtrl->redirect($this, "listItems");
         } else {
             $this->populateFormFromPost();
         }
     }
 }
 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 . "&amp;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 . "&amp;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 . "&amp;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 . "&amp;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 . "&amp;target=" . $item["context_obj_type"] . "_" . $item["ref_id"]);
                     }
                 } else {
                     $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID . "&amp;target=" . $item["context_obj_type"] . "_" . $item["ref_id"]);
                     //echo "<br>".ILIAS_HTTP_PATH."/goto.php?client_id=".CLIENT_ID.
                     //					"&amp;target=".$item["context_obj_type"]."_".$item["ref_id"];
                 }
             }
         }
         $feed_item->setAbout($feed_item->getLink() . "&amp;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);
     }
 }
示例#8
0
 /**
  * Import record
  *
  * @param
  * @return
  */
 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
 {
     //echo $a_entity;
     //var_dump($a_rec);
     switch ($a_entity) {
         case "news":
             $mob_id = null;
             if ($a_rec["MobId"] > 0) {
                 $mob_id = $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["MobId"]);
             }
             $c = (int) $a_rec["ContextObjId"] . ":" . $a_rec["ContextObjType"] . ":" . (int) $a_rec["ContextSubObjId"] . ":" . $a_rec["ContextSubObjType"];
             $context = $a_mapping->getMapping("Services/News", "news_context", $c);
             $context = explode(":", $context);
             //var_dump($c);
             //var_dump($a_mapping->mappings["Services/News"]["news_context"]);
             include_once "./Services/News/classes/class.ilNewsItem.php";
             $newObj = new ilNewsItem();
             $newObj->setTitle($a_rec["Title"]);
             $newObj->setContent($a_rec["Content"]);
             $newObj->setPriority($a_rec["Priority"]);
             $newObj->setContextObjId($context[0]);
             $newObj->setContextObjType($context[1]);
             $newObj->setContextSubObjId($context[2]);
             $newObj->setContextSubObjType($context[3]);
             $newObj->setContentType($a_rec["ContentType"]);
             $newObj->setVisibility($a_rec["Visibility"]);
             $newObj->setContentLong($a_rec["ContentLong"]);
             $newObj->setContentIsLangVar($a_rec["ContentIsLangVar"]);
             $newObj->setMobId($mob_id);
             $newObj->setPlaytime($a_rec["Playtime"]);
             $newObj->create();
             $a_mapping->addMapping("Services/News", "news", $a_rec["Id"], $newObj->getId());
             break;
     }
 }
示例#9
0
 /**
  * Copy items
  *
  * @param
  * @return
  */
 function copyItems($a_new_obj)
 {
     global $ilUser;
     include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
     foreach ($this->readItems(true) as $item) {
         // copy media object
         $mob_id = $item["mob_id"];
         $mob = new ilObjMediaObject($mob_id);
         $new_mob = $mob->duplicate();
         // copy news item
         // create new media cast item
         include_once "./Services/News/classes/class.ilNewsItem.php";
         $mc_item = new ilNewsItem();
         $mc_item->setMobId($new_mob->getId());
         $mc_item->setContentType(NEWS_AUDIO);
         $mc_item->setContextObjId($a_new_obj->getId());
         $mc_item->setContextObjType($a_new_obj->getType());
         $mc_item->setUserId($ilUser->getId());
         $mc_item->setPlaytime($item["playtime"]);
         $mc_item->setTitle($item["title"]);
         $mc_item->setContent($item["content"]);
         $mc_item->setVisibility($item["visibility"]);
         $mc_item->create();
     }
 }