src/Controller/admin/ExperienceController.php line 71

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\Experience;
  26. /**
  27.  * Controller used to manage current user.
  28.  *
  29.  * @author Romain Monteil <monteil.romain@gmail.com>
  30.  */
  31. #[Route('/admin/experience')]
  32. class ExperienceController extends AbstractController {
  33.     #[Route('/general-info'methods: ['GET''POST'], name'add_general_info')]
  34.     public function addGeneralinfo(Request $requestManagerRegistry $doctrine) {
  35.         $em $doctrine->getManager();
  36.         $countries $em->getRepository(Country::class)->findAll();
  37.         $categories $em->getRepository(Category::class)->findAll();
  38.         if ($request->isMethod('post')) {
  39.             $experience = new Experience();
  40.             $experience->setTitle($request->get('title'));
  41.             $experience->setResume($request->get('resume'));
  42.             $experience->setPublished(0);
  43.             $experience->setEnabled(1);
  44.             $experience->setCoachingtype($request->get('coachingtype'));
  45.             $em->persist($experience);
  46.             $em->flush();
  47.             $em->persist($experience);
  48.             $em->flush();
  49.             $this->addFlash('success''Informations générale enregistrées avec succes, continuer a remplir les informations suivantes');
  50.             return $this->redirectToRoute('add_highlights', [
  51.                         'country' => $request->get('country'),
  52.                         'category' => $request->get('category'),
  53.                         'id' => $experience->getId(),
  54.             ]);
  55.         }
  56.         return $this->render('admin/experience/addGeneralinfo.html.twig', [
  57.                     'countries' => $countries,
  58.                     'categories' => $categories,
  59.         ]);
  60.     }
  61.     #[Route('/exp-{id}/add-highlights'methods: ['GET''POST'], name'add_highlights')]
  62.     public function addHighlights(Request $request$idManagerRegistry $doctrine) {
  63.         $em $doctrine->getManager();
  64.         $experience $em->getRepository(Experience::class)->find($id);
  65.         if ($request->get('category')) {
  66.             $category $em->getRepository(Category::class)->find($request->get('category'));
  67.             $country $em->getRepository(Country::class)->find($request->get('country'));
  68.         } else {
  69.             $subcategory $em->getRepository(Subcategory::class)->find($request->get('subcategory'));
  70.             $category $subcategory->getCategory();
  71.         }
  72.         if ($request->isMethod('post')) {
  73.             $experience->setHighlights($request->get('highlights'));
  74.             $destination $em->getRepository(Destination::class)->find($request->get('destination'));
  75.             if (!$destination) {
  76.                 $destination = new Destination();
  77.                 $destination->setName($request->get('destination'));
  78.                 $em->persist($destination);
  79.                 $em->flush();
  80.                 $country->addDestination($destination);
  81.                 $em->persist($country);
  82.             }
  83.             $destination->addExperience($experience);
  84.             $subcategory->addExperience($experience);
  85.             $em->persist($subcategory);
  86.             $em->persist($experience);
  87.             $em->flush();
  88.             $this->addFlash('success''Les grandes lignes enregistrées avec succes, continuer a remplir les informations suivantes');
  89.             return $this->redirectToRoute('add_program', [
  90.                         'id' => $experience->getId(),
  91.             ]);
  92.         }
  93.         return $this->render('admin/experience/addHighlights.html.twig', [
  94.                     'experience' => $experience,
  95.                     'country' => $country,
  96.                     'category' => $category,
  97.         ]);
  98.     }
  99.     #[Route('/exp-{id}/add-program'methods: ['GET''POST'], name'add_program')]
  100.     public function addProgram(Request $request$idManagerRegistry $doctrine) {
  101.         $em $doctrine->getManager();
  102.         $experience $em->getRepository(Experience::class)->find($id);
  103.         if ($request->isMethod('post')) {
  104.             $i 0;
  105.             foreach ($request->get('days') as $p) {
  106.                 $program = new Program();
  107.                 $program->setDay($request->get('days')[$i]);
  108.                 $program->setDescription($request->get('descriptions')[$i]);
  109.                 $em->persist($program);
  110.                 $em->flush();
  111.                 $experience->addProgram($program);
  112.                 $i++;
  113.             }
  114.             $em->persist($experience);
  115.             $em->flush();
  116.             $this->addFlash('success''Programme enregistrées avec succes, continuer a remplir les informations suivantes');
  117.             return $this->redirectToRoute('list_countries', [
  118.                         'country' => $request->get('country'),
  119.                         'category' => $request->get('category'),
  120.             ]);
  121.         }
  122.         return $this->render('admin/experience/addProgram.html.twig', [
  123.                     'experience' => $experience,
  124.         ]);
  125.     }
  126. }