Ejemplo n.º 1
0
 /**
  * Creates a new topic.
  *
  * @param Forum $forum The forum in which the new topic is to be created.
  * @param Post $post The first post of the new topic.
  * @param string $subject The subject of the new topic
  * @param array $attachments File attachments for the post.
  * @param string $question The flag if the new topic is declared as question
  * @param array $criteria All submitted criteria with option.
  * @param string $tags All defined tags for this topic
  * @param string $subscribe The flag if the new topic is subscribed by author
  *
  * @validate $post \Mittwald\Typo3Forum\Domain\Validator\Forum\PostValidator
  * @validate $attachments \Mittwald\Typo3Forum\Domain\Validator\Forum\AttachmentPlainValidator
  * @validate $subject NotEmpty
  */
 public function createAction(Forum $forum, Post $post, $subject, $attachments = array(), $question = '', $criteria = array(), $tags = '', $subscribe = '')
 {
     // Assert authorization
     $this->authenticationService->assertNewTopicAuthorization($forum);
     // Create the new post; add the new post to a new topic and add the new
     // topic to the forum. Then persist the forum object. Not as complicated
     // as is sounds, honestly!
     $this->postFactory->assignUserToPost($post);
     if (!empty($attachments)) {
         $attachments = $this->attachmentService->initAttachments($attachments);
         $post->setAttachments($attachments);
     }
     if ($tags) {
         $tags = $this->tagService->initTags($tags);
         foreach ($tags as $tag) {
             if ($tag->getUid === NULL) {
                 $this->tagRepository->add($tag);
             }
         }
     } else {
         $tags = NULL;
     }
     $topic = $this->topicFactory->createTopic($forum, $post, $subject, (int) $question, $criteria, $tags, (int) $subscribe);
     // Notify potential listeners.
     $this->signalSlotDispatcher->dispatch('Mittwald\\Typo3Forum\\Domain\\Model\\Forum\\Topic', 'topicCreated', ['topic' => $topic]);
     $this->clearCacheForCurrentPage();
     $uriBuilder = $this->controllerContext->getUriBuilder();
     $uri = $uriBuilder->setTargetPageUid($this->settings['pids']['Forum'])->setArguments(array('tx_typo3forum_pi1[forum]' => $forum->getUid(), 'tx_typo3forum_pi1[controller]' => 'Forum', 'tx_typo3forum_pi1[action]' => 'show'))->build();
     $this->purgeUrl('http://' . $_SERVER['HTTP_HOST'] . '/' . $uri);
     // Redirect to single forum display view
     $this->redirect('show', 'Forum', NULL, array('forum' => $forum));
 }
Ejemplo n.º 2
0
 /**
  * Updates a post.
  *
  * @param Post $post The post that is to be updated.
  * @param array $attachments File attachments for the post.
  *
  * @return void
  */
 public function updateAction(Post $post, array $attachments = array())
 {
     if ($post->getAuthor() != $this->authenticationService->getUser() || $post->getTopic()->getLastPost()->getAuthor() != $post->getAuthor()) {
         // Assert authorization
         $this->authenticationService->assertModerationAuthorization($post->getTopic()->getForum());
     }
     if (!empty($attachments)) {
         $attachments = $this->attachmentService->initAttachments($attachments);
         foreach ($attachments as $attachment) {
             $post->addAttachments($attachment);
         }
     }
     $this->postRepository->update($post);
     $this->signalSlotDispatcher->dispatch('Mittwald\\Typo3Forum\\Domain\\Model\\Forum\\Post', 'postUpdated', array('post' => $post));
     $this->controllerContext->getFlashMessageQueue()->enqueue(new FlashMessage(Localization::translate('Post_Update_Success')));
     $this->clearCacheForCurrentPage();
     $this->redirect('show', 'Topic', NULL, array('topic' => $post->getTopic()));
 }