public function run()
 {
     $row = 1;
     $desc = 'The colt 45 ruminates, or the change toward a Coors bestows great honor upon the most difficult steam engine. Any bar stool can graduate from the colt 45 over the lover, but it takes a real Yuengling to plan an escape from the porter living with the Honey Brown a ridiculously flatulent bar tab. For example, a Busch defined by a line dancer indicates that a Red Stripe avoids contact with a Honey Brown for an ESB. A bar tab hesitates, and the precise crank case laughs out loud; however, the corona light assimilates a Left Hand Milk Stout.';
     if (($handle = fopen(storage_path() . "/csvs/beers.csv", "r")) !== FALSE) {
         while (($data = fgetcsv($handle)) !== FALSE) {
             try {
                 $row++;
                 $image = $row % 10;
                 $image++;
                 $beer = new Beer();
                 // $beer->beer_id = $data[0];
                 $beer->brewery_id = $data[1];
                 $beer->name = $data[2];
                 $beer->category_id = $data[3];
                 $beer->style_id = $data[4];
                 $beer->abv = $data[5];
                 $beer->ibu = $data[6];
                 $beer->upc = $data[8];
                 $beer->image = "category{$image}.jpeg";
                 $beer->description = $data[10] == false ? $desc : $data[10];
                 $beer->save();
             } catch (Exception $e) {
             }
         }
         fclose($handle);
     }
 }
 function GetById($id)
 {
     $sql = "SELECT * FROM beers WHERE id = {$id}";
     $qry = mysql_query($sql);
     if ($i = mysql_fetch_array($qry)) {
         $beer = new Beer();
         $beer->setFromArray($i);
         return $beer;
     }
     return null;
 }
 public static function show_vars(&$vars, $id)
 {
     $vars['ratings'] = array();
     foreach (Rating::find_by('user_id', $id) as $k => $v) {
         $vars['ratings'][] = array('rating' => $v, 'beer' => Beer::find($v->beer_id));
     }
 }
Example #4
0
 public function validate_beer_id()
 {
     $errors = array();
     if (!is_integer($this->beer_id) || !Beer::find($this->beer_id)) {
         $errors[] = "beer does not exist";
     }
     return $errors;
 }
Example #5
0
    $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
 public static function show_vars(&$vars, $id)
 {
     $vars['beers'] = Beer::find_by('brewery_id', $id);
 }
Example #7
0
 function test_findByName()
 {
     //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();
     $id = null;
     $name = "Hip Hops";
     $type = "Pale Ale";
     $abv = 3.2;
     $ibu = 4;
     $region = "South Central LA";
     $brewery_id = 2;
     $test_beer2 = new Beer($id, $name, $type, $abv, $ibu, $region, $brewery_id);
     $test_beer2->save();
     //Act
     $result = Beer::findByName($test_beer->getName());
     //Assert
     $this->assertEquals($test_beer, $result);
 }
Example #8
0
 function testDeleteAllBeers()
 {
     //Arrange
     $name = "Person 1";
     $date_of_birth = "1988-03-04";
     $location = "Portland, OR";
     $email = "*****@*****.**";
     $id = 1;
     $password = "******";
     $test_drunk = new Drunk($name, $date_of_birth, $location, $email, $password, $id);
     $test_drunk->save();
     $id2 = null;
     $name2 = "Lip Blaster";
     $type = "IPA";
     $abv = 4.2;
     $ibu = 10;
     $region = "Pacific Northwest";
     $brewery_id = 1;
     $test_beer = new Beer($id2, $name2, $type, $abv, $ibu, $region, $brewery_id);
     $test_beer->save();
     $id3 = null;
     $name3 = "Lip Blaster";
     $type3 = "IPA";
     $abv3 = 4.2;
     $ibu3 = 10;
     $region3 = "Pacific Northwest";
     $brewery_id3 = 1;
     $test_beer2 = new Beer($id3, $name3, $type3, $abv3, $ibu3, $region3, $brewery_id3);
     //Act
     $test_drunk->addBeer($test_beer);
     $test_drunk->addBeer($test_beer2);
     $test_drunk->deleteAllBeers();
     //Assert
     $result = $test_drunk->getBeers();
     $this->assertEquals([], $result);
 }
Example #9
0
 public function showBeer($id)
 {
     return View::make('frontend.beer', ['beer' => Beer::find($id)]);
 }
