src/NewShippingBundle/Entity/Zone.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\NewShippingBundle\Entity;
  3. use App\NewShippingBundle\Entity\Translation\ZoneTranslation;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use PN\LocaleBundle\Model\LocaleTrait;
  8. use PN\LocaleBundle\Model\Translatable;
  9. use PN\ServiceBundle\Interfaces\DateTimeInterface;
  10. use PN\ServiceBundle\Model\DateTimeTrait;
  11. use PN\ServiceBundle\Model\VirtualDeleteTrait;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14. * @ORM\HasLifecycleCallbacks
  15. * @ORM\Table("zone")
  16. * @ORM\Entity(repositoryClass="App\NewShippingBundle\Repository\ZoneRepository")
  17. */
  18. class Zone implements Translatable, DateTimeInterface
  19. {
  20. use VirtualDeleteTrait,
  21. DateTimeTrait,
  22. LocaleTrait;
  23. /**
  24. * @ORM\Column(name="id", type="integer")
  25. * @ORM\Id
  26. * @ORM\GeneratedValue(strategy="AUTO")
  27. */
  28. private ?int $id = null;
  29. /**
  30. * @Assert\NotBlank()
  31. * @ORM\Column(name="title", type="string", length=50)
  32. */
  33. private ?string $title = null;
  34. /**
  35. * @ORM\Column(name="tarteb", type="smallint", nullable=true)
  36. */
  37. private ?int $tarteb = null;
  38. /**
  39. * @ORM\ManyToMany(targetEntity="ShippingZone", mappedBy="zones")
  40. */
  41. private Collection $shippingZones;
  42. /**
  43. * @ORM\OneToMany(targetEntity="App\NewShippingBundle\Entity\Translation\ZoneTranslation", mappedBy="translatable", cascade={"ALL"}, orphanRemoval=true)
  44. */
  45. private Collection $translations;
  46. public function __construct()
  47. {
  48. $this->shippingZones = new ArrayCollection();
  49. $this->translations = new ArrayCollection();
  50. }
  51. public function getObj(): array
  52. {
  53. return [
  54. "id" => $this->getId(),
  55. "title" => $this->getTitle(),
  56. ];
  57. }
  58. public function __toString()
  59. {
  60. return $this->getTitle();
  61. }
  62. public function getTitle(): ?string
  63. {
  64. return !$this->currentTranslation ? $this->title : $this->currentTranslation->getTitle();
  65. }
  66. public function getId(): ?int
  67. {
  68. return $this->id;
  69. }
  70. public function setTitle(string $title): static
  71. {
  72. $this->title = $title;
  73. return $this;
  74. }
  75. public function getTarteb(): ?int
  76. {
  77. return $this->tarteb;
  78. }
  79. public function setTarteb(?int $tarteb): static
  80. {
  81. $this->tarteb = $tarteb;
  82. return $this;
  83. }
  84. /**
  85. * @return Collection<int, ShippingZone>
  86. */
  87. public function getShippingZones(): Collection
  88. {
  89. return $this->shippingZones;
  90. }
  91. public function addShippingZone(ShippingZone $shippingZone): static
  92. {
  93. if (!$this->shippingZones->contains($shippingZone)) {
  94. $this->shippingZones->add($shippingZone);
  95. $shippingZone->addZone($this);
  96. }
  97. return $this;
  98. }
  99. public function removeShippingZone(ShippingZone $shippingZone): static
  100. {
  101. if ($this->shippingZones->removeElement($shippingZone)) {
  102. $shippingZone->removeZone($this);
  103. }
  104. return $this;
  105. }
  106. /**
  107. * @return Collection<int, ZoneTranslation>
  108. */
  109. public function getTranslations(): Collection
  110. {
  111. return $this->translations;
  112. }
  113. public function addTranslation(ZoneTranslation $translation): static
  114. {
  115. if (!$this->translations->contains($translation)) {
  116. $this->translations->add($translation);
  117. $translation->setTranslatable($this);
  118. }
  119. return $this;
  120. }
  121. public function removeTranslation(ZoneTranslation $translation): static
  122. {
  123. if ($this->translations->removeElement($translation)) {
  124. // set the owning side to null (unless already changed)
  125. if ($translation->getTranslatable() === $this) {
  126. $translation->setTranslatable(null);
  127. }
  128. }
  129. return $this;
  130. }
  131. }