/** * Moves all chosen threads and their posts to a new forum * * @param array chosen thread pks * @param integer object id of src forum * @param integer object id of dest forum * @access public */ public function moveThreads($thread_ids = array(), $src_ref_id = 0, $dest_top_frm_fk = 0) { global $ilDB; $src_top_frm_fk = ilObject::_lookupObjectId($src_ref_id); if (is_numeric($src_top_frm_fk) && $src_top_frm_fk > 0 && is_numeric($dest_top_frm_fk) && $dest_top_frm_fk > 0) { $this->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($src_top_frm_fk)); $oldFrmData = $this->getOneTopic(); $this->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($dest_top_frm_fk)); $newFrmData = $this->getOneTopic(); if ($oldFrmData['top_pk'] && $newFrmData['top_pk']) { $moved_posts = 0; $moved_threads = 0; $visits = 0; foreach ($thread_ids as $id) { $objTmpThread = new ilForumTopic($id); $numPosts = $objTmpThread->movePosts($src_top_frm_fk, $oldFrmData['top_pk'], $dest_top_frm_fk, $newFrmData['top_pk']); if (($last_post_string = $objTmpThread->getLastPostString()) != '') { $last_post_string = explode('#', $last_post_string); $last_post_string[0] = $newFrmData['top_pk']; $last_post_string = implode('#', $last_post_string); $objTmpThread->setLastPostString($last_post_string); } $visits += $objTmpThread->getVisits(); $moved_posts += $numPosts; ++$moved_threads; $objTmpThread->setForumId($newFrmData['top_pk']); $objTmpThread->update(); unset($objTmpThread); } // update frm_data source forum $ilDB->setLimit(1); $res = $ilDB->queryf(' SELECT pos_thr_fk, pos_pk FROM frm_posts WHERE pos_top_fk = %s ORDER BY pos_date DESC', array('integer'), array($oldFrmData['top_pk'])); $row = $ilDB->fetchObject($res); $last_post_src = $oldFrmData['top_pk'] . '#' . $row->pos_thr_fk . '#' . $row->pos_pk; $statement = $ilDB->manipulateF(' UPDATE frm_data SET top_num_posts = top_num_posts - %s, top_num_threads = top_num_threads - %s, visits = visits - %s, top_last_post = %s WHERE top_pk = %s', array('integer', 'integer', 'integer', 'text', 'integer'), array($moved_posts, $moved_threads, $visits, $last_post_src, $oldFrmData['top_pk'])); // update frm_data destination forum $ilDB->setLimit(1); $res = $ilDB->queryf(' SELECT pos_thr_fk, pos_pk FROM frm_posts WHERE pos_top_fk = %s ORDER BY pos_date DESC', array('integer'), array($newFrmData['top_kp'])); $row = $ilDB->fetchObject($res); $last_post_dest = $newFrmData['top_pk'] . '#' . $row->pos_thr_fk . '#' . $row->pos_pk; $statement = $ilDB->manipulateF(' UPDATE frm_data SET top_num_posts = top_num_posts + %s, top_num_threads = top_num_threads + %s, visits = visits + %s, top_last_post = %s WHERE top_pk = %s', array('integer', 'integer', 'integer', 'text', 'integer'), array($moved_posts, $moved_threads, $visits, $last_post_dest, $newFrmData['top_pk'])); /* // update news items include_once("./Services/News/classes/class.ilNewsItem.php"); $objNewsItem = new ilNewsItem(); $news_items = $objNewsItem->getNewsForRefId($src_ref_id); foreach ($news_items as $news_item) { $tmpObjNewsItem = new ilNewsItem($news_item['id']); if ($tmpObjNewsItem->getContextObjId() == $src_top_frm_fk) { $tmpObjNewsItem->setContextObjId($dest_top_frm_fk); $tmpObjNewsItem->update(); } unset($tmpObjNewsItem); } */ } } }