src/Controller/admin/ExperienceController.php line 115

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace App\Controller\admin;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use Doctrine\Persistence\ManagerRegistry;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use Knp\Component\Pager\PaginatorInterface;
  19. use App\Entity\Country;
  20. use App\Entity\Category;
  21. use App\Entity\Subcategory;
  22. use App\Entity\Experience;
  23. use App\Entity\Program;
  24. use App\Entity\Destination;
  25. use App\Entity\Media;
  26. use App\Entity\Hebergement;
  27. use App\Entity\Promotion;
  28. use App\Entity\Availability;
  29. //use App\Entity\Experience;
  30. /**
  31.  * Controller used to manage current user.
  32.  *
  33.  * @author Romain Monteil <monteil.romain@gmail.com>
  34.  */
  35. #[Route('/admin/experience')]
  36. class ExperienceController extends AbstractController {
  37.     #[Route('/general-info'methods: ['GET''POST'], name'add_general_info')]
  38.     public function addGeneralinfo(Request $requestManagerRegistry $doctrine) {
  39.         $em $doctrine->getManager();
  40.         $countries $em->getRepository(Country::class)->findAll();
  41.         $categories $em->getRepository(Category::class)->findAll();
  42.         if ($request->isMethod('post')) {
  43.             $experience = new Experience();
  44.             $experience->setTitle($request->get('title'));
  45.             $experience->setResume($request->get('resume'));
  46.             $experience->setPublished(0);
  47.             $experience->setEnabled(1);
  48.             $experience->setCoachingtype($request->get('coachingtype'));
  49.             $experience->setSteps('1');
  50.             $em->persist($experience);
  51.             $em->flush();
  52.             $em->persist($experience);
  53.             $em->flush();
  54.             $this->addFlash('success''Informations générale enregistrées avec succes, continuer a remplir les informations suivantes');
  55.             return $this->redirectToRoute('add_highlights', [
  56.                         'country' => $request->get('country'),
  57.                         'category' => $request->get('category'),
  58.                         'id' => $experience->getId(),
  59.             ]);
  60.         }
  61.         return $this->render('admin/experience/add/addGeneralinfo.html.twig', [
  62.                     'countries' => $countries,
  63.                     'categories' => $categories,
  64.         ]);
  65.     }
  66.     #[Route('/exp-{id}/add-highlights'methods: ['GET''POST'], name'add_highlights')]
  67.     public function addHighlights(Request $request$idManagerRegistry $doctrine) {
  68.         $em $doctrine->getManager();
  69.         $experience $em->getRepository(Experience::class)->find($id);
  70.         if ($request->get('category')) {
  71.             $category $em->getRepository(Category::class)->find($request->get('category'));
  72.             $country $em->getRepository(Country::class)->find($request->get('country'));
  73.         } else {
  74.             $subcategory $em->getRepository(Subcategory::class)->find($request->get('subcategory'));
  75.             $category $subcategory->getCategory();
  76.         }
  77.         if ($request->isMethod('post')) {
  78.             $experience->setHighlights($request->get('highlights'));
  79.             $destination $em->getRepository(Destination::class)->find($request->get('destination'));
  80.             if (!$destination) {
  81.                 $destination = new Destination();
  82.                 $destination->setName($request->get('destination'));
  83.                 $em->persist($destination);
  84.                 $em->flush();
  85.                 $country->addDestination($destination);
  86.                 $em->persist($country);
  87.             }
  88.             $destination->addExperience($experience);
  89.             $experience->addSubcategory($subcategory);
  90.             $experience->setSteps(array('2'));
  91.             $em->persist($subcategory);
  92.             $em->persist($experience);
  93.             $em->flush();
  94.             $this->addFlash('success''Les grandes lignes enregistrées avec succes, continuer a remplir les informations suivantes');
  95.             return $this->redirectToRoute('add_program', [
  96.                         'id' => $experience->getId(),
  97.             ]);
  98.         }
  99.         return $this->render('admin/experience/add/addHighlights.html.twig', [
  100.                     'experience' => $experience,
  101.                     'country' => $country,
  102.                     'category' => $category,
  103.         ]);
  104.     }
  105.     #[Route('/exp-{id}/add-program'methods: ['GET''POST'], name'add_program')]
  106.     public function addProgram(Request $request$idManagerRegistry $doctrine) {
  107.         $em $doctrine->getManager();
  108.         $experience $em->getRepository(Experience::class)->find($id);
  109.         if ($request->isMethod('post')) {
  110.             $i 0;
  111.             foreach ($request->get('days') as $p) {
  112.                 $program = new Program();
  113.                 $program->setDay($request->get('days')[$i]);
  114.                 $program->setDescription($request->get('descriptions')[$i]);
  115.                 $em->persist($program);
  116.                 $em->flush();
  117.                 $experience->addProgram($program);
  118.                 $i++;
  119.             }
  120.             $experience->setSteps('3');
  121.             $em->persist($experience);
  122.             $em->flush();
  123.             $this->addFlash('success''Programme enregistrées avec succes, continuer a remplir les informations suivantes');
  124.             return $this->redirectToRoute('list_countries', [
  125.                         'country' => $request->get('country'),
  126.                         'category' => $request->get('category'),
  127.             ]);
  128.         }
  129.         return $this->render('admin/experience/add/addProgram.html.twig', [
  130.                     'experience' => $experience,
  131.         ]);
  132.     }
  133.     #[Route('/exp-{id}/add-description'methods: ['GET''POST'], name'add_description')]
  134.     public function addDescription(Request $request$idManagerRegistry $doctrine) {
  135.         $em $doctrine->getManager();
  136.         $experience $em->getRepository(Experience::class)->find($id);
  137.         if ($request->isMethod('post')) {
  138.             $experience->setDescription($request->get('description'));
  139.             $experience->setIncluded($request->get('included'));
  140.             $experience->setNotincluded($request->get('notincluded'));
  141.             $experience->setSteps('4');
  142.             $em->persist($experience);
  143.             $em->flush();
  144.             $this->addFlash('success''Description enregistrées avec succes, continuer a remplir les informations restantes');
  145.             return $this->redirectToRoute('list_countries', [
  146.                         'country' => $request->get('country'),
  147.                         'category' => $request->get('category'),
  148.             ]);
  149.         }
  150.         return $this->render('admin/experience/add/addDescription.html.twig', [
  151.                     'experience' => $experience,
  152.         ]);
  153.     }
  154.     #[Route('/exp-{id}/add-hebergement'methods: ['GET''POST'], name'add_hebergement')]
  155.     public function addHebergement(Request $request$idManagerRegistry $doctrine) {
  156.         $em $doctrine->getManager();
  157.         $experience $em->getRepository(Experience::class)->find($id);
  158.         if ($request->isMethod('post')) {
  159.             $hebergement = new Hebergement();
  160.             $hebergement->setDescription($request->get('description'));
  161.             $hebergement->setName($request->get('name'));
  162.             $em->persist($hebergement);
  163.             $em->flush();
  164.             if ($request->files->get('image')) {
  165.                 $file $request->files->get('image');
  166.                 $hebergement->setImage("uploads/medias/experiences/" $hebergement->getId() . "/" $file->getClientOriginalName());
  167.                 $file->move("uploads/medias/experiences/" $hebergement->getId() . "/"$file->getClientOriginalName());
  168.             }
  169.             $experience->addHebergement($hebergement);
  170.             if ($request->files->get('medias')) {
  171.                 $i 0;
  172.                 foreach ($request->files->get('medias') as $file) {
  173.                     $media = new Media();
  174.                     $media->setPath("uploads/medias/experiences/rooms" $experience->getId() . "/" $file->getClientOriginalName());
  175.                     $media->setOrdre('1');
  176.                     $media->setEnabled('1');
  177.                     $file->move("uploads/medias/experiences/rooms" $experience->getId() . "/"$file->getClientOriginalName());
  178.                     $em->persist($media);
  179.                     $hebergement->addMedia($media);
  180.                     $i++;
  181.                 }
  182.                 $experience->setSteps('5');
  183.                 $em->persist($experience);
  184.                 $em->flush();
  185.             }
  186.             $this->addFlash('success''Description enregistrées avec succes, continuer a remplir les informations restantes');
  187.             return $this->redirectToRoute('list_countries', [
  188.                         'country' => $request->get('country'),
  189.                         'category' => $request->get('category'),
  190.             ]);
  191.         }
  192.         return $this->render('admin/experience/add/addHebergement.html.twig', [
  193.                     'experience' => $experience,
  194.         ]);
  195.     }
  196.     #[Route('/exp-{id}/add-media'methods: ['GET''POST'], name'add_media')]
  197.     public function addMedia(Request $request$idManagerRegistry $doctrine) {
  198.         $em $doctrine->getManager();
  199.         $experience $em->getRepository(Experience::class)->find($id);
  200.         if ($request->isMethod('post')) {
  201.             if ($request->files->get('image')) {
  202.                 $file $request->files->get('image');
  203.                 $experience->setImage("uploads/medias/experiences/" $experience->getId() . "/" $file->getClientOriginalName());
  204.                 $file->move("uploads/medias/experiences/" $experience->getId() . "/"$file->getClientOriginalName());
  205.             }
  206.             if ($request->files->get('medias')) {
  207.                 $i 0;
  208.                 foreach ($request->files->get('medias') as $file) {
  209.                     $media = new Media();
  210.                     $media->setPath("uploads/medias/experiences/" $experience->getId() . "/" $file->getClientOriginalName());
  211.                     $media->setOrdre('1');
  212.                     $media->setEnabled('1');
  213.                     $file->move("uploads/medias/experiences/" $experience->getId() . "/"$file->getClientOriginalName());
  214.                     $em->persist($media);
  215.                     $experience->addMedia($media);
  216.                     $i++;
  217.                 }
  218.                 $experience->setSteps('1');
  219.                 $em->persist($experience);
  220.                 $em->flush();
  221.             }
  222.             $this->addFlash('success''Média enregistrées avec succes, continuer a remplir les informations restantes');
  223.             return $this->redirectToRoute('list_countries', [
  224.             ]);
  225.         }
  226.         return $this->render('admin/experience/add/addMedia.html.twig', [
  227.                     'experience' => $experience,
  228.         ]);
  229.     }
  230.     #[Route('/exp-{id}/add-price'methods: ['GET''POST'], name'add_price')]
  231.     public function addPrice(Request $request$idManagerRegistry $doctrine) {
  232.         $em $doctrine->getManager();
  233.         $experience $em->getRepository(Experience::class)->find($id);
  234.         if ($request->isMethod('post')) {
  235.             if ($request->get('onpromo') == "on") {
  236.                 $experience->setOnpromo(1);
  237.                 $promotion = new Promotion();
  238.                 $promotion->setPercent($request->get('percent'));
  239.                 $promotion->setDateend(new \DateTime($request->get('dateend')));
  240.                 $promotion->setDatestart(new \DateTime($request->get('datestart')));
  241.                 $em->persist($promotion);
  242.                 $experience->setPromotion($promotion);
  243.                 $em->persist($experience);
  244.             }
  245.             if ($request->get('hashebergement') == "on") {
  246.                 $experience->setHashebergement(1);
  247.                 $i 0;
  248.                 foreach ($request->get('idhebergements') as $c) {
  249.                     $hebergement $em->getRepository(Hebergement::class)->find($request->get('idhebergements')[$i]);
  250.                     $hebergement->setPrice($request->get('pricehebergements')[$i]);
  251.                     $em->persist($hebergement);
  252.                     $em->flush();
  253.                     $i++;
  254.                 }
  255.             }
  256.             $experience->setCancellation($request->get('cancellation'));
  257.             $experience->setCurrency($request->get('currency'));
  258.             $experience->setPrice($request->get('price'));
  259.             $em->persist($experience);
  260.             $em->flush();
  261.             $this->addFlash('success''Prix enregistrées avec succes, continuer a remplir les informations restantes');
  262.             return $this->redirectToRoute('list_countries', [
  263.             ]);
  264.         }
  265.         return $this->render('admin/experience/add/addPrice.html.twig', [
  266.                     'experience' => $experience,
  267.         ]);
  268.     }
  269.     #[Route('/exp-{id}/add-availability'methods: ['GET''POST'], name'add_availability')]
  270.     public function addAvailability(Request $request$idManagerRegistry $doctrine) {
  271.         $em $doctrine->getManager();
  272.         $experience $em->getRepository(Experience::class)->find($id);
  273.         if ($request->isMethod('post')) {
  274.             $availability = new Availability();
  275.             $availability->setDuration($request->get('duration'));
  276.             $availability->setAvailabilitytype($request->get('availabilitytype'));
  277. //            avalabilty = 1  - unavalibility = 2
  278.             $availability->setDaysbefore($request->get('daysbefore'));
  279.             $availability->setDatesstart($request->get('availabilities'));
  280.             $availability->setUnavailabilities($request->get('unavailabilities'));
  281.             $em->persist($availability);
  282.             $experience->setAvailability($availability);
  283.             $em->persist($experience);
  284.             $em->flush();
  285.             $this->addFlash('success''Disponibilité enregistrées avec succes, continuer a remplir les informations restantes');
  286.             return $this->redirectToRoute('list_countries', [
  287.             ]);
  288.         }
  289.         return $this->render('admin/experience/add/addAvailability.html.twig', [
  290.                     'experience' => $experience,
  291.         ]);
  292.     }
  293.     #[Route('/exp-{id}/overview'methods: ['GET''POST'], name'exp_overview')]
  294.     public function overview($idManagerRegistry $doctrine) {
  295.         $em $doctrine->getManager();
  296.         $experience $em->getRepository(Experience::class)->find($id);
  297.         return $this->render('admin/experience/overview.html.twig', [
  298.                     'experience' => $experience,
  299.         ]);
  300.     }
  301. }