src/NewShippingBundle/Entity/ShippingZone.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\NewShippingBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use PN\ServiceBundle\Interfaces\DateTimeInterface;
  7. use PN\ServiceBundle\Model\DateTimeTrait;
  8. use PN\ServiceBundle\Model\VirtualDeleteTrait;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11. * @ORM\HasLifecycleCallbacks
  12. * @ORM\Table("shipping_zone")
  13. * @ORM\Entity(repositoryClass="App\NewShippingBundle\Repository\ShippingZoneRepository")
  14. */
  15. class ShippingZone implements DateTimeInterface
  16. {
  17. use VirtualDeleteTrait,
  18. DateTimeTrait;
  19. /**
  20. * @ORM\Column(name="id", type="integer")
  21. * @ORM\Id
  22. * @ORM\GeneratedValue(strategy="AUTO")
  23. */
  24. private ?int $id = null;
  25. /**
  26. * @Assert\NotBlank()
  27. * @ORM\Column(name="title", type="string", length=50)
  28. */
  29. private ?string $title = null;
  30. /**
  31. * @ORM\OneToMany(targetEntity="ShippingZonePrice", mappedBy="sourceShippingZone")
  32. */
  33. private Collection $sourceShippingZonePrices;
  34. /**
  35. * @ORM\OneToMany(targetEntity="ShippingZonePrice", mappedBy="targetShippingZone")
  36. */
  37. private Collection $targetShippingZonePrices;
  38. /**
  39. * @ORM\ManyToMany(targetEntity="Zone", inversedBy="shippingZones")
  40. */
  41. private Collection $zones;
  42. public function __construct()
  43. {
  44. $this->zones = new ArrayCollection();
  45. $this->sourceShippingZonePrices = new ArrayCollection();
  46. $this->targetShippingZonePrices = new ArrayCollection();
  47. }
  48. public function __toString()
  49. {
  50. return $this->getTitle();
  51. }
  52. /**
  53. * Now we tell doctrine that before we persist or update we call the updatedTimestamps() function.
  54. *
  55. * @ORM\PrePersist
  56. * @ORM\PreUpdate
  57. */
  58. public function updatedTimestamps(): void
  59. {
  60. $this->setModified(new \DateTime(date('Y-m-d H:i:s')));
  61. if ($this->getCreated() == null) {
  62. $this->setCreated(new \DateTime(date('Y-m-d H:i:s')));
  63. }
  64. }
  65. public function getId(): ?int
  66. {
  67. return $this->id;
  68. }
  69. public function getTitle(): ?string
  70. {
  71. return $this->title;
  72. }
  73. public function setTitle(string $title): self
  74. {
  75. $this->title = $title;
  76. return $this;
  77. }
  78. /**
  79. * @return Collection|Zone[]
  80. */
  81. public function getZones(): Collection
  82. {
  83. return $this->zones;
  84. }
  85. public function addZone(Zone $zone): self
  86. {
  87. if (!$this->zones->contains($zone)) {
  88. $this->zones[] = $zone;
  89. }
  90. return $this;
  91. }
  92. public function removeZone(Zone $zone): self
  93. {
  94. $this->zones->removeElement($zone);
  95. return $this;
  96. }
  97. /**
  98. * @return Collection<int, ShippingZonePrice>
  99. */
  100. public function getSourceShippingZonePrices(): Collection
  101. {
  102. return $this->sourceShippingZonePrices;
  103. }
  104. public function addSourceShippingZonePrice(ShippingZonePrice $sourceShippingZonePrice): static
  105. {
  106. if (!$this->sourceShippingZonePrices->contains($sourceShippingZonePrice)) {
  107. $this->sourceShippingZonePrices->add($sourceShippingZonePrice);
  108. $sourceShippingZonePrice->setSourceShippingZone($this);
  109. }
  110. return $this;
  111. }
  112. public function removeSourceShippingZonePrice(ShippingZonePrice $sourceShippingZonePrice): static
  113. {
  114. if ($this->sourceShippingZonePrices->removeElement($sourceShippingZonePrice)) {
  115. // set the owning side to null (unless already changed)
  116. if ($sourceShippingZonePrice->getSourceShippingZone() === $this) {
  117. $sourceShippingZonePrice->setSourceShippingZone(null);
  118. }
  119. }
  120. return $this;
  121. }
  122. /**
  123. * @return Collection<int, ShippingZonePrice>
  124. */
  125. public function getTargetShippingZonePrices(): Collection
  126. {
  127. return $this->targetShippingZonePrices;
  128. }
  129. public function addTargetShippingZonePrice(ShippingZonePrice $targetShippingZonePrice): static
  130. {
  131. if (!$this->targetShippingZonePrices->contains($targetShippingZonePrice)) {
  132. $this->targetShippingZonePrices->add($targetShippingZonePrice);
  133. $targetShippingZonePrice->setTargetShippingZone($this);
  134. }
  135. return $this;
  136. }
  137. public function removeTargetShippingZonePrice(ShippingZonePrice $targetShippingZonePrice): static
  138. {
  139. if ($this->targetShippingZonePrices->removeElement($targetShippingZonePrice)) {
  140. // set the owning side to null (unless already changed)
  141. if ($targetShippingZonePrice->getTargetShippingZone() === $this) {
  142. $targetShippingZonePrice->setTargetShippingZone(null);
  143. }
  144. }
  145. return $this;
  146. }
  147. }