/**
  * Sets a post as solution
  *
  * @param Post $post The post to be marked as solution.
  *
  * @throws NoAccessException
  */
 public function solutionAction(Post $post)
 {
     if (!$post->getTopic()->checkSolutionAccess($this->authenticationService->getUser())) {
         throw new NoAccessException('Not allowed to set solution by current user.');
     }
     $this->topicFactory->setPostAsSolution($post->getTopic(), $post);
     $this->redirect('show', 'Topic', NULL, array('topic' => $post->getTopic()));
 }
 /**
  * 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()));
 }
 /**
  * Gets the topic to which the reported post belongs to.
  * @return \Mittwald\Typo3Forum\Domain\Model\Forum\Topic The topic.
  */
 public function getTopic()
 {
     return $this->post->getTopic();
 }
 /**
  *
  * Deletes a post and decreases the user's post count by 1.
  *
  * @param Post $post
  */
 public function deletePost(Post $post)
 {
     $topic = $post->getTopic();
     // If the post is the only one in the topic, delete the whole topic instead of
     // this single post. Empty topics are not allowed.
     if ($topic->getPostCount() === 1) {
         $this->topicFactory->deleteTopic($topic);
     } else {
         $post->getAuthor()->decreasePostCount();
         $post->getAuthor()->decreasePoints((int) $this->settings['rankScore']['newPost']);
         $this->frontendUserRepository->update($post->getAuthor());
         $topic->removePost($post);
         $this->topicRepository->update($topic);
     }
 }