-
Notifications
You must be signed in to change notification settings - Fork 57
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
Showing
4 changed files
with
142 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
|
||
namespace AlterPHP\EasyAdminExtensionBundle\Form\Type; | ||
|
||
|
||
use AlterPHP\EasyAdminExtensionBundle\Form\Transformer\Operator\GreaterThanOrEqualModelTransformer; | ||
use AlterPHP\EasyAdminExtensionBundle\Model\ListFilter; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\HiddenType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class ListFilterType extends AbstractType | ||
{ | ||
public static $operators = [ | ||
'equals' => '=', | ||
'gt' => '>', | ||
'gte' => '>=', | ||
'lt' => '<', | ||
'lte' => '<=', | ||
]; | ||
|
||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$operator = $options['operator']; | ||
if (!array_key_exists($operator, static::$operators)) { | ||
throw new \InvalidArgumentException('operator should be one of ' . implode(', ', array_keys(static::$operators)) . ". $operator passed"); | ||
} | ||
|
||
$property = $options['property']; | ||
$type = $options['input_type']; | ||
unset($options['operator'], $options['input_type'], $options['property']); | ||
|
||
$builder | ||
->add('value', $type, $options['input_type_options'] + [ | ||
'label' => false, | ||
'required' => false | ||
]) | ||
->add('operator', HiddenType::class, [ | ||
'data' => self::$operators[$operator] | ||
]); | ||
if ($property !== null) { | ||
$builder | ||
->add('property', HiddenType::class, [ | ||
'data' => $property | ||
]); | ||
} | ||
|
||
} | ||
|
||
|
||
public function configureOptions(OptionsResolver $resolver) | ||
{ | ||
$resolver->setDefaults(array( | ||
'operator' => 'equals', | ||
'data_class' => ListFilter::class, | ||
'input_type' => TextType::class, | ||
'input_type_options' => [] | ||
)); | ||
$resolver->setDefined([ | ||
'property', | ||
]); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
|
||
namespace AlterPHP\EasyAdminExtensionBundle\Model; | ||
|
||
|
||
class ListFilter | ||
{ | ||
/** @var string */ | ||
protected $operator; | ||
/** @var mixed */ | ||
protected $value; | ||
/** | ||
* @var string | ||
* | ||
* Used to override the property, allowing multiple list filter on the same property | ||
*/ | ||
protected $property; | ||
|
||
public function getOperator() | ||
{ | ||
return $this->operator; | ||
} | ||
|
||
public function setOperator(string $operator) | ||
{ | ||
$this->operator = $operator; | ||
} | ||
|
||
public function getValue() | ||
{ | ||
return $this->value; | ||
} | ||
|
||
public function setValue($value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public function getProperty() | ||
{ | ||
return $this->property; | ||
} | ||
|
||
public function setProperty($property) | ||
{ | ||
$this->property = $property; | ||
} | ||
|
||
|
||
} |