/**
  * 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;
 }
Ejemplo n.º 2
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;
 }
 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']));
     }
 }
Ejemplo n.º 5
0
 /**
  * Clone Object
  * @param int $a_target_id
  * @param int $a_copy_id
  * @return object
  */
 public function cloneObject($a_target_id, $a_copy_id = 0)
 {
     /**
      * @var $ilDB ilDB
      */
     global $ilDB;
     $new_obj = parent::cloneObject($a_target_id, $a_copy_id);
     $this->cloneAutoGeneratedRoles($new_obj);
     ilForumProperties::getInstance($this->getId())->copy($new_obj->getId());
     $this->Forum->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($this->getId()));
     $topData = $this->Forum->getOneTopic();
     $nextId = $ilDB->nextId('frm_data');
     $statement = $ilDB->insert('frm_data', array('top_pk' => array('integer', $nextId), 'top_frm_fk' => array('integer', $new_obj->getId()), 'top_name' => array('text', $topData['top_name']), 'top_description' => array('text', $topData['top_description']), 'top_num_posts' => array('integer', $topData['top_num_posts']), 'top_num_threads' => array('integer', $topData['top_num_threads']), 'top_last_post' => array('text', $topData['top_last_post']), 'top_mods' => array('integer', !is_numeric($topData['top_mods']) ? 0 : $topData['top_mods']), 'top_date' => array('timestamp', $topData['top_date']), 'visits' => array('integer', $topData['visits']), 'top_update' => array('timestamp', $topData['top_update']), 'update_user' => array('integer', $topData['update_user']), 'top_usr_id' => array('integer', $topData['top_usr_id'])));
     // read options
     include_once 'Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
     $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
     $options = $cwo->getOptions($this->getRefId());
     $options['threads'] = $this->Forum->_getThreads($this->getId());
     // Generate starting threads
     include_once 'Modules/Forum/classes/class.ilFileDataForum.php';
     $new_frm = $new_obj->Forum;
     $new_frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($new_obj->getId()));
     $new_frm->setForumId($new_obj->getId());
     $new_frm->setForumRefId($new_obj->getRefId());
     $new_topic = $new_frm->getOneTopic();
     foreach ($options['threads'] as $thread_id => $thread_subject) {
         $this->Forum->setMDB2WhereCondition('thr_pk = %s ', array('integer'), array($thread_id));
         $old_thread = $this->Forum->getOneThread();
         $old_post_id = $this->Forum->getFirstPostByThread($old_thread['thr_pk']);
         $old_post = $this->Forum->getOnePost($old_post_id);
         // Now create new thread and first post
         $new_post = $new_frm->generateThread($new_topic['top_pk'], $old_thread['thr_usr_id'], $old_thread['thr_subject'], ilForum::_lookupPostMessage($old_post_id), $old_post['notify'], 0, $old_thread['thr_usr_alias'], $old_thread['thr_date']);
         // Copy attachments
         $old_forum_files = new ilFileDataForum($this->getId(), $old_post_id);
         $old_forum_files->ilClone($new_obj->getId(), $new_post);
     }
     return $new_obj;
 }
