Beispiel #1
0
 public function markPostReadObject()
 {
     /**
      * @var $ilUser ilObjUser
      */
     global $ilUser;
     $this->object->markPostRead($ilUser->getId(), (int) $this->objCurrentTopic->getId(), (int) $this->objCurrentPost->getId());
     $this->viewThreadObject();
 }
    /**
     * Fetches and returns an array of posts from the post tree, starting with the node object passed by
     * the first paramter.
     * 
     * @param    ilForumPost	$a_post_node	node-object of a post
     * @return	array		array of post objects
     * @access	public
     */
    public function getPostTree(ilForumPost $a_post_node)
    {
        global $ilUser;
        $posts = array();
        $data = array();
        $data_types = array();
        $query = '
			SELECT 			is_author_moderator, pos_author_id, pos_pk, fpt_date, rgt, pos_top_fk, pos_thr_fk, 
							pos_display_user_id, pos_usr_alias, pos_subject,
							pos_status, pos_message, pos_date, pos_update,
							update_user, pos_cens, pos_cens_com, notify,
							import_name, fpt_pk, parent_pos, lft, depth,
							(CASE
							WHEN fur.post_id IS NULL ' . ($ilUser->getId() == ANONYMOUS_USER_ID ? ' AND 1 = 2 ' : '') . '
							THEN 0
							ELSE 1
							END) post_read,
							firstname, lastname, title, login
							 
			FROM 			frm_posts_tree
			 
			INNER JOIN 		frm_posts 
				ON 			pos_fk = pos_pk
				
			LEFT JOIN		usr_data
				ON			pos_display_user_id  = usr_id
				
			LEFT JOIN		frm_user_read fur
				ON			fur.thread_id = pos_thr_fk
				AND			fur.post_id = pos_pk
				AND			fur.usr_id = %s
				 
			WHERE 			lft BETWEEN %s AND %s 
				AND 		thr_fk = %s';
        array_push($data_types, 'integer', 'integer', 'integer', 'integer');
        array_push($data, $ilUser->getId(), $a_post_node->getLft(), $a_post_node->getRgt(), $a_post_node->getThreadId());
        if ($this->orderField != "") {
            $query .= " ORDER BY " . $this->orderField . " " . $this->getOrderDirection();
        }
        $res = $this->db->queryf($query, $data_types, $data);
        $usr_ids = array();
        $deactivated = array();
        while ($row = $this->db->fetchAssoc($res)) {
            $tmp_object = new ilForumPost($row['pos_pk'], false, true);
            $tmp_object->assignData($row);
            if (!$this->is_moderator) {
                if (!$tmp_object->isActivated() && $tmp_object->getDisplayUserId() != $ilUser->getId()) {
                    $deactivated[] = $tmp_object;
                    unset($tmp_object);
                    continue;
                }
                foreach ($deactivated as $deactivated_node) {
                    if ($deactivated_node->getLft() < $tmp_object->getLft() && $deactivated_node->getRgt() > $tmp_object->getLft()) {
                        $deactivated[] = $tmp_object;
                        unset($tmp_object);
                        continue 2;
                    }
                }
            }
            if ((int) $row['pos_display_user_id']) {
                $usr_ids[] = (int) $row['pos_display_user_id'];
            }
            if ((int) $row['update_user']) {
                $usr_ids[] = (int) $row['update_user'];
            }
            $posts[] = $tmp_object;
            unset($tmp_object);
        }
        require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
        ilForumAuthorInformationCache::preloadUserObjects(array_unique($usr_ids));
        return $posts;
    }
 /**
  * Get's the repository object ID of a parent object, if possible
  * 
  * see ilWebAccessChecker 
  */
 function getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids = false)
 {
     if (is_int(strpos($a_usage["type"], ":"))) {
         $us_arr = explode(":", $a_usage["type"]);
         $type = $us_arr[1];
         $cont_type = $us_arr[0];
     } else {
         $type = $a_usage["type"];
     }
     $id = $a_usage["id"];
     $obj_id = false;
     switch ($type) {
         // RTE / tiny mce
         case "html":
             switch ($cont_type) {
                 case "qpl":
                     // Question Pool *Question* Text (Test)
                     include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
                     $qinfo = assQuestion::_getQuestionInfo($id);
                     if ($qinfo["original_id"] > 0) {
                         include_once "./Modules/Test/classes/class.ilObjTest.php";
                         $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id);
                         // usage in test
                     } else {
                         $obj_id = $qinfo["obj_fi"];
                         // usage in pool
                     }
                     break;
                 case "spl":
                     // Question Pool *Question* Text (Survey)
                     include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
                     $quest = SurveyQuestion::_instanciateQuestion($id);
                     if ($quest) {
                         if ($quest->getOriginalId() > 0) {
                             $obj_id = $quest->getSurveyId();
                         } else {
                             $obj_id = $quest->getObjId();
                             // usage in pool
                         }
                         unset($quest);
                     }
                     break;
                 case "exca":
                     // Exercise assignment
                     $returned_pk = $a_usage['id'];
                     // we are just checking against exercise object
                     include_once 'Modules/Exercise/classes/class.ilObjExercise.php';
                     $obj_id = ilObjExercise::lookupExerciseIdForReturnedId($returned_pk);
                     break;
                 case "frm":
                     // Forum
                     $post_pk = $a_usage['id'];
                     include_once 'Modules/Forum/classes/class.ilForumPost.php';
                     include_once 'Modules/Forum/classes/class.ilForum.php';
                     $oPost = new ilForumPost($post_pk);
                     $frm_pk = $oPost->getForumId();
                     $obj_id = ilForum::_lookupObjIdForForumId($frm_pk);
                     break;
                     // temporary items (per user)
                 // temporary items (per user)
                 case "frm~":
                 case "exca~":
                     $obj_id = $a_usage['id'];
                     break;
                     // "old" category pages
                 // "old" category pages
                 case "cat":
                     // InfoScreen Text
                 // InfoScreen Text
                 case "tst":
                 case "svy":
                     // data collection
                 // data collection
                 case "dcl":
                     $obj_id = $id;
                     break;
             }
             break;
             // page editor
         // page editor
         case "pg":
             switch ($cont_type) {
                 case "qpl":
                     // Question Pool Question Pages
                     include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
                     $qinfo = assQuestion::_getQuestionInfo($id);
                     if ($qinfo["original_id"] > 0) {
                         include_once "./Modules/Test/classes/class.ilObjTest.php";
                         $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id);
                         // usage in test
                     } else {
                         $obj_id = $qinfo["obj_fi"];
                         // usage in pool
                     }
                     break;
                 case "lm":
                 case "dbk":
                     // learning modules
                     include_once "./Modules/LearningModule/classes/class.ilLMObject.php";
                     $obj_id = ilLMObject::_lookupContObjID($id);
                     break;
                 case "gdf":
                     // glossary definition
                     include_once "./Modules/Glossary/classes/class.ilGlossaryDefinition.php";
                     include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
                     $term_id = ilGlossaryDefinition::_lookupTermId($id);
                     $obj_id = ilGlossaryTerm::_lookGlossaryID($term_id);
                     break;
                 case "wpg":
                     // wiki page
                     include_once 'Modules/Wiki/classes/class.ilWikiPage.php';
                     $obj_id = ilWikiPage::lookupObjIdByPage($id);
                     break;
                 case "sahs":
                     // sahs page
                     // can this implementation be used for other content types, too?
                     include_once './Services/COPage/classes/class.ilPageObject.php';
                     $obj_id = ilPageObject::lookupParentId($id, 'sahs');
                     break;
                 case "prtf":
                     // portfolio
                     include_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
                     $obj_id = ilPortfolioPage::findPortfolioForPage($id);
                     break;
                 case "prtt":
                     // portfolio template
                     include_once "Modules/Portfolio/classes/class.ilPortfolioTemplatePage.php";
                     $obj_id = ilPortfolioTemplatePage::findPortfolioForPage($id);
                     break;
                 case "blp":
                     // blog
                     include_once './Services/COPage/classes/class.ilPageObject.php';
                     $obj_id = ilPageObject::lookupParentId($id, 'blp');
                     break;
                 case "crs":
                 case "grp":
                 case "cat":
                 case "fold":
                 case "root":
                     // repository pages
                     $obj_id = $id;
                     break;
             }
             break;
             // Media Pool
         // Media Pool
         case "mep":
             $obj_id = $id;
             break;
             // News Context Object (e.g. MediaCast)
         // News Context Object (e.g. MediaCast)
         case "news":
             include_once "./Services/News/classes/class.ilNewsItem.php";
             $obj_id = ilNewsItem::_lookupContextObjId($id);
             break;
     }
     return $obj_id;
 }
 /**
  * Print Posting.
  *
  */
 function printPost()
 {
     global $tpl, $lng, $ilAccess, $ilias;
     if (!$ilAccess->checkAccess('read,visible', '', $_GET['ref_id'])) {
         $ilias->raiseError($lng->txt('permission_denied'), $ilias->error_obj->MESSAGE);
     }
     $tplEx = new ilTemplate('tpl.forums_export_print.html', true, true, 'Modules/Forum');
     $tplEx->setVariable('CSSPATH', $tpl->tplPath);
     // get forum- and thread-data
     $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($_GET['top_pk']));
     if (is_array($frmData = $this->frm->getOneTopic())) {
         // post object
         $post = new ilForumPost((int) $_GET['print_post']);
         // headline
         $tplEx->setVariable('HEADLINE', $lng->txt('forum') . ': ' . $frmData['top_name'] . ' > ' . $lng->txt('forums_thread') . ': ' . $post->getThread()->getSubject());
         $tplEx->setCurrentBlock('posts_row');
         $tplEx->setVariable('ROWCOL', 'tblrow2');
         $authorinfo = new ilForumAuthorInformation($post->getUserId(), $post->getUserAlias(), $post->getImportName());
         $tplEx->setVariable('AUTHOR', $authorinfo->getAuthorName());
         if ($post->getUserId()) {
             // get create- and update-dates
             if ($post->getUpdateUserId()) {
                 $authorinfo = new ilForumAuthorInformation($post->getUpdateUserId(), '', '');
                 $tplEx->setVariable('POST_UPDATE', "<br />[" . $lng->txt('edited_on') . ": " . $this->frm->convertDate($post->getChangeDate()) . " - " . strtolower($lng->txt('from')) . " " . $authorinfo->getAuthorName() . "]");
             }
             if ($ilAccess->checkAccess('moderate_frm', '', $_GET['ref_id'])) {
                 $numPosts = $this->frm->countUserArticles($post->getUserId());
             } else {
                 $numPosts = $this->frm->countActiveUserArticles($post->getUserId());
             }
         }
         $tplEx->setVariable('SUBJECT', $post->getSubject());
         $tplEx->setVariable('TXT_CREATE_DATE', $lng->txt('forums_thread_create_date'));
         $tplEx->setVariable('POST_DATE', $this->frm->convertDate($post->getCreateDate()));
         $tplEx->setVariable('SPACER', "<hr noshade width=\"100%\" size=\"1\" align=\"center\" />");
         if ($post->isCensored()) {
             $tplEx->setVariable('POST', nl2br(stripslashes($post->getCensorshipComment())));
         } else {
             /** @todo mjansen: possible bugfix for mantis #8223 */
             if ($post->getMessage() == strip_tags($post->getMessage())) {
                 // We can be sure, that there are not html tags
                 $post->setMessage(nl2br($post->getMessage()));
             }
             $tplEx->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($this->frm->prepareText($post->getMessage(), 0, '', 'export'), 1));
         }
         $tplEx->parseCurrentBlock('posts_row');
         $tplEx->setCurrentBlock('posttable');
         $tplEx->setVariable('TXT_AUTHOR', $lng->txt('author'));
         $tplEx->setVariable('TXT_POST', $lng->txt('forums_thread') . ': ' . $post->getThread()->getSubject());
         $tplEx->parseCurrentBlock('posttable');
     }
     // if (is_array($frmData = $this->frm->getOneTopic()))
     $tplEx->show();
 }
 /**
  * Get's the repository object ID of a parent object, if possible
  */
 function getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids = false)
 {
     if (is_int(strpos($a_usage["type"], ":"))) {
         $us_arr = explode(":", $a_usage["type"]);
         $type = $us_arr[1];
         $cont_type = $us_arr[0];
     } else {
         $type = $a_usage["type"];
     }
     $id = $a_usage["id"];
     $obj_id = false;
     switch ($type) {
         case "html":
             // "old" category pages
             if ($cont_type == "cat") {
                 $obj_id = $id;
             }
             // Test InfoScreen Text
             if ($cont_type == "tst" || $cont_type == "svy") {
                 $obj_id = $id;
                 //var_dump($qinfo);
             }
             // Question Pool *Question* Text (Test)
             if ($cont_type == "qpl") {
                 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
                 $qinfo = assQuestion::_getQuestionInfo($id);
                 if ($qinfo["original_id"] > 0) {
                     include_once "./Modules/Test/classes/class.ilObjTest.php";
                     $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id);
                     // usage in test
                 } else {
                     $obj_id = $qinfo["obj_fi"];
                     // usage in pool
                 }
             }
             // Question Pool *Question* Text (Survey)
             if ($cont_type == "spl") {
                 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
                 $quest = SurveyQuestion::_instanciateQuestion($id);
                 if ($quest) {
                     if ($quest->getOriginalId() > 0) {
                         $obj_id = $quest->getSurveyId();
                     } else {
                         $obj_id = $quest->getObjId();
                         // usage in pool
                     }
                     unset($quest);
                 }
             }
             // Forum
             if ($cont_type == "frm") {
                 $post_pk = $a_usage['id'];
                 include_once 'Modules/Forum/classes/class.ilForumPost.php';
                 include_once 'Modules/Forum/classes/class.ilForum.php';
                 $oPost = new ilForumPost($post_pk);
                 $frm_pk = $oPost->getForumId();
                 $obj_id = ilForum::_lookupObjIdForForumId($frm_pk);
             }
             if ($cont_type == 'frm~') {
                 $obj_id = $a_usage['id'];
             }
             if ($cont_type == "dcl") {
                 $obj_id = $id;
             }
             break;
         case "pg":
             // Question Pool Question Pages
             if ($cont_type == "qpl") {
                 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
                 $qinfo = assQuestion::_getQuestionInfo($id);
                 if ($qinfo["original_id"] > 0) {
                     include_once "./Modules/Test/classes/class.ilObjTest.php";
                     $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id);
                     // usage in test
                 } else {
                     $obj_id = $qinfo["obj_fi"];
                     // usage in pool
                 }
             }
             // learning modules
             if ($cont_type == "lm" || $cont_type == "dbk") {
                 include_once "./Modules/LearningModule/classes/class.ilLMObject.php";
                 $obj_id = ilLMObject::_lookupContObjID($id);
             }
             // glossary definition
             if ($cont_type == "gdf") {
                 include_once "./Modules/Glossary/classes/class.ilGlossaryDefinition.php";
                 include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php";
                 $term_id = ilGlossaryDefinition::_lookupTermId($id);
                 $obj_id = ilGlossaryTerm::_lookGlossaryID($term_id);
             }
             // wiki page
             if ($cont_type == 'wpg') {
                 include_once 'Modules/Wiki/classes/class.ilWikiPage.php';
                 $obj_id = ilWikiPage::lookupObjIdByPage($id);
             }
             // sahs page
             if ($cont_type == 'sahs') {
                 // can this implementation be used for other content types, too?
                 include_once './Services/COPage/classes/class.ilPageObject.php';
                 $obj_id = ilPageObject::lookupParentId($id, 'sahs');
             }
             // repository pages
             if (in_array($cont_type, array("crs", "grp", "cat", "fold", "root"))) {
                 $obj_id = $id;
             }
             if ($cont_type == 'prtf') {
                 include_once "Services/Portfolio/classes/class.ilPortfolioPage.php";
                 $obj_id = ilPortfolioPage::findPortfolioForPage($id);
             }
             if ($cont_type == 'blp') {
                 include_once './Services/COPage/classes/class.ilPageObject.php';
                 $obj_id = ilPageObject::lookupParentId($id, 'blp');
             }
             break;
             // Media Pool
         // Media Pool
         case "mep":
             $obj_id = $id;
             break;
             // News Context Object (e.g. MediaCast)
         // News Context Object (e.g. MediaCast)
         case "news":
             include_once "./Services/News/classes/class.ilNewsItem.php";
             $obj_id = ilNewsItem::_lookupContextObjId($id);
             break;
     }
     return $obj_id;
 }
 /**
  * Standard Version of Fill Row. Most likely to
  * be overwritten by derived class.
  */
 protected function fillRow($a_set)
 {
     global $lng, $ilCtrl;
     $news_set = new ilSetting("news");
     $enable_internal_rss = $news_set->get("enable_rss_for_internal");
     // context
     $obj_id = ilObject::_lookupObjId($a_set["ref_id"]);
     $obj_type = ilObject::_lookupType($obj_id);
     $obj_title = ilObject::_lookupTitle($obj_id);
     // user
     if ($a_set["user_id"] > 0) {
         $this->tpl->setCurrentBlock("user_info");
         if ($obj_type == "frm") {
             include_once "./Modules/Forum/classes/class.ilForumProperties.php";
             if (ilForumProperties::_isAnonymized($a_set["context_obj_id"])) {
                 if ($a_set["context_sub_obj_type"] == "pos" && $a_set["context_sub_obj_id"] > 0) {
                     include_once "./Modules/Forum/classes/class.ilForumPost.php";
                     $post = new ilForumPost($a_set["context_sub_obj_id"]);
                     if ($post->getUserAlias() != "") {
                         $this->tpl->setVariable("VAL_AUTHOR", ilUtil::stripSlashes($post->getUserAlias()));
                     } else {
                         $this->tpl->setVariable("VAL_AUTHOR", $lng->txt("forums_anonymous"));
                     }
                 } else {
                     $this->tpl->setVariable("VAL_AUTHOR", $lng->txt("forums_anonymous"));
                 }
             } else {
                 if (ilObject::_exists($a_set["user_id"])) {
                     $user_obj = new ilObjUser($a_set["user_id"]);
                     $this->tpl->setVariable("VAL_AUTHOR", $user_obj->getLogin());
                 }
             }
         } else {
             if (ilObject::_exists($a_set["user_id"])) {
                 $user_obj = new ilObjUser($a_set["user_id"]);
                 $this->tpl->setVariable("VAL_AUTHOR", $user_obj->getLogin());
             }
         }
         $this->tpl->setVariable("TXT_AUTHOR", $lng->txt("author"));
         $this->tpl->parseCurrentBlock();
     }
     // media player
     if ($a_set["content_type"] == NEWS_AUDIO && $a_set["mob_id"] > 0 && ilObject::_exists($a_set["mob_id"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/MediaObjects/classes/class.ilMediaPlayerGUI.php";
         $mob = new ilObjMediaObject($a_set["mob_id"]);
         $med = $mob->getMediaItem("Standard");
         $mpl = new ilMediaPlayerGUI();
         $mpl->setFile(ilObjMediaObject::_getDirectory($a_set["mob_id"]) . "/" . $med->getLocation());
         $this->tpl->setCurrentBlock("player");
         $this->tpl->setVariable("PLAYER", $mpl->getMp3PlayerHtml());
         $this->tpl->parseCurrentBlock();
     }
     // access
     if ($enable_internal_rss) {
         $this->tpl->setCurrentBlock("access");
         include_once "./Services/Block/classes/class.ilBlockSetting.php";
         $this->tpl->setVariable("TXT_ACCESS", $lng->txt("news_news_item_visibility"));
         if ($a_set["visibility"] == NEWS_PUBLIC || $a_set["priority"] == 0 && ilBlockSetting::_lookup("news", "public_notifications", 0, $obj_id)) {
             $this->tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_public"));
         } else {
             $this->tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_users"));
         }
         $this->tpl->parseCurrentBlock();
     }
     // content
     if ($a_set["content"] != "") {
         $this->tpl->setCurrentBlock("content");
         $this->tpl->setVariable("VAL_CONTENT", ilUtil::makeClickable($a_set["content"], true));
         $this->tpl->parseCurrentBlock();
     }
     if ($a_set["content_long"] != "") {
         $this->tpl->setCurrentBlock("long");
         $this->tpl->setVariable("VAL_LONG_CONTENT", ilUtil::makeClickable($a_set["content_long"], true));
         $this->tpl->parseCurrentBlock();
     }
     if ($a_set["update_date"] != $a_set["creation_date"]) {
         $this->tpl->setCurrentBlock("ni_update");
         $this->tpl->setVariable("TXT_LAST_UPDATE", $lng->txt("last_update"));
         $this->tpl->setVariable("VAL_LAST_UPDATE", ilDatePresentation::formatDate(new ilDateTime($a_set["update_date"], IL_CAL_DATETIME)));
         $this->tpl->parseCurrentBlock();
     }
     // forum hack, not nice
     $add = "";
     if ($obj_type == "frm" && $a_set["context_sub_obj_type"] == "pos" && $a_set["context_sub_obj_id"] > 0) {
         include_once "./Modules/Forum/classes/class.ilObjForumAccess.php";
         $pos = $a_set["context_sub_obj_id"];
         $thread = ilObjForumAccess::_getThreadForPosting($pos);
         if ($thread > 0) {
             $add = "_" . $thread . "_" . $pos;
         }
     }
     $url_target = "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" . $obj_type . "_" . $a_set["ref_id"] . $add;
     $this->tpl->setCurrentBlock("context");
     $cont_loc = new ilLocatorGUI();
     $cont_loc->addContextItems($a_set["ref_id"], true);
     $this->tpl->setVariable("CONTEXT_LOCATOR", $cont_loc->getHTML());
     $this->tpl->setVariable("HREF_CONTEXT_TITLE", $url_target);
     $this->tpl->setVariable("CONTEXT_TITLE", $obj_title);
     $this->tpl->setVariable("ALT_CONTEXT_TITLE", $lng->txt("icon") . " " . $lng->txt("obj_" . $obj_type));
     $this->tpl->setVariable("IMG_CONTEXT_TITLE", ilUtil::getImagePath("icon_" . $obj_type . "_b.png"));
     $this->tpl->parseCurrentBlock();
     $this->tpl->setVariable("HREF_TITLE", $url_target);
     // title
     if ($a_set["content_is_lang_var"]) {
         $this->tpl->setVariable("VAL_TITLE", $lng->txt($a_set["title"]));
     } else {
         $this->tpl->setVariable("VAL_TITLE", ilUtil::stripSlashes($a_set["title"]));
         // title
     }
     // creation date
     $this->tpl->setVariable("VAL_CREATION_DATE", ilDatePresentation::formatDate(new ilDateTime($a_set["creation_date"], IL_CAL_DATETIME)));
     $this->tpl->setVariable("TXT_CREATED", $lng->txt("created"));
     $this->tpl->parseCurrentBlock();
 }
    /**
     * generate new dataset in frm_posts
     * @param	integer	$topic
     * @param	integer	$thread
     * @param	integer	$user
     * @param	string	$message	
     * @param	integer	$parent_pos	
     * @param	integer	$notify	
     * @param	integer	$anonymize	
     * @param	string	$subject	
     * @param	datetime	$date	
     * @return	integer	$lastInsert: new post ID
     * @access	public
     */
    public function generatePost($forum_id, $thread_id, $user, $message, $parent_pos, $notify, $subject = '', $alias = '', $date = '', $status = 1, $send_activation_mail = 0)
    {
        global $ilUser, $ilDB;
        $objNewPost = new ilForumPost();
        $objNewPost->setForumId($forum_id);
        $objNewPost->setThreadId($thread_id);
        $objNewPost->setSubject($subject);
        $objNewPost->setMessage($message);
        $objNewPost->setUserId($user);
        $objNewPost->setUserAlias($alias);
        if ($date == "") {
            $objNewPost->setCreateDate(date("Y-m-d H:i:s"));
        } else {
            if (strpos($date, "-") > 0) {
                $objNewPost->setCreateDate($date);
            } else {
                $objNewPost->setCreateDate(date("Y-m-d H:i:s", $date));
            }
        }
        $objNewPost->setImportName($this->getImportName());
        $objNewPost->setNotification($notify);
        $objNewPost->setStatus($status);
        $objNewPost->insert();
        // entry in tree-table
        if ($parent_pos == 0) {
            $this->addPostTree($objNewPost->getThreadId(), $objNewPost->getId(), $objNewPost->getCreateDate());
        } else {
            $this->insertPostNode($objNewPost->getId(), $parent_pos, $objNewPost->getThreadId(), $objNewPost->getCreateDate());
        }
        //echo "<br>->".$objNewPost->getId()."-".$parent_pos."-".$objNewPost->getThreadId()."-".
        //	$objNewPost->getCreateDate()."-".$forum_id."-".$message."-".$user."-";
        // string last post
        $lastPost = $objNewPost->getForumId() . "#" . $objNewPost->getThreadId() . "#" . $objNewPost->getId();
        // update thread
        $result = $ilDB->manipulateF('
			UPDATE frm_threads 
			SET thr_num_posts = thr_num_posts + 1,
				thr_last_post = %s
			WHERE thr_pk = %s', array('text', 'integer'), array($lastPost, $objNewPost->getThreadId()));
        // update forum
        $result = $ilDB->manipulateF('
			UPDATE frm_data 
			SET top_num_posts = top_num_posts + 1,
			 	top_last_post = %s
			WHERE top_pk = %s', array('text', 'integer'), array($lastPost, $objNewPost->getForumId()));
        // MARK READ
        $forum_obj = ilObjectFactory::getInstanceByRefId($this->getForumRefId());
        $forum_obj->markPostRead($objNewPost->getUserId(), $objNewPost->getThreadId(), $objNewPost->getId());
        $pos_data = $objNewPost->getDataAsArray();
        $pos_data["ref_id"] = $this->getForumRefId();
        // Send notification to moderators if they have to enable a post
        if (!$status && $send_activation_mail) {
            $pos_data["top_name"] = $forum_obj->getTitle();
            $this->sendPostActivationNotification($pos_data);
        }
        // Add Notification to news
        if ($status) {
            require_once 'Services/RTE/classes/class.ilRTE.php';
            include_once "./Services/News/classes/class.ilNewsItem.php";
            $news_item = new ilNewsItem();
            $news_item->setContext($forum_obj->getId(), 'frm', $objNewPost->getId(), 'pos');
            $news_item->setPriority(NEWS_NOTICE);
            $news_item->setTitle($objNewPost->getSubject());
            $news_item->setContent(ilRTE::_replaceMediaObjectImageSrc($this->prepareText($objNewPost->getMessage(), 0), 1));
            $news_item->setUserId($user);
            $news_item->setVisibility(NEWS_USERS);
            $news_item->create();
        }
        return $objNewPost->getId();
    }
Beispiel #8
0
 /**
  * @param $obj_id
  * @param $source_id
  * @param $target_id
  * @throws ilException
  */
 public static function mergeThreads($obj_id, $source_id, $target_id)
 {
     // selected source & target objects
     $source_thread_obj = new ilForumTopic((int) $source_id);
     $target_thread_obj = new ilForumTopic((int) $target_id);
     if ($source_thread_obj->getForumId() != $target_thread_obj->getForumId()) {
         throw new ilException('not_allowed_to_merge_into_another_forum');
     }
     // use the "older" thread as target
     if ($source_thread_obj->getCreateDate() > $target_thread_obj->getCreateDate()) {
         $merge_thread_source = $source_thread_obj;
         $merge_thread_target = $target_thread_obj;
     } else {
         $merge_thread_source = $target_thread_obj;
         $merge_thread_target = $source_thread_obj;
     }
     $thread_subject = $target_thread_obj->getSubject();
     // remember if the threads are open or closed and then close both threads !
     $targed_was_closed = $merge_thread_target->isClosed();
     $merge_thread_source->close();
     if ($targed_was_closed == false) {
         $merge_thread_target->close();
     }
     $source_all_posts = $merge_thread_source->getAllPosts();
     $source_root_node = $merge_thread_source->getFirstPostNode();
     $target_root_node = $merge_thread_target->getFirstPostNode();
     $add_difference = $target_root_node->getRgt();
     // update target root node rgt
     include_once 'Modules/Forum/classes/class.ilForumPostsTree.php';
     //		$new_target_rgt = ($target_root_node->getRgt() + $source_root_node->getRgt() + 1);
     $new_target_rgt = $target_root_node->getRgt() + $source_root_node->getRgt();
     ilForumPostsTree::updateTargetRootRgt($target_root_node->getId(), $new_target_rgt);
     $new_target_root = $target_root_node->getId();
     // get source post tree and update posts tree
     foreach ($source_all_posts as $post) {
         $post_obj = new ilForumPost($post->pos_pk);
         $posts_tree_obj = new ilForumPostsTree();
         $posts_tree_obj->setPosFk($post->pos_pk);
         if ($post_obj->getParentId() == 0) {
             $posts_tree_obj->setParentPos($new_target_root);
             //$posts_tree_obj->setRgt(($post_obj->getRgt() + $add_difference));
             $posts_tree_obj->setRgt($post_obj->getRgt() + $add_difference - 1);
             $posts_tree_obj->setLft($target_root_node->getRgt());
             $posts_tree_obj->setDepth($post_obj->getDepth() + 1);
             $posts_tree_obj->setSourceThreadId($merge_thread_source->getId());
             $posts_tree_obj->setTargetThreadId($merge_thread_target->getId());
             $posts_tree_obj->mergeParentPos();
         } else {
             $posts_tree_obj->setRgt($post_obj->getRgt() + $add_difference - 1);
             $posts_tree_obj->setLft($post_obj->getLft() + $add_difference - 1);
             $posts_tree_obj->setDepth($post_obj->getDepth() + 1);
             $posts_tree_obj->setSourceThreadId($merge_thread_source->getId());
             $posts_tree_obj->setParentPos($post_obj->getParentId());
             $posts_tree_obj->setTargetThreadId($merge_thread_target->getId());
             $posts_tree_obj->merge();
         }
     }
     // update frm_posts pos_thr_fk = target_thr_id
     include_once 'Modules/Forum/classes/class.ilForumPost.php';
     ilForumPost::mergePosts($merge_thread_source->getId(), $merge_thread_target->getId());
     // check notifications
     include_once 'Modules/Forum/classes/class.ilForumNotification.php';
     ilForumNotification::mergeThreadNotificiations($merge_thread_source->getId(), $merge_thread_target->getId());
     // delete frm_thread_access entries
     include_once './Modules/Forum/classes/class.ilObjForum.php';
     ilObjForum::_deleteAccessEntries($merge_thread_source->getId());
     // update frm_user_read
     ilObjForum::mergeForumUserRead($merge_thread_source->getId(), $merge_thread_target->getId());
     // update visits, thr_num_posts, last_post, subject
     $post_date_source = $merge_thread_source->getLastPost()->getCreateDate();
     $post_date_target = $merge_thread_target->getLastPost()->getCreateDate();
     $target_last_post = $merge_thread_target->getLastPostString();
     $exp = explode('#', $target_last_post);
     if ($post_date_source > $post_date_target) {
         $exp[2] = $merge_thread_source->getLastPost()->getId();
     } else {
         $exp[2] = $merge_thread_target->getLastPost()->getId();
     }
     $new_thr_last_post = implode('#', $exp);
     $num_posts_source = (int) $merge_thread_source->getNumPosts();
     $num_visits_source = (int) $merge_thread_source->getVisits();
     $num_posts_target = (int) $merge_thread_target->getNumPosts();
     $num_visits_target = (int) $merge_thread_source->getVisits();
     $frm_topic_obj = new ilForumTopic(0, false, true);
     $frm_topic_obj->setNumPosts($num_posts_source + $num_posts_target);
     $frm_topic_obj->setVisits($num_visits_source + $num_visits_target);
     $frm_topic_obj->setLastPostString($new_thr_last_post);
     $frm_topic_obj->setSubject($thread_subject);
     $frm_topic_obj->setId($merge_thread_target->getId());
     $frm_topic_obj->updateMergedThread();
     // update frm_data:  top_last_post , top_num_threads
     ilForum::updateLastPostByObjId($obj_id);
     // reopen target if was not "closed" before merging
     if (!$targed_was_closed) {
         $merge_thread_target->reopen();
     }
     // delete source thread
     ilForumTopic::deleteByThreadId($merge_thread_source->getId());
 }
 /**
  * @param ilTemplate $tpl
  * @param ilForumPost $post
  * @param int $counter
  * @param int $mode
  */
 protected function renderPostHtml(ilTemplate $tpl, ilForumPost $post, $counter, $mode)
 {
     /**
      * @var $lng            ilLanguage
      * @var $rbacreview     ilRbacReview
      * @var $ilUser         ilObjUser
      * @var $ilObjDataCache ilObjectDataCache
      */
     global $lng, $rbacreview, $ilUser, $ilObjDataCache;
     $tpl->setCurrentBlock('posts_row');
     if (ilForumProperties::getInstance($ilObjDataCache->lookupObjId($_GET['ref_id']))->getMarkModeratorPosts() == 1) {
         if ($post->getIsAuthorModerator() === null && ($is_moderator = ilForum::_isModerator($_GET['ref_id'], $post->getPosAuthorId()))) {
             $rowCol = 'ilModeratorPosting';
         } else {
             if ($post->getIsAuthorModerator()) {
                 $rowCol = 'ilModeratorPosting';
             } else {
                 $rowCol = ilUtil::switchColor($counter, 'tblrow1', 'tblrow2');
             }
         }
     } else {
         $rowCol = ilUtil::switchColor($counter, 'tblrow1', 'tblrow2');
     }
     $tpl->setVariable('ROWCOL', ' ' . $rowCol);
     // post is censored
     if ($post->isCensored()) {
         // display censorship advice
         $tpl->setVariable('TXT_CENSORSHIP_ADVICE', $lng->txt('post_censored_comment_by_moderator'));
         // highlight censored posts
         $rowCol = 'tblrowmarked';
     }
     // set row color
     $tpl->setVariable('ROWCOL', ' ' . $rowCol);
     // if post is not activated display message for the owner
     if (!$post->isActivated() && $post->isOwner($ilUser->getId())) {
         $tpl->setVariable('POST_NOT_ACTIVATED_YET', $lng->txt('frm_post_not_activated_yet'));
     }
     $authorinfo = new ilForumAuthorInformation($post->getPosAuthorId(), $post->getDisplayUserId(), $post->getUserAlias(), $post->getImportName());
     if ($authorinfo->hasSuffix()) {
         $tpl->setVariable('AUTHOR', $authorinfo->getSuffix());
         $tpl->setVariable('USR_NAME', $post->getUserAlias());
     } else {
         $tpl->setVariable('AUTHOR', $authorinfo->getAuthorShortName());
         if ($authorinfo->getAuthorName(true)) {
             $tpl->setVariable('USR_NAME', $authorinfo->getAuthorName(true));
         }
     }
     if (self::MODE_EXPORT_CLIENT == $mode) {
         if ($authorinfo->getAuthor()->getPref('public_profile') != 'n') {
             $tpl->setVariable('TXT_REGISTERED', $lng->txt('registered_since'));
             $tpl->setVariable('REGISTERED_SINCE', $this->frm->convertDate($authorinfo->getAuthor()->getCreateDate()));
         }
         if ($post->getDisplayUserId()) {
             if ($this->is_moderator) {
                 $num_posts = $this->frm->countUserArticles($post->getDisplayUserId());
             } else {
                 $num_posts = $this->frm->countActiveUserArticles($post->getDisplayUserId());
             }
             $tpl->setVariable('TXT_NUM_POSTS', $lng->txt('forums_posts'));
             $tpl->setVariable('NUM_POSTS', $num_posts);
         }
     }
     $tpl->setVariable('USR_IMAGE', $authorinfo->getProfilePicture());
     if ($authorinfo->getAuthor()->getId() && ilForum::_isModerator((int) $_GET['ref_id'], $post->getPosAuthorId())) {
         if ($authorinfo->getAuthor()->getGender() == 'f') {
             $tpl->setVariable('ROLE', $lng->txt('frm_moderator_f'));
         } else {
             if ($authorinfo->getAuthor()->getGender() == 'm') {
                 $tpl->setVariable('ROLE', $lng->txt('frm_moderator_m'));
             }
         }
     }
     // get create- and update-dates
     if ($post->getUpdateUserId() > 0) {
         $spanClass = '';
         // last update from moderator?
         $posMod = $this->frm->getModeratorFromPost($post->getId());
         if (is_array($posMod) && $posMod['top_mods'] > 0) {
             $MODS = $rbacreview->assignedUsers($posMod['top_mods']);
             if (is_array($MODS)) {
                 if (in_array($post->getUpdateUserId(), $MODS)) {
                     $spanClass = 'moderator_small';
                 }
             }
         }
         $post->setChangeDate($post->getChangeDate());
         if ($spanClass == '') {
             $spanClass = 'small';
         }
         require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
         $authorinfo = new ilForumAuthorInformation($post->getPosAuthorId(), $post->getUpdateUserId(), '', '');
         $tpl->setVariable('POST_UPDATE_TXT', $lng->txt('edited_on') . ': ' . $this->frm->convertDate($post->getChangeDate()) . ' - ' . strtolower($lng->txt('by')));
         $tpl->setVariable('UPDATE_AUTHOR', $authorinfo->getLinkedAuthorShortName());
         if ($authorinfo->getAuthorName(true)) {
             $tpl->setVariable('UPDATE_USR_NAME', $authorinfo->getAuthorName(true));
         }
     }
     // prepare post
     $post->setMessage($this->frm->prepareText($post->getMessage()));
     $tpl->setVariable('POST_DATE', $this->frm->convertDate($post->getCreateDate()));
     $tpl->setVariable('SUBJECT', $post->getSubject());
     if (!$post->isCensored()) {
         // post from moderator?
         $modAuthor = $this->frm->getModeratorFromPost($post->getId());
         $spanClass = "";
         if (is_array($modAuthor) && $modAuthor['top_mods'] > 0) {
             $MODS = $rbacreview->assignedUsers($modAuthor['top_mods']);
             if (is_array($MODS) && in_array($post->getDisplayUserId(), $MODS)) {
                 $spanClass = 'moderator';
             }
         }
         // possible bugfix for mantis #8223
         if ($post->getMessage() == strip_tags($post->getMessage())) {
             // We can be sure, that there are not html tags
             $post->setMessage(nl2br($post->getMessage()));
         }
         if ($spanClass != "") {
             $tpl->setVariable('POST', "<span class=\"" . $spanClass . "\">" . ilRTE::_replaceMediaObjectImageSrc($post->getMessage(), 1) . "</span>");
         } else {
             $tpl->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($post->getMessage(), 1));
         }
     } else {
         $tpl->setVariable('POST', "<span class=\"moderator\">" . nl2br($post->getCensorshipComment()) . "</span>");
     }
     $tpl->parseCurrentBlock('posts_row');
 }