選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

UserModel.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. }