<?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 Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use App\Common\Controllers\CrmAbstractController;
use App\Entity\{Csp, CspCountry, Country};
use App\Services\Administration\CspCountryService;
class CspCountryController extends CrmAbstractController
{
/**
* @see CrmAbstractController
*/
protected function initModuleDetails(): array
{
return [
'entityClassName' => CspCountry::class,
'moduleService' => CspCountryService::class,
];
}
#[Route('/administration/csp/{id}/countries', name: 'administration_csp_countries', options: ['expose' => true])]
public function index(CspCountryService $cspCountryService, Csp $csp): Response
{
return new Response($cspCountryService->getList($csp));
}
#[Security("is_granted('ROLE_PM') or is_granted('ROLE_EDM') or is_granted('ROLE_EPA')")]
#[Route(
'/administration/csp-country/{id}/add',
name: 'administration_csp_countries_add',
methods: ['POST'],
options: ['expose' => true])
]
public function add(
Request $request,
CspCountryService $cspCountryService,
CspCountry $cspCountry
): Response {
$cspCountryService->saveCspCountry($cspCountry);
return $this->redirectToRoute('administration_csp_countries', ['id' => $cspCountry->getCsp()->getId()]);
}
#[Security("is_granted('ROLE_PM') or is_granted('ROLE_EDM') or is_granted('ROLE_EPA')")]
#[Route(
'/administration/csp-country/{id}',
name: 'administration_csp_country_item',
options: ['expose' => true])
]
public function getCspCountry(
CspCountryService $cspCountryService,
CspCountry $cspCountry
): Response {
return new Response($cspCountryService->getSerializedEntity($cspCountry));
}
#[Security("is_granted('ROLE_PM') or is_granted('ROLE_EDM') or is_granted('ROLE_EPA')")]
#[Route(
'/administration/csp-country/{id}/delete',
name: 'administration_csp_countries_delete',
options: ['expose' => true])
]
public function delete(
CspCountryService $cspCountryService,
CspCountry $cspCountry
): Response {
$cspCountryService->deleteCspCountry($cspCountry);
return $this->redirectToRoute('administration_csp_countries', ['id' => $cspCountry->getCsp()->getId()]);
}
#[Route(
'/administration/csp/{id}/country/{cId}/details',
name: 'administration_csp_country_details',
options: ['expose' => true])
]
#[ParamConverter('csp', class: Csp::class, options: ['mapping' => ['id' => 'id']])]
#[ParamConverter('country', class: Country::class, options: ['mapping' => ['cId' => 'id']])]
public function cspCountryDetails(CspCountryService $cspCountryService, Csp $csp, Country $country): Response
{
return $this->render(
'administration/csp/csp_country_details.html.twig', [
'cspCountry' => $cspCountryService->getCspCountryEntityByCspAndCountry($csp, $country),
]
);
}
}