Files
myep-team/src/Controller/Administrative/Assignment/DeleteController.php
T

46 lines
1.6 KiB
PHP

<?php
namespace App\Controller\Administrative\Assignment;
use App\Entity\Assignment;
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('/administrative/assignment/delete/{uuid}', name: 'app_administrative_assignment_delete')]
#[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(Assignment $assignment, Request $request): Response
{
if (true === $request->isMethod('POST')) {
$assignment->setDeleted();
$this->entityManager->flush();
$this->logger->info('Delete assignment', [
'assignment_id' => $assignment->getId(),
'destination' => (string) $assignment->getDestination(),
'job_profile' => $assignment->getJobProfile()->getName(),
]);
$this->addFlash('success', 'Der Einsatz wurde gelöscht');
return new HxRedirectResponse($this->generateUrl('app_administrative_assignment_index'));
}
return $this->render('administrative/assignment/modal_delete.html.twig', [
'assignment' => $assignment,
]);
}
}