<?php
namespace FoodAirwaySiteBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
class DefaultController extends BaseController
{
function user_agent(){
$iPod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
if($iPad||$iPhone||$iPod){
return 'ios';
}else if($android){
return 'android';
}else{
return 'pc';
}
}
public function preparingOrdersScreenAction(Request $request) {
$response = $this->render('@FoodAirwaySite/Default/preparingOrderScreen.html.twig');
return $this->etagResponse($response, $request);
}
public function redirectUserToDeviceAction(Request $request) {
if ($this->user_agent()=='android') {
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');
} else if($this->user_agent()=='ios') {
return $this->redirect('https://apps.apple.com/us/app/food-airway/id1552633176');
} else {
return $this->redirect($this->generateUrl('food_airway_site_product_listing'));
}
}
public function googleVerificationAction(Request $request) {
$response = $this->render('@FoodAirwaySite/Default/google6fec763a38f4b25e.html');
return $this->etagResponse($response, $request);
}
public function watchUsAction(Request $request) {
$response = $this->render('@FoodAirwaySite/Default/watchUs.html.twig', array('active'=>'watchus'));
return $this->etagResponse($response, $request);
}
public function watchUsForIphoneAction(Request $request) {
$response = $this->render('@FoodAirwaySite/Default/watchUsMobile.html.twig', array('active'=>'watchus'));
return $this->etagResponse($response, $request);
}
public function privacyPolicyAction(Request $request) {
$response = $this->render('@FoodAirwaySite/Default/privacyPolicy.html.twig');
return $this->etagResponse($response, $request);
}
public function indexAction(Request $request)
{
if ($this->isMobileDevice()) {
return $this->redirect($this->generateUrl('food_airway_site_product_listing'));
}
$dataService = $this->container->get('FoodAirwayApiBundle\Services\DataService');
/* we will pass city here when we expand it to more cities */
$areas = $dataService->fetchAreasByCityId();
$products = $dataService->productListingByCategories();
$response = $this->render('@FoodAirwaySite/Default/index.html.twig',
array('active'=>'home','areas'=>$areas, 'products'=>$products));
return $this->etagResponse($response, $request);
}
public function aboutAction(Request $request)
{
$response = $this->render('@FoodAirwaySite/Default/about-us.html.twig',
array('active'=>'home'));
return $this->etagResponse($response, $request);
}
public function googleFetchAddressAction(Request $request) {
$lat = $request->get('lat');
$long = $request->get('long');
$address = $this->geolocationaddress($lat, $long);
$response = new JsonResponse();
$response->setData(array('success'=>true, 'address'=>$address));
return $response;
}
public static function geolocationaddress($lat, $long)
{
$geocode = "https://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$long&sensor=false&key=AIzaSyDV2KtaL35qr7f36C46grTU6xl1CHNq6Bs";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $geocode);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$output = json_decode($response);
$dataarray = get_object_vars($output);
if ($dataarray['status'] != 'ZERO_RESULTS' && $dataarray['status'] != 'INVALID_REQUEST') {
if (isset($dataarray['results'][0]->formatted_address)) {
return $dataarray['results'][0]->formatted_address;
} else {
return false;
}
} else {
return false;
}
}
public function mobileVerificationAction(Request $request) {
$response = new JsonResponse();
return $response->setData(true);
}
function isMobileDevice(){
$aMobileUA = array(
'/iphone/i' => 'iPhone',
'/ipod/i' => 'iPod',
'/ipad/i' => 'iPad',
'/android/i' => 'Android',
'/blackberry/i' => 'BlackBerry',
'/webos/i' => 'Mobile'
);
//Return true if Mobile User Agent is detected
foreach($aMobileUA as $sMobileKey => $sMobileOS){
if(preg_match($sMobileKey, $_SERVER['HTTP_USER_AGENT'])){
return true;
}
}
//Otherwise return false..
return false;
}
public function staffAction(Request $request) {
$response = $this->render('@FoodAirwaySite/Default/staff.html.twig');
return $this->etagResponse($response, $request);
}
}