From 59efa7378c4f20c670fb3b8aec4719d7f39ee442 Mon Sep 17 00:00:00 2001 From: Daniel Camargo Date: Wed, 10 Jul 2013 09:58:37 -0300 Subject: [PATCH] Curation page - show/hide inactive items --- .../controllers/default/cockpit/home/curation.php | 5 +++-- include/library/Crunchbutton/Restaurant.php | 11 ++++++++--- include/views/default/cockpit/home/curation.phtml | 13 ++++++++++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/include/controllers/default/cockpit/home/curation.php b/include/controllers/default/cockpit/home/curation.php index e62cfb0a9..cb0b8e413 100644 --- a/include/controllers/default/cockpit/home/curation.php +++ b/include/controllers/default/cockpit/home/curation.php @@ -5,6 +5,7 @@ class Controller_home_curation extends Crunchbutton_Controller_Account { public function init() { $orderByCategory = ( c::getPagePiece(2) == 'category' ); + $showInactive = ( $_GET[ 'showInactive' ] ) ? $_GET[ 'showInactive' ] : 0; $data = []; $restaurants = Restaurant::q('SELECT * FROM restaurant WHERE active = 1 ORDER BY name ASC'); @@ -12,9 +13,9 @@ class Controller_home_curation extends Crunchbutton_Controller_Account { $data[ $restaurant->id_restaurant ] = []; $data[ $restaurant->id_restaurant ][ 'Name' ] = $restaurant->name; $data[ $restaurant->id_restaurant ][ 'Food' ] = []; - $foods = $restaurant->foodReport( $orderByCategory ); + $foods = $restaurant->foodReport( $orderByCategory, ( $showInactive == 1 ) ); foreach( $foods as $food ){ - $data[ $restaurant->id_restaurant ][ 'Food' ][] = array( 'name' => $food->dish, 'times' => $food->times, 'category' => $food->category ); + $data[ $restaurant->id_restaurant ][ 'Food' ][] = array( 'name' => $food->dish, 'times' => $food->times, 'category' => $food->category, 'active' => $food->active ); } } diff --git a/include/library/Crunchbutton/Restaurant.php b/include/library/Crunchbutton/Restaurant.php index 24a00222a..e22636e57 100644 --- a/include/library/Crunchbutton/Restaurant.php +++ b/include/library/Crunchbutton/Restaurant.php @@ -43,17 +43,22 @@ class Crunchbutton_Restaurant extends Cana_Table return $this->_top; } - public function foodReport( $orderByCategory = false ){ + public function foodReport( $orderByCategory = false, $showInactive = false ){ if( $orderByCategory ){ $orderBy = 'ORDER BY c.sort ASC, total DESC'; } else { $orderBy = 'ORDER BY total DESC'; } - $query = "SELECT d.name as dish, c.name AS category, ordered.total as times FROM dish d + + if( !$showInactive ){ + $active = ' AND d.active = 1 '; + } + + $query = "SELECT d.name as dish, c.name AS category, ordered.total AS times, d.active AS active FROM dish d INNER JOIN category c ON c.id_category = d.id_category LEFT JOIN ( SELECT COUNT(*) total, id_dish FROM order_dish GROUP BY id_dish ) ordered ON ordered.id_dish = d.id_dish - WHERE d.id_restaurant = {$this->id_restaurant} + WHERE d.id_restaurant = {$this->id_restaurant} {$active} {$orderBy}"; return c::db()->get( $query ); diff --git a/include/views/default/cockpit/home/curation.phtml b/include/views/default/cockpit/home/curation.phtml index d81b7899b..7a848b0ea 100644 --- a/include/views/default/cockpit/home/curation.phtml +++ b/include/views/default/cockpit/home/curation.phtml @@ -23,7 +23,14 @@ Order by times ordered Order by category + +        Show just active dishes + +        Show all dishes +

@@ -35,7 +42,6 @@   @@ -52,9 +58,10 @@ - - + > +