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.

488 lines
12KB

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