<?php
namespace PortalBundle\Controller;
use CoreBundle\Component\CoreFormFactory;
use CoreBundle\Entity\Dealer;
use CoreBundle\Entity\Post;
use CoreBundle\Model\Vehicles\Repository;
use CoreBundle\Services\MediaExtensionVidi;
use DcSiteBundle\Entity\Vacancy;
use Application\Sonata\MediaBundle\Entity\GalleryItem;
use Doctrine\ORM\EntityManagerInterface;
use PortalBundle\Services\OfferedVehicle;
use PortalBundle\Entity\Blog;
use PortalBundle\Entity\BlogCategory;
use PortalBundle\Services\ServiceService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RouterInterface;
class AboutController extends BaseController
{
private MediaExtensionVidi $mediaExtensionVidi;
private OfferedVehicle $offeredVehicleService;
public function __construct(MediaExtensionVidi $mediaExtensionVidi, OfferedVehicle $offeredVehicleService,
CoreFormFactory $coreFormFactory, RequestStack $requestStack, RouterInterface $router,
Repository $vehicleRepository, ServiceService $serviceService)
{
parent::__construct($coreFormFactory, $requestStack, $router, $vehicleRepository, $serviceService);
$this->mediaExtensionVidi = $mediaExtensionVidi;
$this->offeredVehicleService = $offeredVehicleService;
}
public function about(EntityManagerInterface $entityManager): Response
{
$dealers = $entityManager->getRepository(Dealer::class)->getCarDealerOutputOrder();
foreach ($dealers as $dealer) {
$Brand = $dealer->getBrand();
if (!$Brand or $Brand->getId() == 67) {
continue;
}
if (isset($brands[$Brand->getId()])) {
continue;
}
$brands[$Brand->getId()] = $Brand->getId();
$logos[] = [
'image' => $Brand->getLogo(),
'name' => $Brand->getName()
];
}
return $this->basePortalRender('@Portal/About/about.html.twig', [
'logos' => $logos,
'dealers' => $dealers,
]);
}
public function contactsSingle(Request $request, EntityManagerInterface $entityManager): Response
{
$locale = $request->getLocale();
$seo_url = $request->get('seo_url');
$dealer =$entityManager->getRepository(Dealer::class)->findOneBy(['seo_url' => $seo_url]);
if (!$dealer) {
throw $this->createNotFoundException();
}
$new =$entityManager->getRepository(Post::class)->getNewCarActionsByDealerId($dealer->getId(), 3);
$service =$entityManager->getRepository(Post::class)->getServiceActionsByDealerId($dealer->getId(), 3);
$gallery = [];
if ($dealer->getGallery() && $dealer->getGallery()->getGalleryItems()) {
/** @var GalleryItem $galleryItem */
foreach ($dealer->getGallery()->getGalleryItems() as $galleryItem) {
$url = $this->mediaExtensionVidi->getPath($galleryItem->getMedia(), 'reference');
$gallery[] = $url;
}
}
$dealer = [
'id' => $dealer->getId(),
'name' => $dealer->getNameByLocale($locale),
'description' => $dealer->getDescriptionByLocale($locale),
'brandId' => $dealer->getBrand()->getId(),
'gallery' => $gallery,
'brandName' => $dealer->getBrand()->getName(),
'domain' => $dealer->getDomain(),
'url' => $dealer->getUrl(),
'cityId' => ($dealer->getCity()) ? $dealer->getCity()->getId() : null,
'cityName' => ($dealer->getCity()) ? $dealer->getCity()->getCityByLocale($locale) : null,
'logo' => $this->mediaExtensionVidi->getPath($dealer->getBrand()->getLogo(), 'reference'),
'img' => $this->mediaExtensionVidi->getPath($dealer->getImageServiceCenter(), 'reference'),
'address' => $dealer->getAddressByLocale($locale),
'phone' => $dealer->getPhone(),
'href_phone' => preg_replace('/[\s\(\)-]/', '', $dealer->getPhone()),
'openTime' => $dealer->getOpenTime(),
'closeTime' => $dealer->getCloseTime(),
'mapUrl' => 'https://maps.google.com/maps?q=' . $dealer->getLat() . ',' . $dealer->getLng() . '&hl=' . $locale,
'detail_url' => $dealer->getSeoUrl() ? $this->generateUrl('portal_contacts_single', ['seo_url' => $dealer->getSeoUrl()]) : '',
'brandUrl' => $dealer->getBrand()->getUrl(),
];
return $this->basePortalRender('@Portal/Contacts/contacts-single.html.twig', [
'dealerByPage' => $dealer,
'actions' => [
'new_car' => $new,
'service' => $service,
],
'newVehicles' => $this->offeredVehicleService->getLimitedUniqueModelByBrand($locale, 'new', $dealer['brandUrl']),
'usedVehicles' => $this->offeredVehicleService->getLimitedUniqueModelByBrand($locale, 'used', $dealer['brandUrl']),
]);
}
public function qualityPolicy(): Response
{
return $this->basePortalRender('@Portal/About/quality-policy.html.twig');
}
public function information(): Response
{
return $this->basePortalRender('@Portal/About/information.html.twig');
}
public function informationPayment(): Response
{
return $this->basePortalRender('@Portal/About/payment.html.twig');
}
public function informationRules(): Response
{
return $this->basePortalRender('@Portal/About/rules.html.twig');
}
public function sharingRules(): Response
{
return $this->basePortalRender('@Portal/About/sharing.html.twig');
}
public function blog(Request $request, EntityManagerInterface $em): Response
{
$category = $em->getRepository(BlogCategory::class)->findOneBy(['url' => $request->query->get('type')]);
$search = $request->query->get('search');
$page = $request->query->get('page', 1);
$dealers = $em->getRepository(Dealer::class)->getDealerWithPostsOnPortal();
return $this->basePortalrender('@Portal/About/blog/blog.html.twig',[
'dealers' => $dealers,
'category' => $category ? [
'id' => $category->getId(),
'url' => $category->getUrl(),
'title' => $category->getTitle($request->getLocale()),
] : null,
'search' => $search,
'page' => $page,
]);
}
public function blogSingle(Request $request, EntityManagerInterface $em): Response
{
$post = $em->getRepository(Blog::class)->findOneBy(['url' => $request->attributes->get('url')]);
$categoriesUrl = [];
foreach ($post->getCategories() as $category) {
$categoriesUrl[] = $category->getUrl();
}
$interestPosts = $em->getRepository(Blog::class)->getBlogsFromOtherCategories($categoriesUrl, 3);
$similarPosts = $em->getRepository(Blog::class)->getSimilarBlogs($post->getId(), $categoriesUrl, 3);
$post->setViews($post->getViews() + 1);
$em->flush();
$em->persist($post);
return $this->basePortalrender('@Portal/About/blog/blog-single.html.twig',[
'post' => $post,
'interestPosts' => $interestPosts,
'similarPosts' => $similarPosts
]);
}
// Вакансии
public function vacancies(EntityManagerInterface $entityManager): Response
{
$vacancies = $entityManager->getRepository(Vacancy::class)->findBy(['state' => true]);
return $this->basePortalRender('@Portal/About/vacancies.html.twig', ['vacancies' => $vacancies]);
}
// Вакансии/Кар'єра
public function career(EntityManagerInterface $entityManager): Response
{
$dealers = $entityManager->getRepository(Dealer::class)->findBy([], ['position' => 'ASC']);
$logos = [];
foreach ($dealers as $dealer) {
if (!$brand = $dealer->getBrand()) {
continue;
}
$logos[] = [
'image' => $brand->getLogo(),
'name' => $brand->getName(),
];
}
return $this->basePortalRender('@Portal/About/career.html.twig', [
'logos' => $logos,
]);
}
// Вакансии ID
public function singleVacancies($id, EntityManagerInterface $entityManager): Response
{
$vacancyRepo = $entityManager->getRepository(Vacancy::class);
$vacancy = $vacancyRepo->find($id);
$relatedVacancies = $vacancyRepo->findActiveLimitAndExcludeById($id);
$dealers = $entityManager->getRepository(Dealer::class)->findBy([], ['position' => 'ASC']);
$logos = [];
foreach ($dealers as $dealer) {
if (!$brand = $dealer->getBrand()) {
continue;
}
$logos[] = [
'image' => $brand->getLogo(),
'name' => $brand->getName(),
];
}
return $this->basePortalRender('@Portal/About/vacancies-id.html.twig', [
'vacancy' => $vacancy,
'logos' => $logos,
'relatedVacancies' => $relatedVacancies,
'vacancyForm' => $this->CoreFormFactory()->vacancyForm($vacancy->getDealer(), $vacancy)->createView()
]);
}
public function privacyPolicy(): Response
{
return $this->basePortalRender('@Portal/About/privacy-policy.html.twig', []);
}
public function qualityService(): Response
{
return $this->basePortalRender('@Portal/About/quality-service.html.twig');
}
}