src/AppBundle/Controller/PageController.php line 33

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Controller;
  3. use AppBundle\Entity\BuildingPortal;
  4. use AppBundle\Entity\Page;
  5. use AppBundle\Entity\ProjectPortal;
  6. use AppBundle\Util\ChromeItemsHelperTrait;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  8. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  12. use Symfony\Component\Translation\Translator;
  13. /**
  14.  * Pages controller.
  15.  *
  16.  * @Route("pages")
  17.  */
  18. class PageController extends Controller
  19. {
  20.     use ChromeItemsHelperTrait;
  21.     /**
  22.      * Page details.
  23.      *
  24.      * @Route("/{slug}", name="page_details")
  25.      * @param Page $page
  26.      * @return \Symfony\Component\HttpFoundation\Response
  27.      */
  28.     public function showAction(Request $requestPage $pageTranslator $translator)
  29.     {
  30.         if (!$page->getPublished()) {
  31.             throw new NotFoundHttpException('Page not found or not published yet!');
  32.         }
  33.         $ctx = ['page' => $page];
  34.         $em $this->getDoctrine()->getManager();
  35.         $this->prepareItemsInController($request$page$em$translator$ctx);
  36.         if ($page->getType() === Page::PROJECT_PAGE) {
  37.             // preload project, building and floor plans with coordinates
  38.             $projectRepo $em
  39.                 ->getRepository(ProjectPortal::class);
  40.             $portalProject $page->getProjectPortal();
  41.             if ($portalProject) {
  42.                 $projectRepo->assignChildren(
  43.                     $portalProject,
  44.                     BuildingPortal::class,
  45.                     $em
  46.                 );
  47.             }
  48.             $template 'AppBundle:Page:project.html.twig';
  49.         } else {
  50.             $template 'AppBundle:Page:index.html.twig';
  51.         }
  52.         $response $this->render($template$ctx);
  53.         if ($page->getSlug() === '404') {
  54.             $response->setStatusCode(Response::HTTP_NOT_FOUND);
  55.         }
  56.         return $response;
  57.     }
  58. }