Commit b10ac4fc by Julien Jorry

Admin operation prestataire : add filter by groupe

parent f02d2a5a
...@@ -3,10 +3,12 @@ ...@@ -3,10 +3,12 @@
namespace App\Admin; namespace App\Admin;
use App\Entity\AccountPrestataire; use App\Entity\AccountPrestataire;
use App\Entity\Groupe;
use App\Entity\OperationPrestataire; use App\Entity\OperationPrestataire;
use App\Entity\Prestataire; use App\Entity\Prestataire;
use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Datagrid\ListMapper;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
/** /**
* Administration des operation des prestataires. * Administration des operation des prestataires.
...@@ -64,13 +66,38 @@ class OperationPrestataireAdmin extends OperationAdmin ...@@ -64,13 +66,38 @@ class OperationPrestataireAdmin extends OperationAdmin
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{ {
parent::configureDatagridFilters($datagridMapper); parent::configureDatagridFilters($datagridMapper);
$em = $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager();
$datagridMapper $datagridMapper
->add('account.prestataire', null, [ ->add('account.prestataire', null, [
'label' => 'Prestataire', 'label' => 'Prestataire',
'advanced_filter' => false, 'advanced_filter' => false,
'show_filter' => true, 'show_filter' => true,
]) ])
//@TODO : add by groupe filter / ->add('groupe', 'doctrine_orm_callback', [
'label' => 'Groupe local',
'callback' => function ($queryBuilder, $alias, $field, $value) {
if (!$value['value']) {
return;
}
$queryBuilder
->leftJoin($alias . '.account', 'a')
->leftJoin('App\Entity\Prestataire', 'p', 'WITH', 'a.prestataire = p')
->andWhere('p.groupe = :groupe')
->setParameter('groupe', $value['value']);
return true;
},
'advanced_filter' => false,
'show_filter' => true,
'field_type' => ChoiceType::class,
'field_options' => [
'choices' => $em->getRepository(Groupe::class)->findBy(['enabled' => true], ['name' => 'ASC']),
'choice_label' => 'name',
'placeholder' => 'Indifférent',
'expanded' => false,
'multiple' => false,
],
])
; ;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment