*/ class CheckboxFilter { use FilterTrait; public function buildProperty(FormBuilderInterface $builder, FieldDto $fieldDto, $options = array()) { $builder->add($fieldDto->getProperty(), ChoiceType::class, array( 'choices'=> array( 'Oui' => 1, 'Non' => 0, ), 'placeholder'=> '--', 'required'=>false, 'attr'=>array( 'class'=> 'select2 input-sm', 'form'=> 'filters-form' ) )); } public function applyFilter(QueryBuilder $queryBuilder, string $fieldProperty, string $filteredValue= null) { if ($filteredValue !== null) { if ($this->isRelationField($fieldProperty)) { $aliasRelation = $this->getFieldPropertyRelationAlias($fieldProperty); if (array_search($aliasRelation, $queryBuilder->getAllAliases()) === false) { $queryBuilder->innerJoin('entity.'.$aliasRelation, $aliasRelation); } $queryBuilder->andWhere( $fieldProperty.' = :'.$this->getFieldPropertySnake($fieldProperty).'' ); $queryBuilder->setParameter( $this->getFieldPropertySnake($fieldProperty), $filteredValue ); } else { $queryBuilder->andWhere( 'entity.'.$fieldProperty.' = :'.$fieldProperty.'' ); $queryBuilder->setParameter($fieldProperty, $filteredValue); } } } }