예제 #1
0
 public function addThreadObject($a_prevent_redirect = false)
 {
     /**
      * @var $ilUser ilObjUser
      * @var $ilAccess ilAccessHandler
      * @var $lng ilLanguage
      */
     global $ilUser, $ilAccess, $lng;
     $frm = $this->object->Forum;
     $frm->setForumId($this->object->getId());
     $frm->setForumRefId($this->object->getRefId());
     if (!$ilAccess->checkAccess('add_thread', '', $this->object->getRefId())) {
         $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
     }
     $frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
     $topicData = $frm->getOneTopic();
     $this->initTopicCreateForm();
     if ($this->create_topic_form_gui->checkInput()) {
         require_once 'Services/Captcha/classes/class.ilCaptchaUtil.php';
         if ($ilUser->isAnonymous() && !$ilUser->isCaptchaVerified() && ilCaptchaUtil::isActiveForForum()) {
             $ilUser->setCaptchaVerified(true);
         }
         if ($this->objProperties->isAnonymized()) {
             if (!strlen($this->create_topic_form_gui->getInput('alias'))) {
                 $user_alias = $this->lng->txt('forums_anonymous');
             } else {
                 $user_alias = $this->create_topic_form_gui->getInput('alias');
             }
         } else {
             $user_alias = $ilUser->getLogin();
         }
         $status = 1;
         if ($this->objProperties->isPostActivationEnabled() && !$this->is_moderator || $this->objCurrentPost->isAnyParentDeactivated()) {
             $status = 0;
         }
         // build new thread
         $newPost = $frm->generateThread($topicData['top_pk'], $ilUser->getId(), $this->objProperties->isAnonymized() ? 0 : $ilUser->getId(), $this->handleFormInput($this->create_topic_form_gui->getInput('subject'), false), ilRTE::_replaceMediaObjectImageSrc($this->create_topic_form_gui->getInput('message'), 0), $this->create_topic_form_gui->getItemByPostVar('notify') ? (int) $this->create_topic_form_gui->getInput('notify') : 0, $this->create_topic_form_gui->getItemByPostVar('notify_posts') ? (int) $this->create_topic_form_gui->getInput('notify_posts') : 0, $user_alias, '', $status);
         $file = $_FILES['userfile'];
         // file upload
         if (is_array($file) && !empty($file)) {
             $tmp_file_obj = new ilFileDataForum($this->object->getId(), $newPost);
             $tmp_file_obj->storeUploadedFile($file);
         }
         // Visit-Counter
         $frm->setDbTable('frm_data');
         $frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($topicData['top_pk']));
         $frm->updateVisits($topicData['top_pk']);
         $frm->setMDB2WhereCondition('thr_top_fk = %s AND thr_subject = %s AND thr_num_posts = 1 ', array('integer', 'text'), array($topicData['top_pk'], $this->create_topic_form_gui->getInput('subject')));
         // copy temporary media objects (frm~)
         include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
         $mediaObjects = ilRTE::_getMediaObjects($this->create_topic_form_gui->getInput('message'), 0);
         foreach ($mediaObjects as $mob) {
             if (ilObjMediaObject::_exists($mob)) {
                 ilObjMediaObject::_removeUsage($mob, 'frm~:html', $ilUser->getId());
                 ilObjMediaObject::_saveUsage($mob, 'frm:html', $newPost);
             }
         }
         if ($this->ilias->getSetting('forum_notification') == 1) {
             // send notification about new topic
             $objPost = new ilForumPost((int) $newPost, $this->is_moderator);
             $post_data = array();
             $post_data = $objPost->getDataAsArray();
             $titles = $this->getTitlesByRefId(array($this->object->getRefId()));
             $post_data["top_name"] = $titles[0];
             $post_data["ref_id"] = $this->object->getRefId();
             $frm->sendForumNotifications($post_data);
         }
         if (!$a_prevent_redirect) {
             ilUtil::sendSuccess($this->lng->txt('forums_thread_new_entry'), true);
             $this->ctrl->redirect($this);
         } else {
             return $newPost;
         }
     } else {
         $this->create_topic_form_gui->setValuesByPost();
         if (!$this->objProperties->isAnonymized()) {
             $this->create_topic_form_gui->getItemByPostVar('alias')->setValue($ilUser->getLogin());
         }
         return $this->tpl->setContent($this->create_topic_form_gui->getHTML());
     }
 }
