<?php
namespace App\Controller\Front;
use App\Repository\PartyRepository;
use App\Service\FrontService;
use App\Service\HotelApiService;
use App\Service\ParameterService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class BookmarkController extends AbstractController
{
public function __construct(
private readonly HotelApiService $hotelApiService,
private readonly FrontService $frontService,
private readonly ParameterService $parameterService,
){}
#[Route('/bookmark', name: 'app_bookmark')]
public function index(): Response
{
return $this->render('front/bookmark/index.html.twig', [
'controller_name' => 'BookmarkController',
]);
}
#[Route('/wishList', name: 'wish_list_for_hotel_products')]
public function wishListForHotels(Request $request,PartyRepository $partyRepository): Response
{
// HOTELS
$cookies_bookmarked_hotels = $request->cookies->get('bookmarkedHotels');
$bookmarked_hotels = json_decode($cookies_bookmarked_hotels, true);
$responseHotels = [];
if (!empty($bookmarked_hotels)) {
foreach ($bookmarked_hotels as $bookmarked_hotel) {
$codeHotel = substr(strstr($bookmarked_hotel, '-'), 1); // right subString after -
$xmlSourceId = strstr($bookmarked_hotel, '-', true); // left subString before -
if ($xmlSourceId == 0) {
$hotelDetails = $this->hotelApiService->hotelDetails($codeHotel);
}
else {
$hotelDetails = $this->hotelApiService->hotelDetailsHUB($bookmarked_hotel);
}
$responseHotels[] = $hotelDetails;
}
}
// PARTIES
$responseParties =[];
$cookieFavoriteParty = $request->cookies->get('CookieFavoriteParty');
$bookmarked_parties = json_decode($cookieFavoriteParty, true);
if (!empty($bookmarked_parties)) {
foreach ($bookmarked_parties as $bookmarked_party) {
$party = $partyRepository->find($bookmarked_party);
$responseParties[] = $party;
}
}
return $this->render('front/bookmark/wish_list.html.twig',[
'responseHotels' => $responseHotels,
'responseParties' => $responseParties,
'society' => $this->parameterService->getSocietyParameters(),
'social_networks' => $this->frontService->getSocialNetworks(),
'agencies' => $this->frontService->getAgencies(),
'currencies' => $this->frontService->getCurrencies(),
]);
}
}