Files
myep-team/src/Controller/Admin/System/StaffingRule/EditController.php
T

48 lines
1.6 KiB
PHP

<?php
namespace App\Controller\Admin\System\StaffingRule;
use App\Entity\StaffingRule;
use App\Form\StaffingRuleType;
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 EditController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly LoggerInterface $logger,
) {
}
#[Route('/admin/system/staffing-rule/edit/{uuid}', name: 'app_admin_system_staffing_rule_edit')]
#[IsGranted('ROLE_TEAM_ADMIN')]
public function index(StaffingRule $rule, Request $request): Response
{
$form = $this->createForm(StaffingRuleType::class, $rule);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->entityManager->flush();
$this->addFlash('success', 'Die Zeile der Besetzungsmatrix wurde aktualisiert');
$this->logger->info('Edit staffing rule', [
'staffing_rule_id' => $rule->getId(),
'product_code' => $rule->getProductCode(),
]);
return new HxRedirectResponse($this->generateUrl('app_admin_system_staffing_rule_index'));
}
return $this->render('admin/system/staffing_rule/modal_edit.html.twig', [
'form' => $form->createView(),
]);
}
}