wip: first working version
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Booking;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
use function Symfony\Component\String\u;
|
||||
|
||||
class DownloadController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route(
|
||||
path: '/bookings/{id}/documents',
|
||||
name: 'app_booking_documents',
|
||||
requirements: ['id' => '\d+'],
|
||||
defaults: ['fileType' => 'documents']
|
||||
)]
|
||||
#[Route(
|
||||
path: '/bookings/{id}/confirmation',
|
||||
name: 'app_booking_confirmation',
|
||||
requirements: ['id' => '\d+'],
|
||||
defaults: ['fileType' => 'confirmation']
|
||||
)]
|
||||
#[IsGranted("ROLE_USER")]
|
||||
public function documents(int $id, string $fileType, Request $request): Response
|
||||
{
|
||||
$bpnUser = $request->getSession()->get('bpn_user');
|
||||
|
||||
if (null === $bpnUser) {
|
||||
return $this->security->logout();
|
||||
}
|
||||
|
||||
$type = match ($fileType) {
|
||||
'documents' => 'Dokumentendruck',
|
||||
'confirmation' => 'Vorgangdruck',
|
||||
};
|
||||
|
||||
$file = $this
|
||||
->apiClient
|
||||
->getDocuments($bpnUser->getEmail(), $bpnUser->getPassword(), $id, $type)
|
||||
;
|
||||
|
||||
if (null === $file || $file instanceof Notification) {
|
||||
$this->addFlash('error', 'Keine Dokumente vorhanden');
|
||||
|
||||
return $this->redirectToRoute('app_bookings');
|
||||
}
|
||||
|
||||
$filename = u($file->filename)->ascii();
|
||||
|
||||
$response = new Response($file->content);
|
||||
|
||||
$disposition = $response->headers->makeDisposition(
|
||||
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
|
||||
$filename,
|
||||
md5($filename)
|
||||
);
|
||||
|
||||
$response->headers->set('Content-Disposition', $disposition);
|
||||
$response->headers->set('Content-Type', $file->mimeType);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Booking;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\DataLoader\PickupDataLoader;
|
||||
use App\BusProNet\DataLoader\TravelDataLoader;
|
||||
use App\Form\BookingType;
|
||||
use App\Form\Model\BookingData;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class EditController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly TravelDataLoader $travelDataLoader,
|
||||
private readonly PickupDataLoader $pickupDataLoader,
|
||||
private readonly Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/bookings/{id}/edit', name: 'app_booking_edit', requirements: ['id' => '\d+'])]
|
||||
#[IsGranted("ROLE_USER")]
|
||||
public function edit(int $id, Request $request): Response
|
||||
{
|
||||
$bpnUser = $request->getSession()->get('bpn_user');
|
||||
|
||||
if (null === $bpnUser) {
|
||||
return $this->security->logout();
|
||||
}
|
||||
|
||||
$booking = $this->apiClient->getBooking($bpnUser->getEmail(), $bpnUser->getPassword(), $id);
|
||||
|
||||
//$this->denyAccessUnlessGranted('VIEW', $booking);
|
||||
|
||||
$travelData = $this->travelDataLoader->loadById($booking->travelId);
|
||||
|
||||
if (null === $travelData) {
|
||||
$this->addFlash('error', 'Reisedaten nicht (mehr) verfügbar');
|
||||
|
||||
return $this->redirectToRoute('app_bookings');
|
||||
}
|
||||
|
||||
$booking->travelData = $travelData;
|
||||
$mutableFields = $this->apiClient->getMutableFields($booking->travelId);
|
||||
$availabilities = $this->apiClient->getAvailabilities($booking->travelId);
|
||||
|
||||
$this->travelDataLoader->enrichServicesData($travelData, $availabilities);
|
||||
$this->pickupDataLoader->enrichPickupsData($travelData);
|
||||
|
||||
$formData = BookingData::fromBooking($booking);
|
||||
|
||||
$form = $this->createForm(BookingType::class, $formData, [
|
||||
'hx_post' => $this->generateUrl('app_booking_edit', ['id' => $id]),
|
||||
'hx_target' => '#app',
|
||||
'hx_swap' => 'innerHTML show:top',
|
||||
'attr' => ['novalidate' => 'novalidate'],
|
||||
'travel' => $travelData,
|
||||
'mutable_fields' => $mutableFields,
|
||||
]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->apiClient->updateBooking($formData, false);
|
||||
|
||||
$this->addFlash('success', 'Buchung erfolgreich aktualisiert');
|
||||
|
||||
return new HxRedirectResponse($this->generateUrl('app_booking_edit', ['id' => $id]));
|
||||
}
|
||||
|
||||
return $this->render('booking/edit.html.twig', [
|
||||
'booking' => $booking,
|
||||
'travelData' => $travelData,
|
||||
'mutableFields' => $mutableFields,
|
||||
'availabilities' => $availabilities,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Booking;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
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 ApiClient $apiClient,
|
||||
private readonly Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/bookings', name: 'app_bookings')]
|
||||
#[IsGranted("ROLE_USER")]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$bpnUser = $request->getSession()->get('bpn_user');
|
||||
|
||||
if (null === $bpnUser) {
|
||||
return $this->security->logout();
|
||||
}
|
||||
|
||||
$bookings = $this->apiClient->getBookings($bpnUser->getEmail(), $bpnUser->getPassword());
|
||||
|
||||
return $this->render('booking/index.html.twig', [
|
||||
'bookings' => $bookings->getItems(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\DataLoader\PickupDataLoader;
|
||||
use App\BusProNet\DataLoader\TravelDataLoader;
|
||||
use App\BusProNet\Model\File;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\Form\BookingType;
|
||||
use App\Form\Model\BookingData;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
use function Symfony\Component\String\u;
|
||||
|
||||
class BookingController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly TravelDataLoader $travelDataLoader,
|
||||
private readonly PickupDataLoader $pickupDataLoader,
|
||||
private readonly Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/bookings', name: 'app_bookings')]
|
||||
#[IsGranted("ROLE_USER")]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$bpnUser = $request->getSession()->get('bpn_user');
|
||||
|
||||
if (null === $bpnUser) {
|
||||
return $this->security->logout();
|
||||
}
|
||||
|
||||
$bookings = $this->apiClient->getBookings($bpnUser->getEmail(), $bpnUser->getPassword());
|
||||
|
||||
return $this->render('booking/index.html.twig', [
|
||||
'bookings' => $bookings->getItems(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/bookings/{id}/edit', name: 'app_booking_edit', requirements: ['id' => '\d+'])]
|
||||
#[IsGranted("ROLE_USER")]
|
||||
public function edit(int $id, Request $request): Response
|
||||
{
|
||||
$bpnUser = $request->getSession()->get('bpn_user');
|
||||
|
||||
if (null === $bpnUser) {
|
||||
return $this->security->logout();
|
||||
}
|
||||
|
||||
$booking = $this->apiClient->getBooking($bpnUser->getEmail(), $bpnUser->getPassword(), $id);
|
||||
|
||||
//$this->denyAccessUnlessGranted('VIEW', $booking);
|
||||
|
||||
$travelData = $this->travelDataLoader->loadById($booking->travelId);
|
||||
|
||||
if (null === $travelData) {
|
||||
$this->addFlash('error', 'Reisedaten nicht (mehr) verfügbar');
|
||||
|
||||
return $this->redirectToRoute('app_bookings');
|
||||
}
|
||||
|
||||
$mutableFields = $this->apiClient->getMutableFields($booking->travelId);
|
||||
$availabilities = $this->apiClient->getAvailabilities($booking->travelId);
|
||||
|
||||
$this->travelDataLoader->enrichServicesData($travelData, $availabilities);
|
||||
$this->pickupDataLoader->enrichPickupsData($travelData);
|
||||
|
||||
$formData = BookingData::fromBooking($booking);
|
||||
|
||||
$form = $this->createForm(BookingType::class, $formData, [
|
||||
'hx_post' => $this->generateUrl('app_booking_edit', ['id' => $id]),
|
||||
'hx_target' => '#app',
|
||||
'hx_swap' => 'innerHTML show:top',
|
||||
'attr' => ['novalidate' => 'novalidate'],
|
||||
'travel' => $travelData,
|
||||
'mutable_fields' => $mutableFields,
|
||||
]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->apiClient->updateBooking($bpnUser->getEmail(), $bpnUser->getPassword(), $formData);
|
||||
}
|
||||
|
||||
return $this->render('booking/edit.html.twig', [
|
||||
'booking' => $booking,
|
||||
'travelData' => $travelData,
|
||||
'mutableFields' => $mutableFields,
|
||||
'availabilities' => $availabilities,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/bookings/{id}/documents', name: 'app_booking_documents', requirements: ['id' => '\d+'])]
|
||||
#[IsGranted("ROLE_USER")]
|
||||
public function documents(int $id, Request $request): Response
|
||||
{
|
||||
$bpnUser = $request->getSession()->get('bpn_user');
|
||||
|
||||
if (null === $bpnUser) {
|
||||
return $this->security->logout();
|
||||
}
|
||||
|
||||
$file = $this
|
||||
->apiClient
|
||||
->getDocuments($bpnUser->getEmail(), $bpnUser->getPassword(), $id, 'Dokumentdruck')
|
||||
;
|
||||
|
||||
if (null === $file || $file instanceof Notification) {
|
||||
$this->addFlash('error', 'Keine Dokumente vorhanden');
|
||||
|
||||
return $this->redirectToRoute('app_bookings');
|
||||
}
|
||||
|
||||
return $this->createDownloadResponse($file);
|
||||
}
|
||||
|
||||
#[Route('/bookings/{id}/confirmation', name: 'app_booking_confirmation', requirements: ['id' => '\d+'])]
|
||||
#[IsGranted("ROLE_USER")]
|
||||
public function confirmation(int $id, Request $request): Response
|
||||
{
|
||||
$bpnUser = $request->getSession()->get('bpn_user');
|
||||
|
||||
if (null === $bpnUser) {
|
||||
return $this->security->logout();
|
||||
}
|
||||
|
||||
$file = $this
|
||||
->apiClient
|
||||
->getDocuments($bpnUser->getEmail(), $bpnUser->getPassword(), $id, 'Vorgangdruck')
|
||||
;
|
||||
|
||||
return $this->createDownloadResponse($file);
|
||||
}
|
||||
|
||||
private function createDownloadResponse(File $file): Response
|
||||
{
|
||||
$filename = u($file->filename)->ascii();
|
||||
|
||||
$response = new Response($file->content);
|
||||
|
||||
$disposition = $response->headers->makeDisposition(
|
||||
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
|
||||
$filename,
|
||||
md5($filename)
|
||||
);
|
||||
|
||||
$response->headers->set('Content-Disposition', $disposition);
|
||||
$response->headers->set('Content-Type', $file->mimeType);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user