src/NewShippingBundle/Entity/ShippingTime.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\NewShippingBundle\Entity;
  3. use App\NewShippingBundle\Entity\Translation\ShippingTimeTranslation;
  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. /**
  10. * @ORM\Table("shipping_time")
  11. * @ORM\Entity(repositoryClass="App\NewShippingBundle\Repository\ShippingTimeRepository")
  12. */
  13. class ShippingTime implements Translatable
  14. {
  15. use LocaleTrait;
  16. /**
  17. * @ORM\Column(name="id", type="integer")
  18. * @ORM\Id
  19. * @ORM\GeneratedValue(strategy="AUTO")
  20. */
  21. private ?int $id = null;
  22. /**
  23. * @ORM\Column(name="name", type="string", length=45)
  24. */
  25. private ?string $name = null;
  26. /**
  27. * @ORM\Column(name="number_of_delivery_days", type="integer", nullable=true, options={"default" : 0})
  28. */
  29. private int $noOfDeliveryDays = 0;
  30. /**
  31. * @ORM\Column(name="deleted", type="boolean")
  32. */
  33. private bool $deleted = false;
  34. /**
  35. * @ORM\OneToMany(targetEntity="App\NewShippingBundle\Entity\ShippingZonePrice", mappedBy="shippingTime")
  36. */
  37. private Collection $shippingZonePrices;
  38. /**
  39. * @ORM\OneToMany(targetEntity="App\NewShippingBundle\Entity\Translation\ShippingTimeTranslation", mappedBy="translatable", cascade={"ALL"}, orphanRemoval=true)
  40. */
  41. private Collection $translations;
  42. public function __construct()
  43. {
  44. $this->shippingZonePrices = new ArrayCollection();
  45. $this->translations = new ArrayCollection();
  46. }
  47. function __toString()
  48. {
  49. return $this->getName();
  50. }
  51. public function getObj(): array
  52. {
  53. return [
  54. "id" => $this->getId(),
  55. "name" => $this->getName(),
  56. ];
  57. }
  58. public function getName(): string
  59. {
  60. return !$this->currentTranslation ? $this->name : $this->currentTranslation->getName();
  61. }
  62. public function getId(): ?int
  63. {
  64. return $this->id;
  65. }
  66. public function setName(string $name): static
  67. {
  68. $this->name = $name;
  69. return $this;
  70. }
  71. public function getNoOfDeliveryDays(): ?int
  72. {
  73. return $this->noOfDeliveryDays;
  74. }
  75. public function setNoOfDeliveryDays(?int $noOfDeliveryDays): static
  76. {
  77. $this->noOfDeliveryDays = $noOfDeliveryDays;
  78. return $this;
  79. }
  80. public function isDeleted(): ?bool
  81. {
  82. return $this->deleted;
  83. }
  84. public function setDeleted(bool $deleted): static
  85. {
  86. $this->deleted = $deleted;
  87. return $this;
  88. }
  89. /**
  90. * @return Collection<int, ShippingZonePrice>
  91. */
  92. public function getShippingZonePrices(): Collection
  93. {
  94. return $this->shippingZonePrices;
  95. }
  96. public function addShippingZonePrice(ShippingZonePrice $shippingZonePrice): static
  97. {
  98. if (!$this->shippingZonePrices->contains($shippingZonePrice)) {
  99. $this->shippingZonePrices->add($shippingZonePrice);
  100. $shippingZonePrice->setShippingTime($this);
  101. }
  102. return $this;
  103. }
  104. public function removeShippingZonePrice(ShippingZonePrice $shippingZonePrice): static
  105. {
  106. if ($this->shippingZonePrices->removeElement($shippingZonePrice)) {
  107. // set the owning side to null (unless already changed)
  108. if ($shippingZonePrice->getShippingTime() === $this) {
  109. $shippingZonePrice->setShippingTime(null);
  110. }
  111. }
  112. return $this;
  113. }
  114. /**
  115. * @return Collection<int, ShippingTimeTranslation>
  116. */
  117. public function getTranslations(): Collection
  118. {
  119. return $this->translations;
  120. }
  121. public function addTranslation(ShippingTimeTranslation $translation): static
  122. {
  123. if (!$this->translations->contains($translation)) {
  124. $this->translations->add($translation);
  125. $translation->setTranslatable($this);
  126. }
  127. return $this;
  128. }
  129. public function removeTranslation(ShippingTimeTranslation $translation): static
  130. {
  131. if ($this->translations->removeElement($translation)) {
  132. // set the owning side to null (unless already changed)
  133. if ($translation->getTranslatable() === $this) {
  134. $translation->setTranslatable(null);
  135. }
  136. }
  137. return $this;
  138. }
  139. }