Curation page - show/hide inactive items

This commit is contained in:
Daniel Camargo 2013-07-10 09:58:37 -03:00
parent 620dac8857
commit 59efa7378c
3 changed files with 21 additions and 8 deletions

View File

@ -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 );
}
}

View File

@ -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 );

View File

@ -23,7 +23,14 @@
<a href="/home/curation/"><i class="icon-reorder"></i> Order by times ordered</a>
<?php } else { ?>
<a href="/home/curation/category"><i class="icon-reorder"></i> Order by category</a>
<?php }
if( $_GET[ 'showInactive' ] == '1' ) { ?>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?showInactive=0"><i class="icon-eye-close"></i> Show just active dishes</a>
<?php } else { ?>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?showInactive=1"><i class="icon-eye-close"></i> Show all dishes</a>
<?php } ?>
<br/>
<br/>
@ -35,7 +42,6 @@
</tr>
<?php
foreach ( $data as $restaurant ) {
?>
<tr>
<td>&nbsp;</td>
@ -52,9 +58,10 @@
<?php
$foods = $restaurant[ 'Food' ];
foreach( $foods as $food ){
$active = ( $food[ 'active' ] == '0' ) ? 'style="color:#CCC;"' : '';
?>
<tr>
<td><?php echo $food[ 'name' ]; ?></td>
<tr <?php echo $active; ?>>
<td><?php echo $food[ 'name' ]; ?> </td>
<td><?php if( $food[ 'times' ] ){ echo $food[ 'times' ]; } else { echo 0; } ; ?></td>
<td><?php echo $food[ 'category' ]; ?></td>
</tr>