您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

433 行
13KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use App\Entity\Newsletter;
  4. use App\Entity\Ticket;
  5. use App\Entity\UserPointSale;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use FOS\UserBundle\Model\User as UserModelFOS;
  10. use Lc\ShopBundle\Context\MerchantInterface;
  11. use Lc\ShopBundle\Context\TicketInterface;
  12. /**
  13. * @ORM\MappedSuperclass()
  14. *
  15. */
  16. abstract class User extends UserModelFOS
  17. {
  18. /**
  19. * @ORM\Column(type="string", length=20, nullable=true)
  20. */
  21. protected $phone;
  22. /**
  23. * @ORM\Column(type="string", length=64, nullable=true)
  24. */
  25. protected $behaviorDisplayPrice;
  26. /**
  27. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface")
  28. */
  29. protected $merchant;
  30. /**
  31. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\CreditHistoryInterface", mappedBy="user", orphanRemoval=true)
  32. */
  33. protected $creditHistories;
  34. /**
  35. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\AddressInterface", mappedBy="user", cascade={"persist"})
  36. */
  37. protected $addresses;
  38. /**
  39. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderShopInterface", mappedBy="user")
  40. */
  41. protected $orders;
  42. /**
  43. * @ORM\Column(type="string", length=64, nullable=true)
  44. */
  45. protected $firstname;
  46. /**
  47. * @ORM\Column(type="string", length=64, nullable=true)
  48. */
  49. protected $lastname;
  50. /**
  51. * @ORM\Column(type="boolean", nullable=true)
  52. */
  53. protected $gender;
  54. /**
  55. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\NewsletterInterface", inversedBy="users")
  56. */
  57. protected $newsletters;
  58. /**
  59. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\GroupUserInterface", inversedBy="users")
  60. */
  61. protected $groupUsers;
  62. /**
  63. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\ProductFamilyInterface")
  64. */
  65. protected $favoriteProductFamilies;
  66. /**
  67. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\UserPointSaleInterface", mappedBy="user", orphanRemoval=true)
  68. */
  69. protected $userPointSales;
  70. /**
  71. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\UserMerchantInterface", mappedBy="user", orphanRemoval=true)
  72. */
  73. protected $userMerchants;
  74. /**
  75. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\TicketInterface", mappedBy="user")
  76. */
  77. protected $tickets;
  78. public function __construct()
  79. {
  80. parent::__construct();
  81. $this->creditHistories = new ArrayCollection();
  82. $this->addresses = new ArrayCollection();
  83. $this->orders = new ArrayCollection();
  84. $this->groupUsers = new ArrayCollection();
  85. $this->newsletters = new ArrayCollection();
  86. $this->favoriteProductFamilies = new ArrayCollection();
  87. $this->userPointSales = new ArrayCollection();
  88. $this->userMerchants = new ArrayCollection();
  89. }
  90. public function getSummary()
  91. {
  92. return '#'.$this->getId().' '.strtoupper($this->getLastname()).' '.$this->getFirstname(). ' ('.$this->getEmail().')';
  93. }
  94. public function getName()
  95. {
  96. return $this->getFirstname().' '.strtoupper($this->getLastname());
  97. }
  98. public function setEmail($email)
  99. {
  100. $this->setUsername($email);
  101. return parent::setEmail($email);
  102. }
  103. public function getPhone(): ?string
  104. {
  105. return $this->phone;
  106. }
  107. public function setPhone(?string $phone): self
  108. {
  109. $this->phone = $phone;
  110. return $this;
  111. }
  112. public function getBehaviorDisplayPrice(): ?string
  113. {
  114. return $this->behaviorDisplayPrice;
  115. }
  116. public function setBehaviorDisplayPrice(?string $behaviorDisplayPrice): self
  117. {
  118. $this->behaviorDisplayPrice = $behaviorDisplayPrice;
  119. return $this;
  120. }
  121. public function getMerchant(): ?MerchantInterface
  122. {
  123. return $this->merchant;
  124. }
  125. public function setMerchant(?MerchantInterface $merchant): self
  126. {
  127. $this->merchant = $merchant;
  128. return $this;
  129. }
  130. /**
  131. * @return Collection|CreditHistory[]
  132. */
  133. public function getCreditHistories(): Collection
  134. {
  135. return $this->creditHistories;
  136. }
  137. public function addCreditHistory(CreditHistory $creditHistory): self
  138. {
  139. if (!$this->creditHistories->contains($creditHistory)) {
  140. $this->creditHistories[] = $creditHistory;
  141. $creditHistory->setUser($this);
  142. }
  143. return $this;
  144. }
  145. public function removeCreditHistory(CreditHistory $creditHistory): self
  146. {
  147. if ($this->creditHistories->contains($creditHistory)) {
  148. $this->creditHistories->removeElement($creditHistory);
  149. // set the owning side to null (unless already changed)
  150. if ($creditHistory->getUser() === $this) {
  151. $creditHistory->setUser(null);
  152. }
  153. }
  154. return $this;
  155. }
  156. /**
  157. * @return Collection|Address[]
  158. */
  159. public function getAddresses(): Collection
  160. {
  161. return $this->addresses;
  162. }
  163. public function addAddress(Address $address): self
  164. {
  165. if (!$this->addresses->contains($address)) {
  166. $this->addresses[] = $address;
  167. $address->setUser($this);
  168. }
  169. return $this;
  170. }
  171. public function removeAddress(Address $address): self
  172. {
  173. if ($this->addresses->contains($address)) {
  174. $this->addresses->removeElement($address);
  175. // set the owning side to null (unless already changed)
  176. if ($address->getUser() === $this) {
  177. $address->setUser(null);
  178. }
  179. }
  180. return $this;
  181. }
  182. /**
  183. * @return Collection|ShopOrder[]
  184. */
  185. public function getOrders(): Collection
  186. {
  187. return $this->orders;
  188. }
  189. public function addOrder(OrderShop $order): self
  190. {
  191. if (!$this->orders->contains($order)) {
  192. $this->orders[] = $order;
  193. $order->setUser($this);
  194. }
  195. return $this;
  196. }
  197. public function removeOrder(OrderShop $order): self
  198. {
  199. if ($this->orders->contains($order)) {
  200. $this->orders->removeElement($order);
  201. // set the owning side to null (unless already changed)
  202. if ($order->getUser() === $this) {
  203. $order->setUser(null);
  204. }
  205. }
  206. return $this;
  207. }
  208. public function getFirstname(): ?string
  209. {
  210. return $this->firstname;
  211. }
  212. public function setFirstname(?string $firstname): self
  213. {
  214. $this->firstname = $firstname;
  215. return $this;
  216. }
  217. public function getLastname(): ?string
  218. {
  219. return $this->lastname;
  220. }
  221. public function setLastname(?string $lastname): self
  222. {
  223. $this->lastname = $lastname;
  224. return $this;
  225. }
  226. public function getGender(): ?bool
  227. {
  228. return $this->gender;
  229. }
  230. public function setGender(?bool $gender): self
  231. {
  232. $this->gender = $gender;
  233. return $this;
  234. }
  235. /**
  236. * @return Collection|Newsletter[]
  237. */
  238. public function getNewsletters(): Collection
  239. {
  240. return $this->newsletters;
  241. }
  242. public function addNewsletter(Newsletter $newsletter): self
  243. {
  244. if (!$this->newsletters->contains($newsletter)) {
  245. $this->newsletters[] = $newsletter;
  246. }
  247. return $this;
  248. }
  249. public function removeNewsletter(Newsletter $newsletter): self
  250. {
  251. if ($this->newsletters->contains($newsletter)) {
  252. $this->newsletters->removeElement($newsletter);
  253. }
  254. return $this;
  255. }
  256. /**
  257. * @return Collection|GroupUser[]
  258. */
  259. public function getGroupUsers(): Collection
  260. {
  261. return $this->groupUsers;
  262. }
  263. public function addGroupUser(GroupUser $groupUser): self
  264. {
  265. if (!$this->groupUsers->contains($groupUser)) {
  266. $this->groupUsers[] = $groupUser;
  267. $groupUser->addUser($this);
  268. }
  269. return $this;
  270. }
  271. public function removeGroupUser(GroupUser $groupUser): self
  272. {
  273. if ($this->groupUsers->contains($groupUser)) {
  274. $this->groupUsers->removeElement($groupUser);
  275. $groupUser->removeUser($this);
  276. }
  277. return $this;
  278. }
  279. /**
  280. * @return Collection|ProductFamily[]
  281. */
  282. public function getFavoriteProductFamilies(): Collection
  283. {
  284. return $this->favoriteProductFamilies;
  285. }
  286. public function addFavoriteProductFamily(ProductFamily $favoriteProductFamily): self
  287. {
  288. if (!$this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  289. $this->favoriteProductFamilies[] = $favoriteProductFamily;
  290. }
  291. return $this;
  292. }
  293. public function removeFavoriteProductFamily(ProductFamily $favoriteProductFamily): self
  294. {
  295. if ($this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  296. $this->favoriteProductFamilies->removeElement($favoriteProductFamily);
  297. }
  298. return $this;
  299. }
  300. /**
  301. * @return Collection|UserPointSale[]
  302. */
  303. public function getUserPointSales(): Collection
  304. {
  305. return $this->userPointSales;
  306. }
  307. public function addUserPointSale(UserPointSale $userPointSale): self
  308. {
  309. if (!$this->userPointSales->contains($userPointSale)) {
  310. $this->userPointSales[] = $userPointSale;
  311. $userPointSale->setUser($this);
  312. }
  313. return $this;
  314. }
  315. public function removeUserPointSale(UserPointSale $userPointSale): self
  316. {
  317. if ($this->userPointSales->contains($userPointSale)) {
  318. $this->userPointSales->removeElement($userPointSale);
  319. // set the owning side to null (unless already changed)
  320. if ($userPointSale->getUser() === $this) {
  321. $userPointSale->setUser(null);
  322. }
  323. }
  324. return $this;
  325. }
  326. /**
  327. * @return Collection|TicketInterface[]
  328. */
  329. public function getTickets(): Collection
  330. {
  331. return $this->tickets;
  332. }
  333. public function addTicket(TicketInterface $ticket): self
  334. {
  335. if (!$this->tickets->contains($ticket)) {
  336. $this->tickets[] = $ticket;
  337. $ticket->setUser($this);
  338. }
  339. return $this;
  340. }
  341. public function removeTicket(TicketInterface $ticket): self
  342. {
  343. if ($this->tickets->contains($ticket)) {
  344. $this->tickets->removeElement($ticket);
  345. // set the owning side to null (unless already changed)
  346. if ($ticket->getUser() === $this) {
  347. $ticket->setUser(null);
  348. }
  349. }
  350. return $this;
  351. }
  352. }