133 行
3.7KB

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