66 lines
2.1 KiB
PHP
66 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\Administrative\Assignment;
|
|
|
|
use App\Controller\Traits\ReturnUrlTrait;
|
|
use App\Entity\Assignment;
|
|
use App\Entity\User;
|
|
use App\Form\AssignmentType;
|
|
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 CreateController extends AbstractController
|
|
{
|
|
use ReturnUrlTrait;
|
|
|
|
public function __construct(
|
|
private readonly EntityManagerInterface $entityManager,
|
|
private readonly LoggerInterface $logger
|
|
) {
|
|
}
|
|
|
|
#[Route('/administrative/assignment/create', name: 'app_administrative_assignment_create')]
|
|
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
|
public function index(Request $request): Response
|
|
{
|
|
/** @var User $user */
|
|
$user = $this->getUser();
|
|
$assignment = new Assignment();
|
|
$assignment->setOwner($user);
|
|
$returnUrl = $this->getReturnUrl($request, 'app_administrative_assignment_index');
|
|
|
|
$form = $this->createForm(
|
|
AssignmentType::class,
|
|
$assignment,
|
|
[
|
|
'pickup_form_url' => $this->generateUrl('app_administrative_assignment_pickup_form'),
|
|
]
|
|
);
|
|
$form->handleRequest($request);
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
$this->entityManager->persist($assignment);
|
|
$this->entityManager->flush();
|
|
|
|
$this->addFlash('success', 'Der Einsatz wurde angelegt');
|
|
|
|
$this->logger->info('Create assignment', [
|
|
'assignment_id' => $assignment->getId(),
|
|
'destination' => (string) $assignment->getDestination(),
|
|
'job_profile' => $assignment->getJobProfile()->getName(),
|
|
]);
|
|
|
|
return $this->redirect($returnUrl);
|
|
}
|
|
|
|
return $this->render('administrative/assignment/create.html.twig', [
|
|
'form' => $form->createView(),
|
|
'returnUrl' => $returnUrl,
|
|
]);
|
|
}
|
|
} |