<?php
namespace PortalBundle\Controller;
use CoreBundle\Component\CoreFormFactory;
use CoreBundle\Entity\Dealer;
use CoreBundle\Model\Post;
use CoreBundle\Model\Vehicles\Repository;
use Doctrine\ORM\EntityManagerInterface;
use PortalBundle\Services\ServiceService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\RouterInterface;
class PostController extends BaseController
{
public function __construct(CoreFormFactory $coreFormFactory, RequestStack $requestStack, RouterInterface $router,
Repository $vehicleRepository, ServiceService $serviceService)
{
parent::__construct($coreFormFactory, $requestStack, $router, $vehicleRepository, $serviceService);
}
public function actions(EntityManagerInterface $em): Response
{
$new = $em->getRepository(\CoreBundle\Entity\Post::class)->getNewCarActions(0);
$service = $em->getRepository(\CoreBundle\Entity\Post::class)->getServiceActions(0);
return $this->basePortalRender('@Portal/Post/actions.html.twig', [
'newCarActions' => $new,
'serviceActions' => $service,
]);
}
public function actionsSingle(Request $request, EntityManagerInterface $em, Post $postModel): Response
{
$url = $request->get('url');
$dealer = $em->getRepository(Dealer::class)->findOneBy(['url' => $request->get('dealer')]);
if (!$dealer) {
throw new NotFoundHttpException();
}
$post = $postModel->initByUrl($dealer, $url, Post::POST_TYPE_ACTIONS);
if (!$post) {
throw new NotFoundHttpException();
}
$interesting = $postModel->getReadMore();
return $this->basePortalRender('@Portal/Post/actions-single.html.twig', ['post' => $post, 'interesting' => $interesting]);
}
public function news(EntityManagerInterface $em): Response
{
$newsEntities = $em->getRepository(\CoreBundle\Entity\Post::class)->getPortalNews();
return $this->basePortalRender('@Portal/Post/news.html.twig', ['news' => $newsEntities]);
}
public function newsByDealer(Request $request, EntityManagerInterface $em): Response
{
$dealer = $em->getRepository(Dealer::class)->findOneBy(['seo_url' => $request->get('dealer')]);
$posts = $em->getRepository(\CoreBundle\Entity\Post::class)
->findBy(['dealer' => $dealer, 'state' => 1, 'post_type' => 1, 'on_portal' => 1]);
return $this->basePortalrender('@Portal/Post/news.html.twig', ['news' => $posts, 'newsPageDealer' => $dealer]);
}
public function newsSingle(Request $request, Post $postModel, EntityManagerInterface $em): Response
{
$url = $request->get('url');
$dealer = $request->get('dealer');
if(!$dealer) {
throw new NotFoundHttpException();
}
$dealer = $em->getRepository(Dealer::class)->findOneBy(['url' => $dealer]);
if(!$dealer) {
throw new NotFoundHttpException();
}
$post = $postModel->initPortalByUrl($dealer, $url, Post::POST_TYPE_NEWS);
if (!$post) {
throw new NotFoundHttpException();
}
$interesting = $postModel->getReadMore();
return $this->basePortalRender('@Portal/Post/news-single.html.twig', ['news' => $post, 'interesting' => $interesting]);
}
}