Ejemplo n.º 6
0
 /**
  * 
  */
 public function performMergeThreadsObject()
 {
     /**
      * @var $lng ilLanguage
      */
     global $lng;
     if (!$this->is_moderator) {
         $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
     }
     if (!isset($_POST['thread_ids']) || !is_array($_POST['thread_ids']) || count($_POST['thread_ids']) != 2) {
         ilUtil::sendFailure($this->lng->txt('select_one'));
         $this->showThreadsObject();
         return;
     }
     if ((int) $_POST['thread_ids'][0] == (int) $_POST['thread_ids'][1]) {
         ilUtil::sendFailure($this->lng->txt('error_same_thread_ids'));
         $this->showThreadsObject();
         return;
     }
     try {
         ilForum::mergeThreads($this->object->id, (int) $_POST['thread_ids'][0], (int) $_POST['thread_ids'][1]);
         ilUtil::sendSuccess($this->lng->txt('merged_threads_successfully'));
     } catch (ilException $e) {
         return ilUtil::sendFailure($lng->txt($e->getMessage()));
     }
     $this->showThreadsObject();
 }
 protected function sendMails($res)
 {
     global $ilAccess, $ilDB, $lng;
     static $cache = array();
     static $attachments_cache = array();
     include_once 'Modules/Forum/classes/class.ilObjForum.php';
     include_once 'Services/Mail/classes/class.ilMail.php';
     include_once 'Services/User/classes/class.ilObjUser.php';
     include_once 'Services/Language/classes/class.ilLanguage.php';
     $forumObj = new ilObjForum();
     $frm = $forumObj->Forum;
     $numRows = 0;
     $mail_obj = new ilMail(ANONYMOUS_USER_ID);
     $mail_obj->enableSOAP(false);
     while ($row = $ilDB->fetchAssoc($res)) {
         // don not send a notification to the post author
         if ($row['pos_display_user_id'] != $row['user_id']) {
             // GET AUTHOR OF NEW POST
             if ($row['pos_display_user_id']) {
                 $row['pos_usr_name'] = ilObjUser::_lookupLogin($row['pos_display_user_id']);
             } else {
                 if (strlen($row['pos_usr_alias'])) {
                     $row['pos_usr_name'] = $row['pos_usr_alias'] . ' (' . $lng->txt('frm_pseudonym') . ')';
                 }
             }
             if ($row['pos_usr_name'] == '') {
                 $row['pos_usr_name'] = $lng->txt('forums_anonymous');
             }
             // get all references of obj_id
             if (!isset($cache[$row['obj_id']])) {
                 $cache[$row['obj_id']] = ilObject::_getAllReferences($row['obj_id']);
             }
             // check for attachments
             $has_attachments = false;
             if (!isset($attachments_cache[$row['obj_id']][$row['pos_pk']])) {
                 $fileDataForum = new ilFileDataForum($row['obj_id'], $row['pos_pk']);
                 $filesOfPost = $fileDataForum->getFilesOfPost();
                 foreach ($filesOfPost as $attachment) {
                     $attachments_cache[$row['obj_id']][$row['pos_pk']][] = $attachment['name'];
                     $has_attachments = true;
                 }
             } else {
                 $has_attachments = true;
             }
             // do rbac check before sending notification
             $send_mail = false;
             foreach ((array) $cache[$row['obj_id']] as $ref_id) {
                 if ($ilAccess->checkAccessOfUser($row['user_id'], 'read', '', $ref_id)) {
                     $row['ref_id'] = $ref_id;
                     $send_mail = true;
                     break;
                 }
             }
             $attached_files = array();
             if ($has_attachments == true) {
                 $attached_files = $attachments_cache[$row['obj_id']][$row['pos_pk']];
             }
             if ($send_mail) {
                 $frm->setLanguage(ilForum::_getLanguageInstanceByUsrId($row['user_id']));
                 $mail_obj->sendMail(ilObjUser::_lookupLogin($row['user_id']), '', '', $frm->formatNotificationSubject($row), $frm->formatNotification($row, 1, $attached_files, $row['user_id']), array(), array('normal'));
                 $numRows++;
             }
         }
     }
     return $numRows;
 }
 public function cloneWizardPageObject()
 {
     global $ilObjDataCache;
     if (!$_POST['clone_source']) {
         ilUtil::sendInfo($this->lng->txt('select_one'));
         if (isset($_SESSION['wizard_search_title'])) {
             $this->searchCloneSourceObject();
         } else {
             $this->createObject();
         }
         return false;
     }
     $source_id = $_POST['clone_source'];
     $new_type = $_REQUEST['new_type'];
     $this->ctrl->setParameter($this, 'clone_source', (int) $_POST['clone_source']);
     $this->ctrl->setParameter($this, 'new_type', $new_type);
     $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.frm_wizard_page.html', 'Modules/Forum');
     $this->tpl->setVariable('FORMACTION', $this->ctrl->getFormAction($this));
     $this->tpl->setVariable('TYPE_IMG', ilUtil::getImagePath('icon_' . $new_type . '.png'));
     $this->tpl->setVariable('ALT_IMG', $this->lng->txt('obj_' . $new_type));
     $this->tpl->setVariable('TXT_DUPLICATE', $this->lng->txt('frm_wizard_page'));
     $this->tpl->setVariable('INFO_THREADS', $this->lng->txt('fmr_copy_threads_info'));
     $this->tpl->setVariable('THREADS', $this->lng->txt('forums_threads'));
     $forum_id = $ilObjDataCache->lookupObjId((int) $_POST['clone_source']);
     include_once 'Modules/Forum/classes/class.ilForum.php';
     $threads = ilForum::_getThreads($forum_id, ilForum::SORT_TITLE);
     foreach ($threads as $thread_id => $title) {
         $this->tpl->setCurrentBlock('thread_row');
         $this->tpl->setVariable('CHECK_THREAD', ilUtil::formCheckbox(0, 'cp_options[' . $source_id . '][threads][]', $thread_id));
         $this->tpl->setVariable('NAME_THREAD', $title);
         $this->tpl->parseCurrentBlock();
     }
     $this->tpl->setVariable('SELECT_ALL', $this->lng->txt('select_all'));
     $this->tpl->setVariable('JS_FIELD', 'cp_options[' . $source_id . '][threads]');
     $this->tpl->setVariable('BTN_COPY', $this->lng->txt('obj_' . $new_type . '_duplicate'));
     if (isset($_SESSION['wizard_search_title'])) {
         $this->tpl->setVariable('BACK_CMD', 'searchCloneSource');
     } else {
         $this->tpl->setVariable('BACK_CMD', 'create');
     }
     $this->tpl->setVariable('BTN_BACK', $this->lng->txt('btn_back'));
 }
Ejemplo n.º 9
0
 /**
  * checks whether a user is moderator of a given forum object
  * @static
  * @param	int		$a_ref_id	reference id
  * @param	int		$a_usr_id	user id
  * @return	bool
  * @access	public
  */
 public static function _isModerator($a_ref_id, $a_usr_id)
 {
     return in_array($a_usr_id, ilForum::_getModerators($a_ref_id));
 }
Ejemplo n.º 10
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());
 }
Ejemplo n.º 11
0
 /**
  * @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');
 }