<?php
declare(strict_types=1);
namespace App\Controller\Administration;
use Symfony\Component\HttpFoundation\{
Request,
Response
};
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use App\Common\Controllers\CrmAbstractController;
use App\Entity\{Csp, Country, Customer};
use App\Services\Administration\CountryService;
class CountriesPerCspController extends CrmAbstractController
{
/**
* @see CrmAbstractController
*/
protected function initModuleDetails(): array
{
return [
'entityClassName' => Country::class,
'moduleService' => CountryService::class,
];
}
#[Route(
'/administration/customer/{id}/csp/{cId}/countries-per-csp',
name: 'administration_customer_countries_per_csp',
options: ['expose' => true])
]
#[ParamConverter('customer', class: Customer::class, options: ['mapping' => ['id' => 'id']])]
#[ParamConverter('csp', class: Csp::class, options: ['mapping' => ['cId' => 'id']])]
public function index(CountryService $countryService, Customer $customer, Csp $csp): Response
{
return new Response($countryService->getCountriesPerCsp($csp, $customer->getExcludedCsps()));
}
#[Route('/administration/csp/{id}/countries/ddl/{type}', name: 'administration_csp_countries_ddl', options: ['expose' => true])]
public function cspCountriesDdl(CountryService $countryService, Csp $csp, ?string $type = 'list'): Response
{
$template = ('multiple' === $type)
? 'csp_countries_multiple_ddl.html.twig'
: 'csp_countries_ddl.html.twig'
;
return $this->render(
sprintf('administration/csp/%s', $template), [
'countries' => json_decode($countryService->getCountriesPerCsp($csp)),
]
);
}
}