src/Entity/Client.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. use Doctrine\Common\Collections\Criteria;
  6. use App\Repository\ClientRepository;
  7. #[ORM\Entity(repositoryClassClientRepository::class)]
  8. #[ORM\Table(name'`client`')]
  9. #[ORM\HasLifecycleCallbacks()]
  10. class Client
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column(type'integer')]
  15.     private $id;
  16.     #[ORM\Column(type'string'length255nullable:true)]
  17.     private $nom;
  18.     #[ORM\Column(type'boolean'length255nullable:true)]
  19.     private $isActif;
  20.     #[ORM\ManyToMany(targetEntity:"Contact"inversedBy:"clients")]
  21.     #[ORM\JoinTable(name:"contact_client")]
  22.     private $contacts;
  23.     #[ORM\OneToMany(targetEntity:"Projet"mappedBy:"client"cascade:["all"])]
  24.     private $projets;
  25.    
  26.     public function __construct() {
  27.         $this->contacts = new \Doctrine\Common\Collections\ArrayCollection();
  28.         $this->projets = new \Doctrine\Common\Collections\ArrayCollection();
  29.     }
  30.     public function __toString(){
  31.         return $this->getNom();
  32.     }
  33.     public function getId()
  34.     {
  35.         return $this->id;
  36.     }
  37.     public function setNom($nom)
  38.     {
  39.         $this->nom $nom;
  40.         return $this;
  41.     }
  42.     public function getNom()
  43.     {
  44.         return $this->nom;
  45.     }
  46.     public function setIsActif($is_actif)
  47.     {
  48.         $this->isActif $is_actif;
  49.         return $this;
  50.     }
  51.     public function getIsActif()
  52.     {
  53.         return $this->isActif;
  54.     }
  55.     public function setContacts($contacts)
  56.     {
  57.         $this->contacts $contacts;
  58.         return $this;
  59.     }
  60.     public function getContacts()
  61.     {
  62.         return $this->contacts;
  63.     }
  64.     public function clearContacts()
  65.     {
  66.         return $this->contacts->clear();
  67.     }
  68.     public function addContact(Contact $contact)
  69.     {
  70.         $this->contacts->add($contact);
  71.         $contact->getClients()->add($this);
  72.         return $this;
  73.     }
  74.     public function hasContact(Contact $contact){
  75.         return in_array($contact$this->getContacts()->toArray());
  76.     }
  77.     public function removeContact(Contact $contact)
  78.     {
  79.         $this->contacts->removeElement($contact);
  80.         $contact->getClients()->removeElement($this);
  81.         return $this;
  82.     }
  83.     public function getProjets()
  84.     {
  85.         return $this->projets;
  86.     }
  87.     public function getProjetsActifs()
  88.     {
  89.         $criteria Criteria::create()->where(Criteria::expr()->in("lastEtat", [2]));
  90.         $contents $this->getProjets()->matching($criteria);
  91.         return $contents;
  92.     }
  93.     public function addProjet(Projet $projet)
  94.     {
  95.         $this->projets->add($projet);
  96.         return $this;
  97.     }
  98.     public function removeProjet(Projet $projet)
  99.     {
  100.         $this->projets->remove($projet);
  101.         return $this;
  102.     }
  103. }