src/FoodAirwaySiteBundle/Controller/DefaultController.php line 72

Open in your IDE?
  1. <?php
  2. namespace FoodAirwaySiteBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. class DefaultController extends BaseController
  7. {
  8.     function user_agent(){
  9.         $iPod strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
  10.         $iPhone strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
  11.         $iPad strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
  12.         $android strpos($_SERVER['HTTP_USER_AGENT'],"Android");
  13.         
  14.         if($iPad||$iPhone||$iPod){
  15.             return 'ios';
  16.         }else if($android){
  17.             return 'android';
  18.         }else{
  19.             return 'pc';
  20.         }
  21.     }
  22.     public function preparingOrdersScreenAction(Request $request) {
  23.         $response =  $this->render('@FoodAirwaySite/Default/preparingOrderScreen.html.twig');
  24.     
  25.         return $this->etagResponse($response$request);
  26.     }
  27.     public function redirectUserToDeviceAction(Request $request) {
  28.         if ($this->user_agent()=='android') {
  29.             return $this->redirect('https://play.app.goo.gl/?link=https://play.google.com/store/apps/details?id=com.foodairways&ddl=1&pcampaignid=web_ddl_1');
  30.         } else if($this->user_agent()=='ios') {
  31.             return $this->redirect('https://apps.apple.com/us/app/food-airway/id1552633176');
  32.         } else {
  33.             return $this->redirect($this->generateUrl('food_airway_site_product_listing'));
  34.         }
  35.     }
  36.     public function googleVerificationAction(Request $request) {
  37.         $response =  $this->render('@FoodAirwaySite/Default/google6fec763a38f4b25e.html');
  38.     
  39.         return $this->etagResponse($response$request);
  40.     } 
  41.     
  42.     public function watchUsAction(Request $request) {
  43.         $response =  $this->render('@FoodAirwaySite/Default/watchUs.html.twig', array('active'=>'watchus'));
  44.     
  45.         return $this->etagResponse($response$request);
  46.     }
  47.     public function watchUsForIphoneAction(Request $request) {
  48.         $response =  $this->render('@FoodAirwaySite/Default/watchUsMobile.html.twig', array('active'=>'watchus'));
  49.     
  50.         return $this->etagResponse($response$request);
  51.     }
  52.     public function privacyPolicyAction(Request $request) {
  53.         $response =  $this->render('@FoodAirwaySite/Default/privacyPolicy.html.twig');
  54.     
  55.         return $this->etagResponse($response$request);
  56.     }
  57.     public function indexAction(Request $request)
  58.     {
  59.         if ($this->isMobileDevice()) {
  60.             return $this->redirect($this->generateUrl('food_airway_site_product_listing'));
  61.         }
  62.         
  63.         $dataService $this->container->get('FoodAirwayApiBundle\Services\DataService');
  64.         /* we will  pass city here when we expand it to more cities */
  65.         $areas $dataService->fetchAreasByCityId();
  66.         $products $dataService->productListingByCategories();
  67.         $response =  $this->render('@FoodAirwaySite/Default/index.html.twig'
  68.             array('active'=>'home','areas'=>$areas'products'=>$products));
  69.     
  70.         return $this->etagResponse($response$request);
  71.     }
  72.     
  73.     public function aboutAction(Request $request)
  74.     {
  75.         $response =  $this->render('@FoodAirwaySite/Default/about-us.html.twig'
  76.             array('active'=>'home'));
  77.     
  78.         return $this->etagResponse($response$request);
  79.     }
  80.     public function googleFetchAddressAction(Request $request) {
  81.         $lat $request->get('lat');
  82.         $long $request->get('long');
  83.         $address =  $this->geolocationaddress($lat$long);
  84.         $response = new JsonResponse();
  85.         $response->setData(array('success'=>true'address'=>$address));
  86.         
  87.         return $response;
  88.     }
  89.     public static function geolocationaddress($lat$long)
  90.     {
  91.         $geocode "https://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$long&sensor=false&key=AIzaSyDV2KtaL35qr7f36C46grTU6xl1CHNq6Bs";
  92.         $ch curl_init();
  93.         curl_setopt($chCURLOPT_URL$geocode);
  94.         curl_setopt($chCURLOPT_RETURNTRANSFER1);
  95.         curl_setopt($chCURLOPT_PROXYPORT3128);
  96.         curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
  97.         curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
  98.         $response curl_exec($ch);
  99.         curl_close($ch);
  100.         $output json_decode($response);
  101.         $dataarray get_object_vars($output);
  102.         if ($dataarray['status'] != 'ZERO_RESULTS' && $dataarray['status'] != 'INVALID_REQUEST') {
  103.             if (isset($dataarray['results'][0]->formatted_address)) {
  104.                 return $dataarray['results'][0]->formatted_address;
  105.             } else {
  106.                 return false;
  107.             }
  108.         } else {
  109.             return false;
  110.         }
  111.     }
  112.     public function mobileVerificationAction(Request $request) {
  113.         $response = new JsonResponse();
  114.         return $response->setData(true);
  115.     }
  116.     function isMobileDevice(){
  117.         $aMobileUA = array(
  118.             '/iphone/i' => 'iPhone'
  119.             '/ipod/i' => 'iPod'
  120.             '/ipad/i' => 'iPad'
  121.             '/android/i' => 'Android'
  122.             '/blackberry/i' => 'BlackBerry'
  123.             '/webos/i' => 'Mobile'
  124.         );
  125.         //Return true if Mobile User Agent is detected
  126.         foreach($aMobileUA as $sMobileKey => $sMobileOS){
  127.             if(preg_match($sMobileKey$_SERVER['HTTP_USER_AGENT'])){
  128.                 return true;
  129.             }
  130.         }
  131.         //Otherwise return false..  
  132.         return false;
  133.     }
  134.     public function staffAction(Request $request) {
  135.         $response =  $this->render('@FoodAirwaySite/Default/staff.html.twig');
  136.     
  137.         return $this->etagResponse($response$request);
  138.     }
  139. }