Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

211 lines
5.6KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Model\Merchant;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Lc\CaracoleBundle\Model\Address\AddressInterface;
  7. use Lc\CaracoleBundle\Model\Config\TaxRateInterface;
  8. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  9. use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
  10. use Lc\CaracoleBundle\Model\Setting\MerchantSettingInterface;
  11. use Lc\SovBundle\Model\User\GroupUserInterface;
  12. use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;
  13. /**
  14. * @ORM\MappedSuperclass()
  15. */
  16. abstract class MerchantModel extends AbstractFullEntity implements MerchantInterface
  17. {
  18. /**
  19. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Config\TaxRateInterface")
  20. * @ORM\JoinColumn(nullable=false)
  21. */
  22. protected $taxRate;
  23. /**
  24. * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\PointSale\PointSaleInterface", mappedBy="merchants")
  25. */
  26. protected $pointSales;
  27. /**
  28. * @ORM\OneToOne(targetEntity="Lc\CaracoleBundle\Model\Address\AddressInterface", inversedBy="merchant", cascade={"persist", "remove"})
  29. * @ORM\JoinColumn(nullable=true)
  30. */
  31. protected $address;
  32. /**
  33. * @ORM\OneToMany(targetEntity="Lc\SovBundle\Model\User\GroupUserInterface", mappedBy="merchant")
  34. */
  35. protected $groupUsers;
  36. /**
  37. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Setting\MerchantSettingInterface", mappedBy="merchant", orphanRemoval=true, cascade={"persist"}, fetch="EAGER")
  38. */
  39. protected $settings;
  40. /**
  41. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface", mappedBy="merchant")
  42. */
  43. protected $sections;
  44. public function __construct()
  45. {
  46. $this->pointSales = new ArrayCollection();
  47. $this->groupUsers = new ArrayCollection();
  48. $this->settings = new ArrayCollection();
  49. }
  50. public function __toString()
  51. {
  52. return $this->getTitle() ;
  53. }
  54. public function getTaxRate(): ?TaxRateInterface
  55. {
  56. return $this->taxRate;
  57. }
  58. public function setTaxRate(?TaxRateInterface $taxRate): self
  59. {
  60. $this->taxRate = $taxRate;
  61. return $this;
  62. }
  63. /**
  64. * @return Collection|PointSaleInterface[]
  65. */
  66. public function getPointSales(): Collection
  67. {
  68. return $this->pointSales;
  69. }
  70. public function addPointSale(PointSaleInterface $pointSale): self
  71. {
  72. if (!$this->pointSales->contains($pointSale)) {
  73. $this->pointSales[] = $pointSale;
  74. $pointSale->addMerchant($this);
  75. }
  76. return $this;
  77. }
  78. public function removePointSale(PointSaleInterface $pointSale): self
  79. {
  80. if ($this->pointSales->contains($pointSale)) {
  81. $this->pointSales->removeElement($pointSale);
  82. $pointSale->removeMerchant($this);
  83. }
  84. return $this;
  85. }
  86. /**
  87. * @return Collection|MerchantSettingInterface[]
  88. */
  89. public function getSettings(): ?Collection
  90. {
  91. return $this->settings;
  92. }
  93. public function addSetting(MerchantSettingInterface $merchantSetting): self
  94. {
  95. if (!$this->settings->contains($merchantSetting)) {
  96. $this->settings[] = $merchantSetting;
  97. $merchantSetting->setMerchant($this);
  98. }
  99. return $this;
  100. }
  101. public function removeSetting(MerchantSettingInterface $merchantSetting): self
  102. {
  103. if ($this->settings->contains($merchantSetting)) {
  104. $this->settings->removeElement($merchantSetting);
  105. // set the owning side to null (unless already changed)
  106. if ($merchantSetting->getMerchant() === $this) {
  107. $merchantSetting->setMerchant(null);
  108. }
  109. }
  110. return $this;
  111. }
  112. public function getAddress(): ?AddressInterface
  113. {
  114. return $this->address;
  115. }
  116. public function setAddress(AddressInterface $address): self
  117. {
  118. $this->address = $address;
  119. return $this;
  120. }
  121. /**
  122. * @return Collection|GroupUserInterface[]
  123. */
  124. public function getGroupUsers(): Collection
  125. {
  126. return $this->groupUsers;
  127. }
  128. public function addGroupUser(GroupUserInterface $groupUser): self
  129. {
  130. if (!$this->groupUsers->contains($groupUser)) {
  131. $this->groupUsers[] = $groupUser;
  132. $groupUser->setMerchant($this);
  133. }
  134. return $this;
  135. }
  136. public function removeGroupUser(GroupUserInterface $groupUser): self
  137. {
  138. if ($this->groupUsers->contains($groupUser)) {
  139. $this->groupUsers->removeElement($groupUser);
  140. // set the owning side to null (unless already changed)
  141. if ($groupUser->getMerchant() === $this) {
  142. $groupUser->setMerchant(null);
  143. }
  144. }
  145. return $this;
  146. }
  147. /**
  148. * @return Collection|SectionInterface[]
  149. */
  150. public function getSections(): ?Collection
  151. {
  152. return $this->sections;
  153. }
  154. public function addSection(SectionInterface $section): self
  155. {
  156. if (!$this->sections->contains($section)) {
  157. $this->sections[] = $section;
  158. $section->setMerchant($this);
  159. }
  160. return $this;
  161. }
  162. public function removeSection(SectionInterface $section): self
  163. {
  164. if ($this->sections->contains($section)) {
  165. $this->sections->removeElement($section);
  166. // set the owning side to null (unless already changed)
  167. if ($section->getMerchant() === $this) {
  168. $section->setMerchant(null);
  169. }
  170. }
  171. return $this;
  172. }
  173. }