function createTableRow(Cuisine $cuis)
{
    print "<tr>\n";
    print "<td>" . $cuis->getID() . "</td>\n";
    print "<td>" . $cuis->getName() . "</td>\n";
    print "<td>" . $cuis->getDescr() . "</td>\n";
    print "</tr>\n";
}
Ejemplo n.º 2
0
 /**
  * Refresh restaurants by postcode
  * 
  * @param Postcode $currentPostcode
  * @return Postcode
  */
 protected function _refreshPostcode($currentPostcode)
 {
     $manager = $this->getDoctrine()->getManager();
     $result = $this->_callJusteat('restaurants?q=' . $currentPostcode->getPostcode());
     $JERestaurants = json_decode($result);
     $restaurantRepo = $manager->getRepository('TycoonApiBundle:Restaurant');
     $cuisineRepo = $manager->getRepository('TycoonApiBundle:Cuisine');
     foreach ($JERestaurants->Restaurants as $JERestaurant) {
         // Load restaurant
         $currentRestaurant = $restaurantRepo->findOneByJusteatId($JERestaurant->Id);
         if (empty($currentRestaurant)) {
             // Create restaurant
             $currentRestaurant = new Restaurant();
             $currentRestaurant->setJusteatId($JERestaurant->Id);
         }
         $currentRestaurant->setName($JERestaurant->Name);
         $currentRestaurant->setAddress($JERestaurant->Address);
         if (!empty($JERestaurant->City)) {
             $currentRestaurant->setCity($JERestaurant->City);
         }
         if (!empty($JERestaurant->Url)) {
             $currentRestaurant->setUrl($JERestaurant->Url);
         }
         if (!empty($JERestaurant->Logo[0]->StandardResolutionURL)) {
             $currentRestaurant->setLogo($JERestaurant->Logo[0]->StandardResolutionURL);
         }
         if (!empty($JERestaurant->Latitude)) {
             $currentRestaurant->setLatitude($JERestaurant->Latitude);
         }
         if (!empty($JERestaurant->Longitude)) {
             $currentRestaurant->setLongitude($JERestaurant->Longitude);
         }
         if (!empty($JERestaurant->Score)) {
             $currentRestaurant->setScore($JERestaurant->Score);
         }
         foreach ($JERestaurant->CuisineTypes as $cuisineType) {
             // Load cuisine
             $currentCuisine = $cuisineRepo->findOneByJusteatId($cuisineType->Id);
             if (empty($currentCuisine)) {
                 // Create cuisine
                 $currentCuisine = new Cuisine();
                 $currentCuisine->setJusteatId($cuisineType->Id);
                 $currentCuisine->setName($cuisineType->Name);
             }
             $currentRestaurant->addCuisine($currentCuisine);
             $currentCuisine->addRestaurant($currentRestaurant);
             $manager->persist($currentCuisine);
         }
         $currentRestaurant->addPostcode($currentPostcode);
         $currentPostcode->addRestaurant($currentRestaurant);
         $manager->persist($currentRestaurant);
         $manager->flush();
     }
     $currentPostcode->initRefreshedAt();
     $manager->persist($currentPostcode);
     $manager->flush();
     return $currentPostcode;
 }
Ejemplo n.º 3
0
 static function find($search_id)
 {
     $found_cuisine = null;
     $cuisines = Cuisine::getAll();
     foreach ($cuisines as $cuisine) {
         $cuisine_id = $cuisine->getId();
         if ($cuisine_id == $search_id) {
             $found_cuisine = $cuisine;
         }
     }
     return $found_cuisine;
 }
Ejemplo n.º 4
0
 static function search($search_type)
 {
     $found_cuisine = null;
     $cuisines = Cuisine::getAll();
     foreach ($cuisines as $cuisine) {
         $cuisine_type = $cuisine->getCuisineType();
         if ($cuisine_type == $search_type) {
             $found_cuisine_type = $cuisine;
         }
     }
     return $found_cuisine_type;
 }
