public function run() { $row = 1; if (($handle = fopen(storage_path() . "/csvs/breweries.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle)) !== FALSE) { $zip = $data[6]; // echo $zip . PHP_EOL; try { // echo Location::where('postalCode',$zip)->toSql(); $loc = Location::where('postalCode', $zip)->firstOrFail(); $locId = $loc->locId; $brewery = new Brewery(); $brewery->brewery_id = $data[0]; $brewery->name = $data[1]; $brewery->address = $data[2]; $brewery->phone = $data[8]; $brewery->website = $data[9]; $brewery->description = $data[11]; $brewery->locId = $locId; $brewery->save(); } catch (Exception $e) { // echo $e->getMessage(); // throw $e; } } fclose($handle); } else { echo 'false?'; } }
public function validate_brewery_id() { $errors = array(); if (!is_integer($this->brewery_id) || !Brewery::find($this->brewery_id)) { $errors[] = "brewery does not exist"; } return $errors; }
static function find($search_id) { $found_brewery = null; $all_breweries = Brewery::getAll(); foreach ($all_breweries as $brewery) { if ($brewery->getId() == $search_id) { $found_brewery = $brewery; } } return $found_brewery; }
<select name ='style_id' class='form-control'> <?php $styles = Style::getAll(); foreach ($styles as $style) { echo "<option value={$style->id}>{$style->name}</option>"; } ?> </select> </td> </tr> <tr> <th>Brewery:</th> <td> <select name='brewery_id' class='form-control'> <?php $breweries = Brewery::getAll(); foreach ($breweries as $brewery) { echo "<option value={$brewery->id}>{$brewery->name}</option>"; } ?> </select> </td> </tr> <tr> <th>Rating:</th> <td> <?php for ($i = 0; $i <= 4; $i++) { echo "<div class='radio-inline'>"; echo "<input type='radio' name='rating' value='" . ($i + 1) . "'>" . ($i + 1); echo "</div>";
$beer = Beer::find($id); $pub->deleteBeer($beer); return $app['twig']->render('pub_profile.html.twig', array('pub' => $pub, 'beers' => $pub->getBeers())); }); //User signup form $app->get('/signup', function () use($app) { $app['twig']->addGlobal('logged_user', $_SESSION['user']); return $app['twig']->render('drunk_signup.html.twig'); }); //User signup posting and returning to main page (no auto-login) $app->post('/signup', function () use($app) { $app['twig']->addGlobal('logged_user', $_SESSION['user']); $all_beers = Beer::getAll(); $new_drunk = new Drunk($_POST['name'], $_POST['date_of_birth'], $_POST['location'], $_POST['email'], $_POST['password']); $new_drunk->save(); return $app['twig']->render('index.html.twig', array('search_validate' => [], 'all_beers' => $all_beers, 'all_breweries' => Brewery::getAll(), 'all_pubs' => Pub::getAll())); }); //Get user profile $app->get('/public_login/{id}', function ($id) use($app) { $app['twig']->addGlobal('logged_user', $_SESSION['user']); $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); }
<?php require '../session/check_user.php'; require_once '../../models/brewery.php'; if (isset($_GET['id'])) { $id = $_GET['id']; $brewery = new Brewery(); if ($brewery->delete($id)) { header('location: index.php'); die; } }
/** * Remove the specified brewery from storage. * * @param int $id * @return Response */ public function destroy($id) { Brewery::destroy($id); return Redirect::route('breweries.index'); }
<body> <div class="container"> <?php include '../menu_top.php'; ?> <h2>Update brewery</h2> <?php require_once "../../models/brewery.php"; if (isset($_POST['newName']) && isset($_POST['id'])) { $id = $_POST['id']; $newName = $_POST['newName']; if (empty($newName)) { echo "<br><div class='alert alert-info col-md-8'>Fill the name!</div>"; } else { $brewery = new Brewery(); if ($up = $brewery->update($id, $newName)) { header('Location: index.php'); die; } } } ?> <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'])) {
</head> <body> <div class="container"> <?php include '../menu_top.php'; ?> <h2>Add brewery</h2> <?php require_once "../../models/brewery.php"; if (isset($_POST['name'])) { $name = $_POST['name']; if (empty($name)) { echo "<br><div class='alert alert-info col-md-8'>Fill the name!</div>"; } else { $brewery = new Brewery(); if ($brewery->insert($name)) { header('location: index.php'); die; } } } ?> <form action='', method='POST'> <div class="col-md-8"> <table class="table table-striped"> <tr> <th>Name:</th> <td><input type='text', name='name', class='form-control'></td> </tr> </table>
public static function edit_vars(&$vars, $id) { $vars['brewery'] = Brewery::find($vars['val']->brewery_id); $vars['styles'] = Style::all(); }
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); }
<h2>Breweries index</h2> <?php require_once "../../models/brewery.php"; ?> <h3><a href="add.php">Add new brewery</a></h3> <div class="col-md-8"> <table class="table table-striped"> <tr> <th>ID</th> <th>Name</th> <th>Beers</th> <th>Actions</th> </tr> <?php $breweries = Brewery::getAll(); foreach ($breweries as $brewery) { $beers = Brewery::getBeers($brewery->id); echo "<tr>"; echo "<td>{$brewery->id}</td>"; echo "<td>{$brewery->name}</td>"; echo "<td>" . count($beers) . "</td>"; echo "<td>\n\t\t\t\t\t\t\t\t\t<form action='update.php?id={$brewery->id}' method='POST'>\n\t\t\t\t\t\t\t\t\t\t<input type='hidden' name='name' value=\"{$brewery->name}\">\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={$brewery->id}' class='btn btn-danger'>Delete</a>\n\t\t\t\t\t\t\t \t</td>"; echo "</tr>"; } ?> </table> </div> </div> </body> </html>
<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(); ?> </body> </html>
public function index() { $this->render("index", Brewery::findAll()); }