62 lines
2.5 KiB
PHP
62 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\Admin\Application;
|
|
|
|
use App\Entity\Application;
|
|
use App\Event\ApplicationStatusEvent;
|
|
use App\Form\ApplicationCheckType;
|
|
use App\Model\AjaxModalResponseDto;
|
|
use App\Model\ApplicationCheckDto;
|
|
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;
|
|
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
|
|
|
class StatusController extends AbstractController
|
|
{
|
|
public function __construct(
|
|
private readonly EntityManagerInterface $entityManager,
|
|
private readonly EventDispatcherInterface $eventDispatcher,
|
|
private readonly LoggerInterface $logger
|
|
) {
|
|
}
|
|
|
|
#[Route('/admin/application/status/{uuid}', name: 'app_admin_application_status')]
|
|
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
|
#[IsGranted('STATUS', subject: 'application')]
|
|
public function index(Application $application, Request $request): JsonResponse
|
|
{
|
|
$response = new AjaxModalResponseDto();
|
|
$formAction = $this->generateUrl('app_admin_application_status', ['uuid' => $application->getUuid()]);
|
|
$formData = new ApplicationCheckDto($application);
|
|
$form = $this->createForm(ApplicationCheckType::class, $formData, ['action' => $formAction, 'ajax_submit' => true]);
|
|
|
|
$form->handleRequest($request);
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
$this->eventDispatcher->dispatch(new ApplicationStatusEvent($formData), ApplicationStatusEvent::NAME);
|
|
$application->setStatus($formData->getStatus());
|
|
$this->entityManager->flush();
|
|
|
|
$this->addFlash('success', 'Der Status der Bewerbung wurde aktualisiert');
|
|
$this->logger->info('Update application status', [
|
|
'application' => $application->getUuid(),
|
|
'status_new' => $formData->getStatus(),
|
|
]);
|
|
|
|
$response->setCloseAndRedirect($this->generateUrl('app_admin_assignment_detail', [
|
|
'uuid' => $application->getAssignment()->getUuid(),
|
|
]));
|
|
} else {
|
|
$response->setContent($this->renderView('admin/application/status.html.twig', [
|
|
'form' => $form,
|
|
]));
|
|
}
|
|
|
|
return $this->json($response);
|
|
}
|
|
} |