I'm creating a filter(for 'offre' entity) by departement ,experience, type(of contract) and a key word all the filters give the right result but experience I don't know why it doesn't respond however I make it alone without the other filter or with the problem I don't know where is the problem because it's a ChoiceType as ('type' attribut (with type of contract I don't have any problem))here is the offreEmploi.php:
`<?phpnamespace App\Entity;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Cocur\Slugify\Slugify;use App\Entity\Candidat;/** * OffreEmploi * @ORM\Entity */class OffreEmploi{ /** * @var int * * @ORM\Column(name="id", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $id; /** * @var titre * * @ORM\Column(name="titre", type="string", length=255) */ private $titre; /** * @var string * * @ORM\Column(name="description", type="text", length=0, nullable=false) */ private $description; /** * @var \DateTime * * @ORM\Column(name="create_at", type="datetime", nullable=false) */ private $createAt; /** * @var string|null * * @ORM\Column(name="experience", type="string", nullable=false) */ private $experience; /** * @var \DateTime * * @ORM\Column(name="date", type="date", nullable=false) */ private $date; /** * @var int|null * * @ORM\Column(name="remuneration", type="integer", nullable=true) */ private $remuneration ; /** * @var string|null * * @ORM\Column(name="remarque", type="text", length=0, nullable=true) */ private $remarque ; /** * @var string|null * * @ORM\Column(name="reponse", type="text", nullable=true) */ private $reponse ; /** * @var string|null * * @ORM\Column(name="etude_qualification", type="text", nullable=true) */ private $etudeQualification; /** * @ORM\ManyToOne(targetEntity="App\Entity\Metier", inversedBy="offreEmplois") * @ORM\JoinColumn(nullable=false,name="nom_metier",referencedColumnName="nom_metier") */ private $metier; /** * @ORM\ManyToOne(targetEntity="App\Entity\Departement", inversedBy="offreEmplois") * @ORM\JoinColumn(nullable=false,name="code_departement", referencedColumnName="code_departement") */ private $departement; /** * @var string|null * * @ORM\Column(name="type", type="string", nullable=false) */ private $type; /** * @ORM\ManyToOne(targetEntity="App\Entity\Entreprise", inversedBy="offres") * @ORM\JoinColumn(nullable=false, name="email", referencedColumnName="email") */ private $entreprise; /** * @ORM\OneToMany(targetEntity="App\Entity\ApplyOffre", mappedBy="offre", orphanRemoval=true) */ private $applies; public function __construct() { $this->applies = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getTitre():?string { return $this->titre; } public function setTitre(string $titre): self { $this->titre = $titre; return $this; } public function getDescription(): ?string { return $this->description; } public function setDescription(string $description): self { $this->description = $description; return $this; } public function getCreateAt(): ?\DateTimeInterface { return $this->createAt; } public function setCreateAt(\DateTimeInterface $createAt): self { $this->createAt = $createAt; return $this; } public function getExperience(): ?string { return $this->experience; } public function setExperience(?string $experience): self { $this->experience = $experience; return $this; } public function getDate(): ?\DateTimeInterface { return $this->date; } public function setDate(\DateTimeInterface $date): self { $this->date = $date; return $this; } public function getRemuneration(): ?int { return $this->remuneration; } public function setRemuneration(?int $remuneration): self { $this->remuneration = $remuneration; return $this; } public function getRemarque(): ?string { return $this->remarque; } public function setRemarque(?string $remarque): self { $this->remarque = $remarque; return $this; } public function getReponse(): ?string { return $this->reponse; } public function setReponse(?string $reponse): self { $this->reponse = $reponse; return $this; } public function getEtudeQualification(): ?string { return $this->etudeQualification; } public function setEtudeQualification(?string $etudeQualification): self { $this->etudeQualification = $etudeQualification; return $this; } public function getMetier(): ?Metier { return $this->metier; } public function setMetier(?Metier $metier): self { $this->metier = $metier; return $this; } public function getSlug():string{ return (new Slugify())->slugify($this->metier); } public function getDepartement(): ?Departement { return $this->departement; } public function setDepartement(?Departement $departement): self { $this->departement = $departement; return $this; } public function getType(): ?string { return $this->type; } public function setType(?string $type): self { $this->type = $type; return $this; } public function getEntreprise(): ?Entreprise { return $this->entreprise; } public function setEntreprise(?Entreprise $entreprise): self { $this->entreprise = $entreprise; return $this; } public function __toString() { return $this->getTitre(); } /** * @return Collection|ApplyOffre[] */ public function getApplies(): Collection { return $this->applies; } public function addApply(ApplyOffre $apply): self { if (!$this->applies->contains($apply)) { $this->applies[] = $apply; $apply->setOffre($this); } return $this; } public function removeApply(ApplyOffre $apply): self { if ($this->applies->contains($apply)) { $this->applies->removeElement($apply); // set the owning side to null (unless already changed) if ($apply->getOffre() === $this) { $apply->setOffre(null); } } return $this; }}
` and here is a part of filterType as form :
'
<?phpnamespace App\Form; use App\Entity\Departement; use App\Entity\Domaine; use App\Entity\Metier; use App\Entity\Region; use App\Entity\Type; use App\searchData\Filter; use App\searchData\OffreSearchBar; use App\searchData\OffreSearchSide; use Doctrine\ORM\EntityRepository; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class OffreFilterType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('type', ChoiceType::class,['choices' =>['CDI' =>'cdi','CDD' =>'cdd','ALTERNANCE'=>'alternance','STAGE' =>'Stage','CTT' =>'CTT'> ],> 'required'=>false,> 'multiple'=>true,> 'expanded'=>true,> 'label' =>false> ])> > > ->add('experience', ChoiceType::class, [> 'choices'=>[> 'tout'=>'tout',> '<= 1 ans'=>'<=1 ans',> '1 à 3 ans'=>'1 à 3 ans',> 'de 3 à 6 ans'=>'de 3 à 6 ans',> '+ de 5 ans'=>'+ de 5 ans'> ],> 'required' => false,> 'multiple'=>false,> 'expanded'=>true,> 'label' => false,> 'placeholder'=>false> ])> ;> }> public function configureOptions(OptionsResolver $resolver)> {> $resolver->setDefaults([> 'data_class' => Filter::class,> 'csrf_protection'=>false,> 'method' =>'get'> ]);> } }'and here is the repository: public function findSearch(Filter $data){ $query=$this->createQueryBuilder('o'); if($data->metier || $data->motCle || $data->type || $data->departement|| $data->experience){ $query->join('o.metier','m') ->join('o.departement','d') ->addSelect('m') ->addSelect('d') // ->where('o.metier IN (:m)') ->where( $query->expr()->andX( $query->expr()->andX( $query->expr()->eq('o.metier',':m'), $query->expr()->like('o.titre', $query->expr()->literal('%' . $data->motCle . '%')) ), $query->expr()->andX( $query->expr()->andX( $query->expr()->eq('o.type',':type'), $query->expr()->in('o.departement', (':d')) ), $query->expr()->andX( $query->expr()->eq('o.experience',':experience') ) ) ) ) ->setParameter('experience',$data->experience) ->setParameter('d',$data->departement) ->setParameter('m',$data->metier) ->setParameter('type',$data->type); } return $query->getQuery()->getResult(); } }'
someone can tell me why the when I add the filter(experience) it don't give the right result and when I omet the
`$query->expr()->andX( $query->expr()->eq('o.experience',':experience') )`
it works (it give the right result for the other filter) and even when I add it alone in an other query it give zero result