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.

UserModel.php 12KB

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