54 lines
1.8 KiB
PHP
54 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\Admin\System\Fee;
|
|
|
|
use App\Entity\Fee;
|
|
use App\Form\FeeType;
|
|
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/fee/edit/{id}', name: 'app_admin_system_fee_edit')]
|
|
#[IsGranted('ROLE_ADMIN')]
|
|
public function index(Fee $fee, Request $request): JsonResponse
|
|
{
|
|
$response = new AjaxModalResponseDto();
|
|
$action = $this->generateUrl('app_admin_system_fee_edit', ['id' => $fee->getId()]);
|
|
|
|
$form = $this->createForm(FeeType::class, $fee, ['action' => $action, 'ajax_submit' => true]);
|
|
$form->handleRequest($request);
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
$this->entityManager->flush();
|
|
|
|
$this->addFlash('success', 'Das Honorar wurde aktualisiert');
|
|
$this->logger->info('Edit fee', [
|
|
'fee_id' => $fee->getId(),
|
|
'fee_name' => $fee->getNameInternal() ?? $fee->getName(),
|
|
]);
|
|
|
|
$redirectUrl = $this->generateUrl('app_admin_system_fee_index');
|
|
$response->setCloseAndRedirect($redirectUrl);
|
|
} else {
|
|
$content = $this->renderView('admin/system/fee/form.html.twig', [
|
|
'form' => $form
|
|
]);
|
|
$response->setContent($content);
|
|
}
|
|
|
|
return $this->json($response);
|
|
}
|
|
} |