src/Controller/Frontend/Pages/PageController.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Frontend\Pages;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Knp\Component\Pager\PaginatorInterface;
  9. use App\Helper\ConfigHelper;
  10. use App\Helper\ContentHelper;
  11. use App\Entity\Content\Pages\Page;
  12. use App\Entity\Properties\Area;
  13. use App\Entity\Properties\Property;
  14. use App\Entity\Properties\Type;
  15. final class PageController extends AbstractController
  16. {
  17.     public function __construct(EntityManagerInterface $entityManagerPaginatorInterface $paginatorConfigHelper $configHelperContentHelper $contentHelper)
  18.     {
  19.         $this->em $entityManager;
  20.         $this->paginator $paginator;
  21.         $this->configHelper $configHelper;
  22.         $this->contentHelper $contentHelper;
  23.     }
  24.     /**
  25.     * @Route("/", name="frontend_index", priority="-1")
  26.     */
  27.     public function index(Request $request$path ''): Response
  28.     {
  29.         // Get featured properties
  30.         $featuredProperties $this->em->getRepository(Property::class)->findFiltered([
  31.             "showOnWebsite" => true
  32.         ], [], 20);
  33.         // Get all property types
  34.         $allTypes $this->em->getRepository(Type::class)->findFiltered([]);
  35.         // Get all areas
  36.         $allAreas $this->em->getRepository(Area::class)->findFiltered([]);
  37.         // Render view
  38.         return $this->render('Frontend/Pages/index.html.twig', [
  39.             'featuredProperties' => $featuredProperties,
  40.             'allTypes' => $allTypes,
  41.             'allAreas' => $allAreas
  42.         ]);
  43.     }
  44.     /**
  45.     * @Route("/{path}", name="frontend_page", priority="-1", requirements={"path"=".+"})
  46.     */
  47.     public function viewPage(Request $request$path ''): Response
  48.     {
  49.         // Clean the path
  50.         $cleanPath $this->contentHelper->cleanPath($path) ? $this->contentHelper->cleanPath($path) : "index";
  51.         // Url path is index?
  52.         if((strtolower(trim($request->getPathInfo(), "/")) == "index"))
  53.             return $this->redirect(str_replace("index""/"$cleanPath));
  54.         // Find the page
  55.         $page $this->em->getRepository(Page::class)->findOneFiltered(array(
  56.             "path" => $cleanPath
  57.         ));
  58.         // Not found?
  59.         if(!$page)
  60.             throw $this->createNotFoundException("The page you're looking for was not found.");
  61.         // Grab rendered content
  62.         $renderedContent $this->contentHelper->getRenderedPageContent($page$this->getUser());
  63.         // Render view
  64.         return $this->render('Frontend/Pages/page.html.twig', [
  65.             'page' => $page,
  66.             'renderedContent' => $renderedContent
  67.         ]);
  68.     }
  69. }