src/Entity/Street.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\StreetRepository;
  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=StreetRepository::class)
  11.  * @UniqueEntity(
  12.  *  fields="name",
  13.  *  message="Cette valeur existe "
  14.  * )
  15.  */
  16. class Street
  17. {
  18.     /**
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue
  21.      * @ORM\Column(type="integer")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @ORM\Column(type="string", length=255)
  26.      */
  27.     private $name;
  28.     /**
  29.      * @ORM\ManyToOne(targetEntity=City::class, inversedBy="streets")
  30.      * @ORM\JoinColumn(nullable=false)
  31.      */
  32.     private $city;
  33.     /**
  34.      * @ORM\ManyToOne(targetEntity=ShippingAmount::class, inversedBy="street", cascade={"persist"})
  35.      */
  36.     private $shippingAmount;
  37.     /**
  38.      * @ORM\OneToMany(targetEntity=DeliverySpace::class, mappedBy="street")
  39.      */
  40.     private $deliverySpaces;
  41.     public function __construct()
  42.     {
  43.         $this->deliverySpaces = new ArrayCollection();
  44.     }
  45.     public function getId(): ?int
  46.     {
  47.         return $this->id;
  48.     }
  49.     public function getName(): ?string
  50.     {
  51.         return $this->name;
  52.     }
  53.     public function setName(string $name): self
  54.     {
  55.         $this->name $name;
  56.         return $this;
  57.     }
  58.     public function getCity(): ?City
  59.     {
  60.         return $this->city;
  61.     }
  62.     public function setCity(?City $city): self
  63.     {
  64.         $this->city $city;
  65.         return $this;
  66.     }
  67.     public function getShippingAmount(): ?ShippingAmount
  68.     {
  69.         return $this->shippingAmount;
  70.     }
  71.     public function setShippingAmount(?ShippingAmount $shippingAmount): self
  72.     {
  73.         $this->shippingAmount $shippingAmount;
  74.         return $this;
  75.     }
  76.     /**
  77.      * @return Collection|DeliverySpace[]
  78.      */
  79.     public function getDeliverySpaces(): Collection
  80.     {
  81.         return $this->deliverySpaces;
  82.     }
  83.     public function addDeliverySpace(DeliverySpace $deliverySpace): self
  84.     {
  85.         if (!$this->deliverySpaces->contains($deliverySpace)) {
  86.             $this->deliverySpaces[] = $deliverySpace;
  87.             $deliverySpace->setStreet($this);
  88.         }
  89.         return $this;
  90.     }
  91.     public function removeDeliverySpace(DeliverySpace $deliverySpace): self
  92.     {
  93.         if ($this->deliverySpaces->removeElement($deliverySpace)) {
  94.             // set the owning side to null (unless already changed)
  95.             if ($deliverySpace->getStreet() === $this) {
  96.                 $deliverySpace->setStreet(null);
  97.             }
  98.         }
  99.         return $this;
  100.     }
  101. }