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.

483 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\SovBundle\Model\User\User as SovUserModel;
  8. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  9. use Lc\CaracoleBundle\Model\Ticket\TicketInterface;
  10. use Lc\SovBundle\Model\User\UserInterface;
  11. /**
  12. * @ORM\MappedSuperclass()
  13. *
  14. */
  15. abstract class UserModel extends SovUserModel
  16. {
  17. /**
  18. * @ORM\Column(type="string", length=20, nullable=true)
  19. */
  20. protected $phone;
  21. /**
  22. * @ORM\Column(type="string", length=64, nullable=true)
  23. */
  24. protected $behaviorDisplayPrice;
  25. /**
  26. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
  27. */
  28. protected $merchant;
  29. /**
  30. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Address\AddressInterface", mappedBy="user", cascade={"persist"})
  31. */
  32. protected $addresses;
  33. /**
  34. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Order\OrderShopInterface", mappedBy="user")
  35. */
  36. protected $orders;
  37. /**
  38. * @ORM\Column(type="string", length=64, nullable=true)
  39. */
  40. protected $firstname;
  41. /**
  42. * @ORM\Column(type="string", length=64, nullable=true)
  43. */
  44. protected $lastname;
  45. /**
  46. * @ORM\Column(type="boolean", nullable=true)
  47. */
  48. protected $gender;
  49. /**
  50. * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Newsletter\NewsletterInterface", inversedBy="users")
  51. */
  52. protected $newsletters;
  53. /**
  54. * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\User\GroupUserInterface", inversedBy="users")
  55. */
  56. protected $groupUsers;
  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\CaracoleBundle\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()
  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 getMerchant(): ?MerchantInterface
  125. {
  126. return $this->merchant;
  127. }
  128. public function setMerchant(?MerchantInterface $merchant): self
  129. {
  130. $this->merchant = $merchant;
  131. return $this;
  132. }
  133. /**
  134. * @return Collection|Address[]
  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(Address $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(Address $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|OrderShop[]
  171. */
  172. public function getOrders(): Collection
  173. {
  174. return $this->orders;
  175. }
  176. public function addOrder(OrderShop $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(OrderShop $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|Newsletter[]
  224. */
  225. public function getNewsletters(): Collection
  226. {
  227. return $this->newsletters;
  228. }
  229. public function addNewsletter(Newsletter $newsletter): self
  230. {
  231. if (!$this->newsletters->contains($newsletter)) {
  232. $this->newsletters[] = $newsletter;
  233. }
  234. return $this;
  235. }
  236. public function removeNewsletter(Newsletter $newsletter): self
  237. {
  238. if ($this->newsletters->contains($newsletter)) {
  239. $this->newsletters->removeElement($newsletter);
  240. }
  241. return $this;
  242. }
  243. /**
  244. * @return Collection|GroupUserModel[]
  245. */
  246. public function getGroupUsers(): Collection
  247. {
  248. return $this->groupUsers;
  249. }
  250. public function addGroupUser(GroupUserModel $groupUser): self
  251. {
  252. if (!$this->groupUsers->contains($groupUser)) {
  253. $this->groupUsers[] = $groupUser;
  254. $groupUser->addUser($this);
  255. }
  256. return $this;
  257. }
  258. public function removeGroupUser(GroupUserModel $groupUser): self
  259. {
  260. if ($this->groupUsers->contains($groupUser)) {
  261. $this->groupUsers->removeElement($groupUser);
  262. $groupUser->removeUser($this);
  263. }
  264. return $this;
  265. }
  266. /**
  267. * @return Collection|ProductFamily[]
  268. */
  269. public function getFavoriteProductFamilies(): Collection
  270. {
  271. return $this->favoriteProductFamilies;
  272. }
  273. public function addFavoriteProductFamily(ProductFamily $favoriteProductFamily): self
  274. {
  275. if (!$this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  276. $this->favoriteProductFamilies[] = $favoriteProductFamily;
  277. }
  278. return $this;
  279. }
  280. public function removeFavoriteProductFamily(ProductFamily $favoriteProductFamily): self
  281. {
  282. if ($this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  283. $this->favoriteProductFamilies->removeElement($favoriteProductFamily);
  284. }
  285. return $this;
  286. }
  287. /**
  288. * @return Collection|UserPointSaleModel[]
  289. */
  290. public function getUserPointSales(): Collection
  291. {
  292. return $this->userPointSales;
  293. }
  294. public function addUserPointSale(UserPointSale $userPointSale): self
  295. {
  296. if (!$this->userPointSales->contains($userPointSale)) {
  297. $this->userPointSales[] = $userPointSale;
  298. $userPointSale->setUser($this);
  299. }
  300. return $this;
  301. }
  302. public function removeUserPointSale(UserPointSale $userPointSale): self
  303. {
  304. if ($this->userPointSales->contains($userPointSale)) {
  305. $this->userPointSales->removeElement($userPointSale);
  306. // set the owning side to null (unless already changed)
  307. if ($userPointSale->getUser() === $this) {
  308. $userPointSale->setUser(null);
  309. }
  310. }
  311. return $this;
  312. }
  313. /**
  314. * @return Collection|TicketInterface[]
  315. */
  316. public function getTickets(): Collection
  317. {
  318. return $this->tickets;
  319. }
  320. public function addTicket(TicketInterface $ticket): self
  321. {
  322. if (!$this->tickets->contains($ticket)) {
  323. $this->tickets[] = $ticket;
  324. $ticket->setUser($this);
  325. }
  326. return $this;
  327. }
  328. public function removeTicket(TicketInterface $ticket): self
  329. {
  330. if ($this->tickets->contains($ticket)) {
  331. $this->tickets->removeElement($ticket);
  332. // set the owning side to null (unless already changed)
  333. if ($ticket->getUser() === $this) {
  334. $ticket->setUser(null);
  335. }
  336. }
  337. return $this;
  338. }
  339. public function getCreatedAt(): ?\DateTimeInterface
  340. {
  341. return $this->createdAt;
  342. }
  343. public function setCreatedAt(\DateTimeInterface $createdAt): self
  344. {
  345. $this->createdAt = $createdAt;
  346. return $this;
  347. }
  348. public function getUpdatedAt(): ?\DateTimeInterface
  349. {
  350. return $this->updatedAt;
  351. }
  352. public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  353. {
  354. $this->updatedAt = $updatedAt;
  355. return $this;
  356. }
  357. public function getTicketTypesNotification(): ?array
  358. {
  359. return $this->ticketTypesNotification;
  360. }
  361. public function setTicketTypesNotification(?array $ticketTypesNotification): self
  362. {
  363. $this->ticketTypesNotification = $ticketTypesNotification;
  364. return $this;
  365. }
  366. /**
  367. * @return Collection|ReductionCredit[]
  368. */
  369. public function getReductionCredits(): Collection
  370. {
  371. return $this->reductionCredits;
  372. }
  373. public function addReductionCredit(ReductionCredit $reductionCredit): self
  374. {
  375. if (!$this->reductionCredits->contains($reductionCredit)) {
  376. $this->reductionCredits[] = $reductionCredit;
  377. $reductionCredit->addUser($this);
  378. }
  379. return $this;
  380. }
  381. public function removeReductionCredit(ReductionCredit $reductionCredit): self
  382. {
  383. if ($this->reductionCredits->contains($reductionCredit)) {
  384. $this->reductionCredits->removeElement($reductionCredit);
  385. $reductionCredit->removeUser($this);
  386. }
  387. return $this;
  388. }
  389. }