src/Controller/Front/MasjidController.php line 47

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\Comment;
  4. use App\Entity\Masjid;
  5. use Knp\Component\Pager\PaginatorInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. /**
  11.  * @Route({"en" : "/masjid","fr" : "/Mosquees", "ar" : "/مساجد"})
  12.  */
  13. class MasjidController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("/", name="masjid_index", methods={"GET"})
  17.      */
  18.     public function index(Request $requestPaginatorInterface $paginator): Response
  19.     {
  20.         $masjidsAll $this->getDoctrine()
  21.             ->getRepository(Masjid::class)
  22.             ->findAll();
  23.         $pagination $paginator->paginate(
  24.                 $masjidsAll/* query NOT result */
  25.                 $request->query->getInt('page'1), /*page number*/
  26.                 10 /*limit per page*/
  27.         );
  28.         return $this->render('masjid/index.html.twig', [
  29.             'masjids' => $pagination,
  30.         ]);
  31.     }
  32.     /**
  33.      * @Route("/{slug}", name="masjid_show", methods={"GET"})
  34.      * @throws \Doctrine\ORM\NonUniqueResultException
  35.      */
  36.     public function show(Request $requestMasjid $masjid,PaginatorInterface $paginator): Response
  37.     {
  38.         $prevMasjid $this->getDoctrine()
  39.             ->getRepository(Masjid::class)
  40.             ->getPreviousMasjid($masjid->getId(),'prev');
  41.         $nextMasjid $this->getDoctrine()
  42.             ->getRepository(Masjid::class)
  43.             ->getPreviousMasjid($masjid->getId(),'next');
  44.         $listcomment $this->getDoctrine()
  45.             ->getRepository(Comment::class)
  46.             ->findBy(array("masjid"=>$masjid"isEnabled" => true));
  47.         $masjidRandom $this->getDoctrine()
  48.             ->getRepository(Masjid::class)
  49.             ->findByMasjidRandom(2);
  50.         //$masjidRandom = array_slice($masjidRandom, 0, 2);
  51.         $pagination $paginator->paginate(
  52.             $listcomment/* query NOT result */
  53.             $request->query->getInt('page'1), /* page number */
  54.             10 /* limit per page */
  55.         );
  56.         return $this->render('masjid/show.html.twig', [
  57.             'masjid' => $masjid,
  58.             'pagination' => $pagination,
  59.             'masjidRandom' => $masjidRandom,
  60.             'masjidPrev' => $prevMasjid,
  61.             'masjidNext' => $nextMasjid,
  62.         ]);
  63.     }
  64.     /**
  65.      * @Route({"en": "/query/search", "fr": "/recherche/mosquee", "ar" : "/query/search"}, name="search", methods={"GET","POST"})
  66.      */
  67.     public function search(Request $request,PaginatorInterface $paginator):Response
  68.     {
  69.         if ($request->isMethod('post')) {
  70.             ///////////gets  searchs/////////////////////
  71.             $term $request->request->get('term');
  72.             $result $this->getDoctrine()
  73.                 ->getRepository(Masjid::class)
  74.                 ->search($term);
  75.             if($result == null){
  76.                 return $this->render('masjid/no-result.html.twig', [
  77.                 ]);
  78.             }
  79.             $pagination $paginator->paginate(
  80.                 $result/* query NOT result */
  81.                 $request->query->getInt('page'1), /* page number */
  82.                 10 /* limit per page */
  83.             );
  84.             return $this->render('masjid/result.html.twig', [
  85.                 'masjids' => $pagination,
  86.             ]);
  87.         }
  88.         return $this->render('masjid/no-result.html.twig', [
  89.         ]);
  90.     }
  91.     /**
  92.      * @Route("/findNearestToClientLocation/{lat}/{lng}", name="findNearestToClientLocation", methods={"POST"})
  93.      */
  94.     public function findNearestToClientLocation(Request $request$lat$lngint $km 1)
  95.     {
  96.             /*** ICI je récupère les mosquées les plus proches des coorfddonnées GPS transmises 
  97.                  puis je limite à 1 dqns lq requete
  98.                  Ensuite cette mosquée je lq récupère en objet  
  99.                  dans une autre requete pour avoir les translations 
  100.                  car setmaxresult DOCTRINE limite aussi les relations***/
  101.             $masjidNearestToClientLocation $this->getDoctrine()
  102.                 ->getRepository(Masjid::class)
  103.                 ->findNearestToClientLocation($lat$lng);
  104.             $masjidId $masjidNearestToClientLocation[0][0]['id'];
  105.             //var_dump($masjidId);
  106.             $masjid $this->getDoctrine()
  107.                 ->getRepository(Masjid::class)
  108.                 ->getMasjidOne($masjidId);
  109.             
  110.             $response = new Response(json_encode($masjid));
  111.              
  112.             $response->headers->set('Content-Type''Application/json');
  113.                 
  114.             return $response;
  115.     }
  116. }