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);
     }
 }
Beispiel #2
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());
 }
Beispiel #3
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);
 }
Beispiel #4
0
    $user = User::find("id", $user_id);
    $user[0]->updateUserName($_POST['user_name']);
    $user[0]->updatePreferredStyle($_POST['preferred_style']);
    $user[0]->updateRegion($_POST['region']);
    $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));
});
//------------------------------- Begin Beer Functionality -----------------------------------
//from beers
//add and save new beer
//show all beers
$app->post("/{user_id}/beers", function ($user_id) use($app) {
    $beer = new Beer($_POST['beer_name'], $_POST['style'], $_POST['abv'], $_POST['ibu'], $_POST['container'], $_POST['brewery'], $_POST['image']);
    $beer->save();
    $user = User::find("id", $user_id);
    return $app['twig']->render('beers.html.twig', array('all_beers' => Beer::getAll(), 'user' => $user[0]));
});
//from profile
//show all beers
$app->get("/{user_id}/beers", function ($user_id) use($app) {
    $user = User::find("id", $user_id);
    return $app['twig']->render('beers.html.twig', array('all_beers' => Beer::getAll(), 'user' => $user[0]));
});
//from beer
//add store to beer
//show updated beer
$app->post("/{user_id}/beer/{beer_id}", function ($user_id, $beer_id) use($app) {
    $beer = Beer::find("id", $beer_id);
    $beer[0]->addStore($_POST['store_id']);
Beispiel #5
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);
 }
Beispiel #6
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);
 }
Beispiel #7
0
 /**
  * Store a newly created resource in storage.
  * POST /beer
  *
  * @return Response
  */
 public function store()
 {
     if (Input::get('beer_id')) {
         $beer = Beer::find(Input::get('beer_id'));
         echo "already in db beer";
     } else {
         $beer = new Beer();
         echo "new beer!";
     }
     $brewers = [];
     for ($i = 1; $i <= Input::get('brewer-count'); $i++) {
         $brewer = Brewer::find(Input::get('brewer-' . $i . '_id'));
         if (!$brewer) {
             return Redirect::back()->withInput()->withMessage('Invalid Brewer ' . $i);
         }
         $brewers[] = $brewer->id;
     }
     $style = Style::find(Input::get('style_id'));
     if (!$style) {
         return Redirect::back()->withInput()->withMessage('Invalid Style');
     }
     $beer->name = Input::get('name');
     //$beer->brewer_id = $brewer->id;
     $beer->style_id = $style->id;
     $beer->ratebeer = Input::get('ratebeer_url');
     $beer->beeradvocate = Input::get('beeradvocate_url');
     $beer->album = Input::get('album');
     $beer->page = Input::get('page');
     $beer->position = Input::get('position');
     $beer->save();
     $beer->brewer()->sync($brewers);
     for ($i = 1; $i <= Input::get('sticker-count'); $i++) {
         if (Input::hasFile('sticker-' . $i)) {
             $f = Input::file('sticker-' . $i);
             //Change the image name: s<number_of_service>-<filename>.
             $filename = 'beerr-' . $beer->id . '-' . $f->getClientOriginalName();
             //Move it to our public folder
             $f->move(public_path() . '/upload/', $filename);
             //This is the path to show it on the web
             $complete_path = '/upload/' . $filename;
             //create the gallery
             $image = array('path' => $complete_path, 'brewer_id' => NULL, 'beer_id' => $beer->id);
             $img = Image::create($image);
             if (Input::get('sticker-' . $i . '_id') != null) {
                 $sticker = Sticker::find(Input::get('sticker-' . $i . '_id'));
                 $sticker->img_id = $img->id;
                 $sticker->type = "front";
                 //Input::get('sticker-'.$i.'_type');
                 $sticker->save();
             } else {
                 $sticker = Sticker::create(['beer_id' => $beer->id, 'image_id' => $img->id, 'type' => "front"]);
             }
             echo "Sticker created " . $sticker->id;
         } else {
             if (Input::file('sticker-' . $i)->isValid()) {
                 echo "IS F****N VALID";
             } else {
                 echo "IS F****N INVALID";
             }
             echo 'sticker-' . $i . " has no file";
             echo "<pre>" . print_r(Input::all(), 1) . "</pre>";
             exit;
         }
     }
     return Redirect::to('dashboard/beers');
 }
Beispiel #8
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());
 }
Beispiel #9
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);
 }
Beispiel #10
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);
 }