feat: custom destinations
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Autocomplete;
|
||||
|
||||
use App\BusProNet\DataProvider\HotelDataProvider;
|
||||
use App\BusProNet\Model\Hotel;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class HotelController extends AbstractController
|
||||
{
|
||||
public function __construct(private readonly HotelDataProvider $hotelDataProvider)
|
||||
{}
|
||||
|
||||
#[Route('/admin/autocomplete/hotel', name: 'app_admin_autocomplete_hotel')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$query = json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$queryString = $query['search'];
|
||||
} catch (\JsonException $e) {
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
/** @var Hotel[] $hotels */
|
||||
$hotels = $this->hotelDataProvider->getAll();
|
||||
|
||||
$data = [
|
||||
[
|
||||
'value' => '',
|
||||
'text' => '...',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($hotels as $hotel) {
|
||||
if (false !== stripos($hotel->getName(), $queryString)) {
|
||||
$data[] = [
|
||||
'value' => $hotel->getBusProId(),
|
||||
'text' => sprintf('%s (%s)', $hotel->getName(), $hotel->getCode()),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->json($data);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,18 @@
|
||||
namespace App\Entity;
|
||||
|
||||
use App\BusProNet\Model\Pickup;
|
||||
use App\Entity\Traits\BlameableEntity;
|
||||
use App\Entity\Traits\SoftDeletableEntity;
|
||||
use App\Entity\Traits\TimestampableEntity;
|
||||
use App\Repository\DestinationRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[ORM\Entity(repositoryClass: DestinationRepository::class)]
|
||||
class Destination implements TimestampableEntityInterface, SoftDeletableEntityInterface
|
||||
class Destination implements TimestampableEntityInterface, SoftDeletableEntityInterface, BlameableEntityInterface
|
||||
{
|
||||
use BlameableEntity;
|
||||
use TimestampableEntity;
|
||||
use SoftDeletableEntity;
|
||||
|
||||
@@ -20,10 +23,10 @@ class Destination implements TimestampableEntityInterface, SoftDeletableEntityIn
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column]
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $busProId = null;
|
||||
|
||||
#[ORM\Column(length: 32)]
|
||||
#[ORM\Column(length: 32, nullable: true)]
|
||||
private ?string $code = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
||||
@@ -81,7 +84,7 @@ class Destination implements TimestampableEntityInterface, SoftDeletableEntityIn
|
||||
return $this->dateFrom;
|
||||
}
|
||||
|
||||
public function setDateFrom(\DateTimeImmutable $dateFrom): static
|
||||
public function setDateFrom(?\DateTimeImmutable $dateFrom): static
|
||||
{
|
||||
$this->dateFrom = $dateFrom;
|
||||
|
||||
@@ -93,7 +96,7 @@ class Destination implements TimestampableEntityInterface, SoftDeletableEntityIn
|
||||
return $this->dateTo;
|
||||
}
|
||||
|
||||
public function setDateTo(\DateTimeImmutable $dateTo): static
|
||||
public function setDateTo(?\DateTimeImmutable $dateTo): static
|
||||
{
|
||||
$this->dateTo = $dateTo;
|
||||
|
||||
@@ -117,7 +120,7 @@ class Destination implements TimestampableEntityInterface, SoftDeletableEntityIn
|
||||
return $this->product;
|
||||
}
|
||||
|
||||
public function setProduct(string $product): static
|
||||
public function setProduct(?string $product): static
|
||||
{
|
||||
$this->product = $product;
|
||||
|
||||
@@ -129,7 +132,7 @@ class Destination implements TimestampableEntityInterface, SoftDeletableEntityIn
|
||||
return $this->hotel;
|
||||
}
|
||||
|
||||
public function setHotel(string $hotel): static
|
||||
public function setHotel(?string $hotel): static
|
||||
{
|
||||
$this->hotel = $hotel;
|
||||
|
||||
|
||||
@@ -181,7 +181,11 @@ class AssignmentType extends AbstractType
|
||||
$choices = [];
|
||||
|
||||
foreach ($destination->getPickups() as $pickup) {
|
||||
$label = sprintf('%s, %s Uhr', trim($pickup['city']), trim($pickup['time']));
|
||||
if ($pickup['time']) {
|
||||
$label = sprintf('%s, %s Uhr', trim($pickup['city']), trim($pickup['time']));
|
||||
} else {
|
||||
$label = trim($pickup['city']);
|
||||
}
|
||||
$choices[$label] = $pickup['busProId'];
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ class AutocompleteChoiceType extends AbstractType
|
||||
'placeholder' => null,
|
||||
'endpoint_parameters' => [],
|
||||
'controller_action' => null,
|
||||
'initial_label' => null,
|
||||
]);
|
||||
|
||||
$resolver->setAllowedTypes('choices', 'array');
|
||||
@@ -37,7 +38,7 @@ class AutocompleteChoiceType extends AbstractType
|
||||
}
|
||||
$view->vars['placeholder'] = $options['placeholder'];
|
||||
|
||||
$view->vars['initial_label'] = $form->getData();
|
||||
$view->vars['initial_label'] = $options['initial_label'] ?? $form->getData();
|
||||
$view->vars['initial_value'] = $form->getData();
|
||||
$view->vars['action'] = $options['controller_action'];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace App\Form;
|
||||
|
||||
use App\BusProNet\DataProvider\PickupDataProvider;
|
||||
use App\Form\ChoiceLoader\BpnPickupsChoiceLoader;
|
||||
use App\Form\ChoiceLoader\BpnPickupChoiceLoader;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
@@ -21,7 +21,7 @@ class BpnPickupType extends AbstractType
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'choice_loader' => new BpnPickupsChoiceLoader($this->pickups),
|
||||
'choice_loader' => new BpnPickupChoiceLoader($this->pickups),
|
||||
'preferred_choices' => [
|
||||
40, // Köln
|
||||
18, // Essen
|
||||
|
||||
+9
-8
@@ -2,25 +2,26 @@
|
||||
|
||||
namespace App\Form\ChoiceLoader;
|
||||
|
||||
use App\BusProNet\DataProvider\ProductDataProvider;
|
||||
use App\BusProNet\Model\Product;
|
||||
use App\BusProNet\DataProvider\HotelDataProvider;
|
||||
use App\BusProNet\Model\Hotel;
|
||||
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
|
||||
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
|
||||
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
|
||||
|
||||
class BpnProductsChoiceLoader implements ChoiceLoaderInterface
|
||||
class BpnHotelChoiceLoader implements ChoiceLoaderInterface
|
||||
{
|
||||
public function __construct(private readonly ProductDataProvider $products)
|
||||
public function __construct(private readonly HotelDataProvider $dataProvider)
|
||||
{}
|
||||
|
||||
public function loadChoiceList(callable $value = null): ChoiceListInterface
|
||||
{
|
||||
$choices = [];
|
||||
/** @var Product[] $products */
|
||||
$products = $this->products->getAll();
|
||||
/** @var Hotel[] $hotels */
|
||||
$hotels = $this->dataProvider->getAll();
|
||||
|
||||
foreach ($products as $product) {
|
||||
$choices[$product->getName()] = $product->getId();
|
||||
foreach ($hotels as $hotel) {
|
||||
$label = sprintf('%s (%s)', $hotel->getName(), $hotel->getCode());
|
||||
$choices[$label] = $hotel->getBusProId();
|
||||
}
|
||||
|
||||
ksort($choices);
|
||||
+3
-3
@@ -8,16 +8,16 @@ use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
|
||||
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
|
||||
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
|
||||
|
||||
class BpnPickupsChoiceLoader implements ChoiceLoaderInterface
|
||||
class BpnPickupChoiceLoader implements ChoiceLoaderInterface
|
||||
{
|
||||
public function __construct(private readonly PickupDataProvider $pickups)
|
||||
public function __construct(private readonly PickupDataProvider $dataProvider)
|
||||
{}
|
||||
|
||||
public function loadChoiceList(callable $value = null): ChoiceListInterface
|
||||
{
|
||||
$choices = [];
|
||||
/** @var Pickup[] $pickups */
|
||||
$pickups = $this->pickups->getAll();
|
||||
$pickups = $this->dataProvider->getAll();
|
||||
|
||||
foreach ($pickups as $pickup) {
|
||||
$choices[$pickup->getCity()] = $pickup->getBusProId();
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\BusProNet\DataProvider\HotelDataProvider;
|
||||
use App\Model\DestinationDto;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class DestinationType extends AbstractType
|
||||
{
|
||||
public function __construct(private readonly HotelDataProvider $hotelDataProvider)
|
||||
{
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('product', TextType::class, [
|
||||
'label' => 'Bezeichnung',
|
||||
])
|
||||
->add('dateFrom', DatepickerType::class, [
|
||||
'label' => 'Datum von',
|
||||
])
|
||||
->add('dateTo', DatepickerType::class, [
|
||||
'label' => 'Datum bis',
|
||||
])
|
||||
->add('pickups', CollectionType::class, [
|
||||
'label' => 'Zustiege',
|
||||
'entry_type' => BpnPickupType::class,
|
||||
'allow_add' => true,
|
||||
'allow_delete' => true,
|
||||
])
|
||||
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
|
||||
$form = $event->getForm();
|
||||
$data = $event->getData();
|
||||
|
||||
$this->addHotelField($form, $data->getHotelBusProId());
|
||||
})
|
||||
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
|
||||
$form = $event->getForm();
|
||||
$data = $event->getData();
|
||||
|
||||
$this->addHotelField($form, $data['hotelBusProId'] ?? null);
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
private function addHotelField(FormInterface $form, ?string $hotelBusProId): void
|
||||
{
|
||||
$hotelLabel = null;
|
||||
|
||||
if (null !== $hotelBusProId) {
|
||||
$hotel = $this->hotelDataProvider->get($hotelBusProId);
|
||||
$hotelLabel = sprintf('%s (%s)', $hotel->getName(), $hotel->getCode());
|
||||
}
|
||||
|
||||
$form
|
||||
->remove('hotelBusProId')
|
||||
->add('hotelBusProId', AutocompleteChoiceType::class, [
|
||||
'label' => 'Vertragspartner',
|
||||
'endpoint_route' => 'app_admin_autocomplete_hotel',
|
||||
'initial_label' => $hotelLabel,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => DestinationDto::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -126,6 +126,17 @@ class AdminMenuBuilder extends AbstractMenuBuilder
|
||||
],
|
||||
],
|
||||
]);
|
||||
$settingsMenu->addChild('Reisen', [
|
||||
'route' => 'app_administrative_system_destination_index',
|
||||
'linkAttributes' => [
|
||||
'title' => 'Reisen',
|
||||
],
|
||||
'extras' => [
|
||||
'routes' => [
|
||||
['pattern' => '/^app_administrative_system_destination_/']
|
||||
],
|
||||
],
|
||||
]);
|
||||
$settingsMenu->addChild('Feedbackvorlagen', [
|
||||
'route' => 'app_admin_system_feedback_set_index',
|
||||
'linkAttributes' => [
|
||||
|
||||
@@ -72,6 +72,17 @@ class ManagerMenuBuilder extends AbstractMenuBuilder
|
||||
'icon' => 'settings',
|
||||
],
|
||||
]);
|
||||
$settingsMenu->addChild('Reisen', [
|
||||
'route' => 'app_administrative_system_destination_index',
|
||||
'linkAttributes' => [
|
||||
'title' => 'Reisen',
|
||||
],
|
||||
'extras' => [
|
||||
'routes' => [
|
||||
['pattern' => '/^app_administrative_system_destination_/']
|
||||
],
|
||||
],
|
||||
]);
|
||||
$settingsMenu->addChild('FAQ', [
|
||||
'route' => 'app_administrative_system_faq_index',
|
||||
'linkAttributes' => [
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use App\Entity\Destination;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class DestinationDto
|
||||
{
|
||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
||||
private ?string $product = null;
|
||||
|
||||
#[Assert\NotNull(message: 'Bitte das Beginndatum angeben')]
|
||||
private ?\DateTimeImmutable $dateFrom = null;
|
||||
|
||||
#[Assert\NotNull(message: 'Bitte das Enddatum angeben')]
|
||||
private ?\DateTimeImmutable $dateTo = null;
|
||||
|
||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
||||
private ?string $hotelBusProId = null;
|
||||
|
||||
private array $pickups = [];
|
||||
|
||||
public static function fromEntity(Destination $destination): static
|
||||
{
|
||||
$instance = new static();
|
||||
|
||||
$pickupIds = array_map(function (array $pickup) {
|
||||
return $pickup['busProId'];
|
||||
}, $destination->getPickups());
|
||||
|
||||
$instance
|
||||
->setProduct($destination->getProduct())
|
||||
->setDateFrom($destination->getDateFrom())
|
||||
->setDateTo($destination->getDateTo())
|
||||
->setHotelBusProId($destination->getHotelBusProId())
|
||||
->setPickups($pickupIds)
|
||||
;
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public function getProduct(): ?string
|
||||
{
|
||||
return $this->product;
|
||||
}
|
||||
|
||||
public function setProduct(?string $product): static
|
||||
{
|
||||
$this->product = $product;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateFrom(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->dateFrom;
|
||||
}
|
||||
|
||||
public function setDateFrom(?\DateTimeImmutable $dateFrom): static
|
||||
{
|
||||
$this->dateFrom = $dateFrom;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateTo(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->dateTo;
|
||||
}
|
||||
|
||||
public function setDateTo(?\DateTimeImmutable $dateTo): static
|
||||
{
|
||||
$this->dateTo = $dateTo;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHotelBusProId(): ?string
|
||||
{
|
||||
return $this->hotelBusProId;
|
||||
}
|
||||
|
||||
public function setHotelBusProId(?string $hotelBusProId): static
|
||||
{
|
||||
$this->hotelBusProId = $hotelBusProId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPickups(): array
|
||||
{
|
||||
return $this->pickups;
|
||||
}
|
||||
|
||||
public function setPickups(array $pickups): static
|
||||
{
|
||||
$this->pickups = $pickups;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,11 @@ namespace App\Model;
|
||||
|
||||
class EmailAttachmentDto
|
||||
{
|
||||
public function __construct(private string $name, private string $content, private string $mimeType)
|
||||
{
|
||||
public function __construct(
|
||||
private readonly string $name,
|
||||
private readonly string $content,
|
||||
private readonly string $mimeType
|
||||
) {
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
|
||||
+5
-16
@@ -4,24 +4,13 @@ namespace App\Model;
|
||||
|
||||
class UploadDto
|
||||
{
|
||||
private string $uuid;
|
||||
private string $filename;
|
||||
private string $originalFilename;
|
||||
private string $mimeType;
|
||||
private int $size;
|
||||
|
||||
public function __construct(
|
||||
string $uuid,
|
||||
string $filename,
|
||||
string $originalFilename,
|
||||
string $mimeType,
|
||||
int $size
|
||||
private readonly string $uuid,
|
||||
private readonly string $filename,
|
||||
private readonly string $originalFilename,
|
||||
private readonly string $mimeType,
|
||||
private readonly int $size
|
||||
) {
|
||||
$this->uuid = $uuid;
|
||||
$this->filename = $filename;
|
||||
$this->originalFilename = $originalFilename;
|
||||
$this->mimeType = $mimeType;
|
||||
$this->size = $size;
|
||||
}
|
||||
|
||||
public function getUuid(): string
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Repository;
|
||||
use App\Entity\Destination;
|
||||
use App\Repository\Traits\QueryHelperTrait;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
@@ -24,6 +25,20 @@ class DestinationRepository extends ServiceEntityRepository
|
||||
parent::__construct($registry, Destination::class);
|
||||
}
|
||||
|
||||
public function getListQueryForCustom(): Query
|
||||
{
|
||||
$qb = $this->createQueryBuilder('destination');
|
||||
|
||||
return $qb
|
||||
->where(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->isNull('destination.deletedAt'),
|
||||
$qb->expr()->isNull('destination.busProId'))
|
||||
)
|
||||
->getQuery()
|
||||
;
|
||||
}
|
||||
|
||||
public function getAutocompletionData(string $search, bool $upcomingOnly = true): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('destination');
|
||||
|
||||
Reference in New Issue
Block a user