Files
myep-team/src/Controller/Admin/Application/DisposeController.php
T

66 lines
2.5 KiB
PHP

<?php
namespace App\Controller\Admin\Application;
use App\Entity\Application;
use App\Entity\Disposition;
use App\Event\DispositionCreatedEvent;
use App\Form\SpecialAgreementsType;
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;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class DisposeController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly EventDispatcherInterface $eventDispatcher,
private readonly LoggerInterface $logger
) {
}
#[Route('/admin/application/dispose/{uuid}', name: 'app_admin_application_dispose')]
#[IsGranted('ROLE_ADMINISTRATIVE')]
#[IsGranted('DISPOSE', subject: 'application')]
public function index(Application $application, Request $request): Response
{
$disposition = new Disposition($application);
$form = $this->createForm(SpecialAgreementsType::class, $disposition, ['hx_post' => $request->getUri()]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->entityManager->persist($disposition);
$this->entityManager->remove($application);
$this->entityManager->flush();
// Update staffing status of related assignment
$disposition->getAssignment()->updateStaffingStatus();
$this->entityManager->flush();
$this->eventDispatcher->dispatch(new DispositionCreatedEvent($disposition), DispositionCreatedEvent::NAME);
$this->addFlash('success', 'Teamer:in wurde eingeteilt');
$this->logger->info('Create disposition', [
'disposition_id' => $disposition->getId(),
'teamer' => (string) $application->getTeamer(),
]);
$redirectUrl = $this->generateUrl('app_administrative_assignment_detail', [
'uuid' => $application->getAssignment()->getUuid(),
]);
return new HxRedirectResponse($redirectUrl);
}
return $this->render('admin/application/modal_dispose.html.twig', [
'application' => $application,
'form' => $form->createView(),
]);
}
}