How to findBy on one attribute which can be of different values

I’m trying to display a table, in which the user will decide which objets will be shown by selecting different options in a form.

 if ($form->isValid()) {
        $type = $form->get('type')->getData();
        //Getting values from Array $type returned by getData on the form
        foreach ($type as $livraison) {

            $elements = $this->getDoctrine()
                    ->getManager()
                    ->getRepository('etaqenregistrementBundle:Livraison')
                    ->findBy(array('type' => $livraison));
        }

    }

If we selected two options, $type will be an array which contains two different objects $livraison (var_dump($livraison) in the foreach statement ) :

object(etaq\adminBundle\Entity\typeLivraison)[434]
private ‘id’ => int 1
private ‘valeur’ => string ‘Interne’ (length=7)

object(etaq\adminBundle\Entity\typeLivraison)[436]
private ‘id’ => int 3
private ‘valeur’ => string ‘Autorité’ (length=9)

But findBy method returns only one object, the one which was selected first in the form.

What I want is to sort on ONE parameter if user selected one in the form, or to sort on TWO if he selected two, or three … etc

Here is my form :

    $form = $this->createFormBuilder()
            ->add('ecart', 'choice', array(
                'label' => 'Only late :',
                'choices' => array(true => 'Yes', false => 'No'),
                'multiple' => false,
                'expanded' => true,
                'required' => true,
                'empty_data' => false))
            ->add('type', 'entity', array(
                'label' => ' Type :',
                'class' => 'etaqadminBundle:typeLivraison',
                'empty_data' => false,
                'required' => true,
                'property' => 'valeur',
                'multiple' => true,
                'expanded' => true))
            ->getForm();

Thanks guys.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s