Feat: Implement duplicating assignments for admins
This commit is contained in:
1 parent
62ca1666bd
commit
05c925eec1
5 files changed
+56
-7
No files matched your search
@@ -12,7 +12,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class EditController extends AbstractController
|
||||
class DuplicateController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
@@ -20,26 +20,31 @@ class EditController extends AbstractController
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/assignment/edit/{uuid}', name: 'app_admin_assignment_edit')]
|
||||
#[Route('/admin/assignment/duplicate/{uuid}', name: 'app_admin_assignment_duplicate')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Assignment $assignment, Request $request): Response
|
||||
{
|
||||
$form = $this->createForm(AssignmentType::class, $assignment);
|
||||
$copy = Assignment::duplicate($assignment);
|
||||
|
||||
$form = $this->createForm(AssignmentType::class, $copy);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->entityManager->persist($copy);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Der Einsatz wurde aktualisiert');
|
||||
$this->addFlash('success', 'Der Einsatz wurde dupliziert');
|
||||
|
||||
$this->logger->info('Edit assignment', [
|
||||
$this->logger->info('Duplicate assignment', [
|
||||
'assignment' => $assignment->getUuid(),
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_admin_assignment_index');
|
||||
return $this->redirectToRoute('app_admin_assignment_edit', [
|
||||
'uuid' => $copy->getUuid(),
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->render('admin/assignment/edit.html.twig', [
|
||||
return $this->render('admin/assignment/duplicate.html.twig', [
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user