Example #10
0
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php 
require_once 'Beer.php';
require_once 'Brewery.php';
$beers = Beer::getAllBeer();
foreach ($beers as $beer) {
    /**
     *
     * @var \Beer 
     */
    $beer;
    echo $beer->getName() . " " . $beer->getBreweryId() . "<br>\n";
}
$breweries = Brewery::getAllBrewery();
foreach ($breweries as $brewery) {
    /**
     *
     * @var \Brewery 
     */
    $brewery;
    echo $brewery->getName() . "<br>\n";
}
$brwry = Brewery::getBrewery(1);
echo $brwry->getName();
?>
Example #11
0
 function test_deleteBeer()
 {
     //Arrange
     $name = "Yards Brewing Co.";
     $location = "Philthadone";
     $link = "www.makebeer.com";
     $test_brewery = new Brewery($name, $location, $link);
     $test_brewery->save();
     $id = null;
     $name = "Lip Blaster";
     $type = "IPA";
     $abv = 4.2;
     $ibu = 10;
     $region = "Pacific Northwest";
     $brewery_id = $test_brewery->getId();
     $test_beer = new Beer($id, $name, $type, $abv, $ibu, $region, $brewery_id);
     $test_beer->save();
     $name = "Hip Hops";
     $type = "Pale Ale";
     $abv = 3.2;
     $ibu = 4;
     $region = "South Central LA";
     $brewery_id = $test_brewery->getId();
     $test_beer2 = new Beer($id, $name, $type, $abv, $ibu, $region, $brewery_id);
     $test_beer2->save();
     //Act
     $test_brewery->deleteBeer($test_beer);
     //Assert
     $result = $test_brewery->getBeers();
     $this->assertEquals([$test_beer2], $result);
 }
 public static function create_vars(&$vars)
 {
     $vars['beers'] = Beer::all();
 }
Example #13
0
 function test_deleteAllBeers()
 {
     //Arrange
     $name = "Paddys";
     $location = "462 Over There Way";
     $link = "www.paddyspub.com";
     $test_pub = new Pub($name, $location, $link);
     $test_pub->save();
     $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();
     $id = null;
     $name = "Hip Hops";
     $type = "Pale Ale";
     $abv = 3.2;
     $ibu = 4;
     $region = "South Central LA";
     $brewery_id = 2;
     $test_beer2 = new Beer($id, $name, $type, $abv, $ibu, $region, $brewery_id);
     $test_beer2->save();
     $test_pub->addBeer($test_beer);
     $test_pub->addBeer($test_beer2);
     //Act
     $test_pub->deleteAllBeers();
     //Assert
     $result = $test_pub->getBeers();
     $this->assertEquals([], $result);
 }
Example #14
0
 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;
 }
Example #15
0
<?php

require '../session/check_user.php';
require_once '../../models/beer.php';
if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $beer = new Beer();
    if ($beer->delete($id)) {
        header('location: index.php');
    }
}
Example #16
0
 public function showHome()
 {
     $beer = Beer::find(Configuration::where('name', '=', 'beer_id')->orderBy('id', 'desc')->first()->value);
     return View::make('home')->with(['beer' => $beer]);
 }
Example #17
0
			<table class="table table-striped">
				<tr>
					<th>Id</th>
					<th>Name</th>
					<th>Description</th>
					<th>Style</th>
					<th>Brewery</th>
					<th>Rating</th>
					<th>Photo</th>
					<th>Actions</th>
				</tr>
				<?php 
$beers = Beer::getAll();
foreach ($beers as $beer) {
    $brewery = Beer::getBrewery($beer->brewery_id);
    $style = Beer::getStyle($beer->style_id);
    echo "<tr>";
    echo "<td>{$beer->id}</td>";
    echo "<td>{$beer->name}</td>";
    echo "<td>{$beer->description}</td>";
    echo "<td>{$style->name}</td>";
    echo "<td>{$brewery->name}</td>";
    echo "<td>{$beer->rating}</td>";
    echo "<td><img height='150' width='100' src='../../uploads/" . $beer->photo_url . "'</img></td>";
    echo "<td>\n\t\t\t\t\t\t\t\t\t<form action='update.php?id={$beer->id}' method='POST'>\n\t\t\t\t\t\t\t\t\t\t<input type='hidden' name='name' value=\"{$beer->name}\">\n\t\t\t\t\t\t\t\t\t\t<input type='hidden' name='description' value=\"{$beer->description}\">\n\t\t\t\t\t\t\t\t\t\t<input type='hidden' name='style_id' value=\"{$beer->style_id}\">\n\t\t\t\t\t\t\t\t\t\t<input type='hidden' name='brewery_id' value=\"{$beer->brewery_id}\">\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t<input type='hidden' name='rating' value=\"{$beer->rating}\">\n\t\t\t\t\t\t\t\t\t\t<input type='submit' value='Edit' class='btn btn-warning'>\n\t\t\t\t\t\t\t\t\t</form>\n\t\t\t\t\t\t \t\t\t<a href='delete.php?id={$beer->id}' class='btn btn-danger'>Delete</a>\n\t\t\t\t\t\t\t \t</td>";
    echo "</tr>";
}
?>
			</table>
		</div>
	</div>	
