136 行
3.8KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Lc\ShopBundle\Context\FilterMultipleMerchantsInterface;
  7. use Lc\ShopBundle\Context\OrderAmountMinInterface;
  8. /**
  9. * @ORM\MappedSuperclass()
  10. */
  11. abstract class PointSale extends AbstractDocumentEntity implements FilterMultipleMerchantsInterface, OrderAmountMinInterface
  12. {
  13. use OrderAmountMin;
  14. /**
  15. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="pointSales")
  16. */
  17. protected $merchants;
  18. /**
  19. * @ORM\Column(type="string", length=63, nullable=true)
  20. */
  21. protected $code;
  22. /**
  23. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\PointSaleDayInfoInterface", mappedBy="pointSale", orphanRemoval=true)
  24. */
  25. protected $pointSaleDayInfos;
  26. /**
  27. * @ORM\OneToOne(targetEntity="Lc\ShopBundle\Context\AddressInterface", inversedBy="pointSale", cascade={"persist", "remove"})
  28. * @ORM\JoinColumn(nullable=false)
  29. */
  30. protected $address;
  31. public function labelAdminChoice(){
  32. return $this->getTitle();
  33. }
  34. public function __construct()
  35. {
  36. $this->merchants = new ArrayCollection();
  37. $this->pointSaleDayInfos = new ArrayCollection();
  38. }
  39. public function __toString()
  40. {
  41. return $this->getTitle() ;
  42. }
  43. /**
  44. * @return Collection|Merchant[]
  45. */
  46. public function getMerchants(): Collection
  47. {
  48. return $this->merchants;
  49. }
  50. public function addMerchant(Merchant $merchant): self
  51. {
  52. if (!$this->merchants->contains($merchant)) {
  53. $this->merchants[] = $merchant;
  54. }
  55. return $this;
  56. }
  57. public function removeMerchant(Merchant $merchant): self
  58. {
  59. if ($this->merchants->contains($merchant)) {
  60. $this->merchants->removeElement($merchant);
  61. }
  62. return $this;
  63. }
  64. public function getCode(): ?string
  65. {
  66. return $this->code;
  67. }
  68. public function setCode(?string $code): self
  69. {
  70. $this->code = $code;
  71. return $this;
  72. }
  73. /**
  74. * @return Collection|PointSaleDayInfo[]
  75. */
  76. public function getPointSaleDayInfos(): Collection
  77. {
  78. return $this->pointSaleDayInfos;
  79. }
  80. public function addPointSaleDayInfo(PointSaleDayInfo $pointSaleDayInfo): self
  81. {
  82. if (!$this->pointSaleDayInfos->contains($pointSaleDayInfo)) {
  83. $this->pointSaleDayInfos[] = $pointSaleDayInfo;
  84. $pointSaleDayInfo->setPointSale($this);
  85. }
  86. return $this;
  87. }
  88. public function removePointSaleDayInfo(PointSaleDayInfo $pointSaleDayInfo): self
  89. {
  90. if ($this->pointSaleDayInfos->contains($pointSaleDayInfo)) {
  91. $this->pointSaleDayInfos->removeElement($pointSaleDayInfo);
  92. // set the owning side to null (unless already changed)
  93. if ($pointSaleDayInfo->getPointSale() === $this) {
  94. $pointSaleDayInfo->setPointSale(null);
  95. }
  96. }
  97. return $this;
  98. }
  99. public function getAddress(): ?Address
  100. {
  101. return $this->address;
  102. }
  103. public function setAddress(Address $address): self
  104. {
  105. $this->address = $address;
  106. return $this;
  107. }
  108. }