Commit 61d77d24 by Damien Moulard

admin filter flux by adherent subterritory

parent 793313a4
......@@ -3,6 +3,7 @@
namespace App\Admin;
use App\Entity\Flux;
use App\Entity\Subterritory;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
......@@ -11,6 +12,7 @@ use Sonata\Form\Type\DateTimeRangePickerType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType as SChoiceType;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Translation\TranslatorInterface;
use Sonata\DoctrineORMAdminBundle\Filter\CallbackFilter;
/**
* Administration des Flux.
......@@ -172,6 +174,35 @@ class FluxAdmin extends AbstractAdmin
'label' => 'Date',
])
;
if($this->getConfigurationPool()->getContainer()->getParameter('household_based_allowance')) {
$datagridMapper->add('territory', CallbackFilter::class, [
'callback' => [$this, 'getTerritoryFilter'],
'field_type' => SChoiceType::class,
'label' => 'Territoire de l\'adhérent',
'show_filter' => true,
'advanced_filter' => false,
'field_options' => [
'choice_label' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(Subterritory::class)->findAll(),
'choices' => $st
],
]);
}
}
public function getTerritoryFilter($queryBuilder, $alias, $field, $value)
{
if (!$value['value']) {
return;
}
$flux_ids = $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(Flux::class)->getQuerybyAdherentSubterritory($value['value']);
$queryBuilder
->andWhere($queryBuilder->expr()->in($alias . '.id', ':ids'))
->setParameter('ids', $flux_ids);
return true;
}
public function getTemplate($name)
......
......@@ -316,4 +316,26 @@ class FluxRepository extends ServiceEntityRepository
return $results;
}
/**
* @param String $subterritory_name the subterritory name to look for
*
* @return
*/
public function getQuerybyAdherentSubterritory($subterritory_name)
{
$sqlQuery = "SELECT f.id
FROM {$this->tableName} f
LEFT JOIN adherent a ON (a.id = f.adherent_id OR a.id = f.adherent_dest_id)
LEFT JOIN geoloc g ON a.geoloc_id = g.id
LEFT JOIN subterritory st ON g.subterritory_id = st.id
WHERE st.name = :subterritory_name";
$statement = $this->connection->prepare($sqlQuery);
$statement->bindValue(':subterritory_name', $subterritory_name);
$statement->execute();
$results = $statement->fetchAll();
return $results;
}
}
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