pugx / filter-bundle Goto Github PK
View Code? Open in Web Editor NEWUtility for filtering/sorting with Symfony
License: GNU Lesser General Public License v3.0
Utility for filtering/sorting with Symfony
License: GNU Lesser General Public License v3.0
hello , if someone can help me , i don't find any example how ti use the bundle with multiple items to filter my entity,
repository
/**
* @return ExBesoin[] Returns an array of ExBesoin objects
*/
public function exportTest($filter): array
{
$start_week = new \DateTime('monday next week');
$end_week = new \DateTime('sunday next week');
$query = $this
->createQueryBuilder('p');
if (!empty($filtre->minDate)) {
$query = $query
->andWhere('p.dateLivraison >= :minDate')
->setParameter('minDate', $filtre->minDate);
}
if (!empty($filtre->maxDate)) {
$query = $query
->andWhere('p.dateLivraison <= :maxDate')
->setParameter('maxDate', $filtre->maxDate);
}
if (!empty($filtre->fournisseur)) {
$query = $query
->addSelect('a, f, b')
->innerJoin('p.besoinArs','b')
->innerJoin('b.article','a')
->join('a.fournisseur', 'f')
->andWhere('f.id = :fournisseur')
->setParameter('fournisseur' , $filtre->fournisseur);
}
$query = $query
->andWhere('p.is_legume = 0')
->andWhere('p.is_draft = 0')
->orderBy('p.dateLivraison' , 'ASC');
dump($query->getQuery()->getSql());
return $query
->getQuery()->getResult();
}
Form :
class FilterType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('minDate', DateType::class, [
'label' => ' ',
'attr' => [
'class' => 'form-control-sm dateMin pl-3 p-2 input-daterange',
'placeholder' => date("Y-m-d",strtotime('monday this week'))
],
'widget' => 'single_text',
'required' => false,
'html5' => false
])
->add('maxDate', DateType::class, [
'label' => ' ',
'attr' => [
'class' => 'form-control-sm dateMax pl-3 p-2 input-daterange',
'placeholder' => date("Y-m-d",strtotime('friday this week'))
],
'widget' => 'single_text',
'required' => false,
'html5' => false
])
->add('fournisseur', EntityType::class, [
'class' => Fournisseur::class,
'required' => false,
'multiple' => false,
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'csrf_protection' => false,
'method' => 'GET',
'minDate' => null,
'maxDate' => null,
'fournisseur' => null
]);
}
}
Controller
/**
* @Route("/extraire", name="export_Test", methods={"GET","POST"})
*/
public function exporttest(ExBesoinRepository $exBesoinRepository, Request $request, Filter $filter): Response
{
if ($filter->saveFilter(FilterType::class, 'besoin')) {
//$exBesoin = $exBesoinRepository->exportTest($filter->filter('besoin'));
// dd($filter->filter('besoin'));
return $this->redirectToRoute('export_Test', [], Response::HTTP_SEE_OTHER);
}
$exBesoin = $exBesoinRepository->exportTest(
$filter->filter('besoin')
);
//dd( $exBesoin);
return $this->render('admin/besoins/epicerie/export_1.html.twig', [
'besoins' => $exBesoin,
'form' => $filter->getFormView('besoin'),
]);
}
I think that my query is not correct .
Thank you
Hi,
how to add in filter form a ChoiceType field populated using a query?
Thanks in advance.
We should check inside filter
method if the form is already submitted.
If so, we need to avoid submitting again, otherwise an AlreadySubmittedException
is thrown.
Symfony 7 will be released later this month, we need to add support for it.
PRs are welcome
Hi,
is there a simple full code example (controller and template) about sorting?
I'm trying to mix:
php bin/console make:crud
Knp\Component\Pager\PaginatorInterface
PUGX\FilterBundle\Filter
The target is a simple, completed, and nice boostrap5 CRUD interface.
Thanks in advance.
Vittore.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.