function addUser($user_id) { if (Review::findReview($this->getId(), $user_id) == false) { $GLOBALS['DB']->exec("INSERT INTO reviews (beer_id, user_id) VALUES ({$this->getId()}, {$user_id});"); } }
function addBeer($beer) { $user_id = $this->getId(); if (Review::findReview($beer, $user_id) == false) { $GLOBALS['DB']->exec("INSERT INTO reviews (beer_id, user_id) VALUES ({$beer}, {$this->getId()});"); } }
function test_findReview() { //Arrange $beer_id = 1; $user_id = 1; $review = "Great beer"; $date = "2015-10-08"; $id = 3; $test_review = new Review($beer_id, $user_id, $review, $date, $id); $test_review->save(); $beer_id = 2; $user_id = 2; $review = "Bad beer"; $date = "2015-10-09"; $id = 3; $test_review2 = new Review($beer_id, $user_id, $review, $date, $id); $test_review2->save(); //Act $search_beer_id = $test_review2->getBeerId(); $search_user_id = $test_review2->getUserId(); $result = Review::findReview($search_beer_id, $search_user_id); //Assert $this->assertEquals([$test_review2], $result); }
$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)); }); return $app; //End of app, do not code below here