Ejemplo n.º 5
0
	/**
	 * Show specific Cuisine by ID
	 *
	 * @param: $id An integer value representing the Cuisine ID
	 * @return: None
	 */
	public function show($id){
		$this->template->id = $id;

		//Get the Cuisine from the database
		$Cuisines = Cuisine::retrieve(array("id"=>$id));
		//If successful and the count is equal to one (as desired)
		//set the Cuisine object in the template to be displayed
		if(count($Cuisines) == 1){
			$this->template->Cuisine = $Cuisines[0];
		}

		$this->template->display('show.html.php');
	}
Ejemplo n.º 6
0
   /**
    * A method for validating the data
	* 
	* @param $data An array of POSTed data.
	* @return bool Whether the data is valid or not.
	*/
   public static function validates(array &$data) {
      $errors = array();

	  if (!isset($data['CuisineName']) || empty($data['CuisineName'])) {
         $errors['CuisineName'] = 'You must provide your cuisine name.';
	     unset($data['CuisineName']);
	  }
      
      self::$errors = $errors; 
	  if (count($errors)) {
         return false;
	  }
	  return true;
   }
Ejemplo n.º 7
0
 function testGetRestaurants()
 {
     //Arrange
     $type = "Italian";
     $id = null;
     $test_cuisine = new Cuisine($type, $id);
     $test_cuisine->save();
     $test_cuisine_id = $test_cuisine->getId();
     $description = "OK Chinese food";
     $name = "City Chinese";
     $test_restaurant = new Restaurant($description, $id, $test_cuisine_id, $name);
     $test_restaurant->save();
     $description2 = "OK Mexican";
     $name2 = "City Mexican";
     $test_restaurant2 = new Restaurant($description2, $id, $test_cuisine_id, $name2);
     $test_restaurant2->save();
     //Act
     $result = $test_cuisine->getRestaurants();
     //Assert
     $this->assertEquals([$test_restaurant, $test_restaurant2], $result);
 }
Ejemplo n.º 8
0
 function test_find()
 {
     //Arrange
     $test_name = "Toms Tomatos ";
     $test_seats = 15;
     $test_location = "Farmville";
     $test_evenings = true;
     $test_cuisine = new Cuisine("Mexican", true, 1);
     $test_cuisine->save();
     $test_restaurant = new Restaurant($test_name, $test_seats, $test_location, $test_evenings, $test_cuisine->getId());
     $test_restaurant->save();
     //Act
     $result = Restaurant::find($test_restaurant->getId());
     //Assert
     $this->assertEquals($test_restaurant, $result);
 }
 function test_deleteReviews()
 {
     $name = "Asian";
     $id = null;
     $test_cuisine = new Cuisine($name, $id);
     $test_cuisine->save();
     $restaurant_name = "The Golden Duck";
     $location = "898 SW 5th Ave, Portland, OR";
     $description = "A Chill Asian experince";
     $price = "\$\$";
     $cuisine_id = $test_cuisine->getId();
     $test_restaurant = new Restaurant($restaurant_name, $location, $description, $price, $cuisine_id);
     $test_restaurant->save();
     $restaurant_name2 = "The Red Dragon";
     $location2 = "899 SW 5th Ave, Portland, OR";
     $description2 = "A Intense Asian experince";
     $price2 = "\$\$\$";
     $cuisine_id2 = $test_cuisine->getId();
     $test_restaurant2 = new Restaurant($restaurant_name2, $location2, $description2, $price2, $cuisine_id2);
     $test_restaurant2->save();
     $user = "******";
     $stars = 3;
     $headline = "It is aight.";
     $body = "Yeah, pretty aight bro";
     $restaurant_id = $test_restaurant->getId();
     $test_review = new Review($user, $stars, $headline, $body, $restaurant_id);
     $test_review->save();
     $user2 = "6969babygirl";
     $stars2 = 3;
     $headline2 = "XOXO";
     $body2 = "I cant even";
     $restaurant_id2 = $test_restaurant->getId();
     $test_review2 = new Review($user2, $stars2, $headline2, $body2, $restaurant_id2);
     $test_review2->save();
     $test_restaurant->delete();
     $result = Review::getAll();
     //var_dump($result);
     $this->assertEquals([], $result);
 }
