src/Controller/ReunionAvisController.php line 58

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\ReunionAvis;
  4. use App\Entity\Processus;
  5. use App\Entity\User;
  6. use App\Form\ReunionAvisType;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use App\Utils\Utility;
  12. use Symfony\Component\HttpFoundation\JsonResponse;
  13. use Symfony\Component\Validator\Constraints\Json;
  14. use App\Repository\ReunionAvisRepository;
  15. use App\Notification\SendNotification;
  16. use App\Security\ReunionVoter;
  17. /**
  18.  * @Route("/reunion-avis")
  19.  */
  20. class ReunionAvisController extends AbstractController
  21. {
  22.     /**
  23.      * @var SendNotification
  24.      */
  25.     private $notifyOdj;
  26.     private $notifyOdjMeeting;
  27.     public function __construct(SendNotification $notifyOdjSendNotification $notifyOdjMeeting)
  28.     {
  29.         $this->notifyOdj $notifyOdj;
  30.         $this->notifyOdjMeeting $notifyOdjMeeting;
  31.     }
  32.     /**
  33.      * @Route("/", name="reunion_avis_index", methods={"GET"})
  34.      */
  35.     public function index(): Response
  36.     {
  37.         $reunionAvis $this->getDoctrine()
  38.             ->getRepository(ReunionAvis::class)
  39.             ->findAll();
  40.         //menu 
  41.         $menu "processus";
  42.         $left_menu "list_reunions_avis";
  43.         return $this->render('reunion_avis/index.html.twig', [
  44.             'reunion_avis' => $reunionAvis,
  45.             'menu' => $menu,
  46.             'left_menu' => $left_menu,
  47.         ]);
  48.     }
  49.     /**
  50.      * @Route("/listODJ", name="odj_list", methods={"GET"})
  51.      */
  52.     public function list(Request $requestReunionAvisRepository $reunionAvisRepository)
  53.     {
  54.         $odjData $reunionAvisRepository->transformAll();
  55.         return new JsonResponse($odjData);
  56.     }
  57.     /**
  58.      * @Route("/new", name="reunion_avis_new", methods={"GET","POST"})
  59.      */
  60.     public function new(Request $request): Response
  61.     {
  62.         $this->denyAccessUnlessGranted(ReunionVoter::REUNION_CRUD);
  63.         $reunionAvi = new ReunionAvis();
  64.         $user $this->getUser();
  65.         /* genretate ref */
  66.         $lastId 0;
  67.         $lastreunionAvi $this->getDoctrine()->getRepository(ReunionAvis::class)->findOneBy([], ['id' => 'desc']);
  68.         if (is_object($lastreunionAvi)) {
  69.             $lastId $lastreunionAvi->getId();
  70.         }
  71.         $utility = new Utility;
  72.         $ref $utility->generateRef($lastIdReunionAvis::PREFIX);
  73.         $reunionAvi->setRef($ref);
  74.         /* end genretate ref*/
  75.         $reunionAvi->setCreatedBy($user);
  76.         $form $this->createForm(ReunionAvisType::class, $reunionAvi);
  77.         $form->handleRequest($request);
  78.         if ($form->isSubmitted()) {
  79.             $reunionAvi->setCreatedAt(new \DateTime('now'));
  80.             $entityManager $this->getDoctrine()->getManager();
  81.             $entityManager->persist($reunionAvi);
  82.             $date $reunionAvi->getDatePlanification();
  83.             $datePlanification date_format($date'd-m-Y');
  84.             $Hour $reunionAvi->getHourPlanification();
  85.             $hourPlanification date_format($Hour'H:i');
  86.             foreach ($reunionAvi->getInvited() as $invited) {
  87.                 $this->notifyOdj->notifyOdj(
  88.                     $reunionAvi->getCreatedBy()->getEmail(),
  89.                     $invited->getEmail(),
  90.                     $reunionAvi->getRef(),
  91.                     $datePlanification,
  92.                     $hourPlanification
  93.                 );
  94.             }
  95.             $entityManager->flush();
  96.             return $this->redirectToRoute('reunion_avis_index');
  97.         }
  98.         //menu 
  99.         $menu "processus";
  100.         $left_menu "new_odj";
  101.         return $this->render('reunion_avis/new.html.twig', [
  102.             'reunion_avi' => $reunionAvi,
  103.             'form' => $form->createView(),
  104.             'menu' => $menu,
  105.             'left_menu' => $left_menu
  106.         ]);
  107.     }
  108.     /**
  109.      * @Route("/{id}", name="reunion_avis_show", methods={"GET"})
  110.      */
  111.     public function show(ReunionAvis $reunionAvi): Response
  112.     {
  113.         return $this->render('reunion_avis/show.html.twig', [
  114.             'reunion_avi' => $reunionAvi,
  115.         ]);
  116.     }
  117.     /**
  118.      * @Route("/{id}/edit", name="reunion_avis_edit", methods={"GET","POST"})
  119.      */
  120.     public function edit(Request $requestReunionAvis $reunionAvi): Response
  121.     {
  122.         $oldDate $reunionAvi->getDatePlanification();
  123.         $nbrReport $reunionAvi->getnbrReport();
  124.         $form $this->createForm(ReunionAvisType::class, $reunionAvi);
  125.         $form->handleRequest($request);
  126.         if ($form->isSubmitted() && $form->isValid()) {
  127.             $this->denyAccessUnlessGranted(ReunionVoter::REUNION_CRUD);
  128.             if (!empty($reunionAvi->getLastDatePlanification())) {
  129.                 $newDate $reunionAvi->getLastDatePlanification();
  130.                 if ($newDate !== $oldDate) {
  131.                     $reunionAvi->setNbrReport($nbrReport 1);
  132.                 }
  133.             }
  134.             $this->getDoctrine()->getManager()->flush();
  135.             return $this->redirectToRoute('reunion_avis_index');
  136.         }
  137.         //menu 
  138.         $menu "processus";
  139.         $left_menu "list_reunions";
  140.         return $this->render('reunion_avis/edit.html.twig', [
  141.             'reunion_avi' => $reunionAvi,
  142.             'form' => $form->createView(),
  143.             'menu' => $menu,
  144.             'left_menu' => $left_menu
  145.         ]);
  146.     }
  147.     /**
  148.      * @Route("/delete/{id}", name="reunion_avis_delete", methods={"GET"})
  149.      */
  150.     public function delete(Request $requestReunionAvis $reunionAvi): Response
  151.     {
  152.         $this->denyAccessUnlessGranted(ReunionVoter::REUNION_CRUD);
  153.         //if ($this->isCsrfTokenValid('delete'.$reunionAvi->getId(), $request->request->get('_token'))) {
  154.         $entityManager $this->getDoctrine()->getManager();
  155.         $entityManager->remove($reunionAvi);
  156.         $entityManager->flush();
  157.         //}
  158.         return $this->redirectToRoute('reunion_avis_index');
  159.     }
  160.     /**
  161.      * @Route("/loadODJ", name="loadODJ", methods={"POST"})
  162.      */
  163.     public function loadODJ(Request $request)
  164.     {
  165.         $id $request->request->get('id');
  166.         $em $this->getDoctrine()->getManager();
  167.         $reunionAvi $em->getRepository(ReunionAvis::class)->find($id);
  168.         $title $reunionAvi->getReunionTitle()->getTitle(); // $reunionAvi->getReunionTitle()->getTitle();
  169.         $reunionTitle_id $reunionAvi->getReunionTitle()->getId();
  170.         $processus $reunionAvi->getProcessus();
  171.         $processusList = array();
  172.         foreach ($processus as $key => $proc) {
  173.             $processusList[$key]['id'] = $proc->getId();
  174.             $processusList[$key]['title'] = $proc->getTitle();
  175.         }
  176.         $datePlanification $reunionAvi->getDatePlanification(true);
  177.         $lastDatePlanification $reunionAvi->getLastDatePlanification(true);
  178.         $hourPlanification $reunionAvi->getHourPlanification(true);
  179.         $theme $reunionAvi->getTheme();
  180.         $animateur $reunionAvi->getAnimateur()->getId();
  181.         $invited $reunionAvi->getInvited();
  182.         $duration $reunionAvi->getDuration();
  183.         $invitedList = array();
  184.         foreach ($invited as $key => $inv) {
  185.             $invitedList[$key]['id'] = $inv->getId();
  186.             $invitedList[$key]['name'] = $inv->getFullName();
  187.         }
  188.         $data = [
  189.             'title' => $title,
  190.             'processusList' => $processusList,
  191.             'datePlanification' => $datePlanification,
  192.             'lastDatePlanification' => $lastDatePlanification,
  193.             'hourPlanification' => $hourPlanification,
  194.             'theme' => $theme,
  195.             'animateur' => $animateur,
  196.             'invited' => $invitedList,
  197.             'duration' => $duration,
  198.             'reunionTitle_id' => $reunionTitle_id
  199.         ];
  200.         return new JsonResponse($data200);
  201.     }
  202. }