Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

307 lines
8.4KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Model\User;
  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\SovBundle\Model\Newsletter\NewsletterInterface;
  8. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  9. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  10. use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
  11. use Lc\SovBundle\Model\User\UserModel as SovUserModel;
  12. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  13. /**
  14. * @ORM\MappedSuperclass()
  15. *
  16. */
  17. abstract class UserModel extends SovUserModel
  18. {
  19. /**
  20. * @ORM\Column(type="string", length=64, nullable=true)
  21. */
  22. protected $behaviorDisplayPrice;
  23. /**
  24. * @ORM\Column(type="boolean", nullable=true)
  25. */
  26. protected $isSaleAlwaysOpen;
  27. /**
  28. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
  29. */
  30. protected $favoriteMerchant;
  31. /**
  32. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Address\AddressInterface", mappedBy="user", cascade={"persist", "remove"})
  33. */
  34. protected $addresses;
  35. /**
  36. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Order\OrderShopInterface", mappedBy="user")
  37. */
  38. protected $orderShops;
  39. /**
  40. * @ORM\ManyToMany(targetEntity="Lc\SovBundle\Model\Newsletter\NewsletterInterface", inversedBy="users")
  41. */
  42. protected $newsletters;
  43. /**
  44. * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductFamilyInterface")
  45. */
  46. protected $favoriteProductFamilies;
  47. /**
  48. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\User\UserPointSaleInterface", mappedBy="user", orphanRemoval=true)
  49. */
  50. protected $userPointSales;
  51. /**
  52. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\User\UserMerchantInterface", mappedBy="user", orphanRemoval=true)
  53. */
  54. protected $userMerchants;
  55. /**
  56. * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface", mappedBy="users")
  57. */
  58. protected $reductionCredits;
  59. public function __construct()
  60. {
  61. parent::__construct();
  62. $this->addresses = new ArrayCollection();
  63. $this->orderShops = new ArrayCollection();
  64. $this->groupUsers = new ArrayCollection();
  65. $this->newsletters = new ArrayCollection();
  66. $this->favoriteProductFamilies = new ArrayCollection();
  67. $this->userPointSales = new ArrayCollection();
  68. $this->userMerchants = new ArrayCollection();
  69. $this->reductionCredits = new ArrayCollection();
  70. }
  71. public function getBehaviorDisplayPrice(): ?string
  72. {
  73. return $this->behaviorDisplayPrice;
  74. }
  75. public function setBehaviorDisplayPrice(?string $behaviorDisplayPrice): self
  76. {
  77. $this->behaviorDisplayPrice = $behaviorDisplayPrice;
  78. return $this;
  79. }
  80. public function getIsSaleAlwaysOpen(): ?bool
  81. {
  82. return $this->isSaleAlwaysOpen;
  83. }
  84. public function setIsSaleAlwaysOpen(?bool $isSaleAlwaysOpen): self
  85. {
  86. $this->isSaleAlwaysOpen = $isSaleAlwaysOpen;
  87. return $this;
  88. }
  89. public function getFavoriteMerchant(): ?MerchantInterface
  90. {
  91. return $this->favoriteMerchant;
  92. }
  93. public function setFavoriteMerchant(?MerchantInterface $merchant): self
  94. {
  95. $this->favoriteMerchant = $merchant;
  96. return $this;
  97. }
  98. /**
  99. * @return Collection|AddressInterface[]
  100. */
  101. public function getAddresses($status = null): Collection
  102. {
  103. if ($status) {
  104. $addressToReturn = new ArrayCollection();
  105. foreach ($this->addresses as $address) {
  106. if ($address->getStatus() == $status) {
  107. $addressToReturn[] = $address;
  108. }
  109. }
  110. return $addressToReturn;
  111. } else {
  112. return $this->addresses;
  113. }
  114. }
  115. public function addAddress(AddressInterface $address): self
  116. {
  117. if (!$this->addresses->contains($address)) {
  118. $this->addresses[] = $address;
  119. $address->setUser($this);
  120. }
  121. return $this;
  122. }
  123. public function removeAddress(AddressInterface $address): self
  124. {
  125. if ($this->addresses->contains($address)) {
  126. $this->addresses->removeElement($address);
  127. // set the owning side to null (unless already changed)
  128. if ($address->getUser() === $this) {
  129. $address->setUser(null);
  130. }
  131. }
  132. return $this;
  133. }
  134. /**
  135. * @return Collection|OrderShopInterface[]
  136. */
  137. public function getOrderShops(): Collection
  138. {
  139. return $this->orderShops;
  140. }
  141. public function addOrderShop(OrderShopInterface $orderShop): self
  142. {
  143. if (!$this->orderShops->contains($orderShop)) {
  144. $this->orderShops[] = $orderShop;
  145. $orderShop->setUser($this);
  146. }
  147. return $this;
  148. }
  149. public function removeOrderShop(OrderShopInterface $orderShop): self
  150. {
  151. if ($this->orderShops->contains($orderShop)) {
  152. $this->orderShops->removeElement($orderShop);
  153. // set the owning side to null (unless already changed)
  154. if ($orderShop->getUser() === $this) {
  155. $orderShop->setUser(null);
  156. }
  157. }
  158. return $this;
  159. }
  160. /**
  161. * @return Collection|NewsletterInterface[]
  162. */
  163. public function getNewsletters(): Collection
  164. {
  165. return $this->newsletters;
  166. }
  167. public function addNewsletter(NewsletterInterface $newsletter): self
  168. {
  169. if (!$this->newsletters->contains($newsletter)) {
  170. $this->newsletters[] = $newsletter;
  171. }
  172. return $this;
  173. }
  174. public function removeNewsletter(NewsletterInterface $newsletter): self
  175. {
  176. if ($this->newsletters->contains($newsletter)) {
  177. $this->newsletters->removeElement($newsletter);
  178. }
  179. return $this;
  180. }
  181. /**
  182. * @return Collection|ProductFamilyInterface[]
  183. */
  184. public function getFavoriteProductFamilies(): Collection
  185. {
  186. return $this->favoriteProductFamilies;
  187. }
  188. public function addFavoriteProductFamily(ProductFamilyInterface $favoriteProductFamily): self
  189. {
  190. if (!$this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  191. $this->favoriteProductFamilies[] = $favoriteProductFamily;
  192. }
  193. return $this;
  194. }
  195. public function removeFavoriteProductFamily(ProductFamilyInterface $favoriteProductFamily): self
  196. {
  197. if ($this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  198. $this->favoriteProductFamilies->removeElement($favoriteProductFamily);
  199. }
  200. return $this;
  201. }
  202. /**
  203. * @return Collection|UserPointSaleInterface[]
  204. */
  205. public function getUserPointSales(): Collection
  206. {
  207. return $this->userPointSales;
  208. }
  209. public function addUserPointSale(UserPointSaleInterface $userPointSale): self
  210. {
  211. if (!$this->userPointSales->contains($userPointSale)) {
  212. $this->userPointSales[] = $userPointSale;
  213. $userPointSale->setUser($this);
  214. }
  215. return $this;
  216. }
  217. public function removeUserPointSale(UserPointSaleInterface $userPointSale): self
  218. {
  219. if ($this->userPointSales->contains($userPointSale)) {
  220. $this->userPointSales->removeElement($userPointSale);
  221. // set the owning side to null (unless already changed)
  222. if ($userPointSale->getUser() === $this) {
  223. $userPointSale->setUser(null);
  224. }
  225. }
  226. return $this;
  227. }
  228. /**
  229. * @return Collection|ReductionCreditInterface[]
  230. */
  231. public function getReductionCredits(): Collection
  232. {
  233. return $this->reductionCredits;
  234. }
  235. public function addReductionCredit(ReductionCreditInterface $reductionCredit): self
  236. {
  237. if (!$this->reductionCredits->contains($reductionCredit)) {
  238. $this->reductionCredits[] = $reductionCredit;
  239. $reductionCredit->addUser($this);
  240. }
  241. return $this;
  242. }
  243. public function removeReductionCredit(ReductionCreditInterface $reductionCredit): self
  244. {
  245. if ($this->reductionCredits->contains($reductionCredit)) {
  246. $this->reductionCredits->removeElement($reductionCredit);
  247. $reductionCredit->removeUser($this);
  248. }
  249. return $this;
  250. }
  251. }