src/PortalBundle/Controller/PostController.php line 54

Open in your IDE?
  1. <?php
  2. namespace PortalBundle\Controller;
  3. use CoreBundle\Component\CoreFormFactory;
  4. use CoreBundle\Entity\Dealer;
  5. use CoreBundle\Model\Post;
  6. use CoreBundle\Model\Vehicles\Repository;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use PortalBundle\Services\ServiceService;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  13. use Symfony\Component\Routing\RouterInterface;
  14. class PostController extends BaseController
  15. {
  16.     public function __construct(CoreFormFactory $coreFormFactoryRequestStack $requestStackRouterInterface $router,
  17.                                 Repository      $vehicleRepositoryServiceService $serviceService)
  18.     {
  19.         parent::__construct($coreFormFactory$requestStack$router$vehicleRepository$serviceService);
  20.     }
  21.     public function actions(EntityManagerInterface $em): Response
  22.     {
  23.         $new $em->getRepository(\CoreBundle\Entity\Post::class)->getNewCarActions(0);
  24.         $service $em->getRepository(\CoreBundle\Entity\Post::class)->getServiceActions(0);
  25.         return $this->basePortalRender('@Portal/Post/actions.html.twig', [
  26.             'newCarActions' => $new,
  27.             'serviceActions' => $service,
  28.         ]);
  29.     }
  30.     public function actionsSingle(Request $requestEntityManagerInterface $emPost $postModel): Response
  31.     {
  32.         $url $request->get('url');
  33.         $dealer $em->getRepository(Dealer::class)->findOneBy(['url' => $request->get('dealer')]);
  34.         if (!$dealer) {
  35.             throw new NotFoundHttpException();
  36.         }
  37.         $post $postModel->initByUrl($dealer$urlPost::POST_TYPE_ACTIONS);
  38.         if (!$post) {
  39.             throw new NotFoundHttpException();
  40.         }
  41.         $interesting $postModel->getReadMore();
  42.         return $this->basePortalRender('@Portal/Post/actions-single.html.twig', ['post' => $post'interesting' => $interesting]);
  43.     }
  44.     public function news(EntityManagerInterface $em): Response
  45.     {
  46.         $newsEntities $em->getRepository(\CoreBundle\Entity\Post::class)->getPortalNews();
  47.         return $this->basePortalRender('@Portal/Post/news.html.twig', ['news' => $newsEntities]);
  48.     }
  49.     public function newsByDealer(Request $requestEntityManagerInterface $em): Response
  50.     {
  51.         $dealer $em->getRepository(Dealer::class)->findOneBy(['seo_url' => $request->get('dealer')]);
  52.         $posts $em->getRepository(\CoreBundle\Entity\Post::class)
  53.             ->findBy(['dealer' => $dealer'state' => 1'post_type' => 1'on_portal' => 1]);
  54.         return $this->basePortalrender('@Portal/Post/news.html.twig', ['news' => $posts'newsPageDealer' => $dealer]);
  55.     }
  56.     public function newsSingle(Request $requestPost $postModelEntityManagerInterface $em): Response
  57.     {
  58.         $url $request->get('url');
  59.         $dealer $request->get('dealer');
  60.         if(!$dealer) {
  61.             throw new NotFoundHttpException();
  62.         }
  63.         $dealer $em->getRepository(Dealer::class)->findOneBy(['url' => $dealer]);
  64.         if(!$dealer) {
  65.             throw new NotFoundHttpException();
  66.         }
  67.         $post $postModel->initPortalByUrl($dealer$urlPost::POST_TYPE_NEWS);
  68.         if (!$post) {
  69.             throw new NotFoundHttpException();
  70.         }
  71.         $interesting $postModel->getReadMore();
  72.         return $this->basePortalRender('@Portal/Post/news-single.html.twig', ['news' => $post'interesting' => $interesting]);
  73.     }
  74. }