/** * 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; }