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.

457 lines
11KB

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