Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

386 lines
11KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use App\Entity\Newsletter;
  4. use App\Entity\UserPointSale;
  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\Column(type="string", length=64, nullable=true)
  42. */
  43. protected $firstname;
  44. /**
  45. * @ORM\Column(type="string", length=64, nullable=true)
  46. */
  47. protected $lastname;
  48. /**
  49. * @ORM\Column(type="boolean", nullable=true)
  50. */
  51. protected $gender;
  52. /**
  53. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\NewsletterInterface", inversedBy="users")
  54. */
  55. protected $newsletters;
  56. /**
  57. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\GroupUserInterface", inversedBy="users")
  58. */
  59. protected $groupUsers;
  60. /**
  61. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\ProductFamilyInterface")
  62. */
  63. protected $favoriteProductFamilies;
  64. /**
  65. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\UserPointSaleInterface", mappedBy="user", orphanRemoval=true)
  66. */
  67. protected $userPointSales;
  68. public function __construct()
  69. {
  70. parent::__construct();
  71. $this->creditHistories = new ArrayCollection();
  72. $this->addresses = new ArrayCollection();
  73. $this->orders = new ArrayCollection();
  74. $this->groupUsers = new ArrayCollection();
  75. $this->newsletters = new ArrayCollection();
  76. $this->favoriteProductFamilies = new ArrayCollection();
  77. $this->userPointSales = new ArrayCollection();
  78. }
  79. public function getSummary()
  80. {
  81. return strtoupper($this->getLastname()).' '.$this->getFirstname(). ' ('.$this->getEmail().')';
  82. }
  83. public function setEmail($email)
  84. {
  85. $this->setUsername($email);
  86. return parent::setEmail($email);
  87. }
  88. public function getPhone(): ?string
  89. {
  90. return $this->phone;
  91. }
  92. public function setPhone(?string $phone): self
  93. {
  94. $this->phone = $phone;
  95. return $this;
  96. }
  97. public function getBehaviorDisplayPrice(): ?string
  98. {
  99. return $this->behaviorDisplayPrice;
  100. }
  101. public function setBehaviorDisplayPrice(?string $behaviorDisplayPrice): self
  102. {
  103. $this->behaviorDisplayPrice = $behaviorDisplayPrice;
  104. return $this;
  105. }
  106. public function getMerchant(): ?MerchantInterface
  107. {
  108. return $this->merchant;
  109. }
  110. public function setMerchant(?MerchantInterface $merchant): self
  111. {
  112. $this->merchant = $merchant;
  113. return $this;
  114. }
  115. /**
  116. * @return Collection|CreditHistory[]
  117. */
  118. public function getCreditHistories(): Collection
  119. {
  120. return $this->creditHistories;
  121. }
  122. public function addCreditHistory(CreditHistory $creditHistory): self
  123. {
  124. if (!$this->creditHistories->contains($creditHistory)) {
  125. $this->creditHistories[] = $creditHistory;
  126. $creditHistory->setUser($this);
  127. }
  128. return $this;
  129. }
  130. public function removeCreditHistory(CreditHistory $creditHistory): self
  131. {
  132. if ($this->creditHistories->contains($creditHistory)) {
  133. $this->creditHistories->removeElement($creditHistory);
  134. // set the owning side to null (unless already changed)
  135. if ($creditHistory->getUser() === $this) {
  136. $creditHistory->setUser(null);
  137. }
  138. }
  139. return $this;
  140. }
  141. /**
  142. * @return Collection|Address[]
  143. */
  144. public function getAddresses(): Collection
  145. {
  146. return $this->addresses;
  147. }
  148. public function addAddress(Address $address): self
  149. {
  150. if (!$this->addresses->contains($address)) {
  151. $this->addresses[] = $address;
  152. $address->setUser($this);
  153. }
  154. return $this;
  155. }
  156. public function removeAddress(Address $address): self
  157. {
  158. if ($this->addresses->contains($address)) {
  159. $this->addresses->removeElement($address);
  160. // set the owning side to null (unless already changed)
  161. if ($address->getUser() === $this) {
  162. $address->setUser(null);
  163. }
  164. }
  165. return $this;
  166. }
  167. /**
  168. * @return Collection|ShopOrder[]
  169. */
  170. public function getOrders(): Collection
  171. {
  172. return $this->orders;
  173. }
  174. public function addOrder(OrderShop $order): self
  175. {
  176. if (!$this->orders->contains($order)) {
  177. $this->orders[] = $order;
  178. $order->setUser($this);
  179. }
  180. return $this;
  181. }
  182. public function removeOrder(OrderShop $order): self
  183. {
  184. if ($this->orders->contains($order)) {
  185. $this->orders->removeElement($order);
  186. // set the owning side to null (unless already changed)
  187. if ($order->getUser() === $this) {
  188. $order->setUser(null);
  189. }
  190. }
  191. return $this;
  192. }
  193. public function getFirstname(): ?string
  194. {
  195. return $this->firstname;
  196. }
  197. public function setFirstname(?string $firstname): self
  198. {
  199. $this->firstname = $firstname;
  200. return $this;
  201. }
  202. public function getLastname(): ?string
  203. {
  204. return $this->lastname;
  205. }
  206. public function setLastname(?string $lastname): self
  207. {
  208. $this->lastname = $lastname;
  209. return $this;
  210. }
  211. public function getGender(): ?bool
  212. {
  213. return $this->gender;
  214. }
  215. public function setGender(?bool $gender): self
  216. {
  217. $this->gender = $gender;
  218. return $this;
  219. }
  220. /**
  221. * @return Collection|Newsletter[]
  222. */
  223. public function getNewsletters(): Collection
  224. {
  225. return $this->newsletters;
  226. }
  227. public function addNewsletter(Newsletter $newsletter): self
  228. {
  229. if (!$this->newsletters->contains($newsletter)) {
  230. $this->newsletters[] = $newsletter;
  231. }
  232. return $this;
  233. }
  234. public function removeNewsletter(Newsletter $newsletter): self
  235. {
  236. if ($this->newsletters->contains($newsletter)) {
  237. $this->newsletters->removeElement($newsletter);
  238. }
  239. return $this;
  240. }
  241. /**
  242. * @return Collection|GroupUser[]
  243. */
  244. public function getGroupUsers(): Collection
  245. {
  246. return $this->groupUsers;
  247. }
  248. public function addGroupUser(GroupUser $groupUser): self
  249. {
  250. if (!$this->groupUsers->contains($groupUser)) {
  251. $this->groupUsers[] = $groupUser;
  252. $groupUser->addUser($this);
  253. }
  254. return $this;
  255. }
  256. public function removeGroupUser(GroupUser $groupUser): self
  257. {
  258. if ($this->groupUsers->contains($groupUser)) {
  259. $this->groupUsers->removeElement($groupUser);
  260. $groupUser->removeUser($this);
  261. }
  262. return $this;
  263. }
  264. /**
  265. * @return Collection|ProductFamily[]
  266. */
  267. public function getFavoriteProductFamilies(): Collection
  268. {
  269. return $this->favoriteProductFamilies;
  270. }
  271. public function addFavoriteProductFamily(ProductFamily $favoriteProductFamily): self
  272. {
  273. if (!$this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  274. $this->favoriteProductFamilies[] = $favoriteProductFamily;
  275. }
  276. return $this;
  277. }
  278. public function removeFavoriteProductFamily(ProductFamily $favoriteProductFamily): self
  279. {
  280. if ($this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  281. $this->favoriteProductFamilies->removeElement($favoriteProductFamily);
  282. }
  283. return $this;
  284. }
  285. /**
  286. * @return Collection|UserPointSale[]
  287. */
  288. public function getUserPointSales(): Collection
  289. {
  290. return $this->userPointSales;
  291. }
  292. public function addUserPointSale(UserPointSale $userPointSale): self
  293. {
  294. if (!$this->userPointSales->contains($userPointSale)) {
  295. $this->userPointSales[] = $userPointSale;
  296. $userPointSale->setUser($this);
  297. }
  298. return $this;
  299. }
  300. public function removeUserPointSale(UserPointSale $userPointSale): self
  301. {
  302. if ($this->userPointSales->contains($userPointSale)) {
  303. $this->userPointSales->removeElement($userPointSale);
  304. // set the owning side to null (unless already changed)
  305. if ($userPointSale->getUser() === $this) {
  306. $userPointSale->setUser(null);
  307. }
  308. }
  309. return $this;
  310. }
  311. }