/**
  * Delegate for rendering the page that allows a user to create a new post
  * within a topic.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request The request.
  * @param \Rhapsody\SocialBundle\Model\TopicInterface $topic the topic.
  * @return array an array of responses composed of the <code>$topic</code>,
  *     <code>$post</code>, and the <code>$response</code>.
  */
 public function createAction(Request $request, TopicInterface $topic)
 {
     /** @var $user \Symfony\Component\Security\Core\User\UserInterface */
     $user = $this->getUser();
     /** @var $topic \Rhapsody\SocialBundle\Model\TopicInterface */
     $post = $this->postManager->newPost($topic);
     $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();
     }
     $post = $this->postManager->createPost($data, $topic, $user);
     $topic->setLastUpdated($post->getCreated());
     $topic->setLastPost($data);
     $this->topicManager->update($topic);
     $message = $this->get('translator')->trans('rhapsody.social.post.created', array(), 'RhapsodySocialBundle');
     $this->container->get('session')->getFlashBag()->add('success', $message);
     $view = RouteRedirectView::create('rhapsody_social_topic_view', array('topic' => $topic->id, 'post' => $post->id))->setFormat($request->getRequestFormat('html'));
     $response = $this->createResponseBuilder($view);
     return array($topic, $post, $response);
 }
 /**
  * Delegate for posting a new topic to the forum.
  *
  * @param Request $request The request.
  * @param SocialContextInterface $forum The social context.
  */
 public function newAction(Request $request, SocialContextInterface $socialContext)
 {
     /** @var $topic \Rhapsody\SocialBundle\Model\TopicInterface */
     $topic = $this->topicManager->newTopic($socialContext);
     $formFactory = $this->topicManager->getFormFactory();
     $form = $formFactory->create();
     $form->setData($topic);
     $view = View::create(array('socialContext' => $socialContext, 'topic' => $topic, 'form' => $form->createView()))->setFormat($request->getRequestFormat('html'))->setSerializationContext(SerializationContext::create()->setGroups('context'))->setTemplate('RhapsodySocialBundle:Topic:new.html.twig');
     $response = $this->createResponseBuilder($view);
     return array($topic, $response);
 }
 /**
  * React to topic viewing by updating the view count.
  *
  * @param TopicEventInterface $event
  */
 public function onViewTopic(TopicEventInterface $event)
 {
     $topic = $event->getTopic();
     $user = $event->getUser();
     $this->topicManager->markTopicAsViewed($topic, $user);
 }