<?php
namespace App\Controller;
use App\Entity\Garages\Garage;
use App\Entity\Tires\Tire;
use App\Enum\SiteEnum;
use App\Repository\Promotions\LocalPromotionRepository;
use App\Repository\Promotions\NationalPromotionRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Controller that renders code snippets to be called via "curl" from Vulco legacy code.
*
* @Route("/render")
*/
class BridgeController extends AbstractController
{
/**
* @Route("/garage-national-promotions/{id}", name="garage_national_promotions", methods={"GET"})
* @ParamConverter("garage", class="App\Entity\Garages\Garage", options={"mapping": {"id": "id"}})
*/
public function garageNationalPromotions(Garage $garage, NationalPromotionRepository $nationalPromotionRepository): Response
{
$nationalPromotions = $nationalPromotionRepository->findCurrentByGarage($garage);
if ($nationalPromotions) {
return $this->render('bridge/garage_national_promotions.html.twig', [
'national_promotions' => $nationalPromotions,
]);
}
return $this->render('bridge/empty.html.twig');
}
/**
* @Route("/garage-local-promotions/{id}", name="garage_local_promotions", methods={"GET"})
* @ParamConverter("garage", class="App\Entity\Garages\Garage", options={"mapping": {"id": "id"}})
*/
public function garageLocalPromotions(Garage $garage, LocalPromotionRepository $localPromotionRepository): Response
{
$localPromotions = $localPromotionRepository->getActiveByGarage($garage);
if ($localPromotions) {
return $this->render('bridge/garage_local_promotions.html.twig', [
'local_promotions' => $localPromotions,
]);
}
return $this->render('bridge/empty.html.twig');
}
/**
* @Route("/legacy-frontend-garage-detail/{id}/redirect", name="legacy_frontend_garage_detail_redirect", methods={"GET"})
* @ParamConverter("garage", class="App\Entity\Garages\Garage", options={"mapping": {"id": "id"}})
*/
public function legacyFrontendGarageDetailRedirect(Garage $garage, ParameterBagInterface $pb, Request $request): RedirectResponse
{
$base = $pb->get('old_frontend_uri_es');
if (SiteEnum::SITE_STR_PT === $request->getLocale()) {
$base = $pb->get('old_frontend_uri_pt');
}
return $this->redirect($base.$garage->getSlug());
}
/**
* @Route("/legacy-backend-garage-edit/{id}/redirect", name="legacy_backend_garage_edit_redirect", methods={"GET"})
* @ParamConverter("garage", class="App\Entity\Garages\Garage", options={"mapping": {"id": "id"}})
*/
public function legacyBackendGarageDetailRedirect(Garage $garage, ParameterBagInterface $pb, Request $request): RedirectResponse
{
$base = $pb->get('old_frontend_uri_es');
if (SiteEnum::SITE_STR_PT === $request->getLocale()) {
$base = $pb->get('old_frontend_uri_pt');
}
return $this->redirect($base.'admin/garage/'.$garage->getId().'/edit');
}
/**
* @Route("/legacy-frontend-tire-detail/{slug}/redirect", name="legacy_frontend_tire_detail_redirect", methods={"GET"})
* @ParamConverter("tire", class="App\Entity\Tires\Tire", options={"mapping": {"slug": "slug"}})
*/
public function legacyFrontendTireDetailRedirect(Tire $tire, TranslatorInterface $translator, ParameterBagInterface $pb, Request $request): RedirectResponse
{
$base = $pb->get('old_frontend_uri_es');
if (SiteEnum::SITE_STR_PT === $request->getLocale()) {
$base = $pb->get('old_frontend_uri_pt');
}
return $this->redirect($base.$translator->trans('tires.list.show_uri').'/'.$tire->getSlug());
}
}