forked from lexik/LexikFormFilterBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cédric G
committed
Jun 4, 2012
1 parent
cbfba1e
commit 7e5959f
Showing
17 changed files
with
124 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ | |
|
||
namespace Lexik\Bundle\FormFilterBundle\Filter\Extension\Type; | ||
|
||
use Lexik\Bundle\FormFilterBundle\Filter\Expr; | ||
|
||
use Doctrine\ORM\QueryBuilder; | ||
|
||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | ||
|
||
|
@@ -10,14 +14,14 @@ | |
* | ||
* @author Cédric Girard <[email protected]> | ||
*/ | ||
class ChoiceFilterType extends ChoiceType | ||
class ChoiceFilterType extends ChoiceType implements FilterTypeInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getParent() | ||
{ | ||
return isset($options['expanded']) && $options['expanded'] ? 'filter' : 'filter_field'; | ||
return 'filter'; | ||
} | ||
|
||
/** | ||
|
@@ -27,4 +31,22 @@ public function getName() | |
{ | ||
return 'filter_choice'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTransformerId() | ||
{ | ||
return 'lexik_form_filter.transformer.default'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function applyFilter(QueryBuilder $queryBuilder, Expr $expr, $field, array $values) | ||
{ | ||
if (!empty($values['value'])) { | ||
$queryBuilder->andWhere($expr->eq($field, $values['value'])); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
namespace Lexik\Bundle\FormFilterBundle\Filter\Extension\Type; | ||
|
||
use Symfony\Component\Form\AbstractType as FormFieldType; | ||
use Symfony\Component\Form\Extension\Core\Type\FieldType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | ||
|
||
|
@@ -15,32 +15,14 @@ | |
* | ||
* @author Cédric Girard <[email protected]> | ||
*/ | ||
class FieldFilterType extends FormFieldType implements FilterTypeInterface | ||
class FieldFilterType extends FieldType | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
public function getParent() | ||
{ | ||
parent::buildForm($builder, $options); | ||
|
||
if ($options['apply_filter'] instanceof \Closure || is_callable($options['apply_filter'])) { | ||
$builder->setAttribute('apply_filter', $options['apply_filter']); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setDefaultOptions(OptionsResolverInterface $resolver) | ||
{ | ||
parent::setDefaultOptions($resolver); | ||
|
||
$resolver->setDefaults(array( | ||
'required' => false, | ||
'apply_filter' => null, | ||
'compound' => false, | ||
)); | ||
return 'filter'; | ||
} | ||
|
||
/** | ||
|
@@ -50,24 +32,4 @@ public function getName() | |
{ | ||
return 'filter_field'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTransformerId() | ||
{ | ||
return 'lexik_form_filter.transformer.default'; | ||
} | ||
|
||
/** | ||
* Default implementation of the applyFieldFilter() method. | ||
* We just add a 'and where' clause. | ||
*/ | ||
public function applyFilter(QueryBuilder $queryBuilder, Expr $e, $field, array $values) | ||
{ | ||
if (!empty($values['value'])) { | ||
$queryBuilder->andWhere($e->eq($field, $values['value'])); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.