src/Entity/Client.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ClientRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. /**
  10.  * @ORM\Entity(repositoryClass=ClientRepository::class)
  11.  * @UniqueEntity(
  12.  *  fields="user",
  13.  *  message="Cette categorie existe "
  14.  * )
  15.  */
  16. class Client
  17. {
  18.     /**
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue
  21.      * @ORM\Column(type="integer")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @Assert\Valid
  26.      * @ORM\OneToOne(targetEntity=User::class, inversedBy="client", cascade={"persist", "remove"})
  27.      * @ORM\JoinColumn(nullable=false)
  28.      */
  29.     private $user;
  30.     /**
  31.      * @ORM\OneToMany(targetEntity=DeliverySpace::class, mappedBy="client", cascade={"persist", "remove"})
  32.      */
  33.     private $deliverySpaces;
  34.     /**
  35.      * @ORM\OneToMany(targetEntity=ArticleBuy::class, mappedBy="client", orphanRemoval=true)
  36.      */
  37.     private $articleBuys;
  38.     public function __construct()
  39.     {
  40.         $this->deliverySpaces = new ArrayCollection();
  41.         $this->articleBuys = new ArrayCollection();
  42.     }
  43.     public function getId(): ?int
  44.     {
  45.         return $this->id;
  46.     }
  47.     public function getUser(): ?User
  48.     {
  49.         return $this->user;
  50.     }
  51.     public function setUser(User $user): self
  52.     {
  53.         $this->user $user;
  54.         return $this;
  55.     }
  56.     /**
  57.      * @return Collection|DeliverySpace[]
  58.      */
  59.     public function getDeliverySpaces(): Collection
  60.     {
  61.         return $this->deliverySpaces;
  62.     }
  63.     public function addDeliverySpace(DeliverySpace $deliverySpace): self
  64.     {
  65.         if (!$this->deliverySpaces->contains($deliverySpace)) {
  66.             $this->deliverySpaces[] = $deliverySpace;
  67.             $deliverySpace->setClient($this);
  68.         }
  69.         return $this;
  70.     }
  71.     public function removeDeliverySpace(DeliverySpace $deliverySpace): self
  72.     {
  73.         if ($this->deliverySpaces->removeElement($deliverySpace)) {
  74.             // set the owning side to null (unless already changed)
  75.             if ($deliverySpace->getClient() === $this) {
  76.                 $deliverySpace->setClient(null);
  77.             }
  78.         }
  79.         return $this;
  80.     }
  81.     /**
  82.      * @return Collection|ArticleBuy[]
  83.      */
  84.     public function getArticleBuys(): Collection
  85.     {
  86.         return $this->articleBuys;
  87.     }
  88.     public function addArticleBuy(ArticleBuy $articleBuy): self
  89.     {
  90.         if (!$this->articleBuys->contains($articleBuy)) {
  91.             $this->articleBuys[] = $articleBuy;
  92.             $articleBuy->setClient($this);
  93.         }
  94.         return $this;
  95.     }
  96.     public function removeArticleBuy(ArticleBuy $articleBuy): self
  97.     {
  98.         if ($this->articleBuys->removeElement($articleBuy)) {
  99.             // set the owning side to null (unless already changed)
  100.             if ($articleBuy->getClient() === $this) {
  101.                 $articleBuy->setClient(null);
  102.             }
  103.         }
  104.         return $this;
  105.     }
  106. }