Example #18
0
 function testfindBeerStyle()
 {
     $user_name = "Barack Obama";
     $preferred_style = "Belgian";
     $region = "Northwest";
     $id = 1;
     $test_user = new User($user_name, $preferred_style, $region, $id);
     $test_user->save();
     $id = 1;
     $beer_name = "Fat Tire";
     $style = "Belgian";
     $abv = 6.12;
     $ibu = 40;
     $container = "Bottle";
     $brewery = "New Belgium";
     $test_beer = new Beer($beer_name, $style, $abv, $ibu, $container, $brewery, $id);
     $test_beer->save();
     $test_beer_id = $test_beer->getId();
     $id = 2;
     $beer_name = "Golden Shower";
     $style = "Belgian";
     $abv = 6.5;
     $ibu = 10;
     $container = "Bottle";
     $brewery = "New Belgium";
     $image = "../img/test.jpg";
     $test_beer2 = new Beer($beer_name, $style, $abv, $ibu, $container, $brewery, $image);
     $test_beer2->save();
     //Act
     $test_user->addBeer($test_beer_id);
     $preferred_style = $test_user->getPreferredStyle();
     $user_id = $test_user->getId();
     $result = User::findBeerStyle($user_id, $preferred_style);
     //Assert
     $this->assertEquals([$test_beer2], $result);
 }
 public function getBeerByIdAjax($id)
 {
     return Response::json(Beer::find($id));
 }
Example #20
0
 function testDelete()
 {
     //Arrange
     $beer_name = "Your mom";
     $style = "IPA";
     $abv = 4;
     $ibu = 6;
     $container = "bottle";
     $brewery = "daddy";
     $id = 1;
     $image = "../img/test.jpg";
     $test_beer = new Beer($beer_name, $style, $abv, $ibu, $container, $brewery, $image, $id);
     $test_beer->save();
     $user_name = "Wings";
     $preferred_style = "IPA";
     $region = "NW";
     $id2 = 2;
     $test_user = new User($user_name, $preferred_style, $region, $id2);
     $test_user->save();
     //Act
     $test_beer->addUser($test_user->getId());
     $test_beer->delete();
     //Assert
     $this->assertEquals([], $test_user->getBeers());
 }
Example #21
0
 public function beerLocation($id)
 {
     $beer = Beer::find($id);
     if (!$beer) {
         return Response::json(['status' => 0]);
     }
     $locality = $beer->brewer->first()->locality;
     return Response::json(['status' => 1, 'point' => ['lat' => $locality->latitude, 'lng' => $locality->longitude, 'name' => $beer->name]]);
 }
Example #22
0
require_once __DIR__ . '/includes/models/beer.php';
require_once __DIR__ . '/includes/managers/beer_manager.php';
require_once __DIR__ . '/includes/managers/beerStyle_manager.php';
$htmlHelper = new HtmlHelper();
$beerManager = new BeerManager();
$beerStyleManager = new BeerStyleManager();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $beer = new Beer();
    $beer->setFromArray($_POST);
    $beerManager->Save($beer);
    redirect('beer_list.php');
}
if (isset($_GET['id'])) {
    $beer = $beerManager->GetById($_GET['id']);
} else {
    $beer = new Beer();
}
$beerStyleList = $beerStyleManager->GetAll();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>RaspberryPints</title>
<link href="styles/layout.css" rel="stylesheet" type="text/css" />
<link href="styles/wysiwyg.css" rel="stylesheet" type="text/css" />
	<!-- Theme Start -->
<link href="styles.css" rel="stylesheet" type="text/css" />
	<!-- Theme End -->
<link href='http://fonts.googleapis.com/css?family=Fredoka+One' rel='stylesheet' type='text/css'>
Example #23
0
 function testDelete()
 {
     //Arrange
     $store_name = "Chill N Fill";
     $id = 1;
     $category = "bar";
     $region = "North Portland";
     $address = "5215 N Lombard Portland, OR 97203";
     $test_store = new Store($store_name, $category, $region, $address);
     $test_store->save();
     $beer_name = "Bike Beer";
     $style = "Kolsch";
     $abv = 5.6;
     $ibu = 50;
     $container = "Growler";
     $brewery = "Hopworks";
     $id = 1;
     $image = "../img/test.jpg";
     $test_beer = new Beer($beer_name, $style, $abv, $ibu, $container, $brewery, $image, $id);
     $test_beer->save();
     //Act
     $test_store->addBeer($test_beer->getId());
     $test_store->delete();
     //Assert
     $this->assertEquals([], $test_beer->getStores());
 }
