/** * 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 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); }