$app->get('/add_brew', function () use($app) { $app['twig']->addGlobal('logged_user', $_SESSION['user']); $all_beers = Beer::getAll(); $all_pubs = Pub::getAll(); return $app['twig']->render("brew.html.twig", array('all_beers' => $all_beers, 'all_pubs' => $all_pubs)); }); //route posts a brew to a profile page $app->post('/public_login/{id}', function ($id) use($app) { $app['twig']->addGlobal('logged_user', $_SESSION['user']); $new_brew = new Brew($_POST['beer_id'], $_POST['drunk_id'], $_POST['pub_id'], $_POST['rating'], $_POST['date']); $new_brew->save(); $drunk = Drunk::find($id); $drunk_brews = $drunk->getBrews(); $brews = array(); foreach ($drunk_brews as $brew) { $beer = Beer::find($brew->getBeerId()); $beer_name = $beer->getName(); $pub = Pub::find($brew->getPubId()); $pub_name = $pub->getName(); $brew_info = array('beer_name' => $beer_name, 'pub_name' => $pub_name, 'beer_rating' => $brew->getBeerRating(), 'brew_date' => $brew->getBrewDate()); array_push($brews, $brew_info); } return $app['twig']->render("drunk_profile.html.twig", array('drunk' => $drunk, 'brews' => $brews)); }); //Display all beers $app->get('/beers', function () use($app) { $app['twig']->addGlobal('logged_user', $_SESSION['user']); $beers = Beer::getAll(); return $app['twig']->render("beers.html.twig", array("beers" => $beers)); }); return $app;
static function findByName($beer_name) { $found_beer = null; $beers = Beer::getAll(); foreach ($beers as $beer) { if ($beer->getName() == $beer_name) { $found_beer = $beer; } } return $found_beer; }
//find store //show store $app->get("/{user_id}/store/{store_id}", function ($user_id, $store_id) use($app) { $user = User::find("id", $user_id); $store = Store::find("id", $store_id); return $app['twig']->render('store.html.twig', array('store' => $store[0], 'user' => $user[0], 'beers' => $store[0]->getBeers(), 'all_beers' => Beer::getAll())); }); //from store //add beer to store //show store $app->post("/{user_id}/store/{store_id}", function ($user_id, $store_id) use($app) { $store = Store::find("id", $store_id); $beer = Beer::find("id", $_POST['beer_id']); $store[0]->addBeer($beer[0]->getId()); $user = User::find("id", $user_id); return $app['twig']->render('store.html.twig', array('store' => $store[0], 'user' => $user[0], 'beers' => $store[0]->getBeers(), 'all_beers' => Beer::getAll())); }); //--------------------------------------------- Begin Review Functionality ---------------------------------------- $app->get("/{user_id}/review/{beer_id}", function ($user_id, $beer_id) use($app) { $user = User::find("id", $user_id); $beer = Beer::find("id", $beer_id); return $app['twig']->render('review.html.twig', array('user' => $user[0], 'beer' => $beer[0])); }); $app->post("/{user_id}/review/{beer_id}", function ($user_id, $beer_id) use($app) { $user = User::find("id", $user_id); $review = Review::findReview($beer_id, $user_id); $review[0]->update($_POST['beer_review'], $_POST['review_date']); $reviews = Review::find("user_id", $user[0]->getId()); $new_beers = User::findBeerStyle($user[0]->getId(), $user[0]->getPreferredStyle()); $local_stores = Store::find("region", $user[0]->getRegion()); return $app['twig']->render('profile.html.twig', array('user' => $user[0], 'reviews' => $reviews, 'new_beers' => $new_beers, 'local_stores' => $local_stores));
function test_deleteAll() { //arrange $beer_name = "Your mom"; $style = "IPA"; $abv = 4; $ibu = 6; $container = "bottle"; $brewery = "daddy"; $image = "../img/test.jpg"; $test_beer = new Beer($beer_name, $style, $abv, $ibu, $container, $brewery, $image); $test_beer->save(); $beer_name2 = "Your mom2"; $style2 = "IPA2"; $abv2 = 12; $ibu2 = 7; $container2 = "bottle2"; $brewery2 = "daddy2"; $image2 = "../img/test2.jpg"; $test_beer2 = new Beer($beer_name2, $style2, $abv2, $ibu2, $container2, $brewery2, $image2); $test_beer2->save(); //Act Beer::deleteAll(); //Assert $result = Beer::getAll(); $this->assertEquals([], $result); }
function testDeleteBeer() { //Arrange $id = null; $name = "Lip Blaster"; $type = "IPA"; $abv = 4.2; $ibu = 10; $region = "Pacific Northwest"; $brewery_id = 1; $test_beer = new Beer($id, $name, $type, $abv, $ibu, $region, $brewery_id); $test_beer->save(); $new_name = "Hip Hops"; $new_type = "Pale Ale"; $new_abv = 3.2; $new_ibu = 4; $new_region = "South Central LA"; $new_brewery_id = 2; $test_beer2 = new Beer($id, $name, $type, $abv, $ibu, $region, $brewery_id); $test_beer2->save(); //Act $test_beer->delete(); //Assert $result = Beer::getAll(); $this->assertEquals([$test_beer2], $result); }