Example #24
0
$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;
Example #25
0
        echo "</div><div class='row'>";
    }
    $row++;
}
?>
		</div>
	</ul>

	<div class='row'>
		<?php 
$beers = Beer::getAll();
if (isset($_GET['style'])) {
    $beers = Beer::getByStyle($_GET['style']);
}
$row = 1;
foreach ($beers as $beer) {
    $style = Beer::getStyle($beer->style_id);
    $brewery = Beer::getBrewery($beer->brewery_id);
    echo "<div class='col-md-4'>\n\t\t\t\t\t\t<div class='thumbnail'>\n\t\t\t\t\t\t\t<img class='img-thumbnail' height='600' src='uploads/{$beer->photo_url}' width='450'/>\n\t\t\t\t\t\t\t<div class='caption'>\n\t\t\t\t\t\t\t\t<h3>{$beer->name}</h3>\n\t\t\t\t\t\t\t\t<h4>{$style->name} from {$brewery->name}</h4>\n\t\t\t\t\t\t\t\t<p>Rating: ";
    for ($i = 0; $i < $beer->rating; $i++) {
        echo "<img src='assets/images/rate_star.png' height='20' width='20'/>";
    }
    echo "</p>\n\t\t\t\t\t\t\t\t<p>{$beer->description}</p>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>";
    if ($row % 3 == 0) {
        echo "</div><div class='row'>";
    }
    $row++;
}
?>
	</div>
</div>
Example #26
0
		<h2>Update beer</h2>
		<?php 
require_once '../../models/beer.php';
require_once '../../models/style.php';
require_once '../../models/brewery.php';
if (isset($_POST['id']) && isset($_POST['newName']) && isset($_POST['description']) && isset($_POST['style_id']) && isset($_POST['brewery_id']) && isset($_POST['rating'])) {
    $id = $_POST['id'];
    $name = $_POST['newName'];
    $description = $_POST['description'];
    $style = $_POST['style_id'];
    $brewery = $_POST['brewery_id'];
    $rating = $_POST['rating'];
    if (empty($name) || empty($description) || empty($style) || empty($brewery) || empty($rating)) {
        echo "<br><div class='alert alert-info col-md-8'>All fields are required!</div>";
    } else {
        $beer = new Beer();
        if ($beer->update($id, $name, $style, $description, $rating, $brewery)) {
            header('location: index.php');
        }
    }
}
?>
		
		<form id='new-style-form' action='', method='POST'>
			<div class="col-md-8">
				<table class="table table-striped">
					<tr>
						<th>Name:</th>
						<td>
							<input type='text' name='newName' value="<?php 
if (isset($_POST['name'])) {
Example #27
0
 /**
  * Remove the specified resource from storage.
  * DELETE /beer/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $beer = Beer::find($id);
     foreach (Image::where('beer_id', $id) as $img) {
         $img->delete();
     }
     foreach ($beer->image as $image) {
         $image->delete();
     }
     foreach (Sticker::where('beer_id', $id) as $sticker) {
         $sticker->delete();
     }
     $beer->brewer()->sync([]);
     $beer->delete();
     return Redirect::to('/dashboard/beers');
 }
Example #28
0
    $name = $_POST['name'];
    $description = $_POST['description'];
    $style = $_POST['style_id'];
    $brewery = $_POST['brewery_id'];
    $rating = $_POST['rating'];
    $photo_name = $_FILES['photo']['name'];
    $photo_tmp = $_FILES['photo']['tmp_name'];
    $check = getimagesize($_FILES["photo"]["tmp_name"]);
    if ($check == false) {
        echo "<br><div class='alert alert-info col-md-8'>File is not an image!</div>";
    } else {
        if (empty($name) || empty($description) || empty($style) || empty($brewery) || empty($rating)) {
            echo "<br><div class='alert alert-info col-md-8'>All fields are required!</div>";
        } else {
            move_uploaded_file($photo_tmp, '../../uploads/' . $photo_name);
            $beer = new Beer();
            if ($beer->insert($name, $style, $description, $rating, $brewery, $photo_name)) {
                header('location: index.php');
            }
        }
    }
} else {
    echo "<div class='well'>Fill all fields</div>";
}
?>
		<form id='new-style-form' action='', method='POST' enctype="multipart/form-data">
			<div class="col-md-8">
				<table class="table table-striped">
					<tr>
						<th>Name:</th>
						<td><input type='text', name='name', class='form-control'></td>
Example #29
0
 public function index()
 {
     $this->render("index", Beer::findAll());
 }