feat: duplicate an accommodation booking into a new draft

addresses #869f6z44f
This commit is contained in:
fromme committed 2026-09-28 08:55:01 +02:00
1 parent 2aa98b81fe
commit 29f295abf6
9 files changed
+470

No files matched your search

@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace App\Controller\Admin\AccommodationBooking;
use App\Entity\Groups\AccommodationBooking;
use App\Htmx\HxRedirectResponse;
use App\Service\AccommodationBookingService;
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;
/**
* Copying is its own named action rather than a flag on the edit route the way it is for the
* catalog entities (see Admin\AdditionalService\EditController): a booking carries a lifecycle,
* so the copy has to be reset and written before anybody edits it, and the edit form is built
* from a persisted record's house and service catalog.
*
* Unlike absagen and löschen this has no status guard — the original is not touched, so a
* confirmed or discarded booking may be copied just as well as a draft.
*/
#[IsGranted('ROLE_GROUPS_MANAGER')]
class DuplicateController extends AbstractController
{
public function __construct(
private readonly AccommodationBookingService $bookingService,
private readonly LoggerInterface $logger,
) {
}
#[Route('/admin/accommodation-booking/{id}/duplicate', name: 'app_admin_accommodationbooking_duplicate')]
public function index(AccommodationBooking $booking, Request $request): Response
{
if ($request->isMethod(Request::METHOD_POST)) {
if (!$this->isCsrfTokenValid('duplicate_accommodation_booking_'.$booking->getId(), $request->request->getString('_token'))) {
throw $this->createAccessDeniedException('Invalid CSRF token.');
}
$copy = $this->bookingService->duplicate($booking);
$this->addFlash('success', 'Die Kopie wurde als neuer Entwurf angelegt.');
$this->logger->info('Duplicated accommodation booking', [
'id' => $booking->getId(),
'copyId' => $copy->getId(),
'groupName' => $copy->getGroupName(),
]);
// Straight into the copy's edit form — the copy exists to be changed, and that is
// the only reason it was made. The return url is forwarded still encoded, the way
// return_url() handed it over, so "zurück" still leads to the list this started from.
$parameters = ['id' => $copy->getId()];
$returnUrl = $request->query->getString('r');
if ('' !== $returnUrl) {
$parameters['r'] = $returnUrl;
}
return new HxRedirectResponse($this->generateUrl('app_admin_accommodationbooking_edit', $parameters));
}
return $this->render('admin/accommodation_booking/modal_duplicate.html.twig', [
'booking' => $booking,
'csrf_token_id' => 'duplicate_accommodation_booking_'.$booking->getId(),
]);
}
}