<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Controller\admin;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Knp\Component\Pager\PaginatorInterface;
use App\Entity\Country;
use App\Entity\Category;
use App\Entity\Subcategory;
use App\Entity\Experience;
use App\Entity\Program;
use App\Entity\Destination;
use App\Entity\Media;
use App\Entity\Hebergement;
use App\Entity\Promotion;
use App\Entity\Availability;
//use App\Entity\Experience;
/**
* Controller used to manage current user.
*
* @author Romain Monteil <monteil.romain@gmail.com>
*/
#[Route('/admin/experience')]
class ExperienceController extends AbstractController {
#[Route('/general-info', methods: ['GET', 'POST'], name: 'add_general_info')]
public function addGeneralinfo(Request $request, ManagerRegistry $doctrine) {
$em = $doctrine->getManager();
$countries = $em->getRepository(Country::class)->findAll();
$categories = $em->getRepository(Category::class)->findAll();
if ($request->isMethod('post')) {
$experience = new Experience();
$experience->setTitle($request->get('title'));
$experience->setResume($request->get('resume'));
$experience->setPublished(0);
$experience->setEnabled(1);
$experience->setCoachingtype($request->get('coachingtype'));
$experience->setSteps('1');
$em->persist($experience);
$em->flush();
$em->persist($experience);
$em->flush();
$this->addFlash('success', 'Informations générale enregistrées avec succes, continuer a remplir les informations suivantes');
return $this->redirectToRoute('add_highlights', [
'country' => $request->get('country'),
'category' => $request->get('category'),
'id' => $experience->getId(),
]);
}
return $this->render('admin/experience/add/addGeneralinfo.html.twig', [
'countries' => $countries,
'categories' => $categories,
]);
}
#[Route('/exp-{id}/add-highlights', methods: ['GET', 'POST'], name: 'add_highlights')]
public function addHighlights(Request $request, $id, ManagerRegistry $doctrine) {
$em = $doctrine->getManager();
$experience = $em->getRepository(Experience::class)->find($id);
if ($request->get('category')) {
$category = $em->getRepository(Category::class)->find($request->get('category'));
$country = $em->getRepository(Country::class)->find($request->get('country'));
} else {
$subcategory = $em->getRepository(Subcategory::class)->find($request->get('subcategory'));
$category = $subcategory->getCategory();
}
if ($request->isMethod('post')) {
$experience->setHighlights($request->get('highlights'));
$destination = $em->getRepository(Destination::class)->find($request->get('destination'));
if (!$destination) {
$destination = new Destination();
$destination->setName($request->get('destination'));
$em->persist($destination);
$em->flush();
$country->addDestination($destination);
$em->persist($country);
}
$destination->addExperience($experience);
$experience->addSubcategory($subcategory);
$experience->setSteps(array('2'));
$em->persist($subcategory);
$em->persist($experience);
$em->flush();
$this->addFlash('success', 'Les grandes lignes enregistrées avec succes, continuer a remplir les informations suivantes');
return $this->redirectToRoute('add_program', [
'id' => $experience->getId(),
]);
}
return $this->render('admin/experience/add/addHighlights.html.twig', [
'experience' => $experience,
'country' => $country,
'category' => $category,
]);
}
#[Route('/exp-{id}/add-program', methods: ['GET', 'POST'], name: 'add_program')]
public function addProgram(Request $request, $id, ManagerRegistry $doctrine) {
$em = $doctrine->getManager();
$experience = $em->getRepository(Experience::class)->find($id);
if ($request->isMethod('post')) {
$i = 0;
foreach ($request->get('days') as $p) {
$program = new Program();
$program->setDay($request->get('days')[$i]);
$program->setDescription($request->get('descriptions')[$i]);
$em->persist($program);
$em->flush();
$experience->addProgram($program);
$i++;
}
$experience->setSteps('3');
$em->persist($experience);
$em->flush();
$this->addFlash('success', 'Programme enregistrées avec succes, continuer a remplir les informations suivantes');
return $this->redirectToRoute('list_countries', [
'country' => $request->get('country'),
'category' => $request->get('category'),
]);
}
return $this->render('admin/experience/add/addProgram.html.twig', [
'experience' => $experience,
]);
}
#[Route('/exp-{id}/add-description', methods: ['GET', 'POST'], name: 'add_description')]
public function addDescription(Request $request, $id, ManagerRegistry $doctrine) {
$em = $doctrine->getManager();
$experience = $em->getRepository(Experience::class)->find($id);
if ($request->isMethod('post')) {
$experience->setDescription($request->get('description'));
$experience->setIncluded($request->get('included'));
$experience->setNotincluded($request->get('notincluded'));
$experience->setSteps('4');
$em->persist($experience);
$em->flush();
$this->addFlash('success', 'Description enregistrées avec succes, continuer a remplir les informations restantes');
return $this->redirectToRoute('list_countries', [
'country' => $request->get('country'),
'category' => $request->get('category'),
]);
}
return $this->render('admin/experience/add/addDescription.html.twig', [
'experience' => $experience,
]);
}
#[Route('/exp-{id}/add-hebergement', methods: ['GET', 'POST'], name: 'add_hebergement')]
public function addHebergement(Request $request, $id, ManagerRegistry $doctrine) {
$em = $doctrine->getManager();
$experience = $em->getRepository(Experience::class)->find($id);
if ($request->isMethod('post')) {
$hebergement = new Hebergement();
$hebergement->setDescription($request->get('description'));
$hebergement->setName($request->get('name'));
$em->persist($hebergement);
$em->flush();
if ($request->files->get('image')) {
$file = $request->files->get('image');
$hebergement->setImage("uploads/medias/experiences/" . $hebergement->getId() . "/" . $file->getClientOriginalName());
$file->move("uploads/medias/experiences/" . $hebergement->getId() . "/", $file->getClientOriginalName());
}
$experience->addHebergement($hebergement);
if ($request->files->get('medias')) {
$i = 0;
foreach ($request->files->get('medias') as $file) {
$media = new Media();
$media->setPath("uploads/medias/experiences/rooms" . $experience->getId() . "/" . $file->getClientOriginalName());
$media->setOrdre('1');
$media->setEnabled('1');
$file->move("uploads/medias/experiences/rooms" . $experience->getId() . "/", $file->getClientOriginalName());
$em->persist($media);
$hebergement->addMedia($media);
$i++;
}
$experience->setSteps('5');
$em->persist($experience);
$em->flush();
}
$this->addFlash('success', 'Description enregistrées avec succes, continuer a remplir les informations restantes');
return $this->redirectToRoute('list_countries', [
'country' => $request->get('country'),
'category' => $request->get('category'),
]);
}
return $this->render('admin/experience/add/addHebergement.html.twig', [
'experience' => $experience,
]);
}
#[Route('/exp-{id}/add-media', methods: ['GET', 'POST'], name: 'add_media')]
public function addMedia(Request $request, $id, ManagerRegistry $doctrine) {
$em = $doctrine->getManager();
$experience = $em->getRepository(Experience::class)->find($id);
if ($request->isMethod('post')) {
if ($request->files->get('image')) {
$file = $request->files->get('image');
$experience->setImage("uploads/medias/experiences/" . $experience->getId() . "/" . $file->getClientOriginalName());
$file->move("uploads/medias/experiences/" . $experience->getId() . "/", $file->getClientOriginalName());
}
if ($request->files->get('medias')) {
$i = 0;
foreach ($request->files->get('medias') as $file) {
$media = new Media();
$media->setPath("uploads/medias/experiences/" . $experience->getId() . "/" . $file->getClientOriginalName());
$media->setOrdre('1');
$media->setEnabled('1');
$file->move("uploads/medias/experiences/" . $experience->getId() . "/", $file->getClientOriginalName());
$em->persist($media);
$experience->addMedia($media);
$i++;
}
$experience->setSteps('1');
$em->persist($experience);
$em->flush();
}
$this->addFlash('success', 'Média enregistrées avec succes, continuer a remplir les informations restantes');
return $this->redirectToRoute('list_countries', [
]);
}
return $this->render('admin/experience/add/addMedia.html.twig', [
'experience' => $experience,
]);
}
#[Route('/exp-{id}/add-price', methods: ['GET', 'POST'], name: 'add_price')]
public function addPrice(Request $request, $id, ManagerRegistry $doctrine) {
$em = $doctrine->getManager();
$experience = $em->getRepository(Experience::class)->find($id);
if ($request->isMethod('post')) {
if ($request->get('onpromo') == "on") {
$experience->setOnpromo(1);
$promotion = new Promotion();
$promotion->setPercent($request->get('percent'));
$promotion->setDateend(new \DateTime($request->get('dateend')));
$promotion->setDatestart(new \DateTime($request->get('datestart')));
$em->persist($promotion);
$experience->setPromotion($promotion);
$em->persist($experience);
}
if ($request->get('hashebergement') == "on") {
$experience->setHashebergement(1);
$i = 0;
foreach ($request->get('idhebergements') as $c) {
$hebergement = $em->getRepository(Hebergement::class)->find($request->get('idhebergements')[$i]);
$hebergement->setPrice($request->get('pricehebergements')[$i]);
$em->persist($hebergement);
$em->flush();
$i++;
}
}
$experience->setCancellation($request->get('cancellation'));
$experience->setCurrency($request->get('currency'));
$experience->setPrice($request->get('price'));
$em->persist($experience);
$em->flush();
$this->addFlash('success', 'Prix enregistrées avec succes, continuer a remplir les informations restantes');
return $this->redirectToRoute('list_countries', [
]);
}
return $this->render('admin/experience/add/addPrice.html.twig', [
'experience' => $experience,
]);
}
#[Route('/exp-{id}/add-availability', methods: ['GET', 'POST'], name: 'add_availability')]
public function addAvailability(Request $request, $id, ManagerRegistry $doctrine) {
$em = $doctrine->getManager();
$experience = $em->getRepository(Experience::class)->find($id);
if ($request->isMethod('post')) {
$availability = new Availability();
$availability->setDuration($request->get('duration'));
$availability->setAvailabilitytype($request->get('availabilitytype'));
// avalabilty = 1 - unavalibility = 2
$availability->setDaysbefore($request->get('daysbefore'));
$availability->setDatesstart($request->get('availabilities'));
$availability->setUnavailabilities($request->get('unavailabilities'));
$em->persist($availability);
$experience->setAvailability($availability);
$em->persist($experience);
$em->flush();
$this->addFlash('success', 'Disponibilité enregistrées avec succes, continuer a remplir les informations restantes');
return $this->redirectToRoute('list_countries', [
]);
}
return $this->render('admin/experience/add/addAvailability.html.twig', [
'experience' => $experience,
]);
}
#[Route('/exp-{id}/overview', methods: ['GET', 'POST'], name: 'exp_overview')]
public function overview($id, ManagerRegistry $doctrine) {
$em = $doctrine->getManager();
$experience = $em->getRepository(Experience::class)->find($id);
return $this->render('admin/experience/overview.html.twig', [
'experience' => $experience,
]);
}
}