Ejemplo n.º 1
1
 /**
  * Create a new resource
  *
  * @param Request $request
  * @return View view instance
  *
  * @ApiDoc()
  */
 public function postArticlesAction(Request $request)
 {
     $form = $this->getForm();
     $form->bind($request);
     if ($form->isValid()) {
         // Note: use LiipCacheControlBundle to automatically move this flash message to a cookie
         $this->get('session')->setFlash('article', 'Article is stored at path: ' . $form->getData()->getPath());
         // Note: normally one would likely create/update something in the database
         // and/or send an email and finally redirect to the newly created or updated resource url
         $view = RouteRedirectView::create('hello', array('name' => $form->getData()->getTitle()));
     } else {
         $view = View::create($form);
         $view->setTemplate('LiipHelloBundle:Rest:postArticles.html.twig');
     }
     // Note: this would normally not be necessary, just a "hack" to make the format selectable in the form
     $view->setFormat($form->getData()->format);
     return $this->get('fos_rest.view_handler')->handle($view);
 }
Ejemplo n.º 2
0
 public function indexAction($name = null)
 {
     if (!$name) {
         $view = RouteRedirectView::create('_welcome');
     } else {
         $view = View::create(array('name' => $name))->setTemplate(new TemplateReference('LiipHelloBundle', 'Hello', 'index'));
     }
     return $this->viewHandler->handle($view);
 }
Ejemplo n.º 3
0
 public function testSetRoute()
 {
     $routeName = 'users';
     $view = RouteRedirectView::create($routeName);
     $this->assertAttributeEquals($routeName, 'route', $view);
     $this->assertAttributeEquals(null, 'location', $view);
     $this->assertEquals(Codes::HTTP_CREATED, $view->getResponse()->getStatusCode());
     $view->setLocation($routeName);
     $this->assertAttributeEquals($routeName, 'location', $view);
     $this->assertAttributeEquals(null, 'route', $view);
     $view = new View();
     $route = 'route';
     $view->setRoute($route);
     $this->assertEquals($route, $view->getRoute());
 }
Ejemplo n.º 4
0
 /**
  * @Route("", name="post_todo_list")
  * @Method({"POST"})
  * @Rest\View()
  * @ApiDoc
  */
 public function postTodoListAction()
 {
     $data = $this->getRequest()->request;
     $todoList = new TodoList();
     $todoList->setTitle($data->get('title'));
     $em = $this->get('doctrine')->getManager();
     $em->persist($todoList);
     $em->flush();
     // creating the ACL
     $aclProvider = $this->get('security.acl.provider');
     $acl = $aclProvider->createAcl(ObjectIdentity::fromDomainObject($todoList));
     // retrieving the security identity of the currently logged-in user
     $securityContext = $this->get('security.context');
     $securityIdentity = UserSecurityIdentity::fromAccount($securityContext->getToken()->getUser());
     // grant owner access
     $acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_OWNER);
     $aclProvider->updateAcl($acl);
     return RouteRedirectView::create('get_todo', array('id' => $todoList->getId()), HttpCodes::HTTP_CREATED);
 }
Ejemplo n.º 5
0
 /**
  * Forwards the action to the comment view on a successful form submission.
  *
  * @param FormInterface $form Comment delete form
  * @param integer       $id   Thread id
  *
  * @return View
  */
 protected function onRemoveThreadCommentSuccess(FormInterface $form, $id)
 {
     return RouteRedirectView::create('fos_comment_get_thread_comment', array('id' => $id, 'commentId' => $form->getData()->getId()));
 }
Ejemplo n.º 6
0
 /**
  * @Route("", name="add_widget")
  * @Method({"POST"})
  * @ApiDoc
  */
 public function postWidgetAction()
 {
     $data = $this->getRequest()->request;
     $em = $this->get('doctrine')->getManager();
     $widget = new Widget($data->get('identifier'), $data->get('title'), $data->get('description'), $data->get('title'));
     $widget->setWorkspace($em->getRepository('CorujaPlesyndBundle:Workspace')->findOneBy(array('id' => $data->get('workspace_id'))));
     $widget->setIsOfflineCompatible($data->get('is_offline_compatible'));
     $em->flush();
     // creating the ACL
     $aclProvider = $this->get('security.acl.provider');
     $acl = $aclProvider->createAcl(ObjectIdentity::fromDomainObject($widget));
     // retrieving the security identity of the currently logged-in user
     $securityContext = $this->get('security.context');
     $securityIdentity = UserSecurityIdentity::fromAccount($securityContext->getToken()->getUser());
     // grant owner access
     $acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_OWNER);
     $aclProvider->updateAcl($acl);
     return RouteRedirectView::create('get_widget', array('id' => $widget->getId()), HttpCodes::HTTP_CREATED);
 }
Ejemplo n.º 7
0
 /**
  * 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 saveAction(Request $request, TopicInterface $topic, PostInterface $post)
 {
     /** @var $postManager \Rhapsody\ForumBundle\Doctrine\PostManagerInterface */
     $postManager = $this->container->get('rhapsody.forum.doctrine.post_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 */
     $form = $formFactory->createForm();
     $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('RhapsodyForumBundle:Topic:reply.html.twig');
         throw FormExceptionFactory::create('The form is invalid.')->setForm($form)->setView($view)->build();
     }
     $data->editCount += 1;
     $data->lastUpdated = new \DateTime();
     $postManager->update($data);
     $this->container->get('session')->getFlashBag()->add('success', 'rhapsody.forum.post.created');
     $view = RouteRedirectView::create('rhapsody_forum_topic_view', array('topic' => $topic->id, 'post' => $data->id))->setFormat($request->getRequestFormat('html'));
     return $this->createResponseBuilder($view);
 }
Ejemplo n.º 8
0
 /**
  * Create a Route Redirect View
  *
  * Convenience method to allow for a fluent interface.
  *
  * @param string  $route
  * @param mixed   $parameters
  * @param integer $statusCode
  * @param array   $headers
  *
  * @return View
  */
 protected function routeRedirectView($route, array $parameters = array(), $statusCode = Codes::HTTP_CREATED, array $headers = array())
 {
     return RouteRedirectView::create($route, $parameters, $statusCode, $headers);
 }
 /**
  * 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);
 }