Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

469 Zeilen
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\PointSale\PointSaleInterface;
  9. use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
  10. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  11. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  12. use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
  13. use Lc\SovBundle\Model\User\User as SovUserModel;
  14. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  15. use Lc\SovBundle\Model\Ticket\TicketInterface;
  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\SovBundle\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\SovBundle\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. // isUserLinkedToPointSale
  108. public function isLinkedToPointSale(PointSaleInterface $pointSale)
  109. {
  110. foreach ($this->getUserPointSales() as $userPointSale) {
  111. if ($userPointSale->getPointSale()->getId() == $pointSale->getId()) {
  112. return true;
  113. }
  114. }
  115. return false;
  116. }
  117. public function getPhone(): ?string
  118. {
  119. return $this->phone;
  120. }
  121. public function setPhone(?string $phone): self
  122. {
  123. $this->phone = $phone;
  124. return $this;
  125. }
  126. public function getBehaviorDisplayPrice(): ?string
  127. {
  128. return $this->behaviorDisplayPrice;
  129. }
  130. public function setBehaviorDisplayPrice(?string $behaviorDisplayPrice): self
  131. {
  132. $this->behaviorDisplayPrice = $behaviorDisplayPrice;
  133. return $this;
  134. }
  135. public function getFavoriteMerchant(): ?MerchantInterface
  136. {
  137. return $this->favoriteMerchant;
  138. }
  139. public function setFavoriteMerchant(?MerchantInterface $merchant): self
  140. {
  141. $this->favoriteMerchant = $merchant;
  142. return $this;
  143. }
  144. /**
  145. * @return Collection|AddressInterface[]
  146. */
  147. public function getAddresses($status = null): Collection
  148. {
  149. if ($status) {
  150. $addressToReturn = new ArrayCollection();
  151. foreach ($this->addresses as $address) {
  152. if ($address->getStatus() == $status) {
  153. $addressToReturn[] = $address;
  154. }
  155. }
  156. return $addressToReturn;
  157. } else {
  158. return $this->addresses;
  159. }
  160. }
  161. public function addAddress(AddressInterface $address): self
  162. {
  163. if (!$this->addresses->contains($address)) {
  164. $this->addresses[] = $address;
  165. $address->setUser($this);
  166. }
  167. return $this;
  168. }
  169. public function removeAddress(AddressInterface $address): self
  170. {
  171. if ($this->addresses->contains($address)) {
  172. $this->addresses->removeElement($address);
  173. // set the owning side to null (unless already changed)
  174. if ($address->getUser() === $this) {
  175. $address->setUser(null);
  176. }
  177. }
  178. return $this;
  179. }
  180. /**
  181. * @return Collection|OrderShopInterface[]
  182. */
  183. public function getOrders(): Collection
  184. {
  185. return $this->orders;
  186. }
  187. public function addOrder(OrderShopInterface $order): self
  188. {
  189. if (!$this->orders->contains($order)) {
  190. $this->orders[] = $order;
  191. $order->setUser($this);
  192. }
  193. return $this;
  194. }
  195. public function removeOrder(OrderShopInterface $order): self
  196. {
  197. if ($this->orders->contains($order)) {
  198. $this->orders->removeElement($order);
  199. // set the owning side to null (unless already changed)
  200. if ($order->getUser() === $this) {
  201. $order->setUser(null);
  202. }
  203. }
  204. return $this;
  205. }
  206. public function getFirstname(): ?string
  207. {
  208. return $this->firstname;
  209. }
  210. public function setFirstname(?string $firstname): self
  211. {
  212. $this->firstname = $firstname;
  213. return $this;
  214. }
  215. public function getLastname(): ?string
  216. {
  217. return $this->lastname;
  218. }
  219. public function setLastname(?string $lastname): self
  220. {
  221. $this->lastname = $lastname;
  222. return $this;
  223. }
  224. public function getGender(): ?bool
  225. {
  226. return $this->gender;
  227. }
  228. public function setGender(?bool $gender): self
  229. {
  230. $this->gender = $gender;
  231. return $this;
  232. }
  233. /**
  234. * @return Collection|NewsletterInterface[]
  235. */
  236. public function getNewsletters(): Collection
  237. {
  238. return $this->newsletters;
  239. }
  240. public function addNewsletter(NewsletterInterface $newsletter): self
  241. {
  242. if (!$this->newsletters->contains($newsletter)) {
  243. $this->newsletters[] = $newsletter;
  244. }
  245. return $this;
  246. }
  247. public function removeNewsletter(NewsletterInterface $newsletter): self
  248. {
  249. if ($this->newsletters->contains($newsletter)) {
  250. $this->newsletters->removeElement($newsletter);
  251. }
  252. return $this;
  253. }
  254. /**
  255. * @return Collection|ProductFamilyInterface[]
  256. */
  257. public function getFavoriteProductFamilies(): Collection
  258. {
  259. return $this->favoriteProductFamilies;
  260. }
  261. public function addFavoriteProductFamily(ProductFamilyInterface $favoriteProductFamily): self
  262. {
  263. if (!$this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  264. $this->favoriteProductFamilies[] = $favoriteProductFamily;
  265. }
  266. return $this;
  267. }
  268. public function removeFavoriteProductFamily(ProductFamilyInterface $favoriteProductFamily): self
  269. {
  270. if ($this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  271. $this->favoriteProductFamilies->removeElement($favoriteProductFamily);
  272. }
  273. return $this;
  274. }
  275. /**
  276. * @return Collection|UserPointSaleInterface[]
  277. */
  278. public function getUserPointSales(): Collection
  279. {
  280. return $this->userPointSales;
  281. }
  282. public function addUserPointSale(UserPointSaleInterface $userPointSale): self
  283. {
  284. if (!$this->userPointSales->contains($userPointSale)) {
  285. $this->userPointSales[] = $userPointSale;
  286. $userPointSale->setUser($this);
  287. }
  288. return $this;
  289. }
  290. public function removeUserPointSale(UserPointSaleInterface $userPointSale): self
  291. {
  292. if ($this->userPointSales->contains($userPointSale)) {
  293. $this->userPointSales->removeElement($userPointSale);
  294. // set the owning side to null (unless already changed)
  295. if ($userPointSale->getUser() === $this) {
  296. $userPointSale->setUser(null);
  297. }
  298. }
  299. return $this;
  300. }
  301. /**
  302. * @return Collection|TicketInterface[]
  303. */
  304. public function getTickets(): Collection
  305. {
  306. return $this->tickets;
  307. }
  308. public function addTicket(TicketInterface $ticket): self
  309. {
  310. if (!$this->tickets->contains($ticket)) {
  311. $this->tickets[] = $ticket;
  312. $ticket->setUser($this);
  313. }
  314. return $this;
  315. }
  316. public function removeTicket(TicketInterface $ticket): self
  317. {
  318. if ($this->tickets->contains($ticket)) {
  319. $this->tickets->removeElement($ticket);
  320. // set the owning side to null (unless already changed)
  321. if ($ticket->getUser() === $this) {
  322. $ticket->setUser(null);
  323. }
  324. }
  325. return $this;
  326. }
  327. public function getCreatedAt(): ?\DateTimeInterface
  328. {
  329. return $this->createdAt;
  330. }
  331. public function setCreatedAt(\DateTimeInterface $createdAt): self
  332. {
  333. $this->createdAt = $createdAt;
  334. return $this;
  335. }
  336. public function getUpdatedAt(): ?\DateTimeInterface
  337. {
  338. return $this->updatedAt;
  339. }
  340. public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  341. {
  342. $this->updatedAt = $updatedAt;
  343. return $this;
  344. }
  345. public function getTicketTypesNotification(): ?array
  346. {
  347. return $this->ticketTypesNotification;
  348. }
  349. public function setTicketTypesNotification(?array $ticketTypesNotification): self
  350. {
  351. $this->ticketTypesNotification = $ticketTypesNotification;
  352. return $this;
  353. }
  354. /**
  355. * @return Collection|ReductionCreditInterface[]
  356. */
  357. public function getReductionCredits(): Collection
  358. {
  359. return $this->reductionCredits;
  360. }
  361. public function addReductionCredit(ReductionCreditInterface $reductionCredit): self
  362. {
  363. if (!$this->reductionCredits->contains($reductionCredit)) {
  364. $this->reductionCredits[] = $reductionCredit;
  365. $reductionCredit->addUser($this);
  366. }
  367. return $this;
  368. }
  369. public function removeReductionCredit(ReductionCreditInterface $reductionCredit): self
  370. {
  371. if ($this->reductionCredits->contains($reductionCredit)) {
  372. $this->reductionCredits->removeElement($reductionCredit);
  373. $reductionCredit->removeUser($this);
  374. }
  375. return $this;
  376. }
  377. }