Esempio n. 1
0
    /**
     * Moves all posts within the current thread to a new forum
     * 
     * @param    integer 	$old_obj_id object id of the current forum
     * @param    integer 	$old_pk		primary key of old forum
     * @param    integer 	$new_obj_id	object id of the new forum
     * @param    integer 	$new_pk		primary key of new forum
     * @return	integer 	number of afffected rows by updating posts
     * @access	public
     */
    public function movePosts($old_obj_id, $old_pk, $new_obj_id, $new_pk)
    {
        global $ilDB;
        if ($this->id) {
            $nodes = $this->getAllPosts();
            if (is_array($nodes)) {
                // Move attachments
                foreach ($nodes as $node) {
                    $file_obj = new ilFileDataForum((int) $old_obj_id, (int) $node->pos_pk);
                    $file_obj->moveFilesOfPost((int) $new_obj_id);
                    unset($file_obj);
                }
            }
            $this->db->lockTables(array(0 => array('name' => 'frm_user_read', 'type' => ilDB::LOCK_WRITE), 1 => array('name' => 'frm_thread_access', 'type' => ilDB::LOCK_WRITE)));
            $this->db->manipulateF('
				DELETE FROM frm_user_read
				WHERE obj_id = %s AND thread_id =%s', array('integer', 'integer'), array($new_obj_id, $this->id));
            $this->db->manipulateF('
				UPDATE frm_user_read
				SET obj_id = %s
				WHERE thread_id = %s', array('integer', 'integer'), array($new_obj_id, $this->id));
            $this->db->manipulateF('
				DELETE FROM frm_thread_access
				WHERE obj_id = %s AND thread_id =%s', array('integer', 'integer'), array($new_obj_id, $this->id));
            $this->db->manipulateF('
				UPDATE frm_thread_access
				SET obj_id = %s
				WHERE thread_id =%s', array('integer', 'integer'), array($new_obj_id, $this->id));
            $this->db->unlockTables();
            $this->db->manipulateF('
				UPDATE frm_posts
				SET pos_top_fk = %s
				WHERE pos_thr_fk = %s', array('integer', 'integer'), array($new_pk, $this->id));
            // update all related news
            $posts = $ilDB->queryf('
				SELECT * FROM frm_posts WHERE pos_thr_fk = %s', array('integer'), array($this->id));
            $old_obj_id = ilForum::_lookupObjIdForForumId($old_pk);
            $new_obj_id = ilForum::_lookupObjIdForForumId($new_pk);
            while ($post = $posts->fetchRow(DB_FETCHMODE_ASSOC)) {
                include_once "./Services/News/classes/class.ilNewsItem.php";
                $news_id = ilNewsItem::getFirstNewsIdForContext($old_obj_id, "frm", $post["pos_pk"], "pos");
                $news_item = new ilNewsItem($news_id);
                $news_item->setContextObjId($new_obj_id);
                $news_item->update();
                //echo "<br>-".$post["pos_pk"]."-".$old_obj_id."-".$new_obj_id."-";
            }
            return count($nodes);
        }
        return 0;
    }
 /**
  * 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;
 }
 /**
  * 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;
 }
Esempio n. 4
0
 /**
  * 
  */
 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;
         }
     }
 }