|
- <?php
-
- namespace Lc\SovBundle\Field\Filter;
-
- use Doctrine\ORM\EntityRepository;
- use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
- use Lc\SovBundle\Repository\RepositoryQueryInterface;
- use Symfony\Bridge\Doctrine\Form\Type\EntityType;
- use Symfony\Component\Form\FormBuilderInterface;
-
- /**
- * @author La clic ! <contact@laclic.fr>
- */
- class AssociationFilter
- {
- use FilterTrait;
-
-
- public function buildProperty(FormBuilderInterface $builder, FieldDto $fieldDto, $options = array())
- {
- $targetEntity = $options['entity_dto']->getPropertyMetadata($fieldDto->getProperty())->get('targetEntity');
-
- if($fieldDto->getCustomOption('choices')){
- $choices = $fieldDto->getCustomOption('choices');
- }else if($fieldDto->getFormTypeOption('choices') !=null){
- $choices = $fieldDto->getFormTypeOption('choices');
- }else{
- $choices = array();
- }
- //todo utiliser choices plutot que query_builder voir ProductCategoriesFilter
- $builder->add(
- $fieldDto->getProperty(),
- EntityType::class,
- array(
- 'class' => $targetEntity,
- 'placeholder' => '--',
- 'choices' => $choices,
- 'required' => false,
- 'attr' => array(
- 'class' => 'select2 input-sm',
- 'form' => 'filters-form',
- ),
-
-
- )
- );
- }
-
- public function applyFilter(RepositoryQueryInterface $repositoryQuery, string $fieldProperty, $filteredValue = null)
- {
- if ($filteredValue !== null) {
- $repositoryQuery->andWhere('.'.$fieldProperty.' = :'.$fieldProperty.'');
- $repositoryQuery->setParameter($fieldProperty, $filteredValue);
- /* //TODO Faut généraliser avec TreeInterface, ça ne doit pas être ici
- if ($field['type_options']['multiple']) {
- $repositoryQuery->andWhere(':' . $field['property'] . ' MEMBER OF entity.' . $field['property'] . '');
- } else {
- }
-
- if ($filter instanceof TreeInterface && $filter->getParent() == null) {
- $repositoryQuery->setParameter($field['property'], array_merge(array($filter), $filter->getChildrens()->toArray()));
- } else {
- }*/
- }
- }
-
- }
|