Skip to content

Commit

Permalink
Added more visibility into what you've had and what's in your fridge …
Browse files Browse the repository at this point in the history
…when looking at breweries or others' fridges.
  • Loading branch information
cnthompson committed Aug 30, 2012
1 parent 98a131a commit 261e311
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions application/controllers/beer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public function info( $brewery = 0, $beer = 0 ) {
redirect( 'beer/info/' );
} else {
$data[ 'brewery' ] = $breweries[ 0 ];
$data[ 'beers' ] = $this->beers_model->getBeers( $brewery );
$data[ 'beers' ] = $this->beers_model->getBeers( $brewery, (int)$this->authenticator->get_user_id() );
$header[ 'title' ] = 'Brewery Profile - ' . $data[ 'brewery' ][ 'name' ];
$this->load->view( 'templates/header.php', $header );
$this->load->view( 'pages/brewer_profile', $data );
$this->load->view( 'templates/footer.php', null );
}
} else {
$breweries = $this->breweries_model->getBreweries( $brewery );
$beers = $this->beers_model->getBeers( $brewery, $beer );
$beers = $this->beers_model->getBeers( $brewery, (int)$this->authenticator->get_user_id(), $beer );
if( count( $breweries ) == 0 ) {
redirect( 'beer/info/' );
} else if( count( $beers ) == 0 ) {
Expand Down
14 changes: 7 additions & 7 deletions application/controllers/log.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function beer( $id = 0, $extra = '' ) {
$data[ 'editBeer' ] = null;

if( $id > 0 and $extra == '' ) {
$editBeers = $this->beers_model->getBeers( 0, $id );
$editBeers = $this->beers_model->getBeers( 0, (int)$this->authenticator->get_user_id(), $id );
if( count( $editBeers ) == 1 ) {
$editBrewer = $this->breweries_model->getBreweries( $editBeers[ 0 ][ 'brewery_id' ], false );
if( count( $editBrewer ) == 1 ) {
Expand Down Expand Up @@ -295,7 +295,7 @@ function drink( $id = 0, $extra = '' ) {
redirect( 'log/drink' );
}
} else if( $extra == 'd' ) {
$beers = $this->beers_model->getBeers( 0, $id );
$beers = $this->beers_model->getBeers( 0, (int)$this->authenticator->get_user_id(), $id );
if( count( $beers ) == 1 ) {
$data[ 'editDrink' ][ 'id' ] = -1;
$data[ 'editDrink' ][ 'date' ] = date( 'Y-m-d' );
Expand All @@ -314,7 +314,7 @@ function drink( $id = 0, $extra = '' ) {
$data[ 'brew2beerMap' ][ $brewery[ 'brewery_id' ] ] = array();
}

$allBeers = $this->beers_model->getBeers( 0 );
$allBeers = $this->beers_model->getBeers( 0, (int)$this->authenticator->get_user_id() );
foreach( $allBeers as $beer ) {
$data[ 'brew2beerMap' ][ $beer[ 'brewery_id' ] ][ $beer[ 'beer_id' ] ] = $beer[ 'beer_name' ];
}
Expand Down Expand Up @@ -371,7 +371,7 @@ function checkDate( $date ) {

function checkBeer( $beer ) {
$this->authenticator->ensure_auth( $this->uri->uri_string() );
$res = $this->beers_model->getBeers( 0, $beer );
$res = $this->beers_model->getBeers( 0, (int)$this->authenticator->get_user_id(), $beer );
if( count( $res ) == 0 ) {
$this->form_validation->set_message( 'checkBeer', 'Your beer selection is invalid.' );
return FALSE;
Expand Down Expand Up @@ -458,7 +458,7 @@ function scratch( $id = 0, $extra = '' ) {
}

$data[ 'editDrink' ][ 'beer_id' ] = -1;
$allBeers = $this->beers_model->getBeers( 0 );
$allBeers = $this->beers_model->getBeers( 0, (int)$this->authenticator->get_user_id() );
foreach( $allBeers as $beer ) {
$data[ 'brew2beerMap' ][ $beer[ 'brewery_id' ] ][ $beer[ 'beer_id' ] ] = $beer[ 'beer_name' ];
if( ( $data[ 'editDrink' ][ 'brewery' ] == $beer[ 'brewery_id' ] )
Expand Down Expand Up @@ -552,7 +552,7 @@ function fridge( $id = 0, $extra = '' ) {
$data[ 'extra' ] = $extra;

if( $extra == 'a' ) {
$beers = $this->beers_model->getBeers( 0, $id );
$beers = $this->beers_model->getBeers( 0, (int)$this->authenticator->get_user_id(), $id );
if( count( $beers ) != 1 ) {
redirect( 'users/fridge/' );
}
Expand Down Expand Up @@ -584,7 +584,7 @@ function fridge( $id = 0, $extra = '' ) {
$data[ 'brew2beerMap' ][ $brewery[ 'brewery_id' ] ] = array();
}

$allBeers = $this->beers_model->getBeers( 0 );
$allBeers = $this->beers_model->getBeers( 0, (int)$this->authenticator->get_user_id() );
foreach( $allBeers as $beer ) {
$data[ 'brew2beerMap' ][ $beer[ 'brewery_id' ] ][ $beer[ 'beer_id' ] ] = $beer[ 'beer_name' ];
}
Expand Down
9 changes: 6 additions & 3 deletions application/models/beers_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ class Beers_Model extends CI_Model {
function __construct() {
}

public function getBeers( $brewerID, $beerID=0 ) {
public function getBeers( $brewerID, $userID, $beerID=0 ) {
$query = $this
->db
->select( 'beers.*, beer_sub_style.substyle_name, beer_style.style_id, beer_style.family_id' )
->select( 'beers.*, beer_sub_style.substyle_name, beer_style.style_id, beer_style.family_id, drink_log.log_id AS have_had, fridge.id AS in_my_fridge' )
->from( 'beers' )
->join( 'beer_sub_style', 'beers.substyle_id = beer_sub_style.substyle_id' )
->join( 'beer_style', 'beer_sub_style.style_id = beer_style.style_id' )
->order_by( 'beers.beer_name', 'asc' );
->join( 'drink_log', 'beers.beer_id = drink_log.beer_id AND drink_log.user_id = ' . $userID, 'left' )
->join( 'fridge', 'beers.beer_id = fridge.beer_id AND fridge.user_id = ' . $userID, 'left' )
->order_by( 'beers.beer_name', 'asc' )
->group_by( 'beers.beer_id' );
if( $brewerID <= 0 ) {
if( $beerID > 0 ) {
$query = $this
Expand Down
3 changes: 2 additions & 1 deletion application/models/users_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,15 @@ public function updateHomepage( $userID, $page ) {
public function getFridgeBeers( $userID, $curUser, $fridgeID = -1 ) {
$query = $this
->db
->select( 'fridge.*, beers.beer_name, beers.brewery_id, beers.beer_ba_rating, breweries.name AS brewery_name, beer_style.family_id, beer_sub_style.style_id, beer_sub_style.substyle_id, beer_sub_style.substyle_name, serving_size.name AS size_name, drink_log.log_id AS have_had' )
->select( 'fridge.*, beers.beer_name, beers.brewery_id, beers.beer_ba_rating, breweries.name AS brewery_name, beer_style.family_id, beer_sub_style.style_id, beer_sub_style.substyle_id, beer_sub_style.substyle_name, serving_size.name AS size_name, drink_log.log_id AS have_had, f2.id AS in_my_fridge' )
->from( 'fridge' )
->join( 'beers', 'beers.beer_id = fridge.beer_id', 'inner' )
->join( 'breweries', 'breweries.brewery_id = beers.brewery_id', 'inner' )
->join( 'beer_sub_style', 'beers.substyle_id = beer_sub_style.substyle_id', 'inner' )
->join( 'beer_style', 'beer_sub_style.style_id = beer_style.style_id', 'inner' )
->join( 'serving_size', 'serving_size.size_id = fridge.size_id', 'inner' )
->join( 'drink_log', 'fridge.beer_id = drink_log.beer_id AND drink_log.user_id = ' . $curUser, 'left' )
->join( 'fridge AS f2', 'fridge.beer_id = f2.beer_id AND f2.user_id = ' . $curUser, 'left' )
->order_by( 'breweries.name, beers.beer_name, fridge.size_id', 'asc' )
->group_by( 'fridge.id' )
->where( 'fridge.user_id', $userID );
Expand Down
7 changes: 5 additions & 2 deletions application/views/pages/brewer_profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
'table_open' => '<table class="table table-bordered sortable">'
);
$this->table->set_template( $tmpl );
$this->table->set_heading( 'Beer', 'Style', 'ABV', 'BA Rating' );
$this->table->set_heading( 'Beer', 'Style', 'ABV', 'BA Rating', 'I\'ve Had' );
foreach( $beers as $beer ) {
$name = $beer[ 'beer_name' ];
$s1 = base_url( "beer/info/" . $brewery[ 'brewery_id' ] . "/" . $beer[ 'beer_id' ] );
Expand All @@ -89,7 +89,10 @@
$ba = $beer[ 'beer_ba_rating' ];
$ba = $ba == NULL ? '-' : $ba;

$this->table->add_row( $nameAnchor, $ssAnchor, $abvS, $ba );
$haveHad = is_numeric( $beer[ 'have_had' ] ) ? 'X' : '';
$inMyFridge = is_numeric( $beer[ 'in_my_fridge' ] ) ? 'F' : '';

$this->table->add_row( $nameAnchor, $ssAnchor, $abvS, $ba, $haveHad . $inMyFridge );
}
echo $this->table->generate();
?>
Expand Down
3 changes: 2 additions & 1 deletion application/views/pages/user_fridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@
$trade = (int)$fridge[ 'will_trade' ];
$notes = $fridge[ 'notes' ];
$haveHad = is_numeric( $fridge[ 'have_had' ] ) ? 'X' : '';
$inMyFridge = is_numeric( $fridge[ 'in_my_fridge' ] ) ? 'F' : '';
if( $myFridge ) {
$this->table->add_row( $edit, $log, $delete, $brewery, $beer, $sstyle, $size, $ba, $number, $trade, $notes, $haveHad );
} else {
$this->table->add_row( $brewery, $beer, $sstyle, $size, $ba, $number, $trade, $notes, $haveHad );
$this->table->add_row( $brewery, $beer, $sstyle, $size, $ba, $number, $trade, $notes, $haveHad . $inMyFridge );
}
}
echo $this->table->generate();
Expand Down

0 comments on commit 261e311

Please sign in to comment.