<?php 
 
namespace DcSiteBundle\Controller\Citroen; 
 
use CoreBundle\Component\CoreFormFactory; 
use CoreBundle\Component\FormManager; 
use CoreBundle\Factory\Vehicle as VehicleFactory; 
use CoreBundle\Model\Api\OnlineService\ApiServer1C; 
use CoreBundle\Model\Vehicles\Repository; 
use CoreBundle\Services\MediaExtensionVidi; 
use DcSiteBundle\Controller\BaseDcController; 
use Doctrine\ORM\EntityManagerInterface; 
use Doctrine\ORM\NonUniqueResultException; 
use PortalBundle\Model\SeoMetaTag; 
use Symfony\Component\Filesystem\Filesystem; 
use Symfony\Component\HttpFoundation\RequestStack; 
use Symfony\Component\HttpFoundation\Response; 
use Symfony\Component\HttpFoundation\Session\SessionInterface; 
use Symfony\Component\Routing\RouterInterface; 
use Twig\Environment; 
 
class BaseController extends BaseDcController 
{ 
    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); 
    } 
 
    protected function baseCitroenRender($view, array $parameters = [], Response $response = null): ?Response 
    { 
        $parameters = array_merge($parameters, [ 
            'forms' => $this->buildForms(), 
            'newVehicles' => $this->getNewVehicles(), 
            'privacyUrl' => $this->router->generate('citroen_personal_data_agreement'), 
        ]); 
        return parent::baseDcRender($view, $parameters, $response); 
    } 
 
    /** 
     * @return array 
     * @throws NonUniqueResultException 
     */ 
    public function buildForms(): array 
    { 
        return [ 
            'testDrive' => $this->CoreFormFactory()->testDriveForm($this->getDealer())->createView(), 
            'serviceForm' => $this->CoreFormFactory()->serviceForm()->createView(), 
            'callback' => $this->CoreFormFactory()->orderCallForm(null, $this->getDealer())->createView(), 
            'question' => $this->CoreFormFactory()->feedbackQuestionForm(null, $this->getDealer())->createView(), 
            'buyAccForm' => $this->CoreFormFactory()->buyPartsForm($this->getDealer())->createView(), 
        ]; 
    } 
 
    public function getNewVehicles() 
    { 
        $vehicles = $this->vehicleRepository->getNewByDealer($this->getDealer()); 
        $result = []; 
        foreach ($vehicles as $vehicle) { 
            $model = $this->vehicleFactory->createByEntity($vehicle); 
            if(!$model) { 
                continue; 
            } 
            $result[] = $model; 
        } 
 
        return $result; 
    } 
}