|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?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 , FieldDto $fieldDto, string $filteredValue = null)
- {
- $fieldProperty = $this->getFieldProperty($fieldDto);
- 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.'%');
-
- }
- }
-
- }
|