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

344 lines
9.6KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use App\Entity\Newsletter;
  4. use App\Entity\ProductFamily;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use FOS\UserBundle\Model\User as UserModelFOS;
  9. use Lc\ShopBundle\Context\MerchantInterface;
  10. /**
  11. * @ORM\MappedSuperclass()
  12. *
  13. */
  14. abstract class User extends UserModelFOS
  15. {
  16. /**
  17. * @ORM\Column(type="string", length=20, nullable=true)
  18. */
  19. protected $phone;
  20. /**
  21. * @ORM\Column(type="string", length=64, nullable=true)
  22. */
  23. protected $behaviorDisplayPrice;
  24. /**
  25. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface")
  26. */
  27. protected $merchant;
  28. /**
  29. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\CreditHistoryInterface", mappedBy="user", orphanRemoval=true)
  30. */
  31. protected $creditHistories;
  32. /**
  33. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\AddressInterface", mappedBy="user", cascade={"persist"})
  34. */
  35. protected $addresses;
  36. /**
  37. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderShopInterface", mappedBy="user")
  38. */
  39. protected $orders;
  40. /**
  41. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\CartInterface", mappedBy="user")
  42. */
  43. protected $carts;
  44. /**
  45. * @ORM\Column(type="string", length=64, nullable=true)
  46. */
  47. protected $firstname;
  48. /**
  49. * @ORM\Column(type="string", length=64, nullable=true)
  50. */
  51. protected $lastname;
  52. /**
  53. * @ORM\Column(type="boolean", nullable=true)
  54. */
  55. protected $gender;
  56. /**
  57. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\NewsletterInterface", inversedBy="users")
  58. */
  59. protected $newsletters;
  60. /**
  61. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\ProductFamilyInterface")
  62. */
  63. protected $favoriteProductFamilies;
  64. public function __construct()
  65. {
  66. parent::__construct();
  67. $this->creditHistories = new ArrayCollection();
  68. $this->addresses = new ArrayCollection();
  69. $this->orders = new ArrayCollection();
  70. $this->carts = new ArrayCollection();
  71. $this->newsletters = new ArrayCollection();
  72. $this->favoriteProductFamilies = new ArrayCollection();
  73. }
  74. public function setEmail($email)
  75. {
  76. $this->setUsername($email);
  77. return parent::setEmail($email);
  78. }
  79. public function getPhone(): ?string
  80. {
  81. return $this->phone;
  82. }
  83. public function setPhone(?string $phone): self
  84. {
  85. $this->phone = $phone;
  86. return $this;
  87. }
  88. public function getBehaviorDisplayPrice(): ?string
  89. {
  90. return $this->behaviorDisplayPrice;
  91. }
  92. public function setBehaviorDisplayPrice(?string $behaviorDisplayPrice): self
  93. {
  94. $this->behaviorDisplayPrice = $behaviorDisplayPrice;
  95. return $this;
  96. }
  97. public function getMerchant(): ?MerchantInterface
  98. {
  99. return $this->merchant;
  100. }
  101. public function setMerchant(?MerchantInterface $merchant): self
  102. {
  103. $this->merchant = $merchant;
  104. return $this;
  105. }
  106. /**
  107. * @return Collection|CreditHistory[]
  108. */
  109. public function getCreditHistories(): Collection
  110. {
  111. return $this->creditHistories;
  112. }
  113. public function addCreditHistory(CreditHistory $creditHistory): self
  114. {
  115. if (!$this->creditHistories->contains($creditHistory)) {
  116. $this->creditHistories[] = $creditHistory;
  117. $creditHistory->setUser($this);
  118. }
  119. return $this;
  120. }
  121. public function removeCreditHistory(CreditHistory $creditHistory): self
  122. {
  123. if ($this->creditHistories->contains($creditHistory)) {
  124. $this->creditHistories->removeElement($creditHistory);
  125. // set the owning side to null (unless already changed)
  126. if ($creditHistory->getUser() === $this) {
  127. $creditHistory->setUser(null);
  128. }
  129. }
  130. return $this;
  131. }
  132. /**
  133. * @return Collection|Address[]
  134. */
  135. public function getAddresses(): Collection
  136. {
  137. return $this->addresses;
  138. }
  139. public function addAddress(Address $address): self
  140. {
  141. if (!$this->addresses->contains($address)) {
  142. $this->addresses[] = $address;
  143. $address->setUser($this);
  144. }
  145. return $this;
  146. }
  147. public function removeAddress(Address $address): self
  148. {
  149. if ($this->addresses->contains($address)) {
  150. $this->addresses->removeElement($address);
  151. // set the owning side to null (unless already changed)
  152. if ($address->getUser() === $this) {
  153. $address->setUser(null);
  154. }
  155. }
  156. return $this;
  157. }
  158. /**
  159. * @return Collection|ShopOrder[]
  160. */
  161. public function getOrders(): Collection
  162. {
  163. return $this->orders;
  164. }
  165. public function addOrder(OrderShop $order): self
  166. {
  167. if (!$this->orders->contains($order)) {
  168. $this->orders[] = $order;
  169. $order->setUser($this);
  170. }
  171. return $this;
  172. }
  173. public function removeOrder(OrderShop $order): self
  174. {
  175. if ($this->orders->contains($order)) {
  176. $this->orders->removeElement($order);
  177. // set the owning side to null (unless already changed)
  178. if ($order->getUser() === $this) {
  179. $order->setUser(null);
  180. }
  181. }
  182. return $this;
  183. }
  184. /**
  185. * @return Collection|Cart[]
  186. */
  187. public function getCarts(): Collection
  188. {
  189. return $this->carts;
  190. }
  191. public function addCart(Cart $cart): self
  192. {
  193. if (!$this->carts->contains($cart)) {
  194. $this->carts[] = $cart;
  195. $cart->setUser($this);
  196. }
  197. return $this;
  198. }
  199. public function removeCart(Cart $cart): self
  200. {
  201. if ($this->carts->contains($cart)) {
  202. $this->carts->removeElement($cart);
  203. // set the owning side to null (unless already changed)
  204. if ($cart->getUser() === $this) {
  205. $cart->setUser(null);
  206. }
  207. }
  208. return $this;
  209. }
  210. public function getFirstname(): ?string
  211. {
  212. return $this->firstname;
  213. }
  214. public function setFirstname(?string $firstname): self
  215. {
  216. $this->firstname = $firstname;
  217. return $this;
  218. }
  219. public function getLastname(): ?string
  220. {
  221. return $this->lastname;
  222. }
  223. public function setLastname(?string $lastname): self
  224. {
  225. $this->lastname = $lastname;
  226. return $this;
  227. }
  228. public function getGender(): ?bool
  229. {
  230. return $this->gender;
  231. }
  232. public function setGender(?bool $gender): self
  233. {
  234. $this->gender = $gender;
  235. return $this;
  236. }
  237. /**
  238. * @return Collection|Newsletter[]
  239. */
  240. public function getNewsletters(): Collection
  241. {
  242. return $this->newsletters;
  243. }
  244. public function addNewsletter(Newsletter $newsletter): self
  245. {
  246. if (!$this->newsletters->contains($newsletter)) {
  247. $this->newsletters[] = $newsletter;
  248. }
  249. return $this;
  250. }
  251. public function removeNewsletter(Newsletter $newsletter): self
  252. {
  253. if ($this->newsletters->contains($newsletter)) {
  254. $this->newsletters->removeElement($newsletter);
  255. }
  256. return $this;
  257. }
  258. /**
  259. * @return Collection|ProductFamily[]
  260. */
  261. public function getFavoriteProductFamilies(): Collection
  262. {
  263. return $this->favoriteProductFamilies;
  264. }
  265. public function addFavoriteProductFamily(ProductFamily $favoriteProductFamily): self
  266. {
  267. if (!$this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  268. $this->favoriteProductFamilies[] = $favoriteProductFamily;
  269. }
  270. return $this;
  271. }
  272. public function removeFavoriteProductFamily(ProductFamily $favoriteProductFamily): self
  273. {
  274. if ($this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  275. $this->favoriteProductFamilies->removeElement($favoriteProductFamily);
  276. }
  277. return $this;
  278. }
  279. }