Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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