Ejemplo n.º 10
0
    return $app['twig']->render('cuisines.html.twig', array('cuisines' => $cuisine, 'restaurants' => $cuisine->getRestaurants()));
});
//brings user to a page that allows a specific restaurant to be edited
$app->get('/restaurant/{id}/edit', function ($id) use($app) {
    $restaurant = Restaurant::find($id);
    return $app['twig']->render('restaurant_edit.html.twig', array('restaurants' => $restaurant));
});
//posts edited data to the database to update a property in the existing restaurant
$app->patch('/restaurant/{id}', function ($id) use($app) {
    $restaurant = Restaurant::find($id);
    $cuisine = Cuisine::find($_POST['cuisine_id']);
    foreach ($_POST as $key => $value) {
        if (!empty($value)) {
            $restaurant->update($key, $value);
        }
    }
    return $app['twig']->render('cuisines.html.twig', array('cuisines' => $cuisine, 'restaurants' => $cuisine->getRestaurants()));
});
//delete all restaurants in a specific cuisine
$app->post('/delete_restaurants', function () use($app) {
    Restaurant::deleteAll();
    return $app['twig']->render('index.html.twig', array('restaurants' => Restaurant::getAll()));
});
//deletes specific restaurant
$app->delete('/restaurant/{id}', function ($id) use($app) {
    $restaurant = Restaurant::find($id);
    $cuisine = Cuisine::find($_POST['cuisine_id']);
    $restaurant->delete();
    return $app['twig']->render('cuisines.html.twig', array('cuisines' => $cuisine, 'restaurants' => $cuisine->getRestaurants()));
});
return $app;
 function testDelete()
 {
     //Arrange
     $name = "Drinks";
     $id = null;
     $test_Cuisine = new Cuisine($name, $id);
     $test_Cuisine->save();
     $restaurant = "Aalto";
     $address = "123 Belmont";
     $phone = "123-456-7890";
     $cuisine_id = $test_Cuisine->getId();
     $test_restaurant = new Restaurant($restaurant, $address, $phone, $cuisine_id, $id);
     $test_restaurant->save();
     $restaurant2 = "HobNob";
     $address2 = "999 somewhere";
     $phone2 = "234-555-5555";
     $cuisine_id2 = $test_Cuisine->getId();
     $test_restaurant2 = new Restaurant($restaurant, $address, $phone, $cuisine_id, $id);
     $test_restaurant2->save();
     //Act
     $test_restaurant->delete();
     //Assert
     $this->assertEquals([$test_restaurant2], Restaurant::getAll());
 }
Ejemplo n.º 12
0
 function test_deleteVenue()
 {
     //Arrange
     $type = "Thai";
     $id = null;
     $test_cuisine = new Cuisine($type, $id);
     $test_cuisine->save();
     $test_cuisine_id = $test_cuisine->getId();
     $name = "Mai Thai";
     $address = "1139 NW Elm Street";
     $description = "Yum yum for my tum tum";
     $rating = 3;
     $name2 = "Screen Door";
     $address2 = "19849 SW Santee Court";
     $description2 = "Huge lines.  Not worth it.";
     $rating2 = 4;
     $test_venue = new Venue($name, $test_cuisine_id, $id, $rating, $address, $description);
     $test_venue2 = new Venue($name2, $test_cuisine_id, $id, $rating2, $address2, $description2);
     $test_venue->save();
     $test_venue2->save();
     //Act
     $test_venue->deleteVenue();
     //Assert
     $this->assertEquals([$test_venue2], Venue::getAll());
 }
Ejemplo n.º 13
0
 protected function tearDown()
 {
     Cuisine::deleteAll();
     Restaurant::deleteAll();
     Review::deleteAll();
 }
