Я создаю фильтр (для 'offre' лица) по отделу, опыту, типу (контракта) и ключевому слову, все фильтры дают правильный результат, но опыт Я не знаю, почему он не отвечает однако я делаю это один без другого фильтра или с проблемой, я не знаю, в чем проблема, потому что это ChoiceType as (атрибут type) (с типом контракта у меня нет проблем)) вот offreEmploi . php:
`<?php
namespace 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;
}
}
`и вот часть filterType как форма:
'
<?php
namespace 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();
}
}'
кто-то может сказать мне, почему, когда я добавляю фильтр (опыт) не дает правильного результата, и когда я определяю
`$query->expr()->andX(
$query->expr()->eq('o.experience',':experience')
)`
, он работает (это дает правильный результат для другого фильтра), и даже когда я добавляю его один в другой запрос это дает нулевой результат