/**
  * Delegate for posting a reply to a topic in a forum.
  *
  * @param Request $request The request.
  * @param SocialContextInterface $forum The social context.
  * @param TopicInterface $topic The topic.
  * @param PostInterface $post
  */
 public function replyAction(Request $request, SocialContextInterface $socialContext, TopicInterface $topic, $post = null)
 {
     /** @var $post \Rhapsody\SocialBundle\Model\PostInterface */
     $reply = $this->postManager->newPost($topic);
     if ($request->query->getBoolean('quote', false)) {
         $reply->text = $this->postManager->quoteText($post);
     }
     $formFactory = $this->postManager->getFormFactory();
     $form = $formFactory->create();
     $form->setData($reply);
     $posts = $this->postManager->findRecentByTopic($topic);
     $view = View::create(array('socialContext' => $socialContext, 'topic' => $topic, 'post' => $reply, 'posts' => $posts, 'form' => $form->createView()))->setFormat($request->getRequestFormat('html'))->setSerializationContext(SerializationContext::create()->setGroups('context'))->setTemplate('RhapsodySocialBundle:Topic:reply.html.twig');
     $response = $this->createResponseBuilder($view);
     return array($topic, $response);
 }
 /**
  * Delegate for rendering the page that allows the user to post a new topic to
  * the forum.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request The request.
  * @param \Rhapsody\SocialBundle\Model\TopicInterface $topic the topic.
  * @param \Rhapsody\SocialBundle\Model\PostInterface $post the post.
  * @return array an array tuple of the <code>$topic</code> the updated
  *     <code>$post</code> and the <code>$response</code>
  */
 public function updateAction(Request $request, TopicInterface $topic, PostInterface $post)
 {
     /** @var $user \Symfony\Component\Security\Core\User\UserInterface */
     $user = $this->getUser();
     $formFactory = $this->postManager->getFormFactory();
     $form = $formFactory->create();
     $form->setData($post);
     $form->handleRequest($request);
     $data = $form->getData();
     if (!$form->isValid()) {
         $view = View::create(array('topic' => $topic, 'post' => $data, 'form' => $form->createView()))->setFormat($request->getRequestFormat('html'))->setSerializationContext(SerializationContext::create()->setGroups('context'))->setTemplate('RhapsodySocialBundle:Topic:reply.html.twig');
         throw FormExceptionFactory::create('The form is invalid.')->setForm($form)->setView($view)->build();
     }
     $data->editCount += 1;
     $data->lastUpdated = new \DateTime();
     $this->postManager->update($data);
     $view = RouteRedirectView::create('rhapsody_forum_topic_view', array('topic' => $topic->id, 'post' => $data->id))->setFormat($request->getRequestFormat('html'));
     $response = $this->createResponseBuilder($view);
     return array($topic, $data, $response);
 }