예제 #1
0
 /**
  * {@inheritDoc}
  */
 public function load($id = 0)
 {
     $this->content = $this->contentManager->getRepository()->find($id);
     if (!$this->content) {
         throw $this->createNotFoundException('No content found for id ' . $id);
     }
     $this->setTemplate($this->content->getTemplate());
     return $this;
 }
예제 #2
0
 /**
  * View a single content page
  *
  * This Controller action is being routed to from either our custom ContentRouter,
  * or the ExceptionController.
  * @see Opifer\SiteBundle\Router\ContentRouter
  *
  * @param Request          $request
  * @param ContentInterface $content
  * @param int              $statusCode
  *
  * @return Response
  *
  * @throws \Exception
  */
 public function viewAction(Request $request, ContentInterface $content, $statusCode = 200)
 {
     $version = $request->query->get('_version');
     $debug = $this->getParameter('kernel.debug');
     $contentDate = $content->getUpdatedAt();
     $templateDate = $content->getTemplate()->getUpdatedAt();
     $date = $contentDate > $templateDate ? $contentDate : $templateDate;
     $response = new Response();
     $response->setLastModified($date);
     $response->setPublic();
     if (null === $version && false == $debug && $response->isNotModified($request)) {
         // return the 304 Response immediately
         return $response;
     }
     $version = $request->query->get('_version');
     /** @var Environment $environment */
     $environment = $this->get('opifer.content.block_environment');
     $environment->setObject($content);
     $response->setStatusCode($statusCode);
     if (null !== $version && $this->isGranted('ROLE_ADMIN')) {
         $environment->setDraft(true);
     }
     $environment->load();
     return $this->render($environment->getView(), $environment->getViewParameters(), $response);
 }
 /**
  * View a single content page
  *
  * This Controller action is being routed to from either our custom ContentRouter,
  * or the ExceptionController.
  * @see Opifer\SiteBundle\Router\ContentRouter
  *
  * @param Request $request
  * @param Content $content
  *
  * @return Response
  */
 public function viewAction(Request $request, ContentInterface $content, $statusCode = 200)
 {
     $presentation = json_decode($content->getRealPresentation(), true);
     if (!$presentation) {
         throw new \Exception('The template ' . $content->getTemplate()->getName() . ' does not have a layout attached.');
     }
     $layout = json_encode($presentation);
     $layout = $this->get('jms_serializer')->deserialize($layout, $this->container->getParameter('opifer_content.layout_class'), 'json');
     // If the layout has an action, forward to that action and pass the layout
     // and the content.
     if ($layout->getAction()) {
         return $this->forward($layout->getAction(), ['content' => $content, 'layout' => $layout]);
     }
     $response = new Response();
     $response->setStatusCode($statusCode);
     return $this->render($layout->getFilename(), ['content' => $content, 'layout' => $layout], $response);
 }
예제 #4
0
 /**
  * View a single content page
  *
  * This Controller action is being routed to from either our custom ContentRouter,
  * or the ExceptionController.
  * @see Opifer\SiteBundle\Router\ContentRouter
  *
  * @param Request          $request
  * @param ContentInterface $content
  * @param int              $statusCode
  *
  * @return Response
  *
  * @throws \Exception
  */
 public function viewAction(Request $request, ContentInterface $content, $statusCode = 200)
 {
     $version = $request->query->get('_version');
     $response = new Response();
     /** @var BlockManager $manager */
     $manager = $this->get('opifer.content.block_manager');
     $block = $content->getBlock();
     $response->setStatusCode($statusCode);
     if (null !== $version && $this->isGranted('ROLE_ADMIN')) {
         $block = $content->getBlock();
         $this->getDoctrine()->getManager()->getFilters()->disable('draftversion');
         $manager->revert($block, $version);
     }
     /** @var BlockServiceInterface $service */
     $service = $manager->getService($block);
     $service->setView($content->getTemplate()->getView());
     return $service->execute($block);
 }