<?php
namespace App\Controller\System;
use App\Controller\BaseController;
use App\Entity\Addressing\Country;
use App\Entity\Addressing\County;
use App\Manager\BitbagStatic\BlockManager;
use App\Entity\Customer\Customer;
use App\Entity\RCA\Availability;
use App\Entity\RCA\FuelType;
use App\Entity\RCA\InsuranceCompany;
use App\Entity\RCA\LeasingCompany;
use App\Entity\RCA\MappedCategory;
use App\Entity\RCA\MappedVehicleMake;
use App\Entity\RCA\UsageType;
use App\Entity\RCA\VehicleType;
use App\Manager\CountryManager;
use App\Manager\Customer\ConfirmationCommercialNotificationManager;
use App\Manager\Rca\RcaManager;
use App\Manager\RoadAssistance\RoadAssistanceManager;
use App\Manager\Customer\VehicleManager;
use App\Manager\HuVignette\HuVignetteManager;
use App\Model\CustomerModel;
use App\Model\ShopUserModel;
use App\Model\VignetteCategoryModel;
use App\Service\CustomerService;
use App\Service\StaticPagesBitbagService;
use App\Service\SystemService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Entity\Vignette\Category as RoVignetteCategory;
use App\Entity\HuVignette\Category as HuVignetteCategory;
class ShopDashboardController extends BaseController
{
public function homepageAction(Request $request, TranslatorInterface $translator): Response
{
$desktopView = SystemService::checkDesktopView($request);
$vignetteCategories = (new VignetteCategoryModel($this->getEntityManager()))->getAllCategories();
$render = '@templates/Front/homepage.html.twig';
if ($this->isMobile && !$desktopView) {
$render = '@templates/Mobile/homepage.html.twig';
}
if (CustomerService::retrieveCustomerFromShopUser($this->getUser())) {
$render = '@templates/Account/vehicle/list.html.twig';
$leasingCompanies = $this->getDoctrine()
->getRepository(LeasingCompany::class)->findAll();
$country = $this->getDoctrine()->getRepository(Country::class)->findOneBy(array('code' => 'RO'));
$roadAssistanceService = $this->getContainer()->get('app.service.road_assistance.road_assistance');
$hashGeneratorService = $this->getContainer()->get('app.service.security.hash_generator');
return $this->render($render,
[
'vignetteCategories' => $vignetteCategories,
'isOneYearHuVignetteAvailableThisYear' => new \DateTime <= new \DateTime(HuVignetteManager::LAST_DATE_FOR_ONE_YEAR_HU_VIGNETTE_AVAILABILITY . '-' . date('Y')),
'customerVehicleOrderByOptions' => VehicleManager::getCustomerVehicleOrderByOptions(),
'customerVehicleSearchByFields' => VehicleManager::getCustomerVehicleSearchByFields(),
'countyList' => $this->getDoctrine()->getRepository(County::class)->findAllCountiesByCountryAsArray($country),
'vehicleTypeList' => $this->getDoctrine()->getRepository(VehicleType::class)->findAllAsArrayForUI(),
'rcaMappedCategoryList' => $this->getDoctrine()->getRepository(MappedCategory::class)->findAllAsArray(),
'defaultMakeList' => $this->getDoctrine()->getRepository(MappedVehicleMake::class)->findByVehicleMappedCategoryAsArray(MappedCategory::MAPPED_CATEGORY_VEHICLE),
'availabilityList' => $this->getDoctrine()->getRepository(Availability::class)->findAllAsArray(),
'availabilityIntervalList' => RcaManager::getAvailabilityIntervalList(),
'insuranceCompanyList' => $this->getDoctrine()->getRepository(InsuranceCompany::class)->findAllOnlyNameOrderedByPositionAsArray(),
'fuelTypeList' => $this->getDoctrine()->getRepository(FuelType::class)->findAllAsArray(),
'usageTypeList' => $this->getDoctrine()->getRepository(UsageType::class)->findAllAsArray(),
'leasingCompanyList' => $this->getDoctrine()->getRepository(LeasingCompany::class)->findAllAsArray(),
'leasingCompanies' => $leasingCompanies,
'step' => $request->get('step'),
'haveOldVehicleValues' => (bool)$request->getSession()->get('rcaVehicle'),
'haveOldCustomerValues' => (bool)$request->getSession()->get('rcaCustomerData'),
'isAdmin' => ShopUserModel::checkIfUserIsAdmin($this->getUser(), $this->getEntityManager()),
'accordionBlocksAboutRca' => StaticPagesBitbagService::getAllFilteredBlocksAsArray($this->getEntityManager(), BlockManager::BLOCK_ACCORDION_TEXT_RCA_CODE_PATTERN),
'roadAssistanceDefaultPrice' => $roadAssistanceService->retrieveDefaultPrice(),
'roadAssistanceTranslations' => RoadAssistanceManager::getTranslationsForUI($translator),
'hash' => $hashGeneratorService->getHash(),
'countries' => CountryManager::getActiveCountriesForRoVignette($this->getEntityManager()),
'roVignetteCategories' => $this->getDoctrine()->getRepository(RoVignetteCategory::class)->findAllAsArray(),
'huVignetteCategories' => $this->getDoctrine()->getRepository(HuVignetteCategory::class)->findAllAsArray(),
]);
}
return $this->render($render,
[
'vignetteCategories' => $vignetteCategories,
]);
}
public function oldHomepageAction(Request $request)
{
$desktopView = SystemService::checkDesktopView($request);
$render = '@templates/Front/homepage.html.twig';
if ($this->isMobile && !$desktopView) {
$render = '@templates/Mobile/homepage.html.twig';
}
$vignetteCategories = (new VignetteCategoryModel($this->getEntityManager()))->getAllCategories();
return $this->render($render,
[
'vignetteCategories' => $vignetteCategories,
]);
}
public function subscribeToNewsletter(Request $request, TranslatorInterface $translator)
{
$redirectToRoute = 'sylius_shop_homepage';
$customer = $this->getEntityManager()->getRepository(Customer::class)->findOneBy(array('email' => $request->get('email')));
if ($customer instanceof Customer) {
$customerModel = new CustomerModel($this->getEntityManager());
$customerModel->subscribeCustomerToNewsletter($customer, $request->getClientIp());
$commercialNotificationService = $this->getContainer()->get('app.service.customer.commercial_notification');
$commercialNotificationService->addToQueueConfirmationEmailForCommercialNotificationForCustomer($customer, ConfirmationCommercialNotificationManager::EMAIL_TYPE_MANUAL_ID);
$this->addFlash('success', SystemService::retrieveMessage('success', $translator));
} else {
$this->addFlash('warning', SystemService::retrieveMessage('could_not_find_a_user_with_this_email_register', $translator));
$redirectToRoute = 'app_shop_customer_register';
}
return $this->redirectToRoute($redirectToRoute);
}
}