예제 #2
0
    /**
     * generate new dataset in frm_posts
     * @param	integer	$topic
     * @param	integer	$thread
     * @param	integer	$user
     * @param	string	$message	
     * @param	integer	$parent_pos	
     * @param	integer	$notify	
     * @param	integer	$anonymize	
     * @param	string	$subject	
     * @param	datetime	$date	
     * @return	integer	$lastInsert: new post ID
     * @access	public
     */
    public function generatePost($forum_id, $thread_id, $user, $message, $parent_pos, $notify, $subject = '', $alias = '', $date = '', $status = 1, $send_activation_mail = 0)
    {
        global $ilUser, $ilDB;
        $objNewPost = new ilForumPost();
        $objNewPost->setForumId($forum_id);
        $objNewPost->setThreadId($thread_id);
        $objNewPost->setSubject($subject);
        $objNewPost->setMessage($message);
        $objNewPost->setUserId($user);
        $objNewPost->setUserAlias($alias);
        if ($date == "") {
            $objNewPost->setCreateDate(date("Y-m-d H:i:s"));
        } else {
            if (strpos($date, "-") > 0) {
                $objNewPost->setCreateDate($date);
            } else {
                $objNewPost->setCreateDate(date("Y-m-d H:i:s", $date));
            }
        }
        $objNewPost->setImportName($this->getImportName());
        $objNewPost->setNotification($notify);
        $objNewPost->setStatus($status);
        $objNewPost->insert();
        // entry in tree-table
        if ($parent_pos == 0) {
            $this->addPostTree($objNewPost->getThreadId(), $objNewPost->getId(), $objNewPost->getCreateDate());
        } else {
            $this->insertPostNode($objNewPost->getId(), $parent_pos, $objNewPost->getThreadId(), $objNewPost->getCreateDate());
        }
        //echo "<br>->".$objNewPost->getId()."-".$parent_pos."-".$objNewPost->getThreadId()."-".
        //	$objNewPost->getCreateDate()."-".$forum_id."-".$message."-".$user."-";
        // string last post
        $lastPost = $objNewPost->getForumId() . "#" . $objNewPost->getThreadId() . "#" . $objNewPost->getId();
        // update thread
        $result = $ilDB->manipulateF('
			UPDATE frm_threads 
			SET thr_num_posts = thr_num_posts + 1,
				thr_last_post = %s
			WHERE thr_pk = %s', array('text', 'integer'), array($lastPost, $objNewPost->getThreadId()));
        // update forum
        $result = $ilDB->manipulateF('
			UPDATE frm_data 
			SET top_num_posts = top_num_posts + 1,
			 	top_last_post = %s
			WHERE top_pk = %s', array('text', 'integer'), array($lastPost, $objNewPost->getForumId()));
        // MARK READ
        $forum_obj = ilObjectFactory::getInstanceByRefId($this->getForumRefId());
        $forum_obj->markPostRead($objNewPost->getUserId(), $objNewPost->getThreadId(), $objNewPost->getId());
        $pos_data = $objNewPost->getDataAsArray();
        $pos_data["ref_id"] = $this->getForumRefId();
        // Send notification to moderators if they have to enable a post
        if (!$status && $send_activation_mail) {
            $pos_data["top_name"] = $forum_obj->getTitle();
            $this->sendPostActivationNotification($pos_data);
        }
        // Add Notification to news
        if ($status) {
            require_once 'Services/RTE/classes/class.ilRTE.php';
            include_once "./Services/News/classes/class.ilNewsItem.php";
            $news_item = new ilNewsItem();
            $news_item->setContext($forum_obj->getId(), 'frm', $objNewPost->getId(), 'pos');
            $news_item->setPriority(NEWS_NOTICE);
            $news_item->setTitle($objNewPost->getSubject());
            $news_item->setContent(ilRTE::_replaceMediaObjectImageSrc($this->prepareText($objNewPost->getMessage(), 0), 1));
            $news_item->setUserId($user);
            $news_item->setVisibility(NEWS_USERS);
            $news_item->create();
        }
        return $objNewPost->getId();
    }