public function restoDish() { if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $json = array(); $json['status_code'] = 1; // fav, nearby $cmd = isset($_GET['cmd']) ? addslashes($_GET['cmd']) : ""; if (!$cmd) { $json['status_code'] = 0; $json['status_message'] = "No ID Found"; echo json_encode($json); die; } $distance = isset($_GET['distance']) ? addslashes($_GET['distance']) : 20; if (!$distance) { $json['status_code'] = 0; $json['status_message'] = "No ID Found"; echo json_encode($json); die; } $lat = isset($_GET['latitude']) ? addslashes($_GET['latitude']) : ""; if (!$lat) { $json['status_code'] = 0; $json['status_message'] = "No ID Found"; echo json_encode($json); die; } $long = isset($_GET['longitude']) ? addslashes($_GET['longitude']) : ""; if (!$long) { $json['status_code'] = 0; $json['status_message'] = "No ID Found"; echo json_encode($json); die; } $page = addslashes($_GET['page']); if ($page == "" || $page < 1) { $json['status_code'] = 0; $json['status_message'] = "No Page Found"; echo json_encode($json); die; } $limit = addslashes($_GET['limit']); if ($limit == "" || $limit < 1) { $json['status_code'] = 0; $json['status_message'] = "Limit Error"; echo json_encode($json); die; } $begin = ($page - 1) * $limit; $objRestaurant = new MasterRestaurantModel(); $objDish = new MasterDishModel(); global $db; $q = "SELECT *,SQRT(POW(69.1 * (latitude - {$lat}), 2) + POW(69.1 * ({$long} - longitude) * COS(latitude / 57.3), 2)) AS distance\nFROM {$objRestaurant->table_name} HAVING distance < {$distance} ORDER BY distance"; //echo $q; $arrResto = $db->query($q, 2); // pr($arrResto); MasterDish::checkCount($arrResto); $exp = explode(",", str_replace(" ", "", $objRestaurant->crud_webservice_allowed)); //tmbh untuk add photo url $arrPicsToAddPhotoUrl = $objRestaurant->crud_add_photourl; $arrPicsDishToAddPhotoUrl = $objRestaurant->crud_add_photourl; $json['results']['Dish'] = array(); if ($cmd == "fav") { $arrDishHelp = array(); $qdish = "SELECT {$objDish->table_name}.*, SQRT(POW(69.1 * ({$objRestaurant->table_name}.latitude - {$lat}), 2) + POW(69.1 * ({$long} - {$objRestaurant->table_name}.longitude) * COS({$objRestaurant->table_name}.latitude / 57.3), 2)) AS distance FROM {$objDish->table_name} LEFT JOIN {$objRestaurant->table_name} ON {$objRestaurant->table_name}.id_restaurant= {$objDish->table_name}.id_restaurant HAVING distance < {$distance} ORDER BY distance, {$objDish->table_name}.fav DESC LIMIT {$begin},{$limit}"; $arrDish = $db->query($qdish, 2); foreach ($arrDish as $dish) { $jarak = $dish->distance; $dish = MasterDish::getDish($dish->id_dish); $dish['distance'] = $jarak; $dish['nama_restaurant'] = MasterRestaurant::getRestoNameByIDResto($dish['id_restaurant']); $arrDishHelp[] = $dish; } $json['results']['Dish'] = $arrDishHelp; } elseif ($cmd == "nearby") { $qdish = "SELECT objDish.*, SQRT(POW(69.1 * (objDish.latitude - {$lat}), 2) + POW(69.1 * ({$long} - objDish.longitude) * COS(objDish.latitude / 57.3), 2)) AS distance" . " FROM (SELECT menurevo__ms_dish.*, menurevo__ms_restaurant.latitude, menurevo__ms_restaurant.longitude FROM menurevo__ms_dish LEFT JOIN menurevo__ms_restaurant ON menurevo__ms_dish.id_restaurant = menurevo__ms_restaurant.id_restaurant ORDER BY menurevo__ms_dish.fav DESC)as objDish " . "GROUP BY objDish.id_restaurant HAVING distance < 20 ORDER BY distance ASC LIMIT {$begin},{$limit}"; // echo $qdish; $arrDish = $db->query($qdish, 2); $arrDishHelp = array(); foreach ($arrDish as $dish) { $jarak = $dish->distance; $dish = MasterDish::getDish($dish->id_dish); $dish['distance'] = $jarak; $dish['nama_restaurant'] = MasterRestaurant::getRestoNameByIDResto($dish['id_restaurant']); $arrDishHelp[] = $dish; } $json['results']['Dish'] = $arrDishHelp; } echo json_encode($json); die; }
public function getHomeResults() { $idHome = Generic::mustCheck($_GET['id_home'], "ID Not Found"); $currentLat = !Generic::IsNullOrEmptyString($_GET['latitude']) ? $_GET['latitude'] : ""; $currentLong = !Generic::IsNullOrEmptyString($_GET['longitude']) ? $_GET['longitude'] : ""; $home = new HomeModel(); $home->getByID($idHome); if ($home->status != "1") { Generic::errorMsg("Not Active Home"); } $page = addslashes($_GET['page']); if ($page == "" || $page < 1) { Generic::errorMsg("No Page Found"); } $limit = addslashes($_GET['limit']); if ($limit == "" || $limit < 1) { Generic::errorMsg("Limit Error"); } $begin = ($page - 1) * $limit; $extraQ = " LIMIT {$begin},{$limit}"; $key = "key"; $results = array(); $searchType = $home->search_type; $searchTerm = $home->search_term; $query = $home->query; switch ($searchType) { case "0": break; case "1": $resto = new MasterRestaurantModel(); $results = $resto->getWhere("restaurant_type='{$searchTerm}' AND show_in_apps='1' ORDER BY fav DESC {$extraQ}"); $exp = explode(",", str_replace(" ", "", $resto->crud_webservice_allowed)); $arrPicsToAddPhotoUrl = $resto->crud_add_photourl; $key = "restaurant"; break; case "2": $resto = new MasterRestaurantModel(); $results = $resto->getWhere("FIND_IN_SET('{$searchTerm}', id_categories) AND show_in_apps='1' ORDER BY fav DESC {$extraQ}"); $exp = explode(",", str_replace(" ", "", $resto->crud_webservice_allowed)); $arrPicsToAddPhotoUrl = $resto->crud_add_photourl; $key = "restaurant"; break; case "3": $resto = new MasterRestaurantModel(); $results = $resto->getWhere("id_cuisine='{$searchTerm}' AND show_in_apps='1' ORDER BY fav DESC {$extraQ}"); $exp = explode(",", str_replace(" ", "", $resto->crud_webservice_allowed)); $arrPicsToAddPhotoUrl = $resto->crud_add_photourl; $key = "restaurant"; break; case "4": $resto = new MasterRestaurantModel(); $results = $resto->getWhere("name LIKE '%{$query}%' AND show_in_apps='1' ORDER BY fav DESC {$extraQ}"); $exp = explode(",", str_replace(" ", "", $resto->crud_webservice_allowed)); $arrPicsToAddPhotoUrl = $resto->crud_add_photourl; $key = "restaurant"; break; case "5": $dish = new MasterDishModel(); $results = $dish->getWhere("'{$searchTerm}' IN (dish_tags) ORDER BY id_dish DESC {$extraQ}"); $exp = explode(",", str_replace(" ", "", $dish->crud_webservice_allowed)); $arrPicsToAddPhotoUrl = $dish->crud_add_photourl; $key = "Dish"; break; case "6": $dish = new MasterDishModel(); $results = $dish->getWhere("name LIKE '%{$query}%' ORDER BY id_dish DESC {$extraQ}"); $exp = explode(",", str_replace(" ", "", $dish->crud_webservice_allowed)); $arrPicsToAddPhotoUrl = $dish->crud_add_photourl; $key = "Dish"; break; case "8888": break; default: break; } $json["results"]["latitude"] = $currentLat; $json["results"]["longitude"] = $currentLong; $json["results"][$key] = array(); foreach ($results as $o) { $sem = array(); foreach ($exp as $attr) { if (in_array($attr, $arrPicsToAddPhotoUrl)) { $sem[$attr] = Generic::insertImageUrl($o->{$attr}); } else { $sem[$attr] = stripslashes($o->{$attr}); } } if ($searchType == "5" || $searchType == "6") { $sem['nama_restaurant'] = MasterRestaurant::getRestoNameByIDResto($o->id_restaurant); } if ($currentLat != "" && $currentLong != "") { $sem["distance"] = sqrt(pow(69.09999999999999 * ($o->latitude - $currentLat), 2) + pow(69.09999999999999 * ($currentLong - $o->longitude) * cos($o->latitude / 57.3), 2)); } else { $sem["distance"] = 0; } // $json["results"]["search_type"] = Generic::homeSearchType($searchType); $json["results"][$key][] = $sem; } $json['status_code'] = 1; echo json_encode($json); die; }