/**
  * (non-PHPDoc)
  * @see Rhapsody\SocialBundle\Doctrine\TopicManagerInterface::update()
  */
 public function updateCounts(TopicInterface $topic)
 {
     $posts = $this->postManager->getPostCountByTopic($topic);
     $topic->setPostCount($posts);
     $topic->setReplyCount($posts - 1);
     $this->update($topic);
 }
 /**
  *
  * @param Request $request The request.
  * @param TopicInterface $topic The topic.
  */
 public function viewAction(Request $request, TopicInterface $topic, $pageSize = 10)
 {
     /** @var $paginator \Knp\Components\Pager\Paginator */
     $paginator = $this->get('knp_paginator');
     $page = $request->query->get('page', 1);
     $posts = $this->postManager->findAllByTopic($topic);
     $paginatedPosts = $paginator->paginate($posts, $page, $pageSize);
     $view = View::create(array('topic' => $topic, 'page' => $page, 'posts' => $paginatedPosts))->setFormat($request->getRequestFormat('html'))->setSerializationContext(SerializationContext::create()->setGroups('context'))->setTemplate('LorecallChronicleBundle:Topic:view.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);
 }