/** * Constructs a new forum post form view * @param ForumPostForm $form * @param unknown_type $title * @param unknown_type $preview * @return null */ public function __construct(ForumPostForm $form, $title = null, $preview = null) { $messageField = $form->getField(ForumPostForm::FIELD_MESSAGE); $emoticonParser = $messageField->getEmoticonParser(); parent::__construct(self::TEMPLATE); $this->set('form', $form); $this->set('title', $title); $this->set('preview', $preview); $this->set('emoticonParser', $emoticonParser); }
public function replyAction($idTopic, $idQuotePost = null) { $topic = $this->models[ForumTopicModel::NAME]->getTopic($idTopic); if (!$topic) { $this->setError404(); return; } $idProfile = null; $profile = $this->getProfile(); if ($profile) { $idProfile = $profile->id; } if (!$topic->board->isNewPostAllowed($profile)) { $this->addError(self::TRANSLATION_ERROR_ALLOW_VIEW, array('object' => $topic->board->name)); return; } $contentFacade = ContentFacade::getInstance(); $post = $this->models[ForumPostModel::NAME]->createData(false); $topicPost = $this->models[ForumPostModel::NAME]->getFirstPostForTopic($topic->id); $post->subject = 'RE: ' . $topicPost->subject; if ($idQuotePost) { $quotePost = $this->models[ForumPostModel::NAME]->findById($idQuotePost, 0); if ($quotePost) { $quotePost->topic = $topic; $quoteUrl = $contentFacade->getUrl(ForumPostModel::NAME, $quotePost); $post->message = '[quote=' . $quoteUrl . ']' . $quotePost->message . '[/quote]'; } } $emoticonParser = $this->models[ForumPostModel::NAME]->getEmoticonParser(); $form = new ForumPostForm($this->request->getBasePath() . '/' . self::ACTION_REPLY . '/' . $topic->id, $post, $emoticonParser); $preview = null; if ($form->isSubmitted()) { if ($form->isCancelled()) { $this->response->setRedirect($this->request->getBasePath() . '/' . self::ACTION_TOPIC . '/' . $topic->id); return; } try { $post = $form->getPost(); if ($form->isSubmitted()) { $post->author = $idProfile; $topic = $this->models[ForumTopicModel::NAME]->replyTopic($topic->id, $post); $post->topic = $topic; $this->response->setRedirect($contentFacade->getUrl(ForumPostModel::NAME, $post)); return; } elseif ($form->getValue(ForumPostForm::FIELD_PREVIEW)) { $preview = $post; } } catch (ValidationException $e) { $form->setValidationException($e); } } $translator = $this->getTranslator(); $board = $this->models[ForumBoardModel::NAME]->findById($topicPost->topic->board, 0); $category = $this->models[ForumCategoryModel::NAME]->findById($board->category, 0); $this->addBreadcrumb($this->request->getBasePath(), $category->name); $this->addBreadcrumb($this->request->getBasePath() . '/' . self::ACTION_BOARD . '/' . $board->id, $board->name); $this->addBreadcrumb($this->request->getBasePath() . '/' . self::ACTION_TOPIC . '/' . $topicPost->topic->id, $topicPost->subject); $this->addBreadcrumb($this->request->getBasePath() . '/' . self::ACTION_REPLY . '/' . $topicPost->topic->id, $translator->translate(self::TRANSLATION_TOPIC_REPLY)); $view = new ForumPostFormView($form, self::TRANSLATION_TOPIC_REPLY, $preview, $emoticonParser); $this->response->setView($view); }