feat: custom destinations
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\System\Destination;
|
||||
|
||||
use App\BusProNet\DataProvider\HotelDataProvider;
|
||||
use App\BusProNet\DataProvider\PickupDataProvider;
|
||||
use App\Entity\Destination;
|
||||
use App\Form\DestinationType;
|
||||
use App\Model\DestinationDto;
|
||||
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 DestinationTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly HotelDataProvider $hotelDataProvider,
|
||||
private readonly PickupDataProvider $pickupDataProvider,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/administrative/destination/create', name: 'app_administrative_system_destination_create')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$destinationDto = new DestinationDto();
|
||||
|
||||
$form = $this->createForm(DestinationType::class, $destinationDto);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$destination = new Destination();
|
||||
$this->updateEntity($destination, $destinationDto);
|
||||
|
||||
$this->entityManager->persist($destination);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Die Reise wurde angelegt');
|
||||
|
||||
$this->logger->info('Create destination', [
|
||||
'destination_id' => $destination->getId(),
|
||||
'destination' => (string) $destination,
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_administrative_system_destination_index');
|
||||
}
|
||||
|
||||
return $this->render('administrative/system/destination/create.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\System\Destination;
|
||||
|
||||
use App\Entity\Destination;
|
||||
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;
|
||||
|
||||
class DeleteController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/administrative/system/destination/delete/{id}', name: 'app_administrative_system_destination_delete')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Destination $destination, Request $request): Response
|
||||
{
|
||||
if (true === $request->isMethod('POST')) {
|
||||
$destination->setDeleted();
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->logger->info('Delete destination', [
|
||||
'destination_id' => $destination->getId(),
|
||||
'destination' => (string) $destination,
|
||||
]);
|
||||
|
||||
$this->addFlash('success', 'Die Reise wurde gelöscht');
|
||||
|
||||
return new HxRedirectResponse($this->generateUrl('app_administrative_system_destination_index'));
|
||||
}
|
||||
|
||||
return $this->render('administrative/system/destination/modal_delete.html.twig', [
|
||||
'destination' => $destination,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\System\Destination;
|
||||
|
||||
use App\Entity\Destination;
|
||||
use App\Model\DestinationDto;
|
||||
|
||||
trait DestinationTrait
|
||||
{
|
||||
private function mapPickups(DestinationDto $destinationDto): array
|
||||
{
|
||||
$pickups = [];
|
||||
|
||||
foreach ($destinationDto->getPickups() as $pickupId) {
|
||||
$pickup = $this->pickupDataProvider->get($pickupId);
|
||||
$pickups[] = [
|
||||
'busProId' => $pickup->getBusProId(),
|
||||
'city' => $pickup->getCity(),
|
||||
'street' => $pickup->getStreet(),
|
||||
'time' => $pickup->getTime(),
|
||||
];
|
||||
}
|
||||
|
||||
return $pickups;
|
||||
}
|
||||
|
||||
private function updateEntity(Destination $destination, DestinationDto $destinationDto): void
|
||||
{
|
||||
$hotel = $this->hotelDataProvider->get($destinationDto->getHotelBusProId());
|
||||
$pickups = $this->mapPickups($destinationDto);
|
||||
|
||||
$destination
|
||||
->setProduct($destinationDto->getProduct())
|
||||
->setDateFrom($destinationDto->getDateFrom())
|
||||
->setDateTo($destinationDto->getDateTo())
|
||||
->setHotel($hotel->getName())
|
||||
->setHotelCode($hotel->getCode())
|
||||
->setHotelBusProId($hotel->getBusProId())
|
||||
->setPickups($pickups)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\System\Destination;
|
||||
|
||||
use App\BusProNet\DataProvider\HotelDataProvider;
|
||||
use App\Entity\Destination;
|
||||
use App\Form\DestinationType;
|
||||
use App\Model\DestinationDto;
|
||||
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 DuplicateController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly HotelDataProvider $hotelDataProvider,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/administrative/system/destination/duplicate/{id}', name: 'app_administrative_system_destination_duplicate')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Destination $destination, Request $request): Response
|
||||
{
|
||||
$destinationDto = DestinationDto::fromEntity($destination);
|
||||
|
||||
$form = $this->createForm(DestinationType::class, $destinationDto);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$hotel = $this->hotelDataProvider->get($destinationDto->getHotelBusProId());
|
||||
|
||||
$copy = new Destination();
|
||||
$copy
|
||||
->setProduct($destinationDto->getProduct())
|
||||
->setDateFrom($destinationDto->getDateFrom())
|
||||
->setDateTo($destinationDto->getDateTo())
|
||||
->setHotel($hotel->getName())
|
||||
->setHotelCode($hotel->getCode())
|
||||
->setHotelBusProId($hotel->getBusProId())
|
||||
;
|
||||
|
||||
$this->entityManager->persist($copy);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Die Reise wurde dupliziert');
|
||||
|
||||
$this->logger->info('Duplicate destination', [
|
||||
'original_id' => $destination->getId(),
|
||||
'duplicate_id' => $copy->getId(),
|
||||
'destination' => (string) $destination,
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_administrative_system_destination_edit', [
|
||||
'id' => $copy->getId(),
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->render('administrative/system/destination/duplicate.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\System\Destination;
|
||||
|
||||
use App\BusProNet\DataProvider\HotelDataProvider;
|
||||
use App\BusProNet\DataProvider\PickupDataProvider;
|
||||
use App\Entity\Destination;
|
||||
use App\Form\DestinationType;
|
||||
use App\Model\DestinationDto;
|
||||
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;
|
||||
|
||||
class EditController extends AbstractController
|
||||
{
|
||||
use DestinationTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly HotelDataProvider $hotelDataProvider,
|
||||
private readonly PickupDataProvider $pickupDataProvider,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/administrative/destination/edit/{id}', name: 'app_administrative_system_destination_edit')]
|
||||
public function index(Destination $destination, Request $request): Response
|
||||
{
|
||||
$destinationDto = DestinationDto::fromEntity($destination);
|
||||
$form = $this->createForm(DestinationType::class, $destinationDto);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->updateEntity($destination, $destinationDto);
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Die Reise wurde aktualisiert');
|
||||
|
||||
$this->logger->info('Edit assignment', [
|
||||
'destination_id' => $destination->getId(),
|
||||
'destination' => (string) $destination,
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_administrative_system_destination_index');
|
||||
}
|
||||
|
||||
return $this->render('administrative/system/destination/edit.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\System\Destination;
|
||||
|
||||
use App\Repository\DestinationRepository;
|
||||
use Knp\Component\Pager\PaginatorInterface;
|
||||
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 IndexController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DestinationRepository $destinationRepository,
|
||||
private readonly PaginatorInterface $paginator,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/administrative/system/destination', name: 'app_administrative_system_destination_index')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$query = $this
|
||||
->destinationRepository
|
||||
->getListQueryForCustom()
|
||||
;
|
||||
|
||||
$pagination = $this->paginator->paginate(
|
||||
$query,
|
||||
$request->query->getInt('page', 1),
|
||||
10,
|
||||
[
|
||||
'defaultSortFieldName' => 'destination.dateFrom',
|
||||
'defaultSortDirection' => 'desc',
|
||||
]
|
||||
);
|
||||
|
||||
return $this->render('administrative/system/destination/index.html.twig', [
|
||||
'pagination' => $pagination,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user