GithubHelp home page GithubHelp logo

pugx / filter-bundle Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 0.0 86 KB

Utility for filtering/sorting with Symfony

License: GNU Lesser General Public License v3.0

PHP 72.75% JavaScript 3.70% Twig 23.55%
bundle php symfony symfony-bundle

filter-bundle's People

Contributors

dependabot-preview[bot] avatar garak avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

filter-bundle's Issues

Avoid AlreadySubmittedException

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.

Code example for sort

Hi,

is there a simple full code example (controller and template) about sorting?
I'm trying to mix:

  • default sf5 CRUD maker: php bin/console make:crud
  • entities pagination using Knp\Component\Pager\PaginatorInterface
  • filter and sort using PUGX\FilterBundle\Filter

The target is a simple, completed, and nice boostrap5 CRUD interface.

Thanks in advance.
Vittore.

How to use Filtre in repository query ?

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

Support Symfony 7

Symfony 7 will be released later this month, we need to add support for it.
PRs are welcome

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.