public function createTopic(TopicInterface $topic, PostInterface $post, $user)
 {
     $topic = parent::createTopic($topic, $post, $user);
     try {
         $topicEventBuilder = TopicEventBuilder::create()->setTopic($topic)->setPost($post)->setUser($user);
         $event = $topicEventBuilder->build();
         $this->eventDispatcher->dispatch(RhapsodyForumEvents::NEW_TOPIC, $event);
     } catch (\Exception $ex) {
         //$this->logger->error("An error occurred while trying ")
         throw $ex;
     }
     return $topic;
 }
 /**
  * Trigger an event upon viewing a topic.
  *
  * @param TopicInterface $topic the topic being viewed.
  * @param mixed $user the user viewing the event.
  * @param string $eventName the event name.
  */
 public function viewTopic(TopicInterface $topic, $user, $eventName = RhapsodySocialEvents::VIEW_TOPIC)
 {
     $topicEventBuilder = TopicEventBuilder::create()->setTopic($topic)->setUser($user);
     $event = $topicEventBuilder->build();
     $this->eventDispatcher->dispatch($eventName, $event);
 }
 /**
  * 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\ForumBundle\Model\ForumInterface $forum The forum.
  * @param mixed $category Optional. The category for the topic.
  */
 public function createAction(Request $request, TopicInterface $topic)
 {
     /** @var $postManager \Rhapsody\ForumBundle\Doctrine\PostManagerInterface */
     $postManager = $this->container->get('rhapsody.forum.doctrine.post_manager');
     /** @var $postManager \Rhapsody\SocialBundle\Doctrine\TopicManagerInterface */
     $topicManager = $this->container->get('rhapsody.forum.doctrine.topic_manager');
     /** @var $formFactory \Rhapsody\SocialBundle\Form\Factory\FactoryInterface */
     $formFactory = $this->container->get('rhapsody_forum.post.form.factory');
     /** @var $user \Symfony\Component\Security\Core\User\UserInterface */
     $user = $this->getUser();
     /** @var $topic \Rhapsody\SocialBundle\Model\TopicInterface */
     $post = $postManager->newPost($topic);
     $form = $formFactory->createForm();
     $form->setData($post);
     $form->handleRequest($request);
     $data = $form->getData();
     if (!$form->isValid()) {
         $view = View::create(array('forum' => $forum, 'topic' => $topic, 'post' => $data, 'form' => $form->createView()))->setFormat($request->getRequestFormat('html'))->setSerializationContext(SerializationContext::create()->setGroups('context'))->setTemplate('RhapsodyForumBundle:Topic:reply.html.twig');
         throw FormExceptionFactory::create('The form is invalid.')->setForm($form)->setView($view)->build();
     }
     $post = $postManager->createPost($data, $topic, $user);
     $topic->setLastUpdated($post->getCreated());
     $topic->setLastPost($data);
     $topicManager->update($topic);
     try {
         $topicEventBuilder = TopicEventBuilder::create()->setTopic($topic)->setPost($post)->setUser($post->author);
         $event = $topicEventBuilder->build();
         $eventDispatcher = $this->container->get('event_dispatcher');
         $eventDispatcher->dispatch(RhapsodyForumEvents::REPLY_TO_TOPIC, $event);
     } catch (\Exception $ex) {
         throw $ex;
     }
     $this->container->get('session')->getFlashBag()->add('success', 'rhapsody.forum.post.created');
     $view = RouteRedirectView::create('rhapsody_forum_topic_view', array('topic' => $topic->id, 'post' => $post->id))->setFormat($request->getRequestFormat('html'));
     return $this->createResponseBuilder($view);
 }