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

396 lines
11KB

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