53 lines
1.9 KiB
PHP
53 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\Admin\System\Availability;
|
|
|
|
use App\Entity\Availability;
|
|
use App\Form\AvailabilityType;
|
|
use App\Model\AjaxModalResponseDto;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
|
|
|
class EditController extends AbstractController
|
|
{
|
|
public function __construct(
|
|
private readonly EntityManagerInterface $entityManager,
|
|
private readonly LoggerInterface $logger
|
|
) {
|
|
}
|
|
|
|
#[Route('/admin/system/availability/edit/{id}', name: 'app_admin_system_availability_edit')]
|
|
#[IsGranted('ROLE_ADMIN')]
|
|
public function index(Availability $availability, Request $request): JsonResponse
|
|
{
|
|
$response = new AjaxModalResponseDto();
|
|
$action = $this->generateUrl('app_admin_system_availability_edit', ['id' => $availability->getId()]);
|
|
|
|
$form = $this->createForm(AvailabilityType::class, $availability, ['action' => $action, 'ajax_submit' => true]);
|
|
$form->handleRequest($request);
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
$this->entityManager->flush();
|
|
|
|
$this->addFlash('success', 'Die Verfügbarkeit wurde aktualisiert');
|
|
$this->logger->info('Edit availability', [
|
|
'availability' => $availability,
|
|
]);
|
|
|
|
$redirectUrl = $this->generateUrl('app_admin_system_availability_index');
|
|
$response->setCloseAndRedirect($redirectUrl);
|
|
} else {
|
|
$content = $this->renderView('admin/system/availability/form.html.twig', [
|
|
'form' => $form
|
|
]);
|
|
$response->setContent($content);
|
|
}
|
|
|
|
return $this->json($response);
|
|
}
|
|
} |