feat: assignment call off
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\Assignment;
|
||||
|
||||
use App\Entity\Assignment;
|
||||
use App\Event\AssignmentCalledOffEvent;
|
||||
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 CallOffController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly EventDispatcherInterface $eventDispatcher,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/administrative/assignment/call-off/{uuid}', name: 'app_administrative_assignment_call_off')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Assignment $assignment, Request $request): Response
|
||||
{
|
||||
if (true === $request->isMethod('POST')) {
|
||||
$assignment->setStatus(Assignment::STATUS_CALLED_OFF);
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this
|
||||
->eventDispatcher
|
||||
->dispatch(new AssignmentCalledOffEvent($assignment), AssignmentCalledOffEvent::NAME)
|
||||
;
|
||||
|
||||
$this->logger->info('Call off assignment', [
|
||||
'assignment_id' => $assignment->getId(),
|
||||
'destination' => (string) $assignment->getDestination(),
|
||||
'job_profile' => $assignment->getJobProfile()->getName(),
|
||||
]);
|
||||
|
||||
$this->addFlash('success', 'Der Einsatz/die Reise wurde abgesagt');
|
||||
|
||||
return new HxRedirectResponse($this->generateUrl('app_administrative_assignment_index'));
|
||||
}
|
||||
|
||||
return $this->render('administrative/assignment/modal_call_off.html.twig', [
|
||||
'assignment' => $assignment,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user