0

I'm working on a filter form in symfony 3.4, I filter users with date, payment method, delivery zone, and nbCommandes but my request does not work in the repository, my question how to add the nbCommands that does not exist in the database in my request ? here is my form : rendering my form :

enter image description here

and error :

enter image description here

thank you for your help

     class FilterClientsType extends AbstractType
     {
      public function buildForm(FormBuilderInterface $builder, array 
      $options)
       {
        $builder
        ->add('dateDebut', DateType::class, array(
            'label'=>false,
            'widget' => 'single_text',
            'html5' => true,

        ))
        ->add('dateFin', DateType::class, array(
            'label'=>false,
            'widget' => 'single_text',
            'html5' => true,


        ))

        ->add('Filter', SubmitType::class, array(
            'attr' => array(
                'class' => 'btn btn-primary',
            )
        ));
}/**
  * {@inheritdoc}
  */
   public function configureOptions(OptionsResolver $resolver)
    {
    $resolver->setDefaults(array(
        'data_class' => null
    ));
   }

 }

Controller:

  public function listAction(Request $request)
  {
    $form = $this->createForm(FilterType::class);
    $form->handleRequest($request);
    if ($form->isSubmitted() && $form->isValid()) {
        $dateDebut = $form->get('dateDebut')->getData();
        $dateFin = $form->get('dateFin')->getData();
        $modePaiement = $form->get('modePaiement')->getData();
        $nbCommande = $form->get('nbCommande')->getData();
        $zoneLivraison = $form->get('zoneLivraison')->getData();
    } else {
        $dateDebut = null;
        $dateFin = null;
        $modePaiement=null;
        $nbCommande=null;
        $zoneLivraison=null;
    }

    $userRepos = $this
        ->getDoctrine()
        ->getManager()
        ->getRepository('CeUtilisateurBundle:User');
        $listUsers = $userRepos->filterUser($dateDebut, $dateFin, $modePaiement, $nbCommande, $zoneLivraison);

         return $this->render('CeUtilisateurBundle:Utilisateur:list.html.twig', array(
        'form' => $form->createView(),
        'listUsers' => $listUsers,
    ));
}

Repository:

 class UserRepository extends\Doctrine\ORM\EntityRepository
             {
             public function filterUser($dateDebut, $dateFin, 
             $modePaiement, $nom, $nbCommandes)
              {
             $qb = $this
             ->createQueryBuilder('u')
             ->leftJoin('u.commandes', 'cmd')
            ->leftJoin('u.zoneLivraison', 'zone')
            ->addSelect('cmd')
           ->addSelect('zone')
        - >addSelect('COUNT(u.id) as nbCommandes')
         ->groupBy('cmd.id');

        if (!is_null($dateDebut) && !is_null($dateFin) && $dateFin >= 
      $dateDebut && !is_null($modePaiement) && !is_null($nom) && 
       !is_null($nbCommandes)) {
        $qb->where('cmd.dateCommande BETWEEN :dateDebut AND :dateFin')
       ->andWhere ('cmd.modePaiement = :modePaiement')
       ->andWhere ('zone.nom = :nom')
        ->setParameter('dateDebut', $dateDebut)
        ->setParameter('dateFin', $dateFin)
        ->setParameter('modePaiement', $modePaiement)
        ->setParameter('nom', $nom)
        ->setParameter('nbCommandes', $nbCommandes);
    }
        return $qb
            ->getQuery()
            ->getResult();

}
Naresh
  • 16,698
  • 6
  • 112
  • 113
  • 1
    Possible duplicate of [#1055 - Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column this is incompatible with sql\_mode=only\_full\_group\_by](https://stackoverflow.com/questions/37951742/1055-expression-of-select-list-is-not-in-group-by-clause-and-contains-nonaggr) – Fabian Schmick Feb 28 '19 at 10:25
  • Thank you you're right finally I fixed the problem with that – Kamela Bessas Feb 28 '19 at 11:16

0 Answers0