Ejemplo n.º 14
0
 function test_update()
 {
     //Arrange
     $cuisine = "Pizza";
     $test_cuisine = new Cuisine($cuisine);
     $test_cuisine->save();
     //Act
     $result = Cuisine::find($test_cuisine->getID());
     $result->setCuisineType("Burgers");
     $result->update();
     $result = $result->getCuisineType();
     //Assert
     $this->assertEquals("Burgers", $result);
 }
 function testDeleteCuisineRestaurants()
 {
     //Arrange
     $name = "Italian";
     $id = null;
     $test_cuisine = new Cuisine($name, $id);
     $test_cuisine->save();
     $name = "Piazza Italia";
     $cuisine_id = $test_cuisine->getId();
     $test_restaurant = new Restaurant($name, $id, $cuisine_id, $rating);
     $test_restaurant->save();
     //Act
     $test_cuisine->delete();
     //Assert
     $this->assertEquals([], Restaurant::getAll());
 }
 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;
 }
Ejemplo n.º 17
0
 function test_DeleteCuisineRestaurants()
 {
     //Arrange
     //cuisine
     $name = "Japanese";
     $id = null;
     $test_cuisine = new Cuisine($name, $id);
     $test_cuisine->save();
     //restaurant
     $name = "Good Fortune";
     $cuisine_id = $test_cuisine->getId();
     $description = "very tasty.";
     $address = "1111 SW 11th Ave";
     $test_restaurant = new Restaurant($name, $id, $cuisine_id, $description, $address);
     $test_restaurant->save();
     //Act
     $test_cuisine->delete();
     //Assert
     $this->assertEquals([], Restaurant::getAll());
 }
 public static function checkUserInsertData($field, $value)
 {
     if ($field == "id_cuisine") {
         if (Cuisine::checkCuisineID($value) == 0) {
             $json['status_code'] = 0;
             $json['status_message'] = "id cuisine couldn't be find!";
             echo json_encode($json);
             die;
         }
     } elseif ($field == "phone_no") {
         if (!is_numeric($value)) {
             $json['status_code'] = 0;
             $json['status_message'] = "Phone Number must be Nummer!";
             echo json_encode($json);
             die;
         }
     } elseif ($field == "latitude") {
         if (!self::checkLatitude($value)) {
             $json['status_code'] = 0;
             $json['status_message'] = "latitude must be Decimal!";
             echo json_encode($json);
             die;
         }
     } elseif ($field == "longitude") {
         if (!self::checklongitude($value)) {
             $json['status_code'] = 0;
             $json['status_message'] = "longitude must be Decimal!";
             echo json_encode($json);
             die;
         }
     } elseif ($field == "email") {
         if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
             $json['status_code'] = 0;
             $json['status_message'] = "Invalid email format";
             echo json_encode($json);
             die;
         }
     } elseif ($field == "birthday") {
         if (self::checkDateFormat($value) == false) {
             $json['status_code'] = 0;
             $json['status_message'] = "Birthday must be in yyyy-mm-dd format";
             echo json_encode($json);
             die;
         }
     }
 }
 function testUpdate()
 {
     //Arrange
     $flavor = "Pizza";
     $id = null;
     $test_cuisine = new Cuisine($flavor, $id);
     $name = "Pizza Party";
     $phone_number = "123-456-7890";
     $address = "1234 Pepperoni Lane";
     $cuisine_id = $test_cuisine->getId();
     $test_restaurant = new Restaurant($name, $phone_number, $address, $id, $cuisine_id);
     $test_restaurant->save();
     $new_name = "Burger Bash";
     //Act
     $test_restaurant->update($new_name);
     //Assert
     $this->assertEquals("Pizza", $test_cuisine->getFlavor());
 }
