public function deleteDish()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     $id_dish = isset($_POST['id_dish']) ? addslashes($_POST['id_dish']) : "";
     $id_restaurant = isset($_POST['id_restaurant']) ? addslashes($_POST['id_restaurant']) : "";
     if (!$id_dish) {
         Generic::errorMsg("No Dish ID Found");
     }
     $dish = new MasterDishModel();
     $dish->getByID($id_dish);
     if (!$id_restaurant) {
         Generic::errorMsg("No Restaurant ID Found");
     }
     $resto = new MasterRestaurantModel();
     $resto->getByID($id_restaurant);
     if ($dish->id_restaurant != $resto->id_restaurant) {
         Generic::errorMsg("Mismatch Dish and Restaurant");
     }
     if ($dish->status == "0") {
         Generic::errorMsg("Dish Already Deleted");
     } else {
         $dish->status = "0";
         $dish->save();
     }
     $json['status_message'] = 'Success';
     echo json_encode($json);
     die;
 }
 public function addDishToMyFavorite()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $idUser = Generic::mustCheck($_GET['id_user'], "User ID not Found");
     $idDish = Generic::mustCheck($_GET['id_dish'], "Dish ID not Found");
     $user = new UserModel();
     $user->getByID($idUser);
     $arrFavDishIds = explode(',', $user->fav_dishes_ids);
     $alreadyInFavorite = count($arrFavDishIds) <= 0 ? false : in_array($idDish, $arrFavDishIds);
     if ($alreadyInFavorite) {
         Generic::errorMsg("Already Favorited");
     }
     if (count($arrFavDishIds) <= 0) {
         $user->fav_dishes_ids = $idDish;
     } else {
         $arrFavDishIds[] = $idDish;
         $arrFavDishIds = array_unique($arrFavDishIds);
         $user->fav_dishes_ids = implode(',', $arrFavDishIds);
     }
     $dish = new MasterDishModel();
     $dish->getByID($idDish);
     $dish->fav = $dish->fav + 1;
     $dish->save();
     $resto = new MasterRestaurantModel();
     $resto->getByID($dish->id_restaurant);
     $resto->fav = $resto->fav + 1;
     $resto->save();
     $user->save();
     $this->success();
 }
 public function reinitiateCategories()
 {
     $idRestaurant = Generic::mustCheck($_GET['id_restaurant'], "BOOO!");
     $catIdDefault = $this->createCategories("OTHERS");
     $md = new MasterDishModel();
     if ($idRestaurant == "all") {
         $arrDishes = $md->getAll();
     } else {
         $arrDishes = $md->getWhere("id_restaurant='{$idRestaurant}'");
     }
     echo "<h1>Default cat id : {$catIdDefault}</h1>";
     foreach ($arrDishes as $d) {
         $dish = new MasterDishModel();
         $dish->getByID($d->id_dish);
         echo "<h2>{$dish->id_dish} - {$dish->name}</h2>";
         echo "<h3>From {$dish->id_category}";
         if (Generic::IsNullOrEmptyString($dish->id_category)) {
             echo "changed to";
             $dish->id_category = $catIdDefault;
             $dish->save();
         } else {
             if (!$this->isCategoryIdValid($dish->id_category)) {
                 echo "changed to";
                 $dish->id_category = $catIdDefault;
                 $dish->save();
             } else {
                 echo "stay at";
             }
         }
         echo " {$dish->id_category}</h3>";
         $resto = new MasterRestaurantModel();
         $resto->getByID($dish->id_restaurant);
         echo "<h2>{$resto->id_restaurant} - {$resto->name}</h2>";
         echo "<h3>From {$resto->id_categories}";
         if (Generic::IsNullOrEmptyString($resto->id_categories)) {
             $resto->id_categories = $catIdDefault;
             $resto->save();
         } else {
             $arrCats = explode(',', $resto->id_categories);
             $arrCats[] = $dish->id_category;
             $arrCats = array_unique($arrCats);
             $resto->id_categories = implode(',', $arrCats);
             $resto->save();
         }
         echo " To {$resto->id_categories}</h3>";
     }
 }