Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

181 lines
4.9KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Model\PointSale;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Lc\CaracoleBundle\Doctrine\Extension\FilterMultipleMerchantsInterface;
  7. use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinTrait;
  8. use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinInterface;
  9. use Lc\CaracoleBundle\Model\Address\AddressInterface;
  10. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  11. use Lc\CaracoleBundle\Model\User\UserPointSaleInterface;
  12. use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;
  13. /**
  14. * @ORM\MappedSuperclass()
  15. */
  16. abstract class PointSaleModel extends AbstractFullEntity implements FilterMultipleMerchantsInterface,
  17. OrderAmountMinInterface
  18. {
  19. use OrderAmountMinTrait;
  20. /**
  21. * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface", inversedBy="pointSales")
  22. */
  23. protected $merchants;
  24. /**
  25. * @ORM\Column(type="string", length=63, nullable=true)
  26. */
  27. protected $code;
  28. /**
  29. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\PointSale\PointSaleDayInfoInterface", mappedBy="pointSale", orphanRemoval=true)
  30. */
  31. protected $pointSaleDayInfos;
  32. /**
  33. * @ORM\OneToOne(targetEntity="Lc\CaracoleBundle\Model\Address\AddressInterface", inversedBy="pointSale", cascade={"persist", "remove"})
  34. * @ORM\JoinColumn(nullable=false)
  35. */
  36. protected $address;
  37. /**
  38. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\User\UserPointSaleInterface", mappedBy="pointSale", orphanRemoval=true)
  39. */
  40. protected $userPointSales;
  41. public function __construct()
  42. {
  43. $this->merchants = new ArrayCollection();
  44. $this->pointSaleDayInfos = new ArrayCollection();
  45. $this->userPointSales = new ArrayCollection();
  46. }
  47. public function __toString()
  48. {
  49. return $this->getTitle();
  50. }
  51. public function labelAdminChoice()
  52. {
  53. return $this->getTitle();
  54. }
  55. /**
  56. * @return Collection|MerchantInterface[]
  57. */
  58. public function getMerchants(): Collection
  59. {
  60. return $this->merchants;
  61. }
  62. public function addMerchant(MerchantInterface $merchant): self
  63. {
  64. if (!$this->merchants->contains($merchant)) {
  65. $this->merchants[] = $merchant;
  66. }
  67. return $this;
  68. }
  69. public function removeMerchant(MerchantInterface $merchant): self
  70. {
  71. if ($this->merchants->contains($merchant)) {
  72. $this->merchants->removeElement($merchant);
  73. }
  74. return $this;
  75. }
  76. public function getCode(): ?string
  77. {
  78. return $this->code;
  79. }
  80. public function setCode(?string $code): self
  81. {
  82. $this->code = $code;
  83. return $this;
  84. }
  85. /**
  86. * @return Collection|PointSaleDayInfoInterface[]
  87. */
  88. public function getPointSaleDayInfos(): Collection
  89. {
  90. return $this->pointSaleDayInfos;
  91. }
  92. public function addPointSaleDayInfo(PointSaleDayInfoInterface $pointSaleDayInfo): self
  93. {
  94. if (!$this->pointSaleDayInfos->contains($pointSaleDayInfo)) {
  95. $this->pointSaleDayInfos[] = $pointSaleDayInfo;
  96. $pointSaleDayInfo->setPointSale($this);
  97. }
  98. return $this;
  99. }
  100. public function removePointSaleDayInfo(PointSaleDayInfoInterface $pointSaleDayInfo): self
  101. {
  102. if ($this->pointSaleDayInfos->contains($pointSaleDayInfo)) {
  103. $this->pointSaleDayInfos->removeElement($pointSaleDayInfo);
  104. // set the owning side to null (unless already changed)
  105. if ($pointSaleDayInfo->getPointSale() === $this) {
  106. $pointSaleDayInfo->setPointSale(null);
  107. }
  108. }
  109. return $this;
  110. }
  111. public function getAddress(): ?AddressInterface
  112. {
  113. return $this->address;
  114. }
  115. public function setAddress(AddressInterface $address): self
  116. {
  117. $this->address = $address;
  118. return $this;
  119. }
  120. /**
  121. * @return Collection|UserPointSaleInterface[]
  122. */
  123. public function getUserPointSales(): Collection
  124. {
  125. return $this->userPointSales;
  126. }
  127. public function addUserPointSale(UserPointSaleInterface $userPointSale): self
  128. {
  129. if (!$this->userPointSales->contains($userPointSale)) {
  130. $this->userPointSales[] = $userPointSale;
  131. $userPointSale->setPointSale($this);
  132. }
  133. return $this;
  134. }
  135. public function removeUserPointSale(UserPointSaleInterface $userPointSale): self
  136. {
  137. if ($this->userPointSales->contains($userPointSale)) {
  138. $this->userPointSales->removeElement($userPointSale);
  139. // set the owning side to null (unless already changed)
  140. if ($userPointSale->getPointSale() === $this) {
  141. $userPointSale->setPointSale(null);
  142. }
  143. }
  144. return $this;
  145. }
  146. }