You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

437 line
12KB

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