Ejemplo n.º 20
0
 function test_DeleteCuisineRestaurantsReviews()
 {
     //Arrange
     //cuisine
     $name = "Japanese";
     $id = null;
     $test_cuisine = new Cuisine($name, $id);
     $test_cuisine->save();
     //restaurant
     $name = "Good Fortune";
     $cuisine_id = $test_cuisine->getId();
     $description = "very tasty.";
     $address = "1111 SW 11th Ave";
     $test_restaurant = new Restaurant($name, $id, $cuisine_id, $description, $address);
     $test_restaurant->save();
     //review
     $username = "******";
     $date = 00 - 00 - 00;
     $rating = 5;
     $comment = "good one.";
     $restaurant_id = $test_restaurant->getId();
     $test_review = new Review($username, $date, $rating, $comment, $restaurant_id, $id);
     //Act
     $test_cuisine->delete();
     //Assert
     $this->assertEquals([], Review::getAll());
 }
Ejemplo n.º 21
0
 function testDeleteCuisineRestaurants()
 {
     //Arrange
     $flavor = "Pizza";
     $id = null;
     $test_cuisine = new Cuisine($flavor, $id);
     $test_cuisine->save();
     $name = "Pizza Party";
     $phone_number = "123-123-1234";
     $address = "1234 Pepporoni Lane";
     $cuisine_id = $test_cuisine->getId();
     $test_restaurant = new Restaurant($name, $phone_number, $address, $id, $cuisine_id);
     $test_restaurant->save();
     //Act
     $test_cuisine->delete();
     //Assert
     $this->assertEquals([], Restaurant::getAll());
 }
 public function searchResto()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     $search = isset($_GET['name']) ? addslashes($_GET['name']) : "";
     $lat = isset($_GET['latitude']) ? addslashes($_GET['latitude']) : "";
     if ($lat != "") {
         if (!Generic::checkLatitude($lat)) {
             Generic::errorMsg("Latitude must be Numeric!");
         }
     } else {
         Generic::errorMsg("Latitude is empty");
     }
     $long = isset($_GET['longitude']) ? addslashes($_GET['longitude']) : "";
     if ($long != "") {
         if (!Generic::checklongitude($long)) {
             Generic::errorMsg("Longitude must be Numeric!");
         }
     } else {
         Generic::errorMsg("Longitude is empty");
     }
     //
     $nearby = isset($_GET['nearby']) ? addslashes($_GET['nearby']) : 20;
     if ($nearby == '1') {
         $nearby = 20;
     } else {
         $nearby = 100000;
     }
     //        echo "near: " . $nearby;
     $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 = " AND CONVERT_TZ(NOW(),@@session.time_zone, '+00:00') >= (CONVERT_TZ(concat(CURRENT_DATE,' ',time_open),@@session.time_zone, '+00:00' )) AND CONVERT_TZ(NOW(),@@session.time_zone, '+00:00') < (CONVERT_TZ(concat(CURRENT_DATE,' ',time_close),@@session.time_zone, '+00:00' ))";
         //            CONVERT_TZ(NOW(),@@session.time_zone, '+00:00') >= (CONVERT_TZ(concat(CURRENT_DATE,' ',time_open),@@session.time_zone, '+00:00' )) AND CONVERT_TZ(NOW(),@@session.time_zone, '+00:00') < (CONVERT_TZ(concat(CURRENT_DATE,' ',time_close),@@session.time_zone, '+00:00' ))
         //            $whereOption = " AND (CURTIME() BETWEEN time_open AND time_close) ";
     }
     $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 name LIKE '%{$search}%' AND aktiv='1' AND show_in_apps='1'";
     if ($whereOption != "") {
         $where = $where . $whereOption;
     }
     foreach ($arrWhere as $key => $val) {
         $where = $where . " AND {$key}= '{$val}'";
     }
     foreach ($arrWhereOr as $key => $val) {
         $where = $where . " AND {$key} != '0'";
     }
     //        pr($where);
     //        die();
     $sort = " ORDER BY ";
     foreach ($arrSort as $key => $val) {
         if ($key == "distance") {
             $sort = $sort . " {$key} ASC,";
         } elseif ($key == "fav") {
             $sort = $sort . " {$key} DESC,";
         } elseif ($key == "houropen") {
             $sort = $sort . " {$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();
     $q = "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 . " LIMIT {$begin},{$limit}";
     //        echo $q;
     $arrResto = $db->query($q, 2);
     Generic::checkCountWithMsg($arrResto, "Can't find the Restaurant");
     $json['results']['restaurant'] = array();
     foreach ($arrResto as $resto) {
         $resto_help = User::getRestaurant($resto->id_restaurant);
         $resto_help['distance'] = $resto->distance;
         $sem[] = $resto_help;
     }
     $json['results']['restaurant'] = $sem;
     echo json_encode($json);
     die;
 }
Ejemplo n.º 23
0
 function test_cuisine_delete()
 {
     $style = "Thai";
     $test_cuisine = new Cuisine($style);
     $test_cuisine->save();
     $style2 = "burgers";
     $test_cuisine2 = new Cuisine($style2);
     $test_cuisine2->save();
     $name = "Pok Pok";
     $category_id = $test_cuisine->getId();
     $test_restaurant = new Restaurant($name, $category_id);
     $test_restaurant->save();
     $name2 = "Dicks";
     $category_id2 = $test_cuisine2->getId();
     $test_restaurant2 = new Restaurant($name2, $category_id2);
     $test_restaurant2->save();
     //Act
     $test_cuisine->delete();
     //Assert
     $this->assertEquals([$test_restaurant2], Restaurant::getAll());
 }
Ejemplo n.º 24
0
 function testGetRestaurants()
 {
     $type = "Thai";
     $id = null;
     $test_Cuisine = new Cuisine($type, $id);
     $test_Cuisine->save();
     $test_Restaurant = new Restaurant("Pok Pok", $id, "555-456-2345", "123 abcd street", "http://www.helloworld.com", $test_Cuisine->getId());
     $test_Restaurant->save();
     $test_Restaurant2 = new Restaurant("Whiskey Soda Lounge", $id, "555-555-5555", "678 DEF street", "http://www.pokpok.com", $test_Cuisine->getId());
     $test_Restaurant2->save();
     $result = $test_Cuisine->getRestaurants();
     $this->assertEquals([$test_Restaurant, $test_Restaurant2], $result);
 }
Ejemplo n.º 25
0
 function testDeleteCuisineRestaraunts()
 {
     //Arrange
     $cuisine_name = "Italian";
     $id = null;
     $test_cuisine = new Cuisine($cuisine_name, $id);
     $test_cuisine->save();
     $restaraunt_name = "Big Bubba/'s Tuscan Pizza";
     $cuisine_id = $test_cuisine->getId();
     $test_restaraunt = new Restaraunt($restaraunt_name, $id, $cuisine_id);
     $test_restaraunt->save();
     //Act
     $test_cuisine->delete();
     //Assert
     $this->assertEquals([], Restaraunt::getAll());
 }
Ejemplo n.º 26
0
    Cuisine::deleteAll();
    return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll(), 'cuisine_check' => false, 'venue_check' => false));
});
//Navigate to cuisine page
$app->get('/cuisines/{id}', function ($id) use($app) {
    $cuisine = Cuisine::find($id);
    return $app['twig']->render('cuisine.html.twig', array('cuisine' => $cuisine, 'venues' => $cuisine->getVenues()));
});
//Create a new venue
$app->post('/venues', function () use($app) {
    $name = $_POST['name'];
    $cuisine_id = $_POST['cuisine_id'];
    $description = $_POST['description'];
    $address = $_POST['address'];
    $rating = $_POST['rating'];
    $venue = new Venue($name, $cuisine_id, $id = null, $rating, $address, $description);
    $venue->save();
    $cuisine = Cuisine::find($cuisine_id);
    return $app['twig']->render('cuisine.html.twig', array('cuisine' => $cuisine, 'venues' => $cuisine->getVenues()));
});
// Delete a single venue from a cuisine
// $app->delete('/cuisine/{id}', function($id) use ($app) {
//     $venues = Venue::find($id);
//     foreach($venues as $venue) {
//         $venue
//     }
//     $venue->deleteVenue();
//     $cuisine = Cuisine::find($id);
//     return $app['twig']->render('cuisine.html.twig', array('cuisine' => $cuisine, 'venues' => $cuisine->getVenues()));
// });
return $app;
 function test_RestarauntDelete()
 {
     //Arrange
     $cuisine_name = "Italian";
     $id = null;
     $test_cuisine = new Cuisine($cuisine_name, $id);
     $test_cuisine->save();
     $restaraunt_name = "Mamas Home Country Cookin";
     $cuisine_id = $test_cuisine->getId();
     $test_restaraunt = new Restaraunt($restaraunt_name, $id, $cuisine_id);
     $test_restaraunt->save();
     $restaraunt_name2 = "Big Bobs Fried Alligator";
     $test_restaraunt2 = new Restaraunt($restaraunt_name2, $id, $cuisine_id);
     $test_restaraunt2->save();
     //Act
     $test_restaraunt->delete();
     //Assert
     $this->assertEquals([$test_restaraunt2], Restaraunt::getAll());
 }
