src/Controller/PagesController.php line 101

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Centers;
  4. use App\Entity\Horaire;
  5. use App\Entity\Image;
  6. use App\Entity\Videos;
  7. use Knp\Component\Pager\PaginatorInterface;
  8. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  9. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  10. use Symfony\Component\HttpFoundation\Cookie;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. class PagesController extends AbstractController
  16. {
  17.    /**
  18.     * @Route("/informations-legales", name="mentions_legales")
  19.     */
  20.    public function renderMentions(): Response
  21.    {
  22.       $this->setTemplateParameters(array('title_seo' => 'Mentions légales'));
  23.       return $this->renderTemplate('pages/mentionslegales.twig');
  24.    }
  25.    /**
  26.     * @Route("/plan-du-site", name="plan_du_site")
  27.     */
  28.    public function renderPlanDuSite(): Response
  29.    {
  30.       $this->setTemplateParameters(array('title_seo' => 'Plan du site'));
  31.       return $this->renderTemplate('pages/plandusite.twig');
  32.    }
  33.    /**
  34.      * @Route("/plan-du-site/page/{page}", name="redirect_page_sitemap")
  35.      */
  36.     public function redirectPage($pagenull) {
  37.       if($page) {
  38.           $url $this->router->generate(
  39.               'plan_du_site'
  40.           );            
  41.       }
  42.       return $this->redirect($url301);
  43.   }
  44.   /**
  45.    * @Route("/clean-images", name="clean_images")
  46.    */
  47.   public function cleanImages() {
  48.     $images $this->getDoctrine()->getRepository(Image::class)->findBy(array(
  49.       'cover' => 1
  50.     ));
  51.     $em $this->getDoctrine()->getManager();
  52.     foreach ($images as $image) {
  53.       $file $this->dataProvider->getBoUrl()."images/".$image->getId()."-mini.jpg";
  54.       if (!@fopen($file"r")) {
  55.         $em->remove($image);
  56.         $em->flush();
  57.       }
  58.       /*if (!@fopen($file, "r")) {
  59.         $em->remove($image);
  60.         $em->flush();
  61.       }*/
  62.     }
  63.     return new Response("Mission accomplished :)");
  64.   }
  65.   /**
  66.    * @Route("/clean-videos", name="clean_videos")
  67.    */
  68.   public function cleanVideos() {
  69.     $videos $this->getDoctrine()->getRepository(Videos::class)->findAllWhereVideoFieldIsNotEmpty();
  70.     $em $this->getDoctrine()->getManager();
  71.     foreach ($videos as $video) {
  72.       if ($video->getVideo()) {
  73.         $file $this->dataProvider->getBoUrl()."/uploads/video/".$video->getVideo();
  74.         $code get_headers($file);
  75.         if (strpos($code[0], '404') != false) {
  76.           $video->setVideo("");
  77.           $em->persist($video);
  78.           $em->flush();
  79.         }
  80.         /*if (!@fopen($file, "r")) {
  81.           $em->remove($image);
  82.           $em->flush();
  83.         }*/
  84.       }
  85.     }
  86.     return new Response("Mission accomplished :)");
  87.   }
  88.   /**
  89.     * @Route("/robots.txt", name="robots")
  90.     */
  91.   public function renderRobotsTxtFileContent(): Response
  92.   {
  93.     $publicResourcesFolderPath $this->get('kernel')->getRootDir() . '/../robots.txt';
  94.     return new BinaryFileResponse($publicResourcesFolderPath);
  95.   }
  96.   /**
  97.     * @Route("/accept-cookie", name="accept_cookie")
  98.     */
  99.   public function acceptCookie(Request $request): Response
  100.   {
  101.     if ($request->request->get('accept')) {
  102.       $this->get('session')->set('accept-cookie''1');
  103.       return new JsonResponse(array("result" => "success"));
  104.     }
  105.     return new JsonResponse(array("result" => "fail"));
  106.   }
  107.   /**
  108.     * @Route("/verif-cookie", name="verif_cookie")
  109.     */
  110.   public function verifCookie(Request $request): Response
  111.   {
  112.       $response = new Response();
  113.       $cookie $request->cookies->get('aa_cookie');
  114.       if ($cookie == "1") {
  115.         return new JsonResponse(array("result" => "success"));
  116.       } else {
  117.         return new JsonResponse(array("result" => "fail"));
  118.       }
  119.   }
  120.   /**
  121.     * @Route("/update-horaires", name="update_horaires")
  122.     */
  123.   public function updateHoraires(): Response
  124.   {
  125.     $em $this->getDoctrine()->getManager();
  126.     $row 0;
  127.     if (($handle fopen("centers.csv""r")) !== FALSE) {
  128.         while (($data fgetcsv($handle1000",")) !== FALSE) {
  129.           if ($row 0) {
  130.             $horaire explode(';'$data[0]);
  131.             $id_centre $horaire[0];
  132.             $entite $horaire[1];
  133.             $monday_open $horaire[2];
  134.             $tuesday_open $horaire[3];
  135.             $wednesday_open $horaire[4];
  136.             $thursday_open $horaire[5];
  137.             $friday_open $horaire[6];
  138.             $saturday_open $horaire[7];
  139.             $monday_morning_startTime = ($horaire[8]) ? $horaire[8] : '00:00:00';
  140.             $monday_morning_endTime = ($horaire[9]) ? $horaire[9] : '00:00:00';
  141.             $monday_afternoon_startTime = ($horaire[10]) ? $horaire[10] : '00:00:00';
  142.             $monday_afternoon_endTime = ($horaire[11]) ? $horaire[11] : '00:00:00';
  143.             $tuesday_morning_startTime = ($horaire[12]) ? $horaire[12] : '00:00:00';
  144.             $tuesday_morning_endTime = ($horaire[13]) ? $horaire[13] : '00:00:00';
  145.             $tuesday_afternoon_startTime = ($horaire[14]) ? $horaire[14] : '00:00:00';
  146.             $tuesday_afternoon_endTime = ($horaire[15]) ? $horaire[15] : '00:00:00';
  147.             $wednesday_morning_startTime = ($horaire[16]) ? $horaire[16] : '00:00:00';
  148.             $wednesday_morning_endTime = ($horaire[17]) ? $horaire[17] : '00:00:00';
  149.             $wednesday_afternoon_startTime = ($horaire[18]) ? $horaire[18] : '00:00:00';
  150.             $wednesday_afternoon_endTime = ($horaire[19]) ? $horaire[19] : '00:00:00';
  151.             $thursday_morning_startTime = ($horaire[20]) ? $horaire[20] : '00:00:00';
  152.             $thursday_morning_endTime = ($horaire[21]) ? $horaire[21] : '00:00:00';
  153.             $thursday_afternoon_startTime = ($horaire[22]) ? $horaire[22] : '00:00:00';
  154.             $thursday_afternoon_endTime = ($horaire[23]) ? $horaire[23] : '00:00:00';
  155.             $friday_morning_startTime = ($horaire[24]) ? $horaire[24] : '00:00:00';
  156.             $friday_morning_endTime = ($horaire[25]) ? $horaire[25] : '00:00:00';
  157.             $friday_afternoon_startTime = ($horaire[26]) ? $horaire[26] : '00:00:00';
  158.             $friday_afternoon_endTime = ($horaire[27]) ? $horaire[27] : '00:00:00';
  159.             $saturday_morning_startTime = ($horaire[28]) ? $horaire[28] : '00:00:00';
  160.             $saturday_morning_endTime = ($horaire[29]) ? $horaire[29] : '00:00:00';
  161.             $saturday_afternoon_startTime = ($horaire[30]) ? $horaire[30] : '00:00:00';
  162.             $saturday_afternoon_endTime = ($horaire[31]) ? $horaire[31] : '00:00:00';
  163.             if ($id_centre)
  164.             {
  165.                 $horaire = new Horaire();
  166.                 $horaire->setEntite('centre_audio');
  167.                 $horaire->setMondayOpen($monday_open);
  168.                 $horaire->setTuesdayOpen($tuesday_open);
  169.                 $horaire->setWednesdayOpen($wednesday_open);
  170.                 $horaire->setThursdayOpen($thursday_open);
  171.                 $horaire->setFridayOpen($friday_open);
  172.                 $horaire->setSaturdayOpen($saturday_open);
  173.                 $horaire->setMondayMorningStarttime(new \DateTime($monday_morning_startTime));
  174.                 $horaire->setMondayMorningEndtime(new \DateTime($monday_morning_endTime));
  175.                 $horaire->setMondayAfternoonStarttime(new \DateTime($monday_afternoon_startTime));
  176.                 $horaire->setMondayAfternoonEndtime(new \DateTime($monday_afternoon_endTime));
  177.                 $horaire->setTuesdayMorningStarttime(new \DateTime($tuesday_morning_startTime));
  178.                 $horaire->setTuesdayMorningEndtime(new \DateTime($tuesday_morning_endTime));
  179.                 $horaire->setTuesdayAfternoonStarttime(new \DateTime($tuesday_afternoon_startTime));
  180.                 $horaire->setTuesdayAfternoonEndtime(new \DateTime($tuesday_afternoon_endTime));
  181.                 $horaire->setWednesdayMorningStarttime(new \DateTime($wednesday_morning_startTime));
  182.                 $horaire->setWednesdayMorningEndtime(new \DateTime($wednesday_morning_endTime));
  183.                 $horaire->setWednesdayAfternoonStarttime(new \DateTime($wednesday_afternoon_startTime));
  184.                 $horaire->setWednesdayAfternoonEndtime(new \DateTime($wednesday_afternoon_endTime));
  185.                 $horaire->setThursdayMorningStarttime(new \DateTime($thursday_morning_startTime));
  186.                 $horaire->setThursdayMorningEndtime(new \DateTime($thursday_afternoon_endTime));
  187.                 $horaire->setThursdayAfternoonStarttime(new \DateTime($thursday_afternoon_startTime));
  188.                 $horaire->setThursdayAfternoonEndtime(new \DateTime($thursday_afternoon_endTime));
  189.                 $horaire->setFridayMorningStarttime(new \DateTime($friday_morning_startTime));
  190.                 $horaire->setFridayMorningEndtime(new \DateTime($friday_morning_endTime));
  191.                 $horaire->setFridayAfternoonStarttime(new \DateTime($friday_afternoon_startTime));
  192.                 $horaire->setFridayAfternoonEndtime(new \DateTime($friday_afternoon_endTime));
  193.                 $horaire->setSaturdayMorningStarttime(new \DateTime($saturday_morning_startTime));
  194.                 $horaire->setSaturdayMorningEndtime(new \DateTime($saturday_morning_endTime));
  195.                 $horaire->setSaturdayAfternoonStarttime(new \DateTime($saturday_afternoon_startTime));
  196.                 $horaire->setSaturdayAfternoonEndtime(new \DateTime($saturday_afternoon_endTime));
  197.                 $em->persist($horaire);
  198.                 $em->flush();
  199.                 $center $this->getDoctrine()->getRepository(Centers::class)->findOneBy(['id' => $id_centre'visible' => 1]);
  200.                 if ($center) {
  201.                   $center->setHoraireId($horaire->getId());
  202.                   $em->flush();
  203.                 }
  204.             }
  205.           }
  206.           $row++;
  207.         }
  208.         fclose($handle);
  209.     }
  210.     return new Response("Mission accomplished :)");
  211.   }
  212. }