45 lines
1.5 KiB
PHP
45 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\Admin\System\Training;
|
|
|
|
use App\Entity\Training;
|
|
use App\Htmx\HxRedirectResponse;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
|
|
|
class DeleteController extends AbstractController
|
|
{
|
|
public function __construct(
|
|
private readonly EntityManagerInterface $entityManager,
|
|
private readonly LoggerInterface $logger,
|
|
) {
|
|
}
|
|
|
|
#[Route('/admin/system/training/delete/{id}', name: 'app_admin_system_training_delete')]
|
|
#[IsGranted('ROLE_TEAM_ADMIN')]
|
|
public function index(Training $training, Request $request): Response
|
|
{
|
|
if (true === $request->isMethod('POST')) {
|
|
$training->setDeleted();
|
|
$this->entityManager->flush();
|
|
|
|
$this->addFlash('success', 'Die Fortbildung wurde gelöscht');
|
|
$this->logger->info('Delete training', [
|
|
'training_id' => $training->getId(),
|
|
'training_name' => $training->getName(),
|
|
]);
|
|
|
|
return new HxRedirectResponse($this->generateUrl('app_admin_system_training_index'));
|
|
}
|
|
|
|
return $this->render('admin/system/training/modal_delete.html.twig', [
|
|
'training' => $training,
|
|
]);
|
|
}
|
|
}
|