Ejemplo n.º 28
0
    return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll()));
});
$app->get("/cuisines/{id}", function ($id) use($app) {
    $cuisine = Cuisine::find($id);
    return $app['twig']->render('cuisine.html.twig', array('cuisine' => $cuisine, 'restaurants' => $cuisine->getRestaurants()));
});
$app->post("/cuisines", function () use($app) {
    $cuisine = new Cuisine($_POST['name']);
    $cuisine->save();
    return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll()));
});
$app->post("/delete_cuisines", function () use($app) {
    Cuisine::deleteAll();
    return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll()));
});
$app->get("/cuisines/{id}/edit", function ($id) use($app) {
    $cuisine = Cuisine::find($id);
    return $app['twig']->render('cuisine_edit.html.twig', array('cuisine' => $cuisine));
});
$app->patch("/cuisines/{id}", function ($id) use($app) {
    $name = $_POST['name'];
    $cuisine = Cuisine::find($id);
    $cuisine->update($name);
    return $app['twig']->render('cuisine.html.twig', array('cuisine' => $cuisine, 'restaurants' => $cuisine->getRestaurants()));
});
$app->delete("/cuisines/{id}", function ($id) use($app) {
    $cuisine = Cuisine::find($id);
    $cuisine->delete();
    return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll()));
});
return $app;
Ejemplo n.º 29
0
 function test_delete()
 {
     //Arrange
     $test_cuisine = new Cuisine("american", false, 4);
     $test_cuisine->save();
     //Act
     $test_cuisine->delete();
     $result = Cuisine::getAll();
     //Assert
     $this->assertEquals([], $result);
 }
 function testUpdate()
 {
     //Arrange
     $type = "french";
     $id = null;
     $test_cuisine = new Cuisine($type, $id);
     $test_cuisine->save();
     $name = "Petit Provence";
     $phone = "555-555-5555";
     $price = "\$\$";
     $cuisine_id = $test_cuisine->getId();
     // $id = null;
     $test_restaurant = new Restaurant($name, $phone, $price, $cuisine_id);
     $test_restaurant->save();
     $new_name = "Escargot";
     $new_phone = "666-666-6666";
     $new_price = "\$\$\$";
     // $cuisine_id = 1;
     // $new_id = null;
     $new_test_restaurant = new Restaurant($new_name, $new_phone, $new_price, $cuisine_id, $test_restaurant->getId());
     // $new_test_restaurant->save();
     // var_dump($new_test_restaurant);
     //Act
     $test_restaurant->update($new_name, $new_phone, $new_price);
     //Assert
     $this->assertEquals($test_restaurant, $new_test_restaurant);
 }