/** * */ public function __construct() { global $lng, $ilCtrl, $ilAccess; $forum = new ilObjForum((int) $_GET['ref_id']); $this->frm = $forum->Forum; $this->frm->setForumId($forum->getId()); $this->frm->setForumRefId($forum->getRefId()); $this->ctrl = $ilCtrl; $lng->loadLanguageModule('forum'); $this->is_moderator = $ilAccess->checkAccess('moderate_frm', '', $_GET['ref_id']); }
/** * get html * @return */ public function getHTML() { global $lng; foreach ($this->getSubItemIds(true) as $sub_item) { if (is_object($this->getHighlighter()) and strlen($this->getHighlighter()->getContent($this->getObjId(), $sub_item))) { $this->tpl->setCurrentBlock('sea_fragment'); $this->tpl->setVariable('TXT_FRAGMENT', $this->getHighlighter()->getContent($this->getObjId(), $sub_item)); $this->tpl->parseCurrentBlock(); } $this->tpl->setCurrentBlock('subitem'); $this->tpl->setVariable('SUBITEM_TYPE', $lng->txt('thread')); $this->tpl->setVariable('SEPERATOR', ':'); $this->getItemListGUI()->setChildId($sub_item); $this->tpl->setVariable('LINK', $this->getItemListGUI()->getCommandLink('thread')); $this->tpl->setVariable('TARGET', $this->getItemListGUI()->getCommandFrame('')); include_once './Modules/Forum/classes/class.ilObjForum.php'; $this->tpl->setVariable('TITLE', ilObjForum::_lookupThreadSubject($sub_item)); // begin-patch mime_filter if (count($this->getSubItemIds(true)) > 1) { $this->parseRelevance($sub_item); } // end-patch mime_filter $this->tpl->parseCurrentBlock(); } $this->showDetailsLink(); return $this->tpl->get(); }
private function getNewForumPk() { global $ilDB; $query = "SELECT top_pk FROM frm_data\n\t\t\t\t\tWHERE top_frm_fk = " . $ilDB->quote($this->forum->getId(), 'integer'); $res = $ilDB->query($query); $data = $ilDB->fetchAssoc($res); return $data['top_pk']; }
/** * Import XML * * @param * @return */ public function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping) { include_once 'Modules/Forum/classes/class.ilObjForum.php'; // case i container if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) { $newObj = ilObjectFactory::getInstanceByObjId($new_id, false); } else { $newObj = new ilObjForum(); $newObj->setType('frm'); $newObj->create(true); } include_once 'Modules/Forum/classes/class.ilForumXMLParser.php'; $parser = new ilForumXMLParser($newObj, $a_xml); $parser->setImportDirectory($this->getImportDirectory()); $parser->setImportInstallId($this->getInstallId()); $parser->startParsing(); $a_mapping->addMapping("Modules/Forum", "frm", $a_id, $newObj->getId()); }
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; }
/** * */ public function mergeThreadsObject() { if (!$this->is_moderator) { $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE); } $selected_thread_id = 0; if (isset($_GET['merge_thread_id']) && (int) $_GET['merge_thread_id']) { $selected_thread_id = (int) $_GET['merge_thread_id']; } else { if (isset($_POST['thread_ids']) && count((array) $_POST['thread_ids']) == 1) { $selected_thread_id = (int) current($_POST['thread_ids']); } else { ilUtil::sendInfo($this->lng->txt('select_one')); $this->showThreadsObject(); return; } } if ($selected_thread_id) { $frm = $this->object->Forum; $frm->setForumId($this->object->getId()); $frm->setForumRefId($this->object->getRefId()); $selected_thread_obj = new ilForumTopic($selected_thread_id); if (ilForum::_lookupObjIdForForumId($selected_thread_obj->getForumId()) != $frm->getForumId()) { ilUtil::sendFailure($this->lng->txt('not_allowed_to_merge_into_another_forum')); $this->showThreadsObject(); return; } $frm->setMDB2Wherecondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId())); $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.forums_threads_liste.html', 'Modules/Forum'); $topicData = $frm->getOneTopic(); if ($topicData) { include_once 'Modules/Forum/classes/class.ilForumTopicTableGUI.php'; $this->ctrl->setParameter($this, 'merge_thread_id', $selected_thread_id); $tbl = new ilForumTopicTableGUI($this, 'mergeThreads', '', (int) $_GET['ref_id'], $topicData, $this->is_moderator, $this->forum_overview_setting); $tbl->setSelectedThread($selected_thread_obj); $tbl->setMapper($frm)->fetchData(); $tbl->populate(); $this->tpl->setVariable('THREADS_TABLE', $tbl->getHTML()); } else { ilUtil::sendFailure($this->lng->txt('select_one')); $this->showThreadsObject(); return; } } }
/** * @static * @param int $ref_id * @return array */ public static function getStatisticsByRefId($ref_id) { return ilObjForum::lookupStatisticsByRefId($ref_id); }
/** * Called after successful login * @return * @param array $a_username * @param object $a_auth */ protected function loginObserver($a_username, $a_auth) { global $ilLog, $ilAppEventHandler, $ilSetting; if ($this->getContainer()->loginObserver($a_username, $a_auth)) { // validate user include_once "Services/User/classes/class.ilObjUser.php"; $user_id = ilObjUser::_loginExists($a_auth->getUsername()); if ($user_id != ANONYMOUS_USER_ID) { $user = new ilObjUser($user_id); // check if profile is complete include_once "Services/User/classes/class.ilUserProfile.php"; if (ilUserProfile::isProfileIncomplete($user) and ilAuthFactory::getContext() != ilAuthFactory::CONTEXT_ECS) { $user->setProfileIncomplete(true); $user->update(); } // --- extended user validation // // we only have a single status, so abort after each one // order from highest priority to lowest // active? if (!$user->getActive()) { $this->status = AUTH_USER_INACTIVE; $a_auth->logout(); return; } // time limit if (!$user->checkTimeLimit()) { $this->status = AUTH_USER_TIME_LIMIT_EXCEEDED; // #16327 $this->exceeded_user_name = $this->getUserName(); $a_auth->logout(); return; } // check client ip $clientip = $user->getClientIP(); if (trim($clientip) != "") { $clientip = preg_replace("/[^0-9.?*,:]+/", "", $clientip); $clientip = str_replace(".", "\\.", $clientip); $clientip = str_replace(array("?", "*", ","), array("[0-9]", "[0-9]*", "|"), $clientip); if (!preg_match("/^" . $clientip . "\$/", $_SERVER["REMOTE_ADDR"])) { $this->status = AUTH_USER_WRONG_IP; $a_auth->logout(); return; } } // simultaneous login if ($ilSetting->get('ps_prevent_simultaneous_logins') && ilObjUser::hasActiveSession($user_id)) { $this->status = AUTH_USER_SIMULTANEOUS_LOGIN; $a_auth->logout(); return; } include_once 'Services/Tracking/classes/class.ilOnlineTracking.php'; ilOnlineTracking::addUser($user_id); include_once 'Modules/Forum/classes/class.ilObjForum.php'; ilObjForum::_updateOldAccess($user_id); require_once 'Services/PrivacySecurity/classes/class.ilSecuritySettings.php'; $security_settings = ilSecuritySettings::_getInstance(); // determine first login of user for setting an indicator // which still is available in PersonalDesktop, Repository, ... // (last login date is set to current date in next step) if ($security_settings->isPasswordChangeOnFirstLoginEnabled() && $user->getLastLogin() == null) { $user->resetLastPasswordChange(); } $user->refreshLogin(); // reset counter for failed logins ilObjUser::_resetLoginAttempts($user_id); } // --- anonymous/registered user $ilLog->write(__METHOD__ . ': logged in as ' . $a_auth->getUsername() . ', remote:' . $_SERVER['REMOTE_ADDR'] . ':' . $_SERVER['REMOTE_PORT'] . ', server:' . $_SERVER['SERVER_ADDR'] . ':' . $_SERVER['SERVER_PORT']); ilSessionControl::handleLoginEvent($a_auth->getUsername(), $a_auth); $ilAppEventHandler->raise('Services/Authentication', 'afterLogin', array('username' => $a_auth->getUsername())); } }
/** * deletes a user * @access public * @param integer user_id */ function delete() { global $rbacadmin, $ilDB; // deassign from ldap groups include_once 'Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php'; $mapping = ilLDAPRoleGroupMapping::_getInstance(); $mapping->deleteUser($this->getId()); // remove mailbox / update sent mails include_once "Services/Mail/classes/class.ilMailbox.php"; $mailbox = new ilMailbox($this->getId()); $mailbox->delete(); $mailbox->updateMailsOfDeletedUser($this->getLogin()); // delete feed blocks on personal desktop include_once "./Services/Block/classes/class.ilCustomBlock.php"; $costum_block = new ilCustomBlock(); $costum_block->setContextObjId($this->getId()); $costum_block->setContextObjType("user"); $c_blocks = $costum_block->queryBlocksForContext(); include_once "./Services/Feeds/classes/class.ilPDExternalFeedBlock.php"; foreach ($c_blocks as $c_block) { if ($c_block["type"] == "pdfeed") { $fb = new ilPDExternalFeedBlock($c_block["id"]); $fb->delete(); } } // delete block settings include_once "./Services/Block/classes/class.ilBlockSetting.php"; ilBlockSetting::_deleteSettingsOfUser($this->getId()); // delete user_account $ilDB->manipulateF("DELETE FROM usr_data WHERE usr_id = %s", array("integer"), array($this->getId())); // delete user_prefs ilObjUser::_deleteAllPref($this->getId()); // delete user_session include_once "./Services/Authentication/classes/class.ilSession.php"; ilSession::_destroyByUserId($this->getId()); // remove user from rbac $rbacadmin->removeUser($this->getId()); // remove bookmarks // TODO: move this to class.ilBookmarkFolder $q = "DELETE FROM bookmark_tree WHERE tree = " . $ilDB->quote($this->getId(), "integer"); $ilDB->manipulate($q); $q = "DELETE FROM bookmark_data WHERE user_id = " . $ilDB->quote($this->getId(), "integer"); $ilDB->manipulate($q); // DELETE FORUM ENTRIES (not complete in the moment) include_once './Modules/Forum/classes/class.ilObjForum.php'; ilObjForum::_deleteUser($this->getId()); // Delete link check notify entries include_once './Services/LinkChecker/classes/class.ilLinkCheckNotify.php'; ilLinkCheckNotify::_deleteUser($this->getId()); // Delete crs entries include_once './Modules/Course/classes/class.ilObjCourse.php'; ilObjCourse::_deleteUser($this->getId()); // Delete user tracking include_once './Services/Tracking/classes/class.ilObjUserTracking.php'; ilObjUserTracking::_deleteUser($this->getId()); include_once 'Modules/Session/classes/class.ilEventParticipants.php'; ilEventParticipants::_deleteByUser($this->getId()); // Delete Tracking data SCORM 2004 RTE include_once 'Modules/Scorm2004/classes/ilSCORM13Package.php'; ilSCORM13Package::_removeTrackingDataForUser($this->getId()); // Delete Tracking data SCORM 1.2 RTE include_once 'Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php'; ilObjSCORMLearningModule::_removeTrackingDataForUser($this->getId()); // remove all notifications include_once "./Services/Notification/classes/class.ilNotification.php"; ilNotification::removeForUser($this->getId()); // remove portfolios include_once "./Modules/Portfolio/classes/class.ilObjPortfolio.php"; ilObjPortfolio::deleteUserPortfolios($this->getId()); // remove workspace include_once "./Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php"; $tree = new ilWorkspaceTree($this->getId()); $tree->cascadingDelete(); // remove disk quota entries include_once "./Services/DiskQuota/classes/class.ilDiskQuotaHandler.php"; ilDiskQuotaHandler::deleteByOwner($this->getId()); // Delete user defined field entries $this->deleteUserDefinedFieldEntries(); // Delete clipboard entries $this->clipboardDeleteAll(); // Reset owner $this->resetOwner(); // Trigger deleteUser Event global $ilAppEventHandler; $ilAppEventHandler->raise('Services/User', 'deleteUser', array('usr_id' => $this->getId())); // delete object data parent::delete(); return true; }
/** * Clone forum moderator role * @access public * @param object $new_obj forum object */ public function cloneAutoGeneratedRoles($new_obj) { /** * @var $rbacadmin ilRbacAdmin * @var $rbacreview ilRbacReview */ global $ilLog, $rbacadmin, $rbacreview; $moderator = ilObjForum::_lookupModeratorRole($this->getRefId()); $new_moderator = ilObjForum::_lookupModeratorRole($new_obj->getRefId()); $source_rolf = $rbacreview->getRoleFolderIdOfObject($this->getRefId()); $target_rolf = $rbacreview->getRoleFolderIdOfObject($new_obj->getRefId()); if (!$moderator || !$new_moderator || !$source_rolf || !$target_rolf) { $ilLog->write(__METHOD__ . ' : Error cloning auto generated role: il_frm_moderator'); } $rbacadmin->copyRolePermissions($moderator, $source_rolf, $target_rolf, $new_moderator, true); $ilLog->write(__METHOD__ . ' : Finished copying of role il_frm_moderator.'); include_once './Modules/Forum/classes/class.ilForumModerators.php'; $obj_mods = new ilForumModerators($this->getRefId()); $old_mods = array(); $old_mods = $obj_mods->getCurrentModerators(); foreach ($old_mods as $user_id) { $rbacadmin->assignUser($new_moderator, $user_id); } }
/** * @return ilForumTopicTableGUI */ public function fetchData() { $this->determineOffsetAndOrder(); $excluded_ids = array(); if ($this->parent_cmd == 'mergeThreads' && $this->getSelectedThread() instanceof ilForumTopic) { $excluded_ids[] = $this->getSelectedThread()->getId(); } $params = array('is_moderator' => $this->getIsModerator(), 'excluded_ids' => $excluded_ids); $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int) $this->getLimit(), (int) $this->getOffset()); if (!count($data['items']) && $this->getOffset() > 0) { $this->resetOffset(); $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int) $this->getLimit(), (int) $this->getOffset()); } $this->setMaxCount($data['cnt']); $this->setData($data['items']); // Collect user ids for preloading user objects $thread_ids = array(); $user_ids = array(); foreach ($data['items'] as $thread) { /** * @var $thread ilForumTopic */ $thread_ids[] = (int) $thread->getId(); if ($thread->getUserId() > 0) { $user_ids[$thread->getUserId()] = (int) $thread->getUserId(); } } $user_ids = array_merge(ilObjForum::getUserIdsOfLastPostsByRefIdAndThreadIds($this->getRefId(), $thread_ids), $user_ids); ilForumAuthorInformationCache::preloadUserObjects(array_unique($user_ids)); return $this; }
public function __appendChildLinks($html, $item, &$item_list_gui) { if (!count($item['child'])) { return $html; } $tpl = new ilTemplate('tpl.detail_links.html', true, true, 'Services/Search'); switch ($item['type']) { case 'lm': $tpl->setVariable("HITS", $this->lng->txt('search_hits')); include_once 'Modules/LearningModule/classes/class.ilLMObject.php'; foreach ($item['child'] as $child) { $tpl->setCurrentBlock("link_row"); switch (ilLMObject::_lookupType($child)) { case 'pg': $tpl->setVariable("CHAPTER_PAGE", $this->lng->txt('obj_pg')); break; case 'st': $tpl->setVariable("CHAPTER_PAGE", $this->lng->txt('obj_st')); break; } $item_list_gui->setChildId($child); $tpl->setVariable("SEPERATOR", ' -> '); $tpl->setVariable("LINK", $item_list_gui->getCommandLink('page')); $tpl->setVariable("TARGET", $item_list_gui->getCommandFrame('page')); $tpl->setVariable("TITLE", ilLMObject::_lookupTitle($child)); $tpl->parseCurrentBlock(); } break; case 'frm': $tpl->setVariable("HITS", $this->lng->txt('search_hits')); include_once './Modules/Forum/classes/class.ilObjForum.php'; foreach ($item['child'] as $child) { $thread_post = explode('_', $child); $tpl->setCurrentBlock("link_row"); $tpl->setVariable("CHAPTER_PAGE", $this->lng->txt('thread')); $item_list_gui->setChildId($thread_post); $tpl->setVariable("SEPERATOR", ': '); $tpl->setVariable("LINK", $item_list_gui->getCommandLink('posting')); $tpl->setVariable("TARGET", $item_list_gui->getCommandFrame('')); $tpl->setVariable("TITLE", ilObjForum::_lookupThreadSubject($thread_post[0])); $tpl->parseCurrentBlock(); } break; case 'glo': $tpl->setVariable("HITS", $this->lng->txt('search_hits')); include_once './Modules/Glossary/classes/class.ilGlossaryTerm.php'; $this->lng->loadLanguageModule('content'); foreach ($item['child'] as $child) { $tpl->setCurrentBlock("link_row"); $tpl->setVariable("CHAPTER_PAGE", $this->lng->txt('cont_term')); $tpl->setVariable("SEPERATOR", ': '); $tpl->setVariable("LINK", ilLink::_getLink($item['ref_id'], 'git', array('target' => 'git_' . $child . '_' . $item['ref_id']))); $tpl->setVariable("TITLE", ilGlossaryTerm::_lookGlossaryTerm($child)); $tpl->parseCurrentBlock(); } break; case 'wiki': $tpl->setVariable("HITS", $this->lng->txt('search_hits')); include_once './Modules/Wiki/classes/class.ilWikiPage.php'; include_once './Modules/Wiki/classes/class.ilWikiUtil.php'; $this->lng->loadLanguageModule('wiki'); foreach ($item['child'] as $child) { $page_title = ilWikiPage::lookupTitle($child); $tpl->setCurrentBlock("link_row"); $tpl->setVariable("CHAPTER_PAGE", $this->lng->txt('wiki_page')); $tpl->setVariable("SEPERATOR", ': '); $tpl->setVariable("LINK", ilLink::_getLink($item['ref_id'], 'wiki', array(), "_" . ilWikiUtil::makeUrlTitle($page_title))); $tpl->setVariable("TITLE", $page_title); $tpl->parseCurrentBlock(); } break; case 'mcst': $tpl->setVariable("HITS", $this->lng->txt('search_hits')); include_once "./Services/News/classes/class.ilNewsItem.php"; foreach ($item['child'] as $child) { $tpl->setCurrentBlock("link_row"); //$tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('item')); $item_list_gui->setChildId($child); //$tpl->setVariable("SEPERATOR",': '); $tpl->setVariable("LINK", $item_list_gui->getCommandLink('listItems')); $tpl->setVariable("TARGET", $item_list_gui->getCommandFrame('')); $tpl->setVariable("TITLE", ilNewsItem::_lookupTitle($child)); $tpl->parseCurrentBlock(); } break; default: } return $html . $tpl->get(); }
/** * Clone forum moderator role * @access public * @param object $new_obj forum object */ public function cloneAutoGeneratedRoles($new_obj) { /** * @var $rbacadmin ilRbacAdmin * @var $ilLog ilLog */ global $ilLog, $rbacadmin; $moderator = ilObjForum::_lookupModeratorRole($this->getRefId()); $new_moderator = ilObjForum::_lookupModeratorRole($new_obj->getRefId()); if (!$moderator || !$new_moderator || !$this->getRefId() || !$new_obj->getRefId()) { $ilLog->write(__METHOD__ . ' : Error cloning auto generated role: il_frm_moderator'); } $rbacadmin->copyRolePermissions($moderator, $this->getRefId(), $new_obj->getRefId(), $new_moderator, true); $ilLog->write(__METHOD__ . ' : Finished copying of role il_frm_moderator.'); include_once './Modules/Forum/classes/class.ilForumModerators.php'; $obj_mods = new ilForumModerators($this->getRefId()); $old_mods = $obj_mods->getCurrentModerators(); foreach ($old_mods as $user_id) { // The object owner is already member of the moderator role when this method is called // Since the new static caches are introduced with ILIAS 5.0, a database error occurs if we try to assign the user here. if ($this->getOwner() != $user_id) { $rbacadmin->assignUser($new_moderator, $user_id); } } }
/** * delete post and sub-posts * @param integer $post: ID * @access public * @return integer 0 or thread-ID */ public function deletePost($post) { global $ilDB; include_once "./Modules/Forum/classes/class.ilObjForum.php"; // delete tree and get id's of all posts to delete $p_node = $this->getPostNode($post); $del_id = $this->deletePostTree($p_node); // Delete User read entries foreach ($del_id as $post_id) { ilObjForum::_deleteReadEntries($post_id); } // DELETE ATTACHMENTS ASSIGNED TO POST $this->__deletePostFiles($del_id); $dead_pos = count($del_id); $dead_thr = 0; // if deletePost is thread opener ... if ($p_node["parent"] == 0) { // delete thread access data include_once './Modules/Forum/classes/class.ilObjForum.php'; ilObjForum::_deleteAccessEntries($p_node['tree']); // delete thread $dead_thr = $p_node["tree"]; $statement = $ilDB->manipulateF(' DELETE FROM frm_threads WHERE thr_pk = %s', array('integer'), array($p_node['tree'])); // update num_threads $statement = $ilDB->manipulateF(' UPDATE frm_data SET top_num_threads = top_num_threads - 1 WHERE top_frm_fk = %s', array('integer'), array($this->id)); // delete all related news $posset = $ilDB->queryf(' SELECT * FROM frm_posts WHERE pos_thr_fk = %s', array('integer'), array($p_node['tree'])); while ($posrec = $ilDB->fetchAssoc($posset)) { include_once "./Services/News/classes/class.ilNewsItem.php"; $news_id = ilNewsItem::getFirstNewsIdForContext($this->id, "frm", $posrec["pos_pk"], "pos"); if ($news_id > 0) { $news_item = new ilNewsItem($news_id); $news_item->delete(); } try { include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php'; $mobs = ilObjMediaObject::_getMobsOfObject('frm:html', $posrec['pos_pk']); foreach ($mobs as $mob) { if (ilObjMediaObject::_exists($mob)) { ilObjMediaObject::_removeUsage($mob, 'frm:html', $posrec['pos_pk']); $mob_obj = new ilObjMediaObject($mob); $mob_obj->delete(); } } } catch (Exception $e) { } } // delete all posts of this thread $statement = $ilDB->manipulateF(' DELETE FROM frm_posts WHERE pos_thr_fk = %s', array('integer'), array($p_node['tree'])); } else { // delete this post and its sub-posts for ($i = 0; $i < $dead_pos; $i++) { $statement = $ilDB->manipulateF(' DELETE FROM frm_posts WHERE pos_pk = %s', array('integer'), array($del_id[$i])); // delete related news item include_once "./Services/News/classes/class.ilNewsItem.php"; $news_id = ilNewsItem::getFirstNewsIdForContext($this->id, "frm", $del_id[$i], "pos"); if ($news_id > 0) { $news_item = new ilNewsItem($news_id); $news_item->delete(); } try { include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php'; $mobs = ilObjMediaObject::_getMobsOfObject('frm:html', $del_id[$i]); foreach ($mobs as $mob) { if (ilObjMediaObject::_exists($mob)) { ilObjMediaObject::_removeUsage($mob, 'frm:html', $del_id[$i]); $mob_obj = new ilObjMediaObject($mob); $mob_obj->delete(); } } } catch (Exception $e) { } } // update num_posts in frm_threads $statement = $ilDB->manipulateF(' UPDATE frm_threads SET thr_num_posts = thr_num_posts - %s WHERE thr_pk = %s', array('integer', 'integer'), array($dead_pos, $p_node['tree'])); // get latest post of thread and update last_post $res1 = $ilDB->queryf(' SELECT * FROM frm_posts WHERE pos_thr_fk = %s ORDER BY pos_date DESC', array('integer'), array($p_node['tree'])); if ($res1->numRows() == 0) { $lastPost_thr = ""; } else { $z = 0; while ($selData = $ilDB->fetchAssoc($res1)) { if ($z > 0) { break; } $lastPost_thr = $selData["pos_top_fk"] . "#" . $selData["pos_thr_fk"] . "#" . $selData["pos_pk"]; $z++; } } $statement = $ilDB->manipulateF(' UPDATE frm_threads SET thr_last_post = %s WHERE thr_pk = %s', array('text', 'integer'), array($lastPost_thr, $p_node['tree'])); } // update num_posts in frm_data $statement = $ilDB->manipulateF(' UPDATE frm_data SET top_num_posts = top_num_posts - %s WHERE top_frm_fk = %s', array('integer', 'integer'), array($dead_pos, $this->id)); // get latest post of forum and update last_post $res2 = $ilDB->queryf(' SELECT * FROM frm_posts, frm_data WHERE pos_top_fk = top_pk AND top_frm_fk = %s ORDER BY pos_date DESC', array('integer'), array($this->id)); if ($res2->numRows() == 0) { $lastPost_top = ""; } else { $z = 0; while ($selData = $ilDB->fetchAssoc($res2)) { if ($z > 0) { break; } $lastPost_top = $selData["pos_top_fk"] . "#" . $selData["pos_thr_fk"] . "#" . $selData["pos_pk"]; $z++; } } $statement = $ilDB->manipulateF(' UPDATE frm_data SET top_last_post = %s WHERE top_frm_fk = %s', array('text', 'integer'), array($lastPost_top, $this->id)); return $dead_thr; }
/** * @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()); }