<?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\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'));
$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/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);
$subcategory->addExperience($experience);
$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/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++;
}
$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/addProgram.html.twig', [
'experience' => $experience,
]);
}
}