public function searchDish() { if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $resto = "resto"; $json = array(); $json['status_code'] = 1; $search = isset($_GET['name']) ? addslashes($_GET['name']) : ""; $lat = isset($_GET['latitude']) ? addslashes($_GET['latitude']) : ""; if ($lat == "" or !$lat) { $lat = MenuRevoConstants::$latitude; } if (!Generic::checkLatitude($lat)) { Generic::errorMsg("Latitude must be Numeric!"); } $long = isset($_GET['longitude']) ? addslashes($_GET['longitude']) : ""; if ($long == "" or !$long) { $long = MenuRevoConstants::$longitude; } if (!Generic::checklongitude($long)) { Generic::errorMsg("Longitude must be Numeric!"); } $nearby = isset($_GET['nearby']) ? addslashes($_GET['nearby']) : 20; if ($nearby == '1') { $nearby = 20; } else { $nearby = 100000; } $arrSort['distance'] = 1; $nearby = " HAVING distance < " . $nearby; $favorite = isset($_GET['fav']) ? addslashes($_GET['fav']) : "0"; if ($favorite == '1') { $arrSort['fav'] = $favorite; } $houropen = isset($_GET['houropen']) ? addslashes($_GET['houropen']) : "0"; if ($houropen == '1') { $whereOption = " CONVERT_TZ(NOW(),@@session.time_zone, '+00:00') >= (CONVERT_TZ(concat(CURRENT_DATE,' ',resto.time_open),@@session.time_zone, '+00:00' )) AND CONVERT_TZ(NOW(),@@session.time_zone, '+00:00') < (CONVERT_TZ(concat(CURRENT_DATE,' ',resto.time_close),@@session.time_zone, '+00:00' ))"; } $cuisine = isset($_GET['id_cuisine']) ? addslashes($_GET['id_cuisine']) : "None"; if (Cuisine::checkCuisineID($cuisine) != 0) { $arrWhere['id_cuisine'] = $cuisine; } $restotype = isset($_GET['id_restotype']) ? addslashes($_GET['id_restotype']) : "None"; if (MasterRestaurantType::isRestoTypeByIDAvailable($restotype) != 0) { $arrWhere['restaurant_type'] = $restotype; } $disc_mr = isset($_GET['disc_mr']) ? addslashes($_GET['disc_mr']) : "None"; if ($disc_mr == 1) { $arrWhereOr['disc_mr'] = $disc_mr; } $disc_cc = isset($_GET['disc_cc']) ? addslashes($_GET['disc_cc']) : "None"; if ($disc_cc == 1) { $arrWhereOr['disc_cc'] = $disc_cc; } $disc_resto = isset($_GET['disc_resto']) ? addslashes($_GET['disc_resto']) : "None"; if ($disc_resto == 1) { $arrWhereOr['disc_resto'] = $disc_resto; } $where = " WHERE dish.name LIKE '%{$search}%' "; if ($whereOption != "") { $where = $where . " AND " . $whereOption; } foreach ($arrWhere as $key => $val) { $where = $where . " AND {$resto}" . ".{$key}= '{$val}'"; } foreach ($arrWhereOr as $key => $val) { $where = $where . " AND {$resto}" . ".{$key} != '0'"; } $sort = $nearby . " ORDER BY "; foreach ($arrSort as $key => $val) { if ($key == "distance") { $sort = $sort . " {$key} ASC,"; } elseif ($key == "fav") { $sort = $sort . " {$resto}" . ".{$key} DESC,"; } elseif ($key == "houropen") { $sort = $sort . " {$resto}" . ".{$key} ASC,"; } } $sort = substr($sort, 0, -1); $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; global $db; $objRestaurant = new MasterRestaurantModel(); $objDish = new MasterDishModel(); $qdish = "SELECT dish.*, resto.name as nama_restaurant, SQRT(POW(69.1 * (resto.latitude - {$lat}), 2) + POW(69.1 * ({$long} - resto.longitude) * COS(resto.latitude / 57.3), 2)) AS distance" . " FROM {$objDish->table_name} dish LEFT JOIN {$objRestaurant->table_name} resto ON dish.id_restaurant=resto.id_restaurant " . $where . $sort . " LIMIT {$begin},{$limit}"; // echo $qdish. "<br>"; $arrDish = $db->query($qdish, 2); if (count($arrDish) == 0) { Generic::errorMsg("No Food found!"); } $arrDishHelp = array(); foreach ($arrDish as $dish) { $dishhlp = MasterDish::getDish($dish->id_dish); $dishhlp['distance'] = $dish->distance; $dishhlp['nama_restaurant'] = $dish->nama_restaurant; $arrDishHelp[] = $dishhlp; } // // // $qResto = "SELECT *, SQRT(POW(69.1 * (latitude - $lat), 2) + POW(69.1 * ($long - longitude) * COS(latitude / 57.3), 2)) AS distance FROM {$objRestaurant->table_name} " . $where . $sort ; //// echo $qResto; // $arrResto = $db->query($qResto, 2); // $checkCountResto = false; // $arrDishHelp = array(); // foreach ($arrResto as $restoID) { // // $arrSearchDish = $objDish->getWhere("name LIKE '%$search%' AND availability='1' AND id_restaurant='$restoID->id_restaurant' LIMIT $begin,$limit"); // // if (count($arrSearchDish) > 0) { // $checkCountResto = true; // $jarak = $restoID->distance; // // foreach ($arrSearchDish as $dish) { // $dish = MasterDish::getDish($dish->id_dish); // $dish['distance'] = $jarak; // $dish['nama_restaurant'] = MasterRestaurant::getRestoNameByIDResto($dish['id_restaurant']); // $arrDishHelp[] = $dish; // } // // } // // } // // if (!$checkCountResto) { // Generic::errorMsg("No Food found!"); // } $json['results']['Dish'] = $arrDishHelp; echo json_encode($json); die; }
public function getMenuRestoForExtra() { if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $json = array(); $json['status_code'] = 1; $id_restaurant = isset($_GET['id_restaurant']) ? addslashes($_GET['id_restaurant']) : ""; if (!$id_restaurant) { Generic::errorMsg("No Restaurant ID Found"); } $id_order = isset($_GET['id_order']) ? addslashes($_GET['id_order']) : ""; if (!$id_restaurant) { Generic::errorMsg("No ID Order Found"); } $objRestaurant = new MasterRestaurantModel(); $arrResto = $objRestaurant->getWhere("id_restaurant={$id_restaurant}"); if (count($arrResto) == 0) { Generic::errorMsg("Can't find Restaurant in the Database!"); } $resto = User::getRestaurant($id_restaurant); $json['results']['restaurant'][] = $resto; global $db; $objDish = new MasterDishModel(); $q = "SELECT id_category FROM {$objDish->table_name} WHERE availability=1 AND id_restaurant={$id_restaurant}"; $arrCat = $objDish->getWhere("id_restaurant='{$id_restaurant}'"); if (count($arrCat) == 0) { $json['status_code'] = 0; $json['status_message'] = "Can't find dish in the Restaurant!"; echo json_encode($json); die; } $catIds = explode(",", $resto["id_categories"]); $objCategory = new MasterCategoryModel(); $objDish = new MasterDishModel(); foreach ($catIds as $val) { $cat = MasterCategory::getCategoryByID($val); $arrDish = $objDish->getWhere("status!='0' AND id_category='{$val}' AND id_restaurant='{$id_restaurant}'"); if (count($arrDish) == 0) { continue; } $dishHelp = array(); foreach ($arrDish as $val) { // echo $val->id_dish; $dishHelp[] = MasterDish::getDish($val->id_dish); } $cat['dishes'] = $dishHelp; $json['results']['categories'][] = $cat; } $json['results']['order_details'][] = OrderDetail::getOrderDetailsByIDOrderForCalc($id_order); echo json_encode($json); die; }
public function loadDish() { if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $cmd = isset($_GET['cmd']) ? addslashes($_GET['cmd']) : ""; $json = array(); $json['status_code'] = 1; if (!$cmd) { $json['status_code'] = 0; $json['status_message'] = "No ID Found"; echo json_encode($json); die; } $id_user = isset($_GET['id']) ? addslashes($_GET['id']) : ""; if (!$id_user) { $json['status_code'] = 0; $json['status_message'] = "No ID Found"; echo json_encode($json); die; } $user = new UserModel(); $arrUser = $user->getWhere("id_user={$id_user}"); if ($cmd == "fav") { foreach ($arrUser as $o) { $dishSearch['fav_dishes_ids'] = $o->fav_dishes_ids; } $objectDish = new MasterDishModel(); $objResto = new MasterRestaurantModel(); $arrdishSearch = explode(",", $dishSearch[fav_dishes_ids]); foreach ($arrdishSearch as $val) { if ($where == "") { $where = "{$objectDish->table_name}.id_dish={$val}"; } else { $where = $where . " or {$objectDish->table_name}.id_dish={$val}"; } } $where = $where . " ORDER BY {$objectDish->table_name}.fav DESC"; $where = $where; global $db; $arrDish = $objectDish->getWhere($where); foreach ($arrDish as $key => $dish) { $arrFavbyResto[] = $dish->id_restaurant; $arrGesDish[$dish->id_restaurant][] = MasterDish::getDish($dish->id_dish); } $arrFavbyResto = array_unique($arrFavbyResto); $sem = array(); foreach ($arrFavbyResto as $resto) { $restoHelp = self::getRestaurant($resto); foreach ($arrGesDish as $key => $valdish) { $dishhelp = array(); if ($key == $resto) { $dishhelp = $valdish; break; } } $restoHelp['dish'] = $dishhelp; $sem['restaurant'][] = $restoHelp; } $json['results'] = $sem; } elseif ($cmd == "his") { foreach ($arrUser as $o) { $dishSearch['history_dishes_ids'] = $o->history_dishes_ids; } $arrdishSearch = explode(",", $dishSearch[history_dishes_ids]); $objectDish = new MasterDishModel(); $objectRestaurant = new MasterRestaurantModel(); $exp = explode(",", str_replace(" ", "", $objectDish->crud_webservice_allowed)); $arrPicsToAddPhotoUrl = $objectDish->crud_add_photourl; foreach ($arrdishSearch as $val) { $arr = $objectDish->getWhere("id_dish=" . $val, "*"); if (count($arr) != 0) { $json['status_code'] = 1; } else { $json['status_code'] = 0; $json['status_message'] = "No ID Found"; echo json_encode($json); die; } $sem = array(); foreach ($arr as $o) { foreach ($exp as $attr) { // echo $attr; if (in_array($attr, $arrPicsToAddPhotoUrl)) { $sem[$attr] = _BPATH . _PHOTOURL . $o->{$attr}; } elseif ($attr == "id_restaurant") { // echo "masuk"; // echo $o->$attr; $sem[$attr] = stripslashes($o->{$attr}); $sem['restaurant'] = $this->getRestaurant($o->{$attr}); } else { $sem[$attr] = stripslashes($o->{$attr}); } } //$sem['restaurant'] = $objectRestaurant->getRestaurant($val); $json["results"][] = $sem; } } } elseif ($cmd == "receipthis") { } else { $json['status_code'] = 0; $json['status_message'] = "No ID Found"; echo json_encode($json); die; } echo json_encode($json); die; }
public function loadRestoDishNearBy() { if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $json = array(); $json['status_code'] = 1; $distance = isset($_GET['distance']) ? addslashes($_GET['distance']) : 20; if (!$distance) { Generic::errorMsg("Not Distance"); } $lat = isset($_GET['latitude']) ? addslashes($_GET['latitude']) : ""; if (!$lat) { Generic::errorMsg("No Lat"); } $long = isset($_GET['longitude']) ? addslashes($_GET['longitude']) : ""; if (!$long) { Generic::errorMsg("No longitude"); } $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; $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"; $arrResto = $db->query($q, 2); 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(); $arrDishHelp = array(); $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; }