src/Controller/FormationsThematicsController.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\Routing\Annotation\Method;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\Routing\Annotation\Security;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use App\Entity\FormationsThematics;
  11. use App\Form\FormationsThematicsType;
  12. use App\Repository\FormationsThematicsRepository;
  13. use OlaSoft\Common;
  14. use App\Entity\UsersActivities;
  15. /**
  16.  * @Route("/os-admin/formationsthematics", name="formationsthematics-")
  17.  */
  18. class FormationsThematicsController extends AbstractController
  19. {
  20.     /**
  21.      * @Route("/",name="admin")
  22.      */
  23.     public function indexAction()
  24.     {
  25.         $request $this->get('request_stack')->getCurrentRequest();
  26.         $em $this->getDoctrine()->getManager();
  27.         $list $em->getRepository(FormationsThematics::class)->findBy(array(),array('id'=>'DESC'));
  28.         $ajax $request->isXmlHttpRequest();
  29.         $response $this->render('Admin\index.html.twig',[
  30.             'list'=>$list,
  31.             'ajax'=>$ajax,
  32.             'noResearch'=>true,
  33.             "title"=> "Gestion des formations",
  34.             "subtitle"=> "Liste des thématiques",
  35.             "addBtnClass"=>"btn-popup semi"
  36.         ]);
  37.         return $ajax ?
  38.             new Response(\json_encode([
  39.                 'content'=>$response->getContent(),
  40.                 "title"=> "Gestion des formations",
  41.                 "subtitle"=> "Liste des thématiques"
  42.             ]))
  43.         : $response;
  44.     }
  45.     /**
  46.      * @Route("/add", name="new")
  47.      * @Route("/{id}/edit", name="edit")
  48.      */
  49.     public function edit(FormationsThematics $item null)
  50.     {
  51.         if(!$item){
  52.             $item = new FormationsThematics;
  53.         }
  54.         $em $this->getDoctrine()->getManager();
  55.         $request $this->get('request_stack')->getCurrentRequest();
  56.         $form $this->createForm(FormationsThematicsType::class, $item);
  57.         $form->handleRequest($request);
  58.         if ($form->isSubmitted() && $form->isValid()){
  59.             // $item->setSlug(Common::slug($item->getLabel()));
  60.             $em->persist($item);
  61.             $em->flush();
  62.             Common::trackChange(new UsersActivities$em$item$this->getUser(), 'edit'"Édition d'une thématique de formation");
  63.             $this->addFlash("notice","Enregistrement effectué avec succès.");
  64.             return $this->redirectToRoute('formationsthematics-admin');
  65.         }
  66.         $ajax $request->isXmlHttpRequest();
  67.         $response $this->render('Admin\edit.html.twig',[
  68.             'form'=>$form->createView(),
  69.             'ajax'=>$ajax,
  70.             "title"=> "Gestion des formations",
  71.             "subtitle"=>"Edition d'une thématique "
  72.         ]);
  73.         return $ajax ?
  74.             new Response(\json_encode([
  75.                 'content'=>$response->getContent(),
  76.                 "title"=> "Gestion des formations",
  77.                 "subtitle"=>"Edition d'une thématique "
  78.             ]))
  79.         : $response;
  80.      }
  81.     /**
  82.      * @Route("/{id}/enable/", name="enable")
  83.      */
  84.     public function enable(FormationsThematics $item)
  85.     {
  86.         $request $this->get('request_stack')->getCurrentRequest();
  87.         $em $this->getDoctrine()->getManager();
  88.         $item->setIsEnabled(!$item->getIsEnabled());
  89.         $em->persist($item);
  90.         $em->flush();
  91.         Common::trackChange(new UsersActivities$em$item$this->getUser(), 'enable'"Activation/désactivation d'une formation");
  92.         $ajax $request->isXmlHttpRequest();
  93.         if(!$ajax)
  94.             $this->addFlash("notice","Activation / Désactivation effectuée avec succès.");
  95.         return $ajax
  96.             ? new Response(\json_encode(['status'=>$item->getIsEnabled(), 'notice'=>'Activation / Désactivation effectuée avec succès.']))
  97.             : $this->redirectToRoute('formationsthematics-admin');
  98.     }
  99. }