src/Controller/Front/MainController.php line 190

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\Picture;
  4. use App\Entity\User;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use App\Entity\Masjid;
  10. use App\Entity\Community;
  11. use Stripe\Stripe;
  12. use Stripe\Checkout;
  13. use Stripe\PaymentIntent;
  14. use Symfony\Component\HttpFoundation\JsonResponse;
  15. use App\Form\DonateType;
  16. use Symfony\Component\Validator\Validation;
  17. use Symfony\Component\Form\FormInterface;
  18. class MainController extends AbstractController
  19. {
  20.     /**
  21.     * @Route("/")
  22.     */
  23.     public function index(): Response
  24.     {
  25.         /*$masjidRandom = $this->getDoctrine()
  26.             ->getRepository(Masjid::class)
  27.             ->findByMasjidRandom();*/
  28.         return $this->render('Main/index.html.twig', [
  29.         ]);
  30.     }
  31.     public function header(Request $request)
  32.     {
  33.          
  34.       
  35.         $masterRequest $this->container->get('request_stack')->getMasterRequest();
  36.         
  37.         $ip $_SERVER['REMOTE_ADDR'];
  38.         /*var_dump($ip);die;
  39.         $json = file_get_contents("http://ipinfo.io/".$ip."/geo?token=bf523ea023e9c0");
  40.         $json     = json_decode($json, true);
  41.         $country  = $json['country'];
  42.         //This variable is the visitor's region
  43.         $region   = $json['region'];
  44.         //This variable is the visitor's city
  45.         $city     = $json['city'];*/
  46.          // Valeurs par défaut en cas d'erreur
  47.         $json = [];
  48.         $country 'AE'// UAE par défaut
  49.         $region '';
  50.         $city '';
  51.         
  52.         try {
  53.             // Tentative d'appel à l'API ipinfo.io
  54.             $context stream_context_create([
  55.                 'http' => [
  56.                     'timeout' => 2// Timeout de 2 secondes
  57.                     'ignore_errors' => true
  58.                 ]
  59.             ]);
  60.             
  61.             $response = @file_get_contents("http://ipinfo.io/".$ip."/geo?token=bf523ea023e9c0"false$context);
  62.             
  63.             if ($response !== false) {
  64.                 $json json_decode($responsetrue);
  65.                 if ($json && isset($json['country'])) {
  66.                     $country $json['country'];
  67.                     $region $json['region'] ?? '';
  68.                     $city $json['city'] ?? '';
  69.                 }
  70.             }
  71.         } catch (\Exception $e) {
  72.             // En cas d'erreur, on utilise les valeurs par défaut
  73.             // L'erreur est silencieuse pour ne pas casser le site
  74.         }
  75.         return $this->render('Main/header.html.twig', [
  76.             'ip'           => $ip,
  77.             'json'         => $json,
  78.             'country'      => $country,
  79.             'region'       => $region,
  80.             'city'         => $city,
  81.             'route'        => $masterRequest->attributes->get('_route'),
  82.             'route_params' => $masterRequest->attributes->get('_route_params'),
  83.         ]);
  84.     }
  85.     /**
  86.     * @Route("/about-us")
  87.     */
  88.     public function about(): Response
  89.     {
  90.         $countMasjid $this->getDoctrine()
  91.             ->getRepository(Masjid::class)
  92.             ->countEntity();
  93.         $countUser $this->getDoctrine()
  94.             ->getRepository(User::class)
  95.             ->countEntity();
  96.         $countPictures $this->getDoctrine()
  97.             ->getRepository(Picture::class)
  98.             ->countEntity();
  99.         $masjidRandom $this->getDoctrine()
  100.             ->getRepository(Masjid::class)
  101.             ->findByMasjidRandom(5);
  102.         return $this->render('Main/about.html.twig', [
  103.             'masjidRandom' => $masjidRandom,
  104.             'countMasjid' => $countMasjid,
  105.             'countUser' => $countUser,
  106.             'countPictures' => $countPictures,
  107.         ]);
  108.     }
  109.     public function aboutFragment(): Response
  110.     {
  111.         $countMasjid $this->getDoctrine()
  112.             ->getRepository(Masjid::class)
  113.             ->countEntity();
  114.         $countUser $this->getDoctrine()
  115.             ->getRepository(User::class)
  116.             ->countEntity();
  117.         $countPictures $this->getDoctrine()
  118.             ->getRepository(Picture::class)
  119.             ->countEntity();
  120.         return $this->render('Main/_about-us.html.twig', [
  121.             'countMasjid' => $countMasjid,
  122.             'countUser' => $countUser,
  123.             'countPictures' => $countPictures,
  124.         ]);
  125.     }
  126.     public function sidebar($masjidId): Response
  127.     {
  128.         $masjid $this->getDoctrine()
  129.             ->getRepository(Masjid::class)
  130.             ->find($masjidId);
  131.         $currentRoute $this->container->get('request_stack')->getMasterRequest()->get('_route');
  132.         $nearestMasjid $this->getDoctrine()
  133.             ->getRepository(Masjid::class)
  134.             ->nearestMasjids($masjid->getLatitude(),$masjid->getLongitude());
  135.         $randomCommunities $this->getDoctrine()
  136.             ->getRepository(Community::class)
  137.             ->randomCommunities();
  138.         $masjidsSameCommunity $this->getDoctrine()
  139.             ->getRepository(Masjid::class)
  140.             ->masjidsSameCommunity($masjid->getCommunity());
  141.         $randomCommunities array_slice($randomCommunities010);
  142.         return $this->render('Main/sidebar.html.twig', [
  143.             'nearestMasjid' => $nearestMasjid,
  144.             'randomCommunities' => $randomCommunities,
  145.             'masjidsSameCommunity' => $masjidsSameCommunity,
  146.             'masjidId' =>$masjidId,
  147.             'masjid' =>$masjid,
  148.             'currentRoute' =>$currentRoute
  149.         ]);
  150.     }
  151.     public function footer(): Response
  152.     {
  153.         $randomMasjids $this->getDoctrine()
  154.             ->getRepository(Masjid::class)
  155.             ->randomMasjids();
  156.         $randomMasjids array_slice($randomMasjids03);
  157.         return $this->render('Main/footer.html.twig', [
  158.             'randomMasjids' => $randomMasjids,
  159.         ]);
  160.     }
  161.     public function newsletter(): Response
  162.     {
  163.         return $this->render('Main/newsletter.html.twig', [
  164.         ]);
  165.     }
  166. }