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.

484 line
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. parent::__construct();
  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()
  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 getMerchant(): ?MerchantInterface
  126. {
  127. return $this->merchant;
  128. }
  129. public function setMerchant(?MerchantInterface $merchant): self
  130. {
  131. $this->merchant = $merchant;
  132. return $this;
  133. }
  134. /**
  135. * @return Collection|Address[]
  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(Address $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(Address $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|OrderShop[]
  172. */
  173. public function getOrders(): Collection
  174. {
  175. return $this->orders;
  176. }
  177. public function addOrder(OrderShop $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(OrderShop $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|Newsletter[]
  225. */
  226. public function getNewsletters(): Collection
  227. {
  228. return $this->newsletters;
  229. }
  230. public function addNewsletter(Newsletter $newsletter): self
  231. {
  232. if (!$this->newsletters->contains($newsletter)) {
  233. $this->newsletters[] = $newsletter;
  234. }
  235. return $this;
  236. }
  237. public function removeNewsletter(Newsletter $newsletter): self
  238. {
  239. if ($this->newsletters->contains($newsletter)) {
  240. $this->newsletters->removeElement($newsletter);
  241. }
  242. return $this;
  243. }
  244. /**
  245. * @return Collection|GroupUserModel[]
  246. */
  247. public function getGroupUsers(): Collection
  248. {
  249. return $this->groupUsers;
  250. }
  251. public function addGroupUser(GroupUserModel $groupUser): self
  252. {
  253. if (!$this->groupUsers->contains($groupUser)) {
  254. $this->groupUsers[] = $groupUser;
  255. $groupUser->addUser($this);
  256. }
  257. return $this;
  258. }
  259. public function removeGroupUser(GroupUserModel $groupUser): self
  260. {
  261. if ($this->groupUsers->contains($groupUser)) {
  262. $this->groupUsers->removeElement($groupUser);
  263. $groupUser->removeUser($this);
  264. }
  265. return $this;
  266. }
  267. /**
  268. * @return Collection|ProductFamily[]
  269. */
  270. public function getFavoriteProductFamilies(): Collection
  271. {
  272. return $this->favoriteProductFamilies;
  273. }
  274. public function addFavoriteProductFamily(ProductFamily $favoriteProductFamily): self
  275. {
  276. if (!$this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  277. $this->favoriteProductFamilies[] = $favoriteProductFamily;
  278. }
  279. return $this;
  280. }
  281. public function removeFavoriteProductFamily(ProductFamily $favoriteProductFamily): self
  282. {
  283. if ($this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  284. $this->favoriteProductFamilies->removeElement($favoriteProductFamily);
  285. }
  286. return $this;
  287. }
  288. /**
  289. * @return Collection|UserPointSaleModel[]
  290. */
  291. public function getUserPointSales(): Collection
  292. {
  293. return $this->userPointSales;
  294. }
  295. public function addUserPointSale(UserPointSale $userPointSale): self
  296. {
  297. if (!$this->userPointSales->contains($userPointSale)) {
  298. $this->userPointSales[] = $userPointSale;
  299. $userPointSale->setUser($this);
  300. }
  301. return $this;
  302. }
  303. public function removeUserPointSale(UserPointSale $userPointSale): self
  304. {
  305. if ($this->userPointSales->contains($userPointSale)) {
  306. $this->userPointSales->removeElement($userPointSale);
  307. // set the owning side to null (unless already changed)
  308. if ($userPointSale->getUser() === $this) {
  309. $userPointSale->setUser(null);
  310. }
  311. }
  312. return $this;
  313. }
  314. /**
  315. * @return Collection|TicketInterface[]
  316. */
  317. public function getTickets(): Collection
  318. {
  319. return $this->tickets;
  320. }
  321. public function addTicket(TicketInterface $ticket): self
  322. {
  323. if (!$this->tickets->contains($ticket)) {
  324. $this->tickets[] = $ticket;
  325. $ticket->setUser($this);
  326. }
  327. return $this;
  328. }
  329. public function removeTicket(TicketInterface $ticket): self
  330. {
  331. if ($this->tickets->contains($ticket)) {
  332. $this->tickets->removeElement($ticket);
  333. // set the owning side to null (unless already changed)
  334. if ($ticket->getUser() === $this) {
  335. $ticket->setUser(null);
  336. }
  337. }
  338. return $this;
  339. }
  340. public function getCreatedAt(): ?\DateTimeInterface
  341. {
  342. return $this->createdAt;
  343. }
  344. public function setCreatedAt(\DateTimeInterface $createdAt): self
  345. {
  346. $this->createdAt = $createdAt;
  347. return $this;
  348. }
  349. public function getUpdatedAt(): ?\DateTimeInterface
  350. {
  351. return $this->updatedAt;
  352. }
  353. public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  354. {
  355. $this->updatedAt = $updatedAt;
  356. return $this;
  357. }
  358. public function getTicketTypesNotification(): ?array
  359. {
  360. return $this->ticketTypesNotification;
  361. }
  362. public function setTicketTypesNotification(?array $ticketTypesNotification): self
  363. {
  364. $this->ticketTypesNotification = $ticketTypesNotification;
  365. return $this;
  366. }
  367. /**
  368. * @return Collection|ReductionCredit[]
  369. */
  370. public function getReductionCredits(): Collection
  371. {
  372. return $this->reductionCredits;
  373. }
  374. public function addReductionCredit(ReductionCredit $reductionCredit): self
  375. {
  376. if (!$this->reductionCredits->contains($reductionCredit)) {
  377. $this->reductionCredits[] = $reductionCredit;
  378. $reductionCredit->addUser($this);
  379. }
  380. return $this;
  381. }
  382. public function removeReductionCredit(ReductionCredit $reductionCredit): self
  383. {
  384. if ($this->reductionCredits->contains($reductionCredit)) {
  385. $this->reductionCredits->removeElement($reductionCredit);
  386. $reductionCredit->removeUser($this);
  387. }
  388. return $this;
  389. }
  390. }