44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\Admin\System\Availability;
|
|
|
|
use App\Entity\Availability;
|
|
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/availability/delete/{id}', name: 'app_admin_system_availability_delete', methods: ['POST'])]
|
|
#[IsGranted('ROLE_ADMIN')]
|
|
public function index(Availability $availability, Request $request): Response
|
|
{
|
|
if (true === $request->isMethod('POST')) {
|
|
$availability->setDeleted();
|
|
$this->entityManager->flush();
|
|
|
|
$this->addFlash('success', 'Die Verfügbarkeit wurde gelöscht');
|
|
$this->logger->info('Delete availability', [
|
|
'availability_id' => $availability->getId(),
|
|
'availability_range' => (string) $availability,
|
|
]);
|
|
|
|
return new HxRedirectResponse($this->generateUrl('app_admin_system_availability_index'));
|
|
}
|
|
|
|
return $this->render('admin/system/availability/modal_delete.html.twig', [
|
|
'availability' => $availability,
|
|
]);
|
|
}
|
|
} |