<?php
namespace DcSiteBundle\Controller\Peugeot;
use CoreBundle\Component\CoreFormFactory;
use CoreBundle\Component\FormManager;
use CoreBundle\Entity\Model;
use CoreBundle\Entity\Post;
use CoreBundle\Factory\Vehicle as VehicleFactory;
use CoreBundle\Model\Api\OnlineService\ApiServer1C;
use CoreBundle\Model\Vehicles\Repository;
use CoreBundle\Model\ViDiDepartmentModel;
use CoreBundle\Services\MediaExtensionVidi;
use DcSiteBundle\Entity\Part;
use DcSiteBundle\Services\VehicleService;
use Doctrine\ORM\EntityManagerInterface;
use PortalBundle\Model\SeoMetaTag;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\RouterInterface;
use Twig\Environment;
class ServiceController extends BaseController
{
public function __construct(CoreFormFactory $coreFormFactory, SeoMetaTag $seoMetaTag, RequestStack $requestStack, RouterInterface $router, FormManager $formManager, EntityManagerInterface $em, ApiServer1C $apiServer1C, SessionInterface $session, Filesystem $filesystem, MediaExtensionVidi $mediaExtensionVidi, Repository $vehicleRepository, VehicleFactory $vehicleFactory, Environment $twig)
{
parent::__construct($coreFormFactory, $seoMetaTag, $requestStack, $router, $formManager, $em, $apiServer1C, $session, $filesystem, $mediaExtensionVidi, $vehicleRepository, $vehicleFactory, $twig);
}
public function paintingTires(): ?Response
{
return $this->basePeugeotRender(
'@DcSite/Peugeot/Service/painting-tires.html.twig',
[
'servicesForm' =>
$this->CoreFormFactory()
->fbDefQuestionForm(
'Интересует Покраска дисков',
null,
null,
$this->getDealer())->createView(),
]
);
}
public function tiresHotel(): ?Response
{
return $this->basePeugeotRender('@DcSite/Peugeot/Service/tires-hotel.html.twig', [
'servicesForm' =>
$this->CoreFormFactory()
->fbDefQuestionForm(
'Интересует Шинный отель',
null,
null,
$this->getDealer())->createView(),
]
);
}
public function bodyRepair(): ?Response
{
$repairPhotoForm = $this->CoreFormFactory()->repairPhotoForm();
return $this->basePeugeotRender('@DcSite/Peugeot/Service/body-repair.html.twig', [
'repairPhotoForm' => $repairPhotoForm->createView(),
]);
}
public function parts(): ?Response
{
//TODO remove magic numbers
$actions = $this->em->getRepository(Post::class)->findBy(['id' => ['692']]);
return $this->basePeugeotRender('@DcSite/Peugeot/Service/parts.html.twig', [
'buyPartsForm' => $this->CoreFormFactory()->buyPartsForm($this->getDealer())->createView(),
'actions' => $actions,
'sparesForm' =>
$this->CoreFormFactory()
->fbDefQuestionForm(
'Консультация по запасным частям',
ViDiDepartmentModel::DEPARTMENT_TYPE_PARTS,
null,
$this->getDealer())->createView(),
]
);
}
public function searchParts(Request $request): JsonResponse
{
$query = $request->request->get('query');
$part = $this->em->getRepository(Part::class)->findOneBy(['dealer' => $this->getDealer(), 'number' => $query, 'state' => 1]);
if (!$part) {
return new JsonResponse(['success' => false]);
}
return new JsonResponse([
'success' => true,
'data' => [
'price' => $part->getPrice(),
'id' => $part->getId(),
'title' => $part->getNameByLocale($request->getLocale()),
'art' => $part->getNumber(),
'count' => $part->getCount(),
]
]);
}
public function warranty(): ?Response
{
return $this->basePeugeotRender('@DcSite/Peugeot/Service/warranty.html.twig');
}
public function regulations(): ?Response
{
return $this->basePeugeotRender('@DcSite/Peugeot/Service/regulations.html.twig', [
'serviceForm' => $this->CoreFormFactory()->serviceForm()->createView()
]);
}
public function orderTo(): ?Response
{
return $this->basePeugeotRender('@DcSite/Peugeot/Service/order-to.html.twig', [
'dealerName' => $this->getDealer()->getBrand()->getName()
]);
}
public function fixedСostTo(): ?Response
{
return $this->basePeugeotRender('@DcSite/Peugeot/Service/fixed-cost-to.html.twig', [
'dealerName' => $this->getDealer()->getBrand()->getName()
]);
}
public function regulationsTo(VehicleService $vehicleService): ?Response
{
$models = $vehicleService->getModelsForRegulationsTo($this->getDealer());
return $this->basePeugeotRender('@DcSite/Peugeot/Service/regulations-to.html.twig', [
'models' => $models,
]);
}
public function regulationsToModel($model): ?Response
{
$model = $this->em->getRepository(Model::class)->findOneBy(['url' => $model]);
if (!$model) {
throw new NotFoundHttpException();
}
return $this->basePeugeotRender('@DcSite/Peugeot/Service/regulations-to-model.html.twig', [
'model' => $model->getId(),
'modelTitle' => $model->getTitle(),
]);
}
public function extendedWarranty(): ?Response
{
return $this->basePeugeotRender('@DcSite/Peugeot/ServiceAgreements/extended-warranty.html.twig', [
'servicesForm' => $this->CoreFormFactory()->fbDefQuestionForm('Розширена гарантія', null, null, $this->getDealer())->createView(),
]);
}
public function extendedWarrantyReplacementParts(): ?Response
{
return $this->basePeugeotRender('@DcSite/Peugeot/ServiceAgreements/extended-warranty-replacement-parts.html.twig', [
'servicesForm' => $this->CoreFormFactory()->fbDefQuestionForm('Розширена гарантія + заміна деталей природного зносу', null, null, $this->getDealer())->createView(),
]);
}
public function extendedWarrantyTo(): ?Response
{
return $this->basePeugeotRender('@DcSite/Peugeot/ServiceAgreements/extended-warranty-to.html.twig', [
'servicesForm' => $this->CoreFormFactory()->fbDefQuestionForm('Розширена гарантія + заміна деталей природного зносу + то', null, null, $this->getDealer())->createView(),
]);
}
public function extendedWarrantyPeugeot(): ?Response
{
return $this->basePeugeotRender('@DcSite/Peugeot/Service/extended-warranty.html.twig', [
'servicesForm' => $this->CoreFormFactory()->extendedWarrantyForm()->createView(),
]);
}
public function multiConsultationEnter(): ?Response
{
return $this->basePeugeotRender('@DcSite/Peugeot/Service/consultation.html.twig');
}
public function multiConsultationForm(): ?Response
{
return $this->basePeugeotRender('@DcSite/Peugeot/Service/consultation-form.html.twig');
}
public function multiConsultationFormOnline(): ?Response
{
return $this->basePeugeotRender('@DcSite/Peugeot/Service/consultation-form-online.html.twig');
}
public function multiConsultationTestdriveForm(): ?Response
{
return $this->basePeugeotRender('@DcSite/Peugeot/Service/consultation-testdrive-form.html.twig');
}
public function operatingInstructions(): ?Response
{
return $this->basePeugeotRender('@DcSite/Peugeot/Service/operating-instructions.html.twig');
}
public function nightServiceAgreement(): ?Response
{
return $this->basePeugeotRender('@DcSite/Peugeot/Service/night-service-agreement.html.twig', [
'dealer' => $this->getDealer()
]);
}
}