/** * 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); }
/** * Delegate for rendering the page that allows the user to post a new topic to * the forum. * * @param Request $request the request. * @param SocialContextInterface $socialContext the social context. * @param mixed $category Optional. The category for the topic. */ public function createAction($request, SocialContextInterface $socialContext, $category = null) { /** @var $user \Symfony\Component\Security\Core\User\UserInterface */ $user = $this->getUser(); /** @var $topic \Rhapsody\SocialBundle\Model\TopicInterface */ $topic = $this->topicManager->newTopic($socialContext, $category); $formFactory = $this->topicManager->getFormFactory(); $form = $formFactory->create(); $form->setData($topic); $form->handleRequest($request); $data = $form->getData(); if (!$form->isValid()) { $view = View::create(array('socialContext' => $socialContext, 'category' => $category, 'topic' => $data, 'form' => $form->createView()))->setFormat($request->getRequestFormat('html'))->setSerializationContext(SerializationContext::create()->setGroups('context'))->setTemplate('RhapsodySocialBundle:Topic:new.html.twig'); throw FormExceptionFactory::create('The form is invalid.')->setForm($form)->setView($view)->build(); } $post = $form->get('post')->getData(); $topic = $this->topicManager->createTopic($data, $post, $user); $this->container->get('session')->getFlashBag()->add('success', 'rhapsody.forum.topic.created'); $view = RouteRedirectView::create('rhapsody_social_topic_view', array('topic' => $data->getId()))->setFormat($request->getRequestFormat('html')); $response = $this->createResponseBuilder($view); return array($topic, $post, $response); }