<?php
namespace App\Controller;
use App\Doctrine\QueryHelper;
use App\Entity\Guest;
use App\Entity\Order;
use App\Entity\Page;
use App\Entity\Product;
use App\Entity\ProductTranslation;
use App\Entity\RestaurantReserve;
use App\Entity\RoomReserve;
use App\Entity\TableTurn;
use App\Entity\Ticket;
use App\Form\TicketGuestType;
use App\Manager\EmailSender\CustomerEmailSender;
use App\Manager\EmailSender\HotelEmailSender;
use App\Manager\TicketManager;
use App\Manager\WiFiPremiumManager;
use App\Repository\DepartmentRepository;
use App\Repository\OrderRepository;
use App\Repository\PageRepository;
use App\Repository\ReportRepository;
use App\Repository\RestaurantRepository;
use App\Repository\RestaurantReserveRepository;
use App\Repository\RoomReserveRepository;
use App\Repository\TicketRepository;
use App\Security\User;
use App\Service\LanguageSwitcher;
use App\Service\RestaurantHelper;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use Omnipay\Omnipay;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Class DefaultController
* @package App\Controller
*/
class DefaultController extends AbstractController
{
/**
* @Route({
* "en": "/",
* "es": "/es",
* "fr": "/fr",
* "de": "/de",
* "ru": "/ru"
* }, name="app_home")
*
* @return Response
* @throws \Exception
*/
public function home(): Response
{
return $this->render('home.html.twig');
}
/**
* @Route({
* "en": "/product/{slug}",
* "es": "/es/product/{slug}",
* "fr": "/fr/product/{slug}",
* "de": "/de/product/{slug}",
* "ru": "/ru/product/{slug}"
* }, name="app_product", priority=100)
*
* @param ProductTranslation $productTranslation
* @param RoomReserveRepository $roomReserveRepository
* @param LanguageSwitcher $languageSwitcher
* @return Response
*/
public function product(
ProductTranslation $productTranslation,
RoomReserveRepository $roomReserveRepository,
WiFiPremiumManager $wiFiPremiumManager,
LanguageSwitcher $languageSwitcher
): Response
{
$user = $this->getUser();
$product = $productTranslation->getTranslatable();
$roomReserve = $roomReserveRepository->findOneBy(['id' => $user->getRoomReserveId()]);
$isPurchasable = $product->isPurchasable($roomReserve);
if (!$product || !$product->isVisible() || !$product->isRoomReserveAvailable($roomReserve)) {
throw new NotFoundHttpException('This resource does not exists');
}
$languageSwitcher->buildPaths($product);
return $this->render('product_detail.html.twig', [
'product' => $product,
'wiFiPremiumAccess' => $wiFiPremiumManager->getCurrentWiFiPremiumAccess($roomReserve),
'roomReserve' => $roomReserve,
'isPurchasable' => $isPurchasable
]);
}
/**
* @Route("/{_locale}/{slug}", name="app_page", defaults={"_locale":"en"}, requirements={"_locale"="%available_locales_requirement%", "slug"=".+"}, priority=-100)
*
* @param string $slug
* @param Request $request
* @param PageRepository $pageRepository
* @param RoomReserveRepository $roomReserveRepository
* @param LanguageSwitcher $languageSwitcher
* @return Response
*/
public function page(
string $slug,
Request $request,
PageRepository $pageRepository,
RoomReserveRepository $roomReserveRepository,
LanguageSwitcher $languageSwitcher
): Response
{
$user = $this->getUser();
$roomReserve = $roomReserveRepository->findOneBy(['id' => $user->getRoomReserveId()]);
$slugs = explode('/', $slug);
$pages = [];
foreach ($slugs as $key => $slugString) {
/** @var Page $section */
$page = $pageRepository->findOneBySlug($slugString);
if (!$page) {
// Try finding the page in the default locale
$locale = $request->getDefaultLocale();
$page = $pageRepository->findOneBySlugAndLocale($slugString, $locale);
if (!$page) {
throw new NotFoundHttpException('This resource does not exists');
}
}
if (!$page->getTourOperators()->isEmpty() && !$page->getTourOperators()->contains($roomReserve->getTourOperator())) {
throw new NotFoundHttpException('This resource does not exists');
}
if ($key > 0) {
$parentPage = $pages[$key - 1];
if (!$page->getParent()->getId()->equals($parentPage->getId())) {
throw new NotFoundHttpException('This resource does not exists');
}
}
$pages[$key] = $page;
}
$currentPage = end($pages);
$languageSwitcher->buildPaths($currentPage);
if (!isset($locale)) {
$locale = $request->getLocale();
}
$children = $currentPage->getChildren()->filter(function(Page $page) use ($roomReserve, $locale) {
return !$page->isDeleted() && ($page->getTourOperators()->isEmpty() || $page->getTourOperators()->contains($roomReserve->getTourOperator())) && array_key_exists($locale, $page->getTranslations()->toArray());
})->toArray();
return $this->render('page.html.twig', [
'page' => $currentPage,
'children' => $children,
'roomReserve' => $roomReserve,
'slug' => $slug,
]);
}
/**
* @Route({
* "en": "/checkout",
* "es": "/es/checkout",
* "fr": "/fr/checkout",
* "de": "/de/checkout",
* "ru": "/ru/checkout"
* }, name="app_checkout", priority=100)
*
* @param Request $request
* @param RequestStack $requestStack
* @param QueryHelper $queryHelper
* @param RouterInterface $router
* @param OrderRepository $orderRepository
* @param TranslatorInterface $translator
* @param ValidatorInterface $validator
* @param EntityManagerInterface $entityManager
* @return Response
*/
public function checkout(
Request $request,
RequestStack $requestStack,
QueryHelper $queryHelper,
RouterInterface $router,
OrderRepository $orderRepository,
TranslatorInterface $translator,
ValidatorInterface $validator,
EntityManagerInterface $entityManager,
WiFiPremiumManager $wiFiPremiumManager
): Response
{
$currentHotel = $queryHelper->getCurrentHotel();
$user = $this->getUser();
$email = '';
$customerNotes = '';
$orderId = $requestStack->getSession()->get('orderId');
$order = $orderId ? $orderRepository->find($orderId) : null;
$defaultErrors = [];
$checkoutErrors = [];
$chargeError = '';
if (!empty($order) && ($order->isDeleted() || $order->getRoomReserve()->getId()->toRfc4122() !== $user->getRoomReserveId())) {
$order = null;
}
$guestEmails = $user->getGuestEmails();
if (!empty($guestEmails)) {
$email = array_pop($guestEmails);
}
if ($request->isMethod('POST')) {
$email = $request->request->get('email');
$customerNotes = $request->request->get('customer-notes');
$order->setEmail($email);
$order->setCustomerNotes($customerNotes);
$defaultErrors = $validator->validate($order);
$checkoutErrors = $validator->validate($order, null, ['checkout']);
$params = [];
if ($request->query->get('mode') === 'kiosk') {
$params['mode'] = 'kiosk';
}
if (empty($chargeError) && count($defaultErrors) === 0 && count($checkoutErrors) === 0) {
// Save guest email address
$this->saveGuestEmail($order->getRoomReserve()->getRegistrant(), $email, $entityManager);
if ($order->getTotal() > 0 && !empty($currentHotel->getStripePublishableKey()) && !empty($currentHotel->getStripeSecretKey())) {
$gateway = Omnipay::create('Stripe\PaymentIntents');
$gateway->initialize([
'apiKey' => $currentHotel->getStripeSecretKey(),
]);
$response = $gateway->purchase([
'amount' => $order->getTotal() / 100,
'currency' => 'USD',
'description' => 'Order for room reserve ' . $order->getRoomReserve()->getNumber() . ' in room ' . $order->getRoomReserve()->getRoom()->getName(),
'paymentMethod' => $request->get('paymentMethodId'),
'returnUrl' => $router->generate('app_checkout_confirm', $params, UrlGeneratorInterface::ABSOLUTE_URL),
'confirm' => true,
'metadata' => [
'order_id' => $order->getId()->toRfc4122(),
],
])->send();
$redirectUrl = null;
if ($response->isSuccessful()) {
$order->setStripeCharge($response->getTransactionReference());
$order->setCreatedAt(new \DateTime());
$entityManager->persist($order);
if ($order->hasWiFiPremium()) {
$wiFiPremiumAccess = $wiFiPremiumManager->createWiFiPremiumAccess($order);
if (!is_null($wiFiPremiumAccess)) {
$orderItem = $order->getOrderItemWithWiFiPremium();
if ($orderItem) {
$orderItem->setWiFiPremiumAccess($wiFiPremiumAccess);
$entityManager->persist($orderItem);
}
$roomReserve = $order->getRoomReserve();
$roomReserve->addWiFiPremiumAccess($wiFiPremiumAccess);
$entityManager->persist($roomReserve);
}
}
$entityManager->flush();
$redirectUrl = $router->generate('app_checkout_finished', $params, UrlGeneratorInterface::ABSOLUTE_URL);
} elseif ($response->isRedirect()) {
$entityManager->persist($order);
$entityManager->flush();
$redirectUrl = $response->getRedirectUrl();
} else {
$chargeError = $response->getMessage();
}
if (!is_null($redirectUrl)) {
return $this->redirect($redirectUrl);
}
} else {
$entityManager->persist($order);
$entityManager->flush();
return $this->redirectToRoute('app_checkout_finished', $params);
}
}
}
return $this->render('checkout.html.twig', [
'order' => $order,
'email' => $email,
'customerNotes' => $customerNotes,
'stripePublishableKey' => $currentHotel->getStripePublishableKey(),
'defaultErrors' => $defaultErrors,
'checkoutErrors' => $checkoutErrors,
'chargeError' => $chargeError
]);
}
/**
* @Route({
* "en": "/checkout-confirm",
* "es": "/es/checkout-confirm",
* "fr": "/fr/checkout-confirm",
* "de": "/de/checkout-confirm",
* "ru": "/ru/checkout-confirm"
* }, name="app_checkout_confirm", priority=100)
*
* @param Request $request
* @param RequestStack $requestStack
* @param QueryHelper $queryHelper
* @param RouterInterface $router
* @param OrderRepository $orderRepository
* @param EntityManagerInterface $entityManager
* @param CustomerEmailSender $customerEmailSender
* @param ValidatorInterface $validator
* @return Response
* @throws \Exception
*/
public function checkoutConfirm(
Request $request,
RequestStack $requestStack,
QueryHelper $queryHelper,
RouterInterface $router,
OrderRepository $orderRepository,
EntityManagerInterface $entityManager,
WiFiPremiumManager $wiFiPremiumManager,
CustomerEmailSender $customerEmailSender,
ValidatorInterface $validator
): Response
{
$currentHotel = $queryHelper->getCurrentHotel();
$user = $this->getUser();
$orderId = $requestStack->getSession()->get('orderId');
$order = $orderId ? $orderRepository->find($orderId) : null;
$params = [];
if ($request->query->get('mode') === 'kiosk') {
$params['mode'] = 'kiosk';
}
$gateway = Omnipay::create('Stripe\PaymentIntents');
$gateway->initialize([
'apiKey' => $currentHotel->getStripeSecretKey(),
]);
$response = $gateway->completePurchase([
'paymentIntentReference' => $request->get('payment_intent'),
'returnUrl' => $router->generate('app_checkout_confirm', $params, UrlGeneratorInterface::ABSOLUTE_URL),
])->send();
if ($response->isSuccessful()) {
$order->setStripeCharge($response->getTransactionReference());
$order->setCreatedAt(new \DateTime());
$entityManager->persist($order);
if ($order->hasWiFiPremium()) {
$wiFiPremiumAccess = $wiFiPremiumManager->createWiFiPremiumAccess($order);
if (!is_null($wiFiPremiumAccess)) {
$orderItem = $order->getOrderItemWithWiFiPremium();
if ($orderItem) {
$orderItem->setWiFiPremiumAccess($wiFiPremiumAccess);
$entityManager->persist($orderItem);
}
$roomReserve = $order->getRoomReserve();
$roomReserve->addWiFiPremiumAccess($wiFiPremiumAccess);
$entityManager->persist($roomReserve);
}
}
$entityManager->flush();
return $this->redirectToRoute('app_checkout_finished', $params);
}
return $this->redirectToRoute('app_checkout', $params);
}
/**
* @Route({
* "en": "/checkout-finished",
* "es": "/es/checkout-finished",
* "fr": "/fr/checkout-finished",
* "de": "/de/checkout-finished",
* "ru": "/ru/checkout-finished"
* }, name="app_checkout_finished", priority=100)
*
* @param RequestStack $requestStack
* @param QueryHelper $queryHelper
* @param OrderRepository $orderRepository
* @param EntityManagerInterface $entityManager
* @param CustomerEmailSender $customerEmailSender
* @param ValidatorInterface $validator
* @return Response
* @throws \Exception
*/
public function checkoutFinished(
RequestStack $requestStack,
QueryHelper $queryHelper,
OrderRepository $orderRepository,
EntityManagerInterface $entityManager,
TicketManager $ticketManager,
CustomerEmailSender $customerEmailSender,
HotelEmailSender $hotelEmailSender,
ValidatorInterface $validator
): Response
{
$user = $this->getUser();
$orderId = $requestStack->getSession()->get('orderId');
$order = $orderId ? $orderRepository->find($orderId) : null;
$errors = $validator->validate($order, null, ['Default', 'checkout']);
$params = [];
if ($requestStack->getCurrentRequest()->query->get('mode') === 'kiosk') {
$params['mode'] = 'kiosk';
}
if (empty($order) ||
$order->isDeleted() ||
$order->getRoomReserve()->getId()->toRfc4122() !== $user->getRoomReserveId() ||
count($errors) > 0) {
return $this->redirectToRoute('app_checkout', $params);
}
foreach($order->getOrderItems() as $item) {
$item->getProduct()->discountStock($item->getAmount());
}
$order->setStatus(Order::STATUS_FINISHED);
$entityManager->persist($order);
$entityManager->flush();
$requestStack->getSession()->remove('orderId');
$sent = $customerEmailSender->sendOrder($order);
$hotelEmailSender->sendOrder($order);
$ticketManager->createTicketsForOrder($order);
$ticketManager->remotePrintOrderTickets($order);
return $this->render('checkout_finished.html.twig', [
'order' => $order,
'emailError' => $sent
]);
}
/**
* @Route({
* "en": "/restaurant-reserve",
* "es": "/es/restaurant-reserve",
* "fr": "/fr/restaurant-reserve",
* "de": "/de/restaurant-reserve",
* "ru": "/ru/restaurant-reserve"
* }, name="app_restaurant_reserve", priority=100)
*
* @param Request $request
* @param RequestStack $requestStack
* @param RestaurantRepository $restaurantRepository
* @param RoomReserveRepository $roomReserveRepository
* @param RestaurantHelper $restaurantHelper
* @param CustomerEmailSender $customerEmailSender
* @param EntityManagerInterface $entityManager
* @return Response
*/
public function restaurants(
Request $request,
RequestStack $requestStack,
RestaurantRepository $restaurantRepository,
RoomReserveRepository $roomReserveRepository,
RestaurantHelper $restaurantHelper,
CustomerEmailSender $customerEmailSender,
EntityManagerInterface $entityManager
): Response
{
/** @var User $user */
$user = $this->getUser();
$today = new \DateTime('today');
$todayKey = $today->format('N');
$tomorrow = new \DateTime('tomorrow');
$tomorrowKey = $tomorrow->format('N');
$params = [];
if ($request->query->get('mode') === 'kiosk') {
$params['mode'] = 'kiosk';
}
$result = [];
$roomReserve = $roomReserveRepository->findOneBy(['id' => $user->getRoomReserveId()]);
$people = $roomReserve->getPeople();
if ($request->isMethod('POST')) {
$restaurant = $request->request->get('restaurant');
$comments = $request->request->get('comments');
$pax = $request->request->getInt('pax');
$day = $request->request->get('day');
$turn = $request->request->get('turn');
$name = $request->request->get('name');
$email = $request->request->get('email');
$restaurant = $restaurantRepository->findOneBy(['id' => $restaurant]);
$result = $restaurantHelper->makeReservation($restaurant, $comments, $pax, $day, $turn, $name, $email, [$roomReserve]);
if (!empty($result) && empty($result['errors']) && !empty($result['reservation'])) {
// Save guest email address
$this->saveGuestEmail($roomReserve->getRegistrant(), $email, $entityManager);
if (empty($email)) {
$emails = $user->getGuestEmails();
$email = array_pop($emails);
}
$requestStack->getSession()->set('saved_email', $email);
/** @var RestaurantReserve $restaurantReserve */
$restaurantReserve = $result['reservation'];
$date = $todayKey === $day ? $today : $tomorrow;
$customerEmailSender->sendRestaurantReservation($restaurantReserve, $email, $date, $comments);
$requestStack->getSession()->set('restaurant_reservation', $restaurantReserve->getId()->toRfc4122());
$requestStack->getSession()->set('restaurant_reservation_pax', $pax);
$requestStack->getSession()->set('restaurant_reservation_comments', $comments);
return $this->redirectToRoute('app_restaurant_reserve_details', $params);
}
}
$restaurants = $restaurantRepository->findAllByCurrentHotel();
$restaurantsData = $restaurantHelper->getRestaurantsData($roomReserve, $people);
return $this->render('restaurants.html.twig', [
'name' => $roomReserve->getRegistrant()->getFullName(),
'email' => $roomReserve->getRegistrant()->getEmail(),
'restaurants' => $restaurants,
'restaurantsData' => $restaurantsData,
'today' => $today,
'todayKey' => $todayKey,
'tomorrow' => $tomorrow,
'tomorrowKey' => $tomorrowKey,
'result' => $result,
]);
}
/**
* @Route({
* "en": "/restaurant-reserve/details",
* "es": "/es/restaurant-reserve/details",
* "fr": "/fr/restaurant-reserve/details",
* "de": "/de/restaurant-reserve/details",
* "ru": "/ru/restaurant-reserve/details"
* }, name="app_restaurant_reserve_details", priority=100)
*
* @param Request $request
* @param RequestStack $requestStack
* @param RestaurantReserveRepository $restaurantReserveRepository
* @return Response
*/
public function restaurantReservationDetails(
Request $request,
RequestStack $requestStack,
RestaurantReserveRepository $restaurantReserveRepository
): Response
{
/** @var User $user */
$user = $this->getUser();
$restaurantReserveId = $requestStack->getSession()->get('restaurant_reservation');
$pax = $requestStack->getSession()->get('restaurant_reservation_pax');
$comments = $requestStack->getSession()->get('restaurant_reservation_comments');
if (empty($restaurantReserveId) || empty($pax)) {
throw new NotFoundHttpException();
}
$restaurantReserve = $restaurantReserveRepository->findOneBy(['id' => $restaurantReserveId]);
$roomReserveIds = array_map(static function (RoomReserve $roomReserve) {return $roomReserve->getId()->toRfc4122();}, $restaurantReserve->getRoomReserves()->toArray());
if (!in_array($user->getRoomReserveId(), $roomReserveIds, true)) {
throw new NotFoundHttpException();
}
$restaurantName = $restaurantReserve->getRestaurant()->getName();
/** @var TableTurn $tableTurn */
$tableTurn = $restaurantReserve->getTableTurns()->first();
$turnName = $tableTurn->getTurnDay()->getTurn()->getName();
$turnTime = $tableTurn->getTurnDay()->getTurn()->getTime();
$today = new \DateTime('today');
$todayKey = $today->format('N');
$tomorrow = new \DateTime('tomorrow');
$tomorrowKey = $tomorrow->format('N');
$date = $todayKey === $restaurantReserve->getReservedAt()->format('N') ? $today : $tomorrow;
$roomReserves = $restaurantReserve->getRoomReserves();
$roomNumbers = array_map(static function (RoomReserve $roomReserve) {return $roomReserve->getRoom()->getName();}, $roomReserves->toArray());
$roomNumbers = implode(',', $roomNumbers);
$requestStack->getSession()->remove('restaurant_reservation');
$requestStack->getSession()->remove('restaurant_reservation_pax');
$requestStack->getSession()->remove('restaurant_reservation_comments');
return $this->render('restaurant_reservation_details.html.twig', [
'restaurantReserve' => $restaurantReserve,
'roomNumbers' => $roomNumbers,
'restaurantName' => $restaurantName,
'date' => $date,
'pax' => $pax,
'turnName' => $turnName,
'turnTime' => $turnTime,
'comments' => $comments,
]);
}
/**
* @Route({
* "en": "/create-ticket",
* "es": "/es/create-ticket",
* "fr": "/fr/create-ticket",
* "de": "/de/create-ticket",
* "ru": "/ru/create-ticket"
* }, name="app_create_ticket", priority=100)
*
* @param Request $request
* @param RoomReserveRepository $roomReserveRepository
* @param TicketManager $ticketManager
* @param CustomerEmailSender $customerEmailSender
* @param ValidatorInterface $validator
*/
public function createTicket(
Request $request,
RoomReserveRepository $roomReserveRepository,
TicketManager $ticketManager,
CustomerEmailSender $customerEmailSender,
ValidatorInterface $validator,
EntityManagerInterface $entityManager
): Response
{
$params = [];
if ($request->query->get('mode') === 'kiosk') {
$params['mode'] = 'kiosk';
}
/** @var User $user */
$user = $this->getUser();
$roomReserve = $roomReserveRepository->findOneBy(['id' => $user->getRoomReserveId()]);
$ticket = new Ticket();
$form = $this->createForm(TicketGuestType::class, $ticket, ['room_reserve' => $roomReserve]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$ticketManager->updateTicket($ticket);
$entityManager->persist($ticket);
$entityManager->flush();
/** @var Ticket $ticket */
$ticket = $form->getData();
$department = $ticket->getDepartment();
$report = $ticket->getReport();
$detail = $ticket->getDetail();
$comments = $ticket->getDescription();
$email = $form->get('email')->getData();
if (!empty($email)) {
$emailConstraint = new Assert\Email();
$errors = $validator->validate($email, $emailConstraint);
if (count($errors) > 0) {
$email = null;
}
}
if (empty($email)) {
$emails = $user->getGuestEmails();
$email = $emails[0];
} else {
// Save guest email address
$this->saveGuestEmail($roomReserve->getRegistrant(), $email, $entityManager);
}
$originName = 'Guest Max';
$departmentName = $department->getName();
$reportName = $report ? $report->getName() : null;
$detailName = $detail ? $detail->getName() : null;
$customerEmailSender->sendTicket($ticket, $email, $originName, $departmentName, $reportName, $detailName, $comments, $user);
$params['id'] = $ticket->getId();
return $this->redirectToRoute('app_create_ticket_result', $params);
}
$response = $this->render('create_ticket.html.twig', [
'ticket' => $ticket,
'form' => $form->createView(),
]);
return $this->forceRevalidate($response);
}
/**
* @Route({
* "en": "/create-ticket-reports",
* "es": "/es/create-ticket-reports",
* "fr": "/fr/create-ticket-reports",
* "de": "/de/create-ticket-reports",
* "ru": "/ru/create-ticket-reports"
* }, name="app_create_ticket_reports", priority=100)
*
* @param Request $request
* @param RoomReserveRepository $roomReserveRepository
* @param DepartmentRepository $departmentRepository,
* @return Response
*/
public function createTicketReports(
Request $request,
RoomReserveRepository $roomReserveRepository,
DepartmentRepository $departmentRepository
): Response
{
/** @var User $user */
$user = $this->getUser();
$result = [];
if ($request->isMethod('POST')) {
$department = $request->request->get('department');
$roomReserve = $roomReserveRepository->findOneBy(['id' => $user->getRoomReserveId()]);
$hotel = $roomReserve->getRoom()->getHotel();
$department = $departmentRepository->findOneBy(['id' => $department]);
if ($hotel->getDepartments()->contains($department)) {
foreach ($department->getReports() as $report) {
$result[] = ['id' => $report->getId()->toRfc4122(), 'name' => $report->translate($request->getLocale())->getName()];
}
}
}
return new JsonResponse($result);
}
/**
* @Route({
* "en": "/create-ticket-details",
* "es": "/es/create-ticket-details",
* "fr": "/fr/create-ticket-details",
* "de": "/de/create-ticket-details",
* "ru": "/ru/create-ticket-details"
* }, name="app_create_ticket_details", priority=100)
*
* @param Request $request
* @param RoomReserveRepository $roomReserveRepository
* @param ReportRepository $reportRepository
* @return Response
*/
public function createTicketDetails(
Request $request,
RoomReserveRepository $roomReserveRepository,
ReportRepository $reportRepository
): Response
{
/** @var User $user */
$user = $this->getUser();
$result = [];
if ($request->isMethod('POST')) {
$report = $request->request->get('report');
$roomReserve = $roomReserveRepository->findOneBy(['id' => $user->getRoomReserveId()]);
$hotel = $roomReserve->getRoom()->getHotel();
$report = $reportRepository->findOneBy(['id' => $report]);
$department = $report->getDepartment();
if ($hotel->getDepartments()->contains($department)) {
foreach ($report->getDetails() as $detail) {
$result[] = ['id' => $detail->getId()->toRfc4122(), 'name' => $detail->translate($request->getLocale())->getName()];
}
}
}
return new JsonResponse($result);
}
/**
* @Route({
* "en": "/create-ticket/{id}",
* "es": "/es/create-ticket/{id}",
* "fr": "/fr/create-ticket/{id}",
* "de": "/de/create-ticket/{id}",
* "ru": "/ru/create-ticket/{id}"
* }, name="app_create_ticket_result", priority=100)
*
* @param Request $request
* @param TicketRepository $ticketRepository
* @param RoomReserveRepository $roomReserveRepository
* @param string $id
* @return Response
*/
public function createTicketResult(
Request $request,
TicketRepository $ticketRepository,
RoomReserveRepository $roomReserveRepository,
string $id
): Response
{
/** @var User $user */
$user = $this->getUser();
$ticket = $ticketRepository->findOneBy(['id' => $id]);
$roomReserve = $roomReserveRepository->findOneBy(['id' => $user->getRoomReserveId()]);
if (empty($ticket) || empty($roomReserve) || $ticket->getRoomReserve()->getId()->toRfc4122() !== $roomReserve->getId()->toRfc4122()) {
throw new NotFoundHttpException();
}
return $this->render('create_ticket_result.html.twig', [
'ticket' => $ticket,
]);
}
public function languageSwitcher(RequestStack $requestStack, LanguageSwitcher $languageSwitcher): Response
{
return $this->render('_language_switcher.html.twig', [
'paths' => $languageSwitcher->getPaths(),
'isKiosk' => $requestStack->getCurrentRequest()->query->get('mode') === 'kiosk' || $requestStack->getSession()->get('mode') === 'kiosk',
]);
}
private function saveGuestEmail(?Guest $guest, ?string $email, EntityManagerInterface $entityManager)
{
if ($email && $guest) {
$guest->setEmail($email);
$entityManager->persist($guest);
$entityManager->flush();
}
}
private function forceRevalidate(Response $response): Response
{
$response->setMaxAge(0);
$response->headers->addCacheControlDirective('must-revalidate', true);
$response->headers->addCacheControlDirective('no-cache', true);
$response->headers->addCacheControlDirective('no-store', true);
return $response;
}
}