src/Controller/Admin/InformationController.php line 223

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use App\Entity\Information;
  4. use App\Form\Admin\InformationType;
  5. use App\Repository\InformationRepository;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\RedirectResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  14. use Symfony\Component\Routing\RequestContext;
  15. #[Route('/admin/information'name'hs_training_center_information_')]
  16. class InformationController extends AbstractController
  17. {
  18.     public function __construct(
  19.         private readonly InformationRepository $informationRepository,
  20.         private readonly RequestStack $requestStack,
  21.         private readonly UrlGeneratorInterface $urlGenerator,
  22.         private readonly RequestContext $requestContext
  23.     ){
  24.     }
  25.     #[Route('/'name'index'options:['expose'=> 'true'], methods: ['GET'])]
  26.     public function index(): Response
  27.     {
  28.         $items $this->informationRepository->findAll();
  29.         return $this->render('Admin/information/index.html.twig', [
  30.             'items' => $items,
  31.             'genre'=>'info_institute'
  32.         ]);
  33.     }
  34.     #[Route('/new'name'new'options:['expose'=> 'true'], methods: ['GET''POST'])]
  35.     public function new(Request $request): Response
  36.     {
  37.         $items=$this->informationRepository->findAll();
  38.         $information = new Information();
  39.         return $this->getForm($information$request$items);
  40.     }
  41.     #[Route('/{id}'name'show'options:['expose'=> 'true'], methods: ['GET'])]
  42.     public function show(Information $information): Response
  43.     {
  44.         return $this->render('Admin/information/show.html.twig', [
  45.             'information' => $information,
  46.         ]);
  47.     }
  48.     #[Route('/{id}/edit'name'edit'options:['expose'=> 'true'], methods: ['GET''POST'])]
  49.     public function edit(Information $informationRequest $request): Response
  50.     {
  51.         $items=$this->informationRepository->findAll();
  52.         return $this->getForm($information$request$items);
  53.     }
  54.     #[Route('/remove/{id}'name'remove'options: ['expose'=> 'true'])]
  55.     public function delete(Information $information): Response
  56.     {
  57.             $this->informationRepository->remove($informationtrue);
  58.             $this->addFlash('success','Information deleted with success.');
  59.         return $this->redirectToRoute('hs_training_center_information_index', [], Response::HTTP_SEE_OTHER);
  60.     }
  61.     #[Route('/remove_prompt/{ids}'name'remove_prompt'options: ['expose'=> 'true'])]
  62.     public function deletePromptAction($idsRequest $request){
  63.         $items=explode("|",(string) $ids);
  64.         if (empty($items)) {
  65.             $this->addFlash('warning','No items selected !!!! ');
  66.             return $this->redirectToRoute('hs_training_center_information_index');
  67.         }
  68.         $count=0;
  69.         foreach ($items as $item){
  70.             /** @var Information $item */
  71.             $item=$this->informationRepository->find($item);
  72.             if (!empty($item)) {
  73.                 $this->informationRepository->remove($itemtrue);
  74.                 $count++;
  75.             }
  76.         }
  77.         $this->addFlash('success'$count.' items successfully deleted.');
  78.         return $this->redirectToRoute('hs_training_center_information_index');
  79.     }
  80.     #[Route('/statut/{id}'name'statut'options:['expose'=> 'true'])]
  81.     public function statutAction(Information $information)
  82.     {
  83.         if($information->isPublished()) {
  84.             $information->setPublished(false);
  85.         } else {
  86.             $information->setPublished(true);
  87.         }
  88.         $button=$information->getButtonEnable();
  89.         $this->informationRepository->save($informationtrue);
  90.         return new Response($button);
  91.     }
  92.     /**
  93.      * @return RedirectResponse|Response
  94.      */
  95.     public function getForm(Information $informationRequest $request, array $items): Response|RedirectResponse
  96.     {
  97.         $form $this->createForm(InformationType::class, $information);
  98.         $form->handleRequest($request);
  99.         if ($form->isSubmitted() && $form->isValid()) {
  100.             $this->informationRepository->save($informationtrue);
  101.             $this->addFlash('success''Successfully executed operation.');
  102.             if ($form->get('SaveList')->isClicked()) return $this->redirectToRoute('hs_training_center_information_index', [], Response::HTTP_SEE_OTHER);
  103.             if ($form->get('SaveNew')->isClicked()) return $this->redirectToRoute('hs_training_center_information_new', [], Response::HTTP_SEE_OTHER);
  104.             return $this->redirectToRoute('hs_training_center_information_edit', ['id' => $information->getId()], Response::HTTP_SEE_OTHER);
  105.         }
  106.         return $this->renderForm('Admin/information/form.html.twig', [
  107.             'item' => $information,
  108.             'form' => $form,
  109.             'type' => 'New',
  110.             'items' => $items,
  111.             'genre' => 'info_institute'
  112.         ]);
  113.     }
  114.     #[Route('/rest/{groupe}'name'rest'options:['expose'=> 'true'])]
  115.     public function rest(string $groupe){
  116.         $list=[
  117.             'Diplome'=>[
  118.                 'sitting_diplome_auto_num' => "Numéro d'Autorisation",
  119.                 'sitting_diplome_auto_date' => "Date d'Autorisation",
  120.                 'sitting_diplome_acc_num' => "Numéro d'Accréditation",
  121.                 'sitting_diplome_acc_date' => "Date d'Accréditation",
  122.                 'sitting_diplome_pve_date' => "Date du procès verbal",
  123.                 'sitting_assurance_police_num' => "N° POLICE D’ASSURANCE",
  124.                 'sitting_assurance_start_date' => "Date de début",
  125.                 'sitting_assurance_end_date' => "Date de fin",
  126.             ],
  127.             'Assurance'=>[
  128.                 'sitting_assurance_police_num' => "N° POLICE D’ASSURANCE",
  129.                 'sitting_assurance_start_date' => "Date de début",
  130.                 'sitting_assurance_end_date' => "Date de fin",
  131.             ],
  132.             'Informations'=>[
  133.                 'sitting_institute_name' => 'Nom de l’Institut',
  134.                 'sitting_institute_director' => 'Nom du Directeur',
  135.                 'sitting_institute_num_docs' => 'Numéro de document',
  136.             ],
  137.             'Coordonnées'=>[
  138.                 'sitting_institute_phone1' => 'Téléphone 1',
  139.                 'sitting_institute_phone2' => 'Téléphone 2',
  140.                 'sitting_institute_email' => 'E-mail',
  141.                 'sitting_institute_adress' => 'Adresse',
  142.                 'sitting_institute_website' => 'Site Web',
  143.             ],
  144.             'Réseaux sociaux'=>[
  145.                 'sitting_social_link_facebook' => 'Facebook',
  146.                 'sitting_social_link_twitter' => 'Twitter',
  147.                 'sitting_social_link_plus' => 'Google +',
  148.                 'sitting_social_link_instagram' => 'Instagram',
  149.                 'sitting_social_link_youtube' => 'Youtube',
  150.             ],
  151.             'Accueil'=>[
  152.                 'sitting_accueil_01' => 'Soutien',
  153.                 'sitting_accueil_02' => 'Langue',
  154.                 'sitting_accueil_03' => 'Contest'
  155.             ],
  156.         ];
  157.         if ($groupe=='all'){
  158.             foreach ($list as $key1 => $value1){
  159.                 $groupe=$key1;
  160.                 $infos=$value1;
  161.                 foreach ($infos as $key => $value){
  162.                     $information=$this->informationRepository->findOneBy(['slug'=>$key]);
  163.                     if (empty($information)) {
  164.                         $information = new Information();
  165.                         $information->setSlug($key);
  166.                     }
  167.                     $information->setCategory($groupe);
  168.                     $information->setType('Autre');
  169.                     $information->setName($value);
  170.                     $information->setVal('');
  171.                     $this->informationRepository->save($informationtrue);
  172.                 }
  173.             }
  174.         }
  175.         $infos=$list[$groupe]??[];
  176.         foreach ($infos as $key => $value){
  177.             $information=$this->informationRepository->findOneBy(['slug'=>$key]);
  178.             if (empty($information)) {
  179.                 $information = new Information();
  180.                 $information->setCategory($groupe);
  181.                 $information->setType('Autre');
  182.                 $information->setName($value);
  183.                 $information->setSlug($key);
  184.             }
  185.             $information->setVal('');
  186.             $this->informationRepository->save($informationtrue);
  187.         }
  188.         return $this->redirectToRoute('hs_training_center_information_index');
  189.     }
  190.     public function redirectToPreviousRoute()
  191.     {
  192.         $referer $this->requestStack->getMainRequest()->headers->get('referer');
  193.         // Modifiez le contexte de la requête pour générer des URL relatives
  194.         $this->requestContext->fromRequest($this->requestStack->getMainRequest());
  195.         $this->urlGenerator->setContext($this->requestContext);
  196.         // Générez une URL absolue à partir de l'URL de référence
  197.         $url $this->urlGenerator->generate($referer);
  198.         return new RedirectResponse($url);
  199.     }
  200.     public function widgetAction($widget$pole='gestion')
  201.     {
  202.         $infoParms $this->informationRepository->findByCategory('Informations');
  203.         $coorParms $this->informationRepository->findByCategory('Coordonnées');
  204.         $info_soc = [];
  205.         foreach ($infoParms as $parm) {
  206.             $info_soc[$parm->getSlug()] = $parm->getVal();
  207.         }
  208.         foreach ($coorParms as $parm) {
  209.             $info_soc[$parm->getSlug()] = $parm->getVal();
  210.         }
  211.         return $this->render(
  212.             'Admin/Widget/' $widget '.html.twig',
  213.             ['parms' => $info_soc'pole' => $pole]
  214.         );
  215.     }
  216. }