|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
-
- namespace Lc\SovBundle\Field\Filter;
-
-
- use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
- use Lc\SovBundle\Repository\RepositoryQueryInterface;
- use Lc\SovBundle\Translation\TranslatorAdmin;
- use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
- use Symfony\Component\Form\FormBuilderInterface;
-
- use function Symfony\Component\String\u;
-
-
- /**
- * @author La clic ! <contact@laclic.fr>
- */
- class ChoiceFilter
- {
- use FilterTrait;
-
- protected $translatorAdmin;
-
- public function __construct(?TranslatorAdmin $translatorAdmin = null)
- {
- $this->translatorAdmin = $translatorAdmin;
- }
-
- public function buildProperty(FormBuilderInterface $builder, FieldDto $fieldDto, $options = array())
- {
- if($fieldDto->getCustomOption('choices')){
- $choices = $fieldDto->getCustomOption('choices');
- }else if($fieldDto->getFormTypeOption('choices') !=null){
- $choices = $fieldDto->getFormTypeOption('choices');
- }else{
- $choices = array();
- }
- $builder->add(
- $fieldDto->getProperty(),
- ChoiceType::class,
- array(
- 'required' => false,
- 'choices' => $choices,
- 'attr' => array(
- 'class' => 'select2 input-sm',
- 'form' => 'filters-form',
- ),
- )
- );
- }
-
- public function applyFilter(RepositoryQueryInterface $repositoryQuery , string $fieldProperty, string $filteredValue = null)
- {
- if ($filteredValue !== null) {
- // if ($this->isRelationField($fieldProperty)) {
- // $aliasRelation = $this->getFieldPropertyRelationAlias($fieldProperty);
- // if (array_search($aliasRelation, $repositoryQuery->getAllAliases()) === false) {
- // $repositoryQuery->innerJoin('entity.'.$aliasRelation, $aliasRelation);
- // }
- // $repositoryQuery->andWhere(
- // $fieldProperty.' LIKE :'.$this->getFieldPropertySnake($fieldProperty).''
- // );
- // $repositoryQuery->setParameter(
- // $this->getFieldPropertySnake($fieldProperty),
- // '%'.$filteredValue.'%'
- // );
- // } else {
- $repositoryQuery->andWhere(
- '.'.$fieldProperty.' LIKE :'.$fieldProperty.''
- );
- $repositoryQuery->setParameter($fieldProperty, '%'.$filteredValue.'%');
-
- }
- }
-
- }
|