public function fillTreeTemplate() { $emptyOnLoad = false; $nodes_to_request = $_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes']; if (!$_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes'] || count($_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes']) == 1 && $_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes'][0] == 0) { $emptyOnLoad = true; $nodes_to_request = array(); } $objects = $this->topic->getNestedSetPostChildren(null, $nodes_to_request); $counter = 0; $onloadNodes = array(); $nodesFetchedWithChildren = array(); $frm = new ilForum(); $pageHits = $frm->getPageHits(); include_once 'Services/JSON/classes/class.ilJsonUtil.php'; foreach ($objects as $object) { if ($object['pos_pk'] != $this->root_id && !in_array($object['parent_pos'], $onloadNodes)) { continue; } if (in_array((int) $object['parent_pos'], $onloadNodes) && !in_array((int) $object['parent_pos'], $nodesFetchedWithChildren)) { $nodesFetchedWithChildren[] = (int) $object['parent_pos']; } $html = self::getTreeNodeHtml($object, $this->gui, $pageHits); $hasChildren = $object['children'] >= 1; $node = new stdClass(); $node->html = $html; if ($object['pos_pk'] == $this->root_id) { $this->tpl->setVariable('FRM_TREE_ROOT_NODE_VARIABLE', 'frmNode' . $object['pos_pk']); $this->tpl->setVariable('FRM_TREE_ROOT_NODE_LINK', ilJsonUtil::encode($node)); $this->tpl->setVariable('FRM_TREE_ROOT_NODE_HAS_CHILDREN', $hasChildren ? 'true' : 'false'); } else { $this->tpl->setCurrentBlock('frm_nodes'); $this->tpl->setVariable('FRM_NODES_VARNAME', 'frmNode' . $object['pos_pk']); $this->tpl->setVariable('FRM_NODES_PARENT_VARNAME', 'frmNode' . $object['parent_pos']); $this->tpl->setVariable('FRM_NODES_LINK', ilJsonUtil::encode($node)); $this->tpl->setVariable('FRM_NODES_HAS_CHILDREN', $hasChildren ? 'true' : 'false'); $this->tpl->parseCurrentBlock(); } $onloadNodes[] = (int) $object['pos_pk']; ++$counter; } $this->tpl->setVariable('THR_ONLOAD_NODES', ilJsonUtil::encode($onloadNodes)); $this->tpl->setVariable('THR_ONLOAD_NODES_FETCHED_WITH_CHILDREN', ilJsonUtil::encode($nodesFetchedWithChildren)); if ($emptyOnLoad) { $this->tpl->setVariable('THR_OPEN_NODES', ilJsonUtil::encode($onloadNodes)); $_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes'] = array_unique(array_merge(array(0), $onloadNodes)); } else { $this->tpl->setVariable('THR_OPEN_NODES', ilJsonUtil::encode($_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes'])); } }
protected function initHeaderAction($a_sub_type = null, $a_sub_id = null) { /** * @var $ilUser ilObjUser */ global $ilUser; $lg = parent::initHeaderAction(); // Workaround: Do not show "desktop actions" in thread view if ($this->objCurrentTopic->getId()) { $container_obj = null; $lg->setContainerObject($container_obj); } if ($lg instanceof ilObjForumListGUI) { include_once 'Modules/Forum/classes/class.ilForumNotification.php'; $frm_noti = new ilForumNotification((int) $_GET['ref_id']); $frm_noti->setUserId($ilUser->getId()); $user_toggle = $frm_noti->isUserToggleNotification(); // Notification button $notificiation_enabled = false; if ($ilUser->getId() != ANONYMOUS_USER_ID && $this->ilias->getSetting('forum_notification') != 0 && $user_toggle != 1) { $frm = $this->object->Forum; $frm->setForumId($this->object->getId()); $frm->setForumRefId($this->object->getRefId()); $frm->setMDB2Wherecondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId())); if ($this->objCurrentTopic->getId()) { $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId()); } if ($frm->isForumNotificationEnabled($ilUser->getId())) { $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'disableForumNotification'), "forums_disable_forum_notification"); $notificiation_enabled = true; } else { $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'enableForumNotification'), "forums_enable_forum_notification"); } if ($this->objCurrentTopic->getId()) { if ($this->objCurrentTopic->isNotificationEnabled($ilUser->getId())) { $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'toggleThreadNotification'), "forums_disable_notification"); $notificiation_enabled = true; } else { $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'toggleThreadNotification'), "forums_enable_notification"); } } $this->ctrl->setParameter($this, 'thr_pk', ''); if ($notificiation_enabled) { $lg->addHeaderIcon("not_icon", ilUtil::getImagePath("notification_on.png"), $this->lng->txt("frm_notification_activated")); } else { $lg->addHeaderIcon("not_icon", ilUtil::getImagePath("notification_off.png"), $this->lng->txt("frm_notification_deactivated")); } } } return $lg; }
/** * Export to HTML. * */ function exportHTML() { global $lng, $tpl, $ilUser, $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_html.html', true, true, 'Modules/Forum'); // threads //for ($j = 0; $j < count($_POST['forum_id']); $j++) for ($j = 0; $j < count($_POST['thread_ids']); $j++) { //$objCurrentTopic = new ilForumTopic(addslashes($_POST['forum_id'][$j]), $ilAccess->checkAccess('moderate_frm', '', $_GET['ref_id'])); $objCurrentTopic = new ilForumTopic(addslashes($_POST['thread_ids'][$j]), $ilAccess->checkAccess('moderate_frm', '', $_GET['ref_id'])); // get forum- and thread-data $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($objCurrentTopic->getForumId())); if (is_array($frmData = $this->frm->getOneTopic())) { $objFirstPostNode = $objCurrentTopic->getFirstPostNode(); $objCurrentTopic->setOrderField('frm_posts_tree.rgt'); $postTree = $objCurrentTopic->getPostTree($objFirstPostNode); $posNum = count($postTree); $z = 0; foreach ($postTree as $post) { $tplEx->setCurrentBlock('posts_row'); $rowCol = ilUtil::switchColor($z++, 'tblrow2', 'tblrow1'); $tplEx->setVariable('ROWCOL', $rowCol); $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 ($authorinfo->getAuthor()->getPref('public_profile') != 'n') { $tplEx->setVariable('TXT_REGISTERED', $lng->txt('registered_since')); $tplEx->setVariable('REGISTERED_SINCE', $this->frm->convertDate($authorinfo->getAuthor()->getCreateDate())); } if ($ilAccess->checkAccess('moderate_frm', '', $_GET['ref_id'])) { $numPosts = $this->frm->countUserArticles($post->getUserId()); } else { $numPosts = $this->frm->countActiveUserArticles($post->getUserId()); } $tplEx->setVariable('TXT_NUM_POSTS', $lng->txt('forums_posts')); $tplEx->setVariable('NUM_POSTS', $numPosts); } $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'); unset($author); } // foreach ($postTree as $post) $tplEx->setCurrentBlock('posttable'); $tplEx->setVariable('TXT_AUTHOR', $lng->txt('author')); $tplEx->setVariable('TXT_POST', $lng->txt('forums_thread') . ': ' . $objCurrentTopic->getSubject()); $tplEx->parseCurrentBlock('posttable'); // Thread Headline $tplEx->setCurrentBlock('thread_headline'); $tplEx->setVariable('T_TITLE', $objCurrentTopic->getSubject()); if ($ilAccess->checkAccess('moderate_frm', '', $_GET['ref_id'])) { $tplEx->setVariable('T_NUM_POSTS', $objCurrentTopic->countPosts()); } else { $tplEx->setVariable('T_NUM_POSTS', $objCurrentTopic->countActivePosts()); } $tplEx->setVariable('T_NUM_VISITS', $objCurrentTopic->getVisits()); $tplEx->setVariable('T_FORUM', $frmData['top_name']); $authorinfo = new ilForumAuthorInformation($objCurrentTopic->getUserId(), $objCurrentTopic->getUserAlias(), $objCurrentTopic->getImportName()); $tplEx->setVariable('T_AUTHOR', $authorinfo->getAuthorName()); $tplEx->setVariable('T_TXT_FORUM', $lng->txt('forum') . ': '); $tplEx->setVariable('T_TXT_TOPIC', $lng->txt('forums_thread') . ': '); $tplEx->setVariable('T_TXT_AUTHOR', $lng->txt('forums_thread_create_from') . ': '); $tplEx->setVariable('T_TXT_NUM_POSTS', $lng->txt('forums_articles') . ': '); $tplEx->setVariable('T_TXT_NUM_VISITS', $lng->txt('visits') . ': '); $tplEx->parseCurrentBlock('thread_headline'); $tplEx->setCurrentBlock('thread_block'); $tplEx->parseCurrentBlock('thread_block'); $tplEx->setCurrentBlock('forum_block'); $tplEx->parseCurrentBlock('forum_block'); } // if (is_array($frmData = $this->frm->getOneTopic())) } // for ($j = 0; $j < count($_POST["forum_id"]); $j++) ilUtil::deliverData($tplEx->get(), 'forum_html_export_' . $_GET['ref_id'] . '.html'); exit; }
/** * */ public function confirmMergeThreadsObject() { if (!$this->is_moderator) { $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE); } if (!isset($_GET['merge_thread_id']) || !(int) $_GET['merge_thread_id'] || !is_array($_POST['thread_ids']) || count($_POST['thread_ids']) != 1) { ilUtil::sendFailure($this->lng->txt('select_one')); $this->mergeThreadsObject(); return; } $source_thread_id = (int) $_GET['merge_thread_id']; $target_thread_id = (int) current($_POST['thread_ids']); if ($source_thread_id == $target_thread_id) { ilUtil::sendFailure($this->lng->txt('error_same_thread_ids')); $this->showThreadsObject(); return; } if (ilForumTopic::lookupForumIdByTopicId($source_thread_id) != ilForumTopic::lookupForumIdByTopicId($target_thread_id)) { ilUtil::sendFailure($this->lng->txt('not_allowed_to_merge_into_another_forum')); $this->ctrl->clearParameters($this); $this->showThreadsObject(); return; } if (ilForumTopic::_lookupDate($source_thread_id) < ilForumTopic::_lookupDate($target_thread_id)) { ilUtil::sendInfo($this->lng->txt('switch_threads_for_merge')); } include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php'; $c_gui = new ilConfirmationGUI(); $c_gui->setFormAction($this->ctrl->getFormAction($this, 'performMergeThreads')); $c_gui->setHeaderText($this->lng->txt('frm_sure_merge_threads')); $c_gui->setCancel($this->lng->txt('cancel'), 'showThreads'); $c_gui->setConfirm($this->lng->txt('confirm'), 'performMergeThreads'); $c_gui->addItem('thread_ids[]', $source_thread_id, sprintf($this->lng->txt('frm_merge_src'), ilForumTopic::_lookupTitle($source_thread_id))); $c_gui->addItem('thread_ids[]', $target_thread_id, sprintf($this->lng->txt('frm_merge_target'), ilForumTopic::_lookupTitle($target_thread_id))); $this->tpl->setContent($c_gui->getHTML()); return; }
/** * @param ilForumTopic $thread */ public function fillRow(ilForumTopic $thread) { /** * @var $ilUser ilObjUser */ global $ilUser; $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', $thread->getId()); if ('mergeThreads' == $this->parent_cmd) { $checked = $this->max_count == 1 || isset($_POST['thread_ids']) && in_array($thread->getId(), $_POST['thread_ids']); $this->tpl->setVariable('VAL_CHECK', ilUtil::formRadioButton($checked, 'thread_ids[]', $thread->getId())); } else { if ('showThreads' == $this->parent_cmd) { $this->tpl->setVariable('VAL_CHECK', ilUtil::formCheckbox(isset($_POST['thread_ids']) && in_array($thread->getId(), $_POST['thread_ids']) ? true : false, 'thread_ids[]', $thread->getId())); } else { if ($thread->isSticky()) { $this->tpl->setVariable('VAL_SORTING_NAME', 'thread_sorting[' . $thread->getId() . ']'); $this->tpl->setVariable('VAL_SORTING', (int) $this->position * 10); } else { $this->tpl->setVariable('VAL_CHECK', ''); } $this->position++; } } $subject = ''; if ($thread->isSticky()) { $subject .= '<span class="light">[' . $this->lng->txt('sticky') . ']</span> '; } if ($thread->isClosed()) { $subject .= '<span class="light">[' . $this->lng->txt('topic_close') . ']</span> '; } if (!$ilUser->isAnonymous() && $this->ilias->getSetting('forum_notification') != 0 && $thread->getUserNotificationEnabled()) { $subject .= '<span class="light">[' . $this->lng->txt('forums_notification_enabled') . ']</span> '; } $num_posts = $thread->getNumPosts(); $num_unread = $thread->getNumUnreadPosts(); $num_new = $thread->getNumNewPosts(); if ($num_posts > 0) { $subject = '<div><a href="' . $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '">' . $thread->getSubject() . '</a></div>' . $subject; } else { $subject = $thread->getSubject() . $subject; } $this->tpl->setVariable('VAL_SUBJECT', $subject); // Author $this->ctrl->setParameter($this->getParentObject(), 'backurl', urlencode($this->ctrl->getLinkTargetByClass("ilrepositorygui", ""))); $this->ctrl->setParameter($this->getParentObject(), 'user', $thread->getUserId()); $authorinfo = new ilForumAuthorInformation($thread->getUserId(), $thread->getUserAlias(), $thread->getImportName(), array('class' => 'il_ItemProperty', 'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'showUser'))); $this->tpl->setVariable('VAL_AUTHOR', $authorinfo->getLinkedAuthorName()); $topicStats = $num_posts; if (!$ilUser->isAnonymous()) { if ($num_unread > 0) { $topicStats .= '<br /><span class="alert ilWhiteSpaceNowrap">' . $this->lng->txt('unread') . ': ' . $num_unread . '</span>'; } if ($num_new > 0 && $this->getOverviewSetting() == 0) { $topicStats .= '<br /><span class="alert ilWhiteSpaceNowrap">' . $this->lng->txt('new') . ': ' . $num_new . '</span>'; } } $this->tpl->setVariable('VAL_ARTICLE_STATS', $topicStats); $this->tpl->setVariable('VAL_NUM_VISIT', $thread->getVisits()); // Last posting if ($num_posts > 0) { if ($this->getIsModerator()) { $objLastPost = $thread->getLastPost(); } else { $objLastPost = $thread->getLastActivePost(); } if (is_object($objLastPost)) { $authorinfo = new ilForumAuthorInformation($objLastPost->getUserId(), $objLastPost->getUserAlias(), $objLastPost->getImportName(), array('href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '#' . $objLastPost->getId())); $this->tpl->setVariable('VAL_LP_DATE', '<div class="ilWhiteSpaceNowrap">' . ilDatePresentation::formatDate(new ilDateTime($objLastPost->getCreateDate(), IL_CAL_DATETIME)) . '</div>' . '<div class="ilWhiteSpaceNowrap">' . $this->lng->txt('from') . ' ' . $authorinfo->getLinkedAuthorName() . '</div>'); } } // Row style $css_row = $this->css_row; if ($thread->isSticky()) { $css_row = $css_row == 'tblrow1' ? 'tblstickyrow1' : 'tblstickyrow2'; } $this->tpl->setVariable('CSS_ROW', $css_row); $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', ''); $this->ctrl->setParameter($this->getParentObject(), 'user', ''); $this->ctrl->setParameter($this->getParentObject(), 'backurl', ''); }
/** * @param $a_topic_id * @param bool $is_moderator * @param int $limit * @param int $offset * @return array */ public function getAllThreads($a_topic_id, $is_moderator = false, $limit = 0, $offset = 0) { global $ilDB, $ilUser; // Count all threads for the passed forum $query = 'SELECT COUNT(thr_pk) cnt FROM frm_threads WHERE thr_top_fk = %s'; $res = $ilDB->queryF($query, array('integer'), array($a_topic_id)); $data = $ilDB->fetchAssoc($res); $cnt = (int) $data['cnt']; $threads = array(); $data = array(); $data_types = array(); $active_query = ''; $active_inner_query = ''; if (!$is_moderator) { $active_query = ' AND (pos_status = %s OR pos_usr_id = %s) '; $active_inner_query = ' AND (ipos.pos_status = %s OR ipos.pos_usr_id = %s) '; } if (!$ilUser->isAnonymous()) { $query = "SELECT\n\t\t\t\t (CASE WHEN COUNT(DISTINCT(notification_id)) > 0 THEN 1 ELSE 0 END) usr_notification_is_enabled,\n\t\t\t\t MAX(pos_date) post_date,\n\t\t\t\t COUNT(DISTINCT(pos_pk)) num_posts,\n\t\t\t\t \n\t\t\t\t COUNT(DISTINCT(pos_pk)) - COUNT(DISTINCT(postread.post_id)) num_unread_posts,\n\t\t\t\t \n\t\t\t\t (\n\t\t\t\t \tSELECT COUNT(DISTINCT(ipos.pos_pk))\n\t\t\t\t\tFROM frm_posts ipos\n\t\t\t\t\tLEFT JOIN frm_user_read iread ON iread.post_id = ipos.pos_pk AND iread.usr_id = %s\n\t\t\t\t\tLEFT JOIN frm_thread_access iacc ON (iacc.thread_id = ipos.pos_thr_fk AND iacc.usr_id = %s)\n\t\t\t\t\tWHERE ipos.pos_thr_fk = thr_pk\n\t\t\t\t\t \n\t\t\t\t\tAND (\n\t\t\t\t\t\t(ipos.pos_date > iacc.access_old_ts OR ipos.pos_update > iacc.access_old_ts)\n\t\t\t\t\t\tOR\n\t\t\t\t\t\t(iacc.access_old IS NULL AND (ipos.pos_date > " . $ilDB->quote(date('Y-m-d H:i:s', NEW_DEADLINE), 'timestamp') . " OR ipos.pos_update > " . $ilDB->quote(date('Y-m-d H:i:s', NEW_DEADLINE), 'timestamp') . "))\n\t\t\t\t\t\t)\n\t\t\t\t\t \n\t\t\t\t\tAND ipos.pos_usr_id != %s\n\t\t\t\t\tAND iread.usr_id IS NULL {$active_inner_query}\n\t\t\t\t ) num_new_posts,\n\t\t\t\t \n\t\t\t\t thr_pk, thr_top_fk, thr_subject, thr_usr_id, thr_usr_alias, thr_num_posts, thr_last_post, thr_date, thr_update, visits, frm_threads.import_name, is_sticky, is_closed\n\t\t\t\t \n\t\t\t\t FROM frm_threads\n\t\t\t\t \n\t\t\t\t LEFT JOIN frm_notification\n\t\t\t\t \tON frm_notification.thread_id = thr_pk\n\t\t\t\t \tAND frm_notification.user_id = %s\n\t\t\t\t \n\t\t\t\t LEFT JOIN frm_posts\n\t\t\t\t \tON pos_thr_fk = thr_pk {$active_query}\n\t\t\t\t \n\t\t\t\t LEFT JOIN frm_user_read postread\n\t\t\t\t \tON postread.post_id = pos_pk\n\t\t\t\t \tAND postread.usr_id = %s\n\t\t\t\t \n\t\t\t\t WHERE thr_top_fk = %s\n\t\t\t\t\tGROUP BY thr_pk, thr_top_fk, thr_subject, thr_usr_id, thr_usr_alias, thr_num_posts, thr_last_post, thr_date, thr_update, visits, frm_threads.import_name, is_sticky, is_closed\n\t\t\t\t\tORDER BY is_sticky DESC, post_date DESC, thr_date DESC"; $data_types[] = 'integer'; $data_types[] = 'integer'; $data_types[] = 'integer'; if (!$is_moderator) { array_push($data_types, 'integer', 'integer'); } $data_types[] = 'integer'; if (!$is_moderator) { array_push($data_types, 'integer', 'integer'); } $data_types[] = 'integer'; $data_types[] = 'integer'; $data[] = $ilUser->getId(); $data[] = $ilUser->getId(); $data[] = $ilUser->getId(); if (!$is_moderator) { array_push($data, '1', $ilUser->getId()); } $data[] = $ilUser->getId(); if (!$is_moderator) { array_push($data, '1', $ilUser->getId()); } $data[] = $ilUser->getId(); $data[] = $a_topic_id; } else { $query = "SELECT\n\t\t\t\t\t 0 usr_notification_is_enabled,\n\t\t\t\t\t MAX(pos_date) post_date,\n\t\t\t\t\t COUNT(DISTINCT(pos_pk)) num_posts,\n\t\t\t\t\t COUNT(DISTINCT(pos_pk)) num_unread_posts,\n\t\t\t\t\t COUNT(DISTINCT(pos_pk)) num_new_posts,\n\t\t\t\t\t thr_pk, thr_top_fk, thr_subject, thr_usr_id, thr_usr_alias, thr_num_posts, thr_last_post, thr_date, thr_update, visits, frm_threads.import_name, is_sticky, is_closed\n\t\t\t\t\t FROM frm_threads\n\t\t\t\t\t \n\t\t\t\t\t LEFT JOIN frm_posts\n\t\t\t\t\t\tON pos_thr_fk = thr_pk {$active_query}"; $query .= " WHERE thr_top_fk = %s\n\t\t\t\t\t\tGROUP BY thr_pk, thr_top_fk, thr_subject, thr_usr_id, thr_usr_alias, thr_num_posts, thr_last_post, thr_date, thr_update, visits, frm_threads.import_name, is_sticky, is_closed\n\t\t\t\t\t\tORDER BY is_sticky DESC, thr_date DESC"; if (!$is_moderator) { array_push($data_types, 'integer', 'integer'); } $data_types[] = 'integer'; if (!$is_moderator) { array_push($data, '1', $ilUser->getId()); } $data[] = $a_topic_id; } if ($limit || $offset) { $ilDB->setLimit($limit, $offset); } $res = $ilDB->queryF($query, $data_types, $data); while ($row = $ilDB->fetchAssoc($res)) { $thread = new ilForumTopic($row['thr_pk'], $is_moderator, true); $thread->assignData($row); $threads[] = $thread; } return array('items' => $threads, 'cnt' => $cnt); }
/** * @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()); }
/** * */ public function exportHTML() { /** * @var $tpl ilTemplate * @var $lng ilLanguage * @var $ilAccess ilAccessHandler * @var $ilias ILIAS */ global $lng, $tpl, $ilAccess, $ilias; if (!$ilAccess->checkAccess('read,visible', '', $_GET['ref_id'])) { $ilias->raiseError($lng->txt('permission_denied'), $ilias->error_obj->MESSAGE); } ilDatePresentation::setUseRelativeDates(false); $tpl = new ilTemplate('tpl.forums_export_html.html', true, true, 'Modules/Forum'); $location_stylesheet = ilUtil::getStyleSheetLocation(); $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet); $tpl->setVariable('BASE', substr(ILIAS_HTTP_PATH, -1) == '/' ? ILIAS_HTTP_PATH : ILIAS_HTTP_PATH . '/'); $num_threads = count((array) $_POST['thread_ids']); for ($j = 0; $j < $num_threads; $j++) { $topic = new ilForumTopic((int) $_POST['thread_ids'][$j], $this->is_moderator); $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($topic->getForumId())); if (is_array($thread_data = $this->frm->getOneTopic())) { if (0 == $j) { $tpl->setVariable('TITLE', $thread_data['top_name']); } $first_post = $topic->getFirstPostNode(); $topic->setOrderField('frm_posts_tree.rgt'); $post_collection = $topic->getPostTree($first_post); $z = 0; foreach ($post_collection as $post) { $this->renderPostHtml($tpl, $post, $z++, self::MODE_EXPORT_CLIENT); } $tpl->setCurrentBlock('thread_headline'); $tpl->setVariable('T_TITLE', $topic->getSubject()); if ($this->is_moderator) { $tpl->setVariable('T_NUM_POSTS', $topic->countPosts()); } else { $tpl->setVariable('T_NUM_POSTS', $topic->countActivePosts()); } $tpl->setVariable('T_NUM_VISITS', $topic->getVisits()); $tpl->setVariable('T_FORUM', $thread_data['top_name']); $authorinfo = new ilForumAuthorInformation($topic->getThrAuthorId(), $topic->getDisplayUserId(), $topic->getUserAlias(), $topic->getImportName()); $tpl->setVariable('T_AUTHOR', $authorinfo->getAuthorName()); $tpl->setVariable('T_TXT_FORUM', $lng->txt('forum') . ': '); $tpl->setVariable('T_TXT_TOPIC', $lng->txt('forums_thread') . ': '); $tpl->setVariable('T_TXT_AUTHOR', $lng->txt('forums_thread_create_from') . ': '); $tpl->setVariable('T_TXT_NUM_POSTS', $lng->txt('forums_articles') . ': '); $tpl->setVariable('T_TXT_NUM_VISITS', $lng->txt('visits') . ': '); $tpl->parseCurrentBlock(); } $tpl->setCurrentBlock('thread_block'); $tpl->parseCurrentBlock(); } ilUtil::deliverData($tpl->get('DEFAULT', false, false, false, true, false, false), 'forum_html_export_' . $_GET['ref_id'] . '.html'); }