Skip to content

Commit

Permalink
Added an active only / all filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
louim committed Dec 23, 2014
1 parent be7d0b7 commit 49fc60d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
18 changes: 17 additions & 1 deletion web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
'theme' => 'Theme'
)
))
->add('active_only', 'choice', array(
'choices' => array(
1 => 'Active',
0 => 'All'
)
))
->add('search', 'submit')
->getForm();

Expand All @@ -92,6 +98,7 @@
$app->get('/search', function (Request $request) use ($app, $searchForm) {
$queryBuilder = $app['db']->createQueryBuilder();
$type = $request->get('type');
$active = $request->get('active_only');
$query = $request->get('q');
$results = array();
$data = array(
Expand Down Expand Up @@ -121,8 +128,17 @@
break;
}

switch ($active) {
case 1:
$queryBuilder->andWhere('is_active', true);
break;

default:
$queryBuilder->orderBy('is_active', 'DESC');
break;
}

$queryBuilder
->orderBy('is_active', 'DESC')
->addOrderBy('name LIKE :order', 'DESC')
->addOrderBy('name', 'ASC')
->setParameter(':name', "%{$query}%")
Expand Down
11 changes: 7 additions & 4 deletions web/templates/searchbar.twig
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{{ form_start(searchForm, {'attr': {'class': 'row collapse'}}) }}
<div class="large-9 columns">
<div class="large-8 columns">
<div class="row collapse">
<div class="small-12 columns">
{{ form_widget(searchForm.q, {'required': false, 'attr': {'autofocus': 'true'}}) }}
</div>
</div>
</div>
<div class="large-3 columns">
<div class="large-4 columns">
<div class="row collapse">
<div class="small-6 columns">
<div class="small-4 columns">
{{ form_widget(searchForm.type) }}
</div>
<div class="small-6 columns">
<div class="small-3 columns">
{{ form_widget(searchForm.active_only) }}
</div>
<div class="small-5 columns">
{{ form_widget(searchForm.search, { 'label': 'Search »','attr': {'class': 'primary-color postfix'}}) }}
</div>
</div>
Expand Down

0 comments on commit 49fc60d

Please sign in to comment.