<?php
namespace App\Controller\Frontend;
use App\Entity\Age;
use App\Entity\User;
use App\Entity\Article;
use App\Entity\ArticlePresse;
use App\Entity\Contact;
use App\Entity\ContactRappel;
use App\Entity\Country;
use App\Entity\CroqinfoAbonne;
use App\Entity\DemandeSejourCorse;
use App\Entity\DemandeRappel;
use App\Entity\Departement;
use App\Entity\Newsletter;
use App\Entity\FrontOption;
use App\Entity\Inscription;
use App\Entity\Sejour;
use App\Entity\MediaCategorie;
use App\Entity\Media;
use App\Entity\Saison;
use App\Entity\Theme;
use App\Entity\VilleDesservie;
use App\Form\InscriptionStartType;
use App\Form\ContactRappelType;
use App\Form\CroqinfoAbonnementType;
use App\Form\DemandeSejourCorseType;
use App\Message\SendEmailMessage;
use App\Repository\ArticlePresseRepository;
use App\Repository\SejourRepository;
use App\Repository\FrontOptionRepository;
use App\Utility\UpdateParticipantSession;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\ORM\EntityManagerInterface;
use Knp\Component\Pager\PaginatorInterface;
use Presta\SitemapBundle\Controller\SitemapController;
use Presta\SitemapBundle\Event\SitemapPopulateEvent;
use Presta\SitemapBundle\Sitemap\Sitemapindex;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Vich\UploaderBundle\Templating\Helper\UploaderHelper;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\JsonLdNormalizer;
use App\Entity\SejourSession;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
use App\Form\ContactPropertyValueType;
use App\Entity\ContactPropertyValue;
use App\Entity\Commande;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\Mime\Address;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
class FrontendController extends AbstractController
{
/**
* @Route("/date", name="frontend_date",options={"sitemap" = false})
*/
public function showdate(): Response
{
date_default_timezone_set('Europe/Paris');
$dateTime = new \DateTime('now', new \DateTimeZone('Europe/Paris'));
$date = new \DateTime(); // create a new date object
$dateString = $date->format('Y-m-d H:i:s'); // format the date as a string
return new Response($dateString);
}
/**
* @Route("/", name="frontend_homepage",options={"sitemap" = true})
*/
public function index(EntityManagerInterface $em): Response
{
$monOption = $em->getRepository(FrontOption::class)->findOneBy(['name' => 'sejoursAccueil']);
$ids = $monOption !== null ? $monOption->getContent() : [];
$output = [];
foreach ($ids as $id) {
$output[] = $em->getRepository(Sejour::class)->findOneById($id);
}
$header = $em->getRepository(Article::class)->findOneByTitle('Header');
return $this->render('frontend/index.html.twig', [
'sejours' => $output,
'footer_seo' => $em->getRepository(Article::class)->findOneBy(['title' => 'footer']),
'headerMain' => $header
]);
}
/**
* @Route("/merci", name="merci")
*/
public function merci()
{
if ($this->getUser() !== null)
return $this->redirectToRoute('frontend_homepage');
return $this->render('frontend/merci.html.twig');
}
/**
* @Route("/validateProperty", name="validateProperty")
*/
public function validateProperty(Request $request, EntityManagerInterface $em)
{
$property = $em->getRepository(ContactPropertyValue::class)->findOneById($request->get('id'));
if($property == null)
return new JsonResponse(['ok']);
$property->setValue($request->get('value'));
if ($property->getProperty()->getValidationClass() == null)
return new JsonResponse(['ok' => '']);
$enfant = $property->getContact();
$this->denyAccessUnlessGranted('view', $enfant);
$form = $this->createForm(ContactPropertyValueType::class, $property);
$form->submit($request->request->all());
//$form->add('Sauver', SubmitType::class, ['attr' => ['class' => 'button bounce item-sejour__button'],'label'=>'Enregistrer et Sauver']);
$form->handleRequest($request);
if (!$form->isValid()) {
$vcString = $property->getProperty()->getValidationClass();
if ($vcString !== null) {
$vc = new $vcString();
if (!$vc->validate($property->getValue()))
return new JsonResponse(['error' => $vc->getErrorMessage()]);
}
}
return new JsonResponse(['ok']);
}
/**
* @Route("/croqinfos.html",name="frontend_croqinfos",options={"sitemap" = true})
*/
public function croqinfos(EntityManagerInterface $em, Request $request, MessageBusInterface $bus): Response
{
$abonne = new CroqinfoAbonne();
$form = $this->createForm(CroqinfoAbonnementType::class, $abonne);
$mediaType = $em->getRepository(MediaCategorie::class)->findOneBy(['name' => 'Documentation']);
$medias = $em->getRepository(Media::class)->findBy(
['mediaCategorie' => $mediaType],
['position' => 'ASC']
);
$form->handleRequest($request);
if ($form->isSubmitted() and $form->isValid()) {
$em->persist($abonne);
$em->flush();
$bus->dispatch((new SendEmailMessage('inscription_croqinfo', Abonnee::class, $abonne->getId())));
$this->addFlash('success', 'Votre demande d\'abonnement est bien prise en compte');
}
return $this->render('frontend/croqinfos.html.twig', [
'medias' => $medias,
'form' => $form->createView()
]);
}
/**
* @Route("/catalogue-en-ligne.html", name="frontend_catalogue-en-ligne",options={"sitemap" = true})
*/
public function catalogueEnLigne(EntityManagerInterface $em): Response
{
$photos = $em->getRepository(Media::class)->findByMediaCategorie('CataloguePhoto');
$pdf = $em->getRepository(Media::class)->findByMediaCategorie('Catalogue');
return $this->render('frontend/catalogue_en_ligne.html.twig', [
'photos' => $photos,
'pdf' => $pdf,
]);
}
/**
* @Route("/contact.html", name="frontend_contact",options={"sitemap" = true})
*/
public function contact(EntityManagerInterface $em, Request $request, MessageBusInterface $bus)
{
$demandeContact = new DemandeRappel();
$form = $this->createForm(\App\Form\FormulaireContactType::class, $demandeContact);
$pa = $em->getRepository(Media::class)->findOneByMediaCategorie('plan_acces');
$text = $em->getRepository(Article::class)->findOneBy(['title' => 'Permanences téléphoniques']);
$form->handleRequest($request);
if ($form->isSubmitted() and $form->isValid()) {
$formData = $form->getData();
if (property_exists($formData, 'nom') && is_string($formData->getNom())) {
$formData->setNom(strtoupper($formData->getNom()));
}
if (property_exists($formData, 'nom_enfant') && is_string($formData->getNomEnfant())) {
$formData->setNomEnfant(strtoupper($formData->getNomEnfant()));
}
if (property_exists($formData, 'prenom') && is_string($formData->getPrenom())) {
$formData->setPrenom(ucfirst(strtolower($formData->getPrenom())));
}
if (property_exists($formData, 'prenom_enfant') && is_string($formData->getPrenomEnfant())) {
$formData->setPrenomEnfant(ucfirst(strtolower($formData->getPrenomEnfant())));
}
$em->persist($formData);
$em->flush();
$this->addFlash('success', 'Merci pour votre demande, nous reviendrons vers vous dès que possible.');
$bus->dispatch(new SendEmailMessage('demandeContact', '', $demandeContact->getId(),'0testingall@gmail.com'));
// $bus->dispatch(new SendEmailMessage('demandeContact', '', $demandeContact->getId(),$this->getParameter('email_accueil')));
// $bus->dispatch(new SendEmailMessage('demandeContact', '', $demandeContact->getId(),$this->getParameter('email_info_')));
$bus->dispatch(new SendEmailMessage('accuseReception', '', $demandeContact->getId(), $demandeContact->getEmail()));
}
return $this->render('frontend\contact.html.twig', ['form' => $form->createView(), 'acces' => $pa, 'text' => $text]);
}
/**
* @Route("/contact-rappel", name="frontend_contact_rappel",options={"sitemap" = true})
*/
public function contactRappel(Request $request, EntityManagerInterface $em, MessageBusInterface $bus)
{
$contactRappel = new ContactRappel();
$form = $this->createForm(ContactRappelType::class, $contactRappel);
$pa = $em->getRepository(Media::class)->findOneByMediaCategorie('plan_acces');
$text = $em->getRepository(Article::class)->findOneBy(['title' => 'Permanences téléphoniques']);
$form->handleRequest($request);
if ($form->isSubmitted() and $form->isValid()) {
$formData = $form->getData();
if (property_exists($formData, 'name') && is_string($formData->getName())) {
$formData->setName(strtoupper($formData->getName()));
}
if (property_exists($formData, 'nom_enfant') && is_string($formData->getNomEnfant())) {
$formData->setNomEnfant(strtoupper($formData->getNomEnfant()));
}
if (property_exists($formData, 'prenom') && is_string($formData->getPrenom())) {
$formData->setPrenom(ucfirst(strtolower($formData->getPrenom())));
}
if (property_exists($formData, 'prenom_enfant') && is_string($formData->getPrenomEnfant())) {
$formData->setPrenomEnfant(ucfirst(strtolower($formData->getPrenomEnfant())));
}
$em->persist($formData);
$em->flush();
$this->addFlash('success', 'Merci pour votre demande, nous reviendrons vers vous dès que possible.');
$bus->dispatch(new SendEmailMessage('demandeRappel', '', $contactRappel->getId()));
}
return $this->render('frontend/rappel.html.twig', ['form' => $form->createView(), 'pageTitle' => 'C\'est occupé? On vous rappelle']);
}
/**
* @Route("/colonie-vacances-petit-prix.html", name="frontend_colonie-vacances-petit-prix",options={"sitemap" = true})
*/
public function ColonieVacancesPetitPrix(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'Des colonies de vacances à des prix accessibles']);
$liste = $em->getRepository(FrontOption::class)->findOneBy(['name' => 'sejourPrixMini']);
$sejours = $em->getRepository(Sejour::class)->findBy(['id' => $liste->getContent()]);
return $this->render('frontend/actualite/showArticle.html.twig', [
'article' => $article,
'sejourTitle' => 'Sélection de séjours Petits budgets',
'sejours' => $sejours
]);
}
/**
* @Route("/conditions-de-vente", name="frontend_conditions-de-vente",options={"sitemap" = true})
*/
public function ConditionsDeVente(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'Conditions générales d\'inscription']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/GPRD", name="frontend_gprd",options={"sitemap" = true})
* @Route("/RGPD", name="frontend_gprd",options={"sitemap" = true})
*/
public function GPRD(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'La protection de vos données personnelles']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/charte-de-qualite.html", name="frontend_charte-de-qualite",options={"sitemap" = true})
*/
public function CharteQualite(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'Notre charte « Qualité »']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/nos-garanties.html", name="frontend_nos-garanties",options={"sitemap" = true})
*/
public function NosGaranties(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'Garanties de nos colonies de vacances']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("projet-educatif.html", name="frontend_projet-educatif",options={"sitemap" = true})
*/
public function ProjetEducatif(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'Projet éducatif']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/projet-ecocitoyen", name="frontend_charte-ecologique",options={"sitemap" = true})
*/
public function CharteEcologique(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'Projet éco-citoyen Croq’ Vacances']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/avant-de-partir.html", name="frontend_avant-de-partir",options={"sitemap" = true})
*/
public function AvantDePartir(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'Bon à savoir avant de partir en colonie de vacances !']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/info-vie-du-groupe-colonie-de-vacances.html", name="frontend_vie-du-groupe",options={"sitemap" = true})
*/
public function VieDuGroupe(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'Vie du groupe']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/info-encadrement-colonie-de-vacances.html", name="frontend_encadrement",options={"sitemap" = true})
*/
public function Encadrement(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'L\'encadrement des colonies de vacances']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/conditions-de-vente-ce.html", name="frontend_conditions_ce",options={"sitemap" = true})
*/
public function ConditionsCE(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'Conditions générales d\'inscription réservées aux CSE, Administrations, Écoles et Œuvres Sociales']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/info-communication-colonie-de-vacances.html", name="frontend_communication",options={"sitemap" = true})
*/
public function Communication(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'Gardez le Contact']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/aide-financiere.html", name="frontend_aide-financiere",options={"sitemap" = true})
*/
public function AideFinanciere(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'Les aides financières pour un séjour à croq’ vacances']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/isLogged", name="frontend_is_logged")
*/
public function isLogged(): Response
{
if ($this->getUser() !== null)
return new JsonResponse(true);
return new JsonResponse(false);
}
/**
* @Route("/infos-legales.html", name="frontend_infos-legales",options={"sitemap" = true})
*/
public function InfoLegales(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'Mentions légales']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/conditions-de-vente.html", name="frontend_conditions-vente",options={"sitemap" = true})
*/
public function CGU(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'Conditions générales d\'inscription']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/edito-du-president.html", name="frontend_edito-president",options={"sitemap" = true})
*/
public function MotPresident(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'Le Mot du Président']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/historique-de-l-association.html", name="frontend_historique-association",options={"sitemap" = true})
*/
public function Historique(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'Historique de l\'association']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/info-alimentation-en-colonie-de-vacances.html", name="frontend_info-alimentation-en-colonie-de-vacances",options={"sitemap" = true})
*/
public function Alimentation(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'L\'alimentation']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/info-organisation-colonie-de-vacances.html", name="frontend_transport",options={"sitemap" = true})
*/
public function Transport(EntityManagerInterface $em): Response
{
$article = $em->getRepository(Article::class)->findOneBy(['title' => 'Le transport']);
return $this->render('frontend/actualite/showArticle.html.twig', ['article' => $article]);
}
/**
* @Route("/newsletter.html", name="inscription_newsletter",options={"sitemap" = true})
*/
public function inscriptionNewsletter(
Request $request,
EntityManagerInterface $em,
UserPasswordEncoderInterface $passwordEncoder
) {
if ($request->isMethod('GET')) {
return $this->render('frontend/merciNewsletter.html.twig');
}
$contactInfo = $this->getParameter('mailjet');
$apiKey = $contactInfo['apiKey'];
$secretKey = $contactInfo['secretKey'];
// Compte partagé "assocroqvacances@gmail.com"
// Liste de contacts "Abonnements"
$contacts_id = '1';
$subscriberEmail = $request->get('email');
if ($this->validateEmail($subscriberEmail)) {
$newsletterDone = $em->getRepository(Newsletter::class)->findOneByEmail($subscriberEmail);
if ($newsletterDone !== null)
return $this->render('frontend/merciNewsletter.html.twig');
$newsletter = new Newsletter();
$newsletter->setEmail($subscriberEmail);
$newsletter->setCreationDate(new \DateTime());
$em->persist($newsletter);
$em->flush();
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERPWD, $apiKey . ':' . $secretKey);
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
));
// recherche du contact
$url = 'https://api.mailjet.com/v3/REST/contact/' . $subscriberEmail;
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_POST, 0);
$buffer = curl_exec($curl_handle);
$contact = json_decode($buffer);
if (!isset($contact->Data[0]->ID)) {
// création du contact
$url = 'https://api.mailjet.com/v3/REST/contact';
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, json_encode(array(
'Email' => $subscriberEmail,
)));
curl_setopt($curl_handle, CURLOPT_POST, 1);
$buffer = curl_exec($curl_handle);
$contact = json_decode($buffer);
}
if ($contact !== null) {
// ajout du contact à la liste
$url = 'https://api.mailjet.com/v3/REST/listrecipient';
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, json_encode(array(
'ContactID' => $contact->Data[0]->ID,
'ListID' => $contacts_id
)));
$buffer = curl_exec($curl_handle);
$response_code = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE);
curl_close($curl_handle);
$em->flush();
}
}
return $this->render('frontend/merciNewsletter.html.twig');
}
/**
* @Route("sessionphotos", name="sessionPhotoCode-detail")
*/
public function sessionPhotoCode(Request $request, EntityManagerInterface $em)
{
if ($request->isMethod('POST')) {
$code = $request->request->get('code');
$sejourSession = $em->getRepository(SejourSession::class)->findOneBy(['codeGen' => $code]);
return $this->render('frontend/sessionphotos.html.twig', ['sejourSession' => $sejourSession]);
}
return $this->render('frontend/sessionphotos.html.twig');
}
/**
* @Route("colonie-de-vacances-{slug}_{id}.html", name="frontend_colonie-detail")
*/
public function colonieDetail(Request $request, SejourRepository $sr, $slug, $id, UpdateParticipantSession $ups, UploaderHelper $helper, FrontOptionRepository $frontRepo)
{
$referer = $request->headers->get('referer');
$sejour = $sr->findOneById($id);
if (!$sejour || $sejour->getIsActive() == 0) {
throw $this->createNotFoundException('The product does not exist');
}
foreach ($sejour->getSejourSessions() as $session) {
$ups->updateSingleSejourSession($session);
}
$phrase = $frontRepo->findOneByName('phrase');
$title = $sejour->getTitle() . " " . $sejour->getSaisons()[0]->getTitle() . " " . $sejour->getSaisons()[0]->getAnneeAffichee() . " - Croq' Vacances";
$description = strip_tags(str_replace('</li>', ',', $sejour->getDescription()));
$descriptionArray = explode(",", $description);
$descriptionOutput = "";
foreach ($descriptionArray as $desc) {
if (strlen($descriptionOutput) > 160) continue;
$descriptionOutput .= $desc . " , ";
}
$inscription = new Inscription();
$form = $this->createForm(InscriptionStartType::class, $inscription, ['sejour' => $sejour]);
$media = $sejour->getMedias();
$img_path = "";
try {
$img1 = $media[0];
$img_path = $helper->asset($img1);
} catch (\Throwable $th) {
//throw $th;
}
$jsonLd = [
"@context" => "http://schema.org",
"@type" => "Product",
"brand" => "Croqvacances",
"description" => html_entity_decode(str_replace(array("\r", "\n"), '', $description), ENT_QUOTES | ENT_HTML5, 'UTF-8'),
"name" => $sejour->getTitle(),
"image" => "https://{$_SERVER['HTTP_HOST']}{$img_path}",
"offers" => [
"@type" => "Offer",
"availability" => "http://schema.org/InStock",
"price" => $sejour->getMinPrice(),
"priceCurrency" => "EUR"
]
];
$jsonLdScript = sprintf('<script type="application/ld+json">%s</script>', json_encode($jsonLd, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
return $this->render('frontend/sejour.html.twig', [
'sejour' => $sejour,
'form' => $form->createView(),
'referer' => $referer,
'seo' => ['title' => $title, 'description' => substr($descriptionOutput, 0, -3)],
'jsonLdScript' => $jsonLdScript,
'phrase' => $phrase
]);
}
public function sejoursOrder(EntityManagerInterface $em, CacheInterface $cache)
{
$cache->get('sejours_order_last_execution', function (ItemInterface $item) use ($em) {
$lastExecutionTimestamp = $item->get();
if (!$lastExecutionTimestamp || (time() - $lastExecutionTimestamp) >= 86400) { // 86400 seconds = 1 day
$dql = "SELECT s FROM App\Entity\Sejour s WHERE s.isActive = true ORDER BY s.position ASC";
$query = $em->createQuery($dql);
$sejours = $query->getResult();
$now = new \DateTime(); // Get the current date and time
foreach ($sejours as $sejour) {
$sejour->setBientot(true);
foreach ($sejour->getSejourSessions() as $session) {
if ($session->getDatedebut() >= $now) {
$sejour->setBientot(false);
// $sejour->setPosition(0);
break;
}
}
}
$item->set(time());
$em->flush();
}
});
}
/**
* @Route("/colonie-de-vacances", name="frontend_resa_liste_colonies",options={"sitemap" = true})
* @Route("/liste-des-colonies/", name="frontend_resa_liste_colonies2",options={"sitemap" = false})
*/
public function listeDesColonies(EntityManagerInterface $em, PaginatorInterface $paginator, Request $request, CacheInterface $cache): Response
{
$this->sejoursOrder($em, $cache);
$dql = "SELECT s FROM App\Entity\Sejour s WHERE s.isActive = true ORDER BY s.isBientot ASC, s.position ASC";
$query = $em->createQuery($dql);
$pageNumber = $request->query->getInt('page', 1);
$pagination = $paginator->paginate(
$query,
$pageNumber,
11
);
$theme = $em->getRepository(Theme::class)->findOneByTitle('general');
$annee = $em->getRepository(FrontOption::class)->findOneBy(['name' => 'anneGenerale'])->getContent();
$dql_data = "SELECT count(s) as offerCount , MIN(s.price) as min_price , MAX(s.price) as max_price FROM App\Entity\Sejour s WHERE s.isActive = true ORDER BY s.position ASC";
$query_data = $em->createQuery($dql_data);
$json_data = $query_data->getSingleResult();
$jsonLd = [
"@context" => "http://schema.org",
"@type" => "Product",
"name" => "Colonies de vacances",
"offers" => [
"@type" => "AggregateOffer",
"lowPrice" => $json_data['min_price'],
"highPrice" => $json_data['max_price'],
"offerCount" => $json_data['offerCount'],
"priceCurrency" => "EUR"
]
];
$jsonLdScript = sprintf('<script type="application/ld+json">%s</script>', json_encode($jsonLd, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
return $this->render('frontend/resa/index.html.twig', [
'pagination' => $pagination,
'title' => 'Liste de nos colonies de vacances ' . $annee,
'theme' => $theme,
'noIndex' => $pageNumber > 1,
'jsonLdScript' => $jsonLdScript
]);
}
/**
* @Route("colonie-de-vacances/{path}", name="frontend_resa_dynamique_liste_colonies", requirements={"path"=".+"})
*/
public function dynamiqueListeColonies($path, PaginatorInterface $paginator, EntityManagerInterface $em, UploaderHelper $helper, Request $request)
{
$keywords = explode("/", $path);
$annee = $em->getRepository(FrontOption::class)->findOneBy(['name' => 'anneGenerale'])->getContent();
$searchKW = [];
$searchKW['saison'] = $em->getRepository(Saison::class)->findOneBy(['title' => $keywords]);
$searchKW['theme'] = $em->getRepository(Theme::class)->findOneBy(['slug' => $keywords, 'isActivite' => false]);
$searchKW['activite'] = $em->getRepository(Theme::class)->findOneBy(['slug' => $keywords, 'isActivite' => true]);
$searchKW['age'] = $em->getRepository(Age::class)->findOneBy(['slug' => $keywords]);
$searchKW['location'] = $em->getRepository(Country::class)->findOneBy(['slug' => $keywords]);
$searchKW['villeDesservie'] = $em->getRepository(VilleDesservie::class)->findOneBy(['slug' => $keywords,'isActive'=>true]);
$query = $em->getRepository(Sejour::class)->colonieSearch($searchKW);
// var_dump($json_data);
// return new Response("");
$pagination = $paginator->paginate(
$query, /* query NOT result */
$request->query->getInt('page', 1), /* page number */
11, /* limit per page */
);
$noIndex = $request->query->getInt('page') >= 1;
$pageId = $request->query->getInt('page', 1);
if ($searchKW["saison"] !== null)
$annee = $searchKW["saison"]->getAnneeAffichee();
$title = "Colonies de vacances " . implode(', ', $keywords) . " " . $annee;
$hassecond = false;
if (count(array_filter($searchKW)) > 1) {
$theme = $em->getRepository(Theme::class)->findOneByTitle("second niveau");
$hassecond = true;
$title = "Colonies de vacances ";
foreach (array_filter($searchKW) as $key => $entity) {
switch ($key) {
case "age":
$title .= " à partir de " . $entity->getTitle();
break;
case "villeDesservie":
$title .= " au départ de " . $entity->getTitle();
break;
case "saison":
$annee = $entity->getAnneeAffichee();
$title .= " " . $entity->getTitle() . " " . $annee;
break;
default:
$title .= " " . $entity->getTitle();
}
}
$noIndex = true;
} elseif (count(array_filter($searchKW)) == 1) {
$theme = array_values(array_filter($searchKW))[0];
$title = "Colonies de vacances ";
foreach (array_filter($searchKW) as $key => $entity) {
switch ($key) {
case "age":
$title .= " à partir de " . $entity->getTitle();
break;
case "villeDesservie":
$title .= " au départ de " . $entity->getTitle();
break;
case "saison":
$annee = $entity->getAnneeAffichee();
$title .= " " . $entity->getTitle() . " " . $annee;
break;
default:
$title .= " " . $entity->getTitle();
}
}
} else {
$theme = $em->getRepository(Theme::class)->findOneByTitle('general');
}
$maxPrice = 0;
$minPrice = 0;
$img_path = null;
foreach ($pagination as $item) {
// Assuming each item has a 'price' property, adjust the property name accordingly
if ($item->hasFutureSejourSessions() && !$item->isFutureComplete()) {
$price = $item->getMinPrice();
if ($maxPrice === 0 || $price > $maxPrice) {
$maxPrice = $price;
}
if ($minPrice === 0 || $price < $minPrice) {
$minPrice = $price;
}
if ($img_path == null) {
$media = $item->getMedias();
try {
$img1 = $media[0];
$img_path = $helper->asset($img1);
} catch (\Throwable $th) {
//throw $th;
}
}
}
}
$jsonLd = [
"@context" => "http://schema.org",
"@type" => "Product",
"name" => "Colonies de vacances",
"image" => "https://{$_SERVER['HTTP_HOST']}{$img_path}",
"offers" => [
"@type" => "AggregateOffer",
"lowPrice" => $minPrice == 0 ? "Bientot" : $minPrice,
"highPrice" => $maxPrice == 0 ? "Bientot" : $maxPrice,
"offerCount" => count($pagination),
"priceCurrency" => "EUR"
]
];
$jsonLdScript = sprintf('<script type="application/ld+json">%s</script>', json_encode($jsonLd, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
return $this->render('frontend/resa/index.html.twig', [
'pagination' => $pagination,
'title' => $title,
'theme' => $theme,
'noIndex' => $noIndex,
'searchKW' => $searchKW,
'hassecond' => $hassecond,
'jsonLdScript' => $jsonLdScript,
]);
}
/**
* @Route("/colonie-de-vacances-autour-de-moi", name="frontend_resa_liste_colonies_map",options={"sitemap" = true})
*/
public function listeDesColoniesMap(EntityManagerInterface $em, PaginatorInterface $paginator, Request $request, CacheInterface $cache): Response
{
$this->sejoursOrder($em, $cache);
$min = $request->query->get('min');
$max = $request->query->get('max');
if ($min !== null && $max !== null) {
$dql = "SELECT s FROM App\Entity\Sejour s join s.sejourSessions ss WHERE s.isActive = true and ss.prix >= $min and ss.prix <= $max ORDER BY s.isBientot ASC, s.position ASC";
} else {
$dql = "SELECT s FROM App\Entity\Sejour s WHERE s.isActive = true ORDER BY s.isBientot ASC, s.position ASC";
}
$query = $em->createQuery($dql);
$pageNumber = $request->query->getInt('page', 1);
$pagination = $paginator->paginate(
$query, /* query NOT result */
$request->query->getInt('page', 1), /* page number */
10, /* limit per page */
);
// $sejours = $query->getResult();
$theme = $em->getRepository(Theme::class)->findOneByTitle('general');
$annee = $em->getRepository(FrontOption::class)->findOneBy(['name' => 'anneGenerale'])->getContent();
$dql_data = "SELECT count(s) as offerCount , MIN(s.price) as min_price , MAX(s.price) as max_price FROM App\Entity\Sejour s WHERE s.isActive = true ORDER BY s.position ASC";
$query_data = $em->createQuery($dql_data);
$json_data = $query_data->getSingleResult();
$jsonLd = [
"@context" => "http://schema.org",
"@type" => "Product",
"name" => "Colonies de vacances",
"offers" => [
"@type" => "AggregateOffer",
"lowPrice" => $json_data['min_price'],
"highPrice" => $json_data['max_price'],
"offerCount" => $json_data['offerCount'],
"priceCurrency" => "EUR"
]
];
$jsonLdScript = sprintf('<script type="application/ld+json">%s</script>', json_encode($jsonLd, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
return $this->render('frontend/sejour_map.html.twig', [
'pagination' => $pagination,
// 'sejours' => $sejours,
'title' => 'Liste de nos colonies de vacances ' . $annee,
'theme' => $theme,
'noIndex' => $pageNumber > 1,
"lowPrice" => $json_data['min_price'],
"highPrice" => $json_data['max_price'],
'jsonLdScript' => $jsonLdScript
]);
}
/**
* @Route("/colonie-de-vacances-autour-de-moi/{path}", name="frontend_resa_dynamique_liste_colonies_map", requirements={"path"=".+"})
*/
public function dynamiqueListeColoniesMap($path, PaginatorInterface $paginator, EntityManagerInterface $em, Request $request)
{
$keywords = explode("/", $path);
$annee = $em->getRepository(FrontOption::class)->findOneBy(['name' => 'anneGenerale'])->getContent();
$searchKW = [];
$searchKW['saison'] = $em->getRepository(Saison::class)->findBy(['title' => $keywords]);
$searchKW['theme'] = $em->getRepository(Theme::class)->findBy(['slug' => $keywords, 'isActivite' => false]);
$searchKW['activite'] = $em->getRepository(Theme::class)->findBy(['slug' => $keywords, 'isActivite' => true]);
$searchKW['age'] = $em->getRepository(Age::class)->findOneBy(['slug' => $keywords]);
$searchKW['location'] = $em->getRepository(Country::class)->findBy(['slug' => $keywords]);
$searchKW['villeDesservie'] = $em->getRepository(VilleDesservie::class)->findBy(['slug' => $keywords]);
$min = $request->query->get('min');
$max = $request->query->get('max');
if ($min == null || $max == null) {
$min = 0;
$max = 9999999999;
}
$query = $em->getRepository(Sejour::class)->colonieWithORSearch($searchKW, $min, $max);
$pagination = $paginator->paginate(
$query,
$request->query->getInt('page', 1),
10,
);
// $sejours = $query->getResult();
$noIndex = $request->query->getInt('page') >= 1;
$pageId = $request->query->getInt('page', 1);
// if ($searchKW["saison"] !== null)
// $annee = $searchKW["saison"]->getAnneeAffichee();
$title = "Colonies de vacances " . implode(', ', $keywords) . " " . $annee;
$hassecond = false;
if (count(array_filter($searchKW)) > 1) {
$theme = $em->getRepository(Theme::class)->findOneByTitle("second niveau");
$hassecond = true;
$title = "Colonies de vacances ";
// foreach (array_filter($searchKW) as $key => $entity) {
// switch ($key) {
// case "age":
// $title .= " à partir de " . $entity->getTitle();
// break;
// case "villeDesservie":
// $title .= " au départ de " . $entity->getTitle();
// break;
// case "saison":
// $annee = $entity->getAnneeAffichee();
// $title .= " " . $entity->getTitle() . " " . $annee;
// break;
// default:
// $title .= " " . $entity->getTitle();
// }
// }
$noIndex = true;
} elseif (count(array_filter($searchKW)) == 1) {
$theme = array_values(array_filter($searchKW))[0];
$title = "Colonies de vacances ";
// foreach (array_filter($searchKW) as $key => $entity) {
// switch ($key) {
// case "age":
// $title .= " à partir de " . $entity->getTitle();
// break;
// case "villeDesservie":
// $title .= " au départ de " . $entity->getTitle();
// break;
// case "saison":
// $annee = $entity->getAnneeAffichee();
// $title .= " " . $entity->getTitle() . " " . $annee;
// break;
// default:
// $title .= " " . $entity->getTitle();
// }
// }
} else {
$theme = $em->getRepository(Theme::class)->findOneByTitle('general');
}
$maxPrice = 0;
$minPrice = 0;
$img_path = null;
foreach ($pagination as $item) {
// Assuming each item has a 'price' property, adjust the property name accordingly
if ($item->hasFutureSejourSessions() && !$item->isFutureComplete()) {
$price = $item->getMinPrice();
if ($maxPrice === 0 || $price > $maxPrice) {
$maxPrice = $price;
}
if ($minPrice === 0 || $price < $minPrice) {
$minPrice = $price;
}
if ($img_path == null) {
$media = $item->getMedias();
try {
$img1 = $media[0];
$img_path = $helper->asset($img1);
} catch (\Throwable $th) {
//throw $th;
}
}
}
}
// $theme = $em->getRepository(Theme::class)->findOneByTitle('general');
$jsonLd = [
"@context" => "http://schema.org",
"@type" => "Product",
"name" => "Colonies de vacances",
"image" => "https://{$_SERVER['HTTP_HOST']}{$img_path}",
"offers" => [
"@type" => "AggregateOffer",
"lowPrice" => $minPrice == 0 ? "Bientot" : $minPrice,
"highPrice" => $maxPrice == 0 ? "Bientot" : $maxPrice,
"offerCount" => 0,
"priceCurrency" => "EUR"
]
];
$jsonLdScript = sprintf('<script type="application/ld+json">%s</script>', json_encode($jsonLd, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
$searchKW['saison'] = !empty($searchKW['saison']) ? $searchKW['saison'][0] : null;
$searchKW['theme'] = !empty($searchKW['theme']) ? $searchKW['theme'][0] : null;
$searchKW['activite'] = !empty($searchKW['activite']) ? $searchKW['activite'][0] : null;
$searchKW['location'] = !empty($searchKW['location']) ? $searchKW['location'][0] : null;
$searchKW['villeDesservie'] = !empty($searchKW['villeDesservie']) ? $searchKW['villeDesservie'][0] : null;
$dql_data = "SELECT count(s) as offerCount , MIN(s.price) as min_price , MAX(s.price) as max_price FROM App\Entity\Sejour s WHERE s.isActive = true ORDER BY s.position ASC";
$query_data = $em->createQuery($dql_data);
$json_data = $query_data->getSingleResult();
return $this->render('frontend/sejour_map.html.twig', [
'pagination' => $pagination,
'title' => $title,
'theme' => $theme,
'noIndex' => $noIndex,
'searchKW' => $searchKW,
'hassecond' => $hassecond,
'jsonLdScript' => $jsonLdScript,
"lowPrice" => $json_data['min_price'],
"highPrice" => $json_data['max_price'],
]);
}
/**
* @Route("/sejour-disponible", name="sejour_search_by_date")
*/
public function sejourSearchByDate(Request $request, EntityManagerInterface $em, PaginatorInterface $paginator)
{
$dateDebut = $request->query->get('dateDebut');
$dateFin = $request->query->get('dateFin');
$startDate = new \DateTime($dateDebut);
$endDate = new \DateTime($dateFin);
$qb = $em->getRepository(Sejour::class)->createQueryBuilder('s');
$sejours = $qb->select('s')
->leftJoin('s.sejourSessions', 'ss')
->where('s.isActive = true')
->andWhere('ss.dateDebut = :startDate')
->andWhere('ss.dateFin = :endDate')
->setParameter('startDate', $startDate)
->setParameter('endDate', $endDate)
->getQuery()
->getResult();
$sejoursAvl = [];
foreach ($sejours as $sejour) {
$sejourSessions = $sejour->getSejourSessions();
foreach ($sejourSessions as $sejourSession) {
if ($sejourSession->getDateDebut() == $startDate && $sejourSession->getDateFin() == $endDate) {
if ($sejourSession->getFreePlacesNumber() > 0) {
$sejoursAvl[] = $sejour;
break;
}
}
}
}
$pagination = $paginator->paginate(
$sejoursAvl, /* result after filtering */
$request->query->getInt('page', 1), /* page number */
11 /* limit per page */
);
$pageId = $request->query->getInt('page', 1);
$theme = $em->getRepository(Theme::class)->findOneByTitle('general');
return $this->render('frontend/resa/index.html.twig', [
'pagination' => $pagination,
'title' => 'Liste de nos colonies de vacances ',
'theme' => $theme,
'noIndex' => $pageId > 0
]);
}
/**
* @Route("FCMICRO",name="frontend_fc_micro")
*/
public function fcmicro()
{
$this->getDoctrine()->getManager()->getRepository(FrontOption::class)->findAll();
return new JsonResponse("ce franck, il est quand meme cool");
}
/**
* @Route("goa", name="frontend_goa")
*/
public function goa(EntityManagerInterface $em, UploaderHelper $helper)
{
// $mediaType = $em->getRepository(MediaCategorie::class)->findOneBy(['name' => 'Documentation']);
// $media = $em->getRepository(Media::class)->findOneBy(
// [
// 'name' => 'Garantie Option annulation',
// 'mediaCategorie' => $mediaType
// ],
// );
// $path = $helper->asset($media, 'imgFile');
// return $this->redirect($path);
$response = new BinaryFileResponse("files/GOA.2024.pdf");
$response->headers->set('Content-Type', 'application/pdf');
$response->headers->set('Content-Disposition', 'inline; filename="GOA.pdf"');
return $response;
}
/**
* @Route("ajax/enfant/{id}",name="ajax_enfant_id")
*/
public function ajaxEnfant(EntityManagerInterface $em, $id)
{
//TODO: voters
$enfant = $em->getRepository(Contact::class)->findOneBy([
'id' => $id,
'parent' => $this->getUser()->getContact()
]);
return new JsonResponse([
'id' => $id,
'firstName' => $enfant->getFirstName(),
'lastName' => $enfant->getLastName(),
'sexe' => $enfant->getSexe(),
'birthDate' => $enfant->getBirthdate()->format('Y-m-d'),
]);
}
/**
* @Route("ficheinscriptionCorse.html",name="frontend_demande_sejour_corse",options={"sitemap" = true})
*/
public function demandeSejourCorse(Request $request, EntityManagerInterface $em, MessageBusInterface $bus)
{
$demandeSejourCorse = new DemandeSejourCorse();
$form = $this->createForm(DemandeSejourCorseType::class, $demandeSejourCorse);
$form->handleRequest($request);
$imageCategorie = $em->getRepository(MediaCategorie::class)->findOneByName('sejourCorse');
$images = $em->getRepository(Media::class)->findBy(['mediaCategorie' => $imageCategorie]);
if ($form->isSubmitted() and $form->isValid()) {
$email = $demandeSejourCorse->getContact()->getEmail();
$contact = $em->getRepository(Contact::class)->findOneByEmail($email);
if ($contact !== null) {
$demandeSejourCorse->setCOntact($contact);
}
$em->persist($demandeSejourCorse);
$em->flush();
$this->addFlash('success', 'Merci pour votre demande, nous reviendrons vers vous dès que possible.');
$bus->dispatch(new SendEmailMessage('inscription_corse', '', $demandeSejourCorse->getId(),$this->params->get('email_info')));
}
return $this->render('frontend/formCorse.html.twig', [
'form' => $form->createView(),
'pageTitle' => "Demande de devis Accueil Groupes en Corse",
'images' => $images
]);
}
/**
* @Route("plan-du-site.html",name="frontend_plan_du_site")
*/
public function PlanDuSite(HttpClientInterface $client)
{
$response = $client->request(
'GET',
'https://croqvacances.org/sitemap.colonies.xml'
);
$xml = simplexml_load_string($response->getContent(), "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode($xml);
$colonies = json_decode($json, TRUE);
$response = $client->request(
'GET',
'https://croqvacances.org/sitemap.default.xml'
);
$xml = simplexml_load_string($response->getContent(), "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode($xml);
$defaults = json_decode($json, TRUE);
$response = $client->request(
'GET',
'https://croqvacances.org/sitemap.sejour.xml'
);
$xml = simplexml_load_string($response->getContent(), "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode($xml);
$sejours = json_decode($json, TRUE);
$response = $client->request(
'GET',
'https://croqvacances.org/sitemap.article.xml'
);
$xml = simplexml_load_string($response->getContent(), "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode($xml);
$articles = json_decode($json, TRUE);
return $this->render('frontend/planDuSite.html.twig', ['default' => $defaults, 'sejours' => $sejours, 'articles' => $articles, 'colonies2' => $colonies]);
}
/**
* @Route("vie-associative.html", name="frontend_vie-associative",options={"sitemap" = {"name"="tralala"}})
*/
public function vieAssoviative(EntityManagerInterface $em)
{
$articles = $em->getRepository(Article::class)->findBy([
'title' => ['vie_associative_soutenir', 'vie_associative_devenir_benevole', 'vie_associative_temoignage', 'vie_associative_histoire_associative']
]);
return $this->render('frontend/vie-associative.html.twig', ['articles' => $articles]);
}
/**
* @Route("revue-de-presse.html", name="article_de_presse",options={"sitemap" = true})
*/
public function articleDePresse(ArticlePresseRepository $apr)
{
$articles = $apr->findBy(['isActive' => true], ['date' => 'DESC']);
return $this->render('frontend/article_de_presse.html.twig', ['articles' => $articles]);
}
function validateEmail($email)
{
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
}