Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

User.php 14KB

4 år sedan
4 år sedan
4 år sedan
4 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use App\Entity\Newsletter;
  4. use App\Entity\Ticket;
  5. use App\Entity\UserPointSale;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use FOS\UserBundle\Model\User as UserModelFOS;
  11. use Lc\ShopBundle\Context\MerchantInterface;
  12. use Lc\ShopBundle\Context\TicketInterface;
  13. /**
  14. * @ORM\MappedSuperclass()
  15. *
  16. */
  17. abstract class User extends UserModelFOS
  18. {
  19. /**
  20. * @ORM\Column(type="string", length=20, nullable=true)
  21. */
  22. protected $phone;
  23. /**
  24. * @ORM\Column(type="string", length=64, nullable=true)
  25. */
  26. protected $behaviorDisplayPrice;
  27. /**
  28. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface")
  29. */
  30. protected $merchant;
  31. /**
  32. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\AddressInterface", mappedBy="user", cascade={"persist"})
  33. */
  34. protected $addresses;
  35. /**
  36. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderShopInterface", mappedBy="user")
  37. */
  38. protected $orders;
  39. /**
  40. * @ORM\Column(type="string", length=64, nullable=true)
  41. */
  42. protected $firstname;
  43. /**
  44. * @ORM\Column(type="string", length=64, nullable=true)
  45. */
  46. protected $lastname;
  47. /**
  48. * @ORM\Column(type="boolean", nullable=true)
  49. */
  50. protected $gender;
  51. /**
  52. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\NewsletterInterface", inversedBy="users")
  53. */
  54. protected $newsletters;
  55. /**
  56. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\GroupUserInterface", inversedBy="users")
  57. */
  58. protected $groupUsers;
  59. /**
  60. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\ProductFamilyInterface")
  61. */
  62. protected $favoriteProductFamilies;
  63. /**
  64. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\UserPointSaleInterface", mappedBy="user", orphanRemoval=true)
  65. */
  66. protected $userPointSales;
  67. /**
  68. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\UserMerchantInterface", mappedBy="user", orphanRemoval=true)
  69. */
  70. protected $userMerchants;
  71. /**
  72. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\TicketInterface", mappedBy="user")
  73. */
  74. protected $tickets;
  75. /**
  76. * @ORM\Column(type="datetime")
  77. * @Gedmo\Timestampable(on="create")
  78. */
  79. protected $createdAt;
  80. /**
  81. * @ORM\Column(type="datetime")
  82. * @Gedmo\Timestampable(on="update")
  83. */
  84. protected $updatedAt;
  85. /**
  86. * @ORM\Column(type="array", nullable=true)
  87. */
  88. protected $ticketTypesNotification = [];
  89. /**
  90. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\ReductionCreditInterface", mappedBy="users")
  91. */
  92. protected $reductionCredits;
  93. public function __construct()
  94. {
  95. parent::__construct();
  96. $this->addresses = new ArrayCollection();
  97. $this->orders = new ArrayCollection();
  98. $this->groupUsers = new ArrayCollection();
  99. $this->newsletters = new ArrayCollection();
  100. $this->favoriteProductFamilies = new ArrayCollection();
  101. $this->userPointSales = new ArrayCollection();
  102. $this->userMerchants = new ArrayCollection();
  103. $this->reductionCredits = new ArrayCollection();
  104. $this->tickets = new ArrayCollection();
  105. }
  106. public function __toString()
  107. {
  108. return $this->getSummary();
  109. }
  110. public function getSummary()
  111. {
  112. return '#'.$this->getId().' '.strtoupper($this->getLastname()).' '.$this->getFirstname(). ' ('.$this->getEmail().')';
  113. }
  114. public function getName()
  115. {
  116. return (string) ucfirst(strtolower($this->getFirstname())). ' '.strtoupper($this->getLastname());
  117. }
  118. public function setEmail($email)
  119. {
  120. $this->setUsername($email);
  121. return parent::setEmail($email);
  122. }
  123. public function getPhone(): ?string
  124. {
  125. return $this->phone;
  126. }
  127. public function setPhone(?string $phone): self
  128. {
  129. $this->phone = $phone;
  130. return $this;
  131. }
  132. public function getBehaviorDisplayPrice(): ?string
  133. {
  134. return $this->behaviorDisplayPrice;
  135. }
  136. public function setBehaviorDisplayPrice(?string $behaviorDisplayPrice): self
  137. {
  138. $this->behaviorDisplayPrice = $behaviorDisplayPrice;
  139. return $this;
  140. }
  141. public function getMerchant(): ?MerchantInterface
  142. {
  143. return $this->merchant;
  144. }
  145. public function setMerchant(?MerchantInterface $merchant): self
  146. {
  147. $this->merchant = $merchant;
  148. return $this;
  149. }
  150. /**
  151. * @return Collection|Address[]
  152. */
  153. public function getAddresses($status = null): Collection
  154. {
  155. if($status){
  156. $addressToReturn = new ArrayCollection();
  157. foreach ($this->addresses as $address){
  158. if($address->getStatus() == $status) {
  159. $addressToReturn[] = $address;
  160. }
  161. }
  162. return $addressToReturn;
  163. }else{
  164. return $this->addresses;
  165. }
  166. }
  167. public function addAddress(Address $address): self
  168. {
  169. if (!$this->addresses->contains($address)) {
  170. $this->addresses[] = $address;
  171. $address->setUser($this);
  172. }
  173. return $this;
  174. }
  175. public function removeAddress(Address $address): self
  176. {
  177. if ($this->addresses->contains($address)) {
  178. $this->addresses->removeElement($address);
  179. // set the owning side to null (unless already changed)
  180. if ($address->getUser() === $this) {
  181. $address->setUser(null);
  182. }
  183. }
  184. return $this;
  185. }
  186. /**
  187. * @return Collection|OrderShop[]
  188. */
  189. public function getOrders(): Collection
  190. {
  191. return $this->orders;
  192. }
  193. public function addOrder(OrderShop $order): self
  194. {
  195. if (!$this->orders->contains($order)) {
  196. $this->orders[] = $order;
  197. $order->setUser($this);
  198. }
  199. return $this;
  200. }
  201. public function removeOrder(OrderShop $order): self
  202. {
  203. if ($this->orders->contains($order)) {
  204. $this->orders->removeElement($order);
  205. // set the owning side to null (unless already changed)
  206. if ($order->getUser() === $this) {
  207. $order->setUser(null);
  208. }
  209. }
  210. return $this;
  211. }
  212. public function getFirstname(): ?string
  213. {
  214. return $this->firstname;
  215. }
  216. public function setFirstname(?string $firstname): self
  217. {
  218. $this->firstname = $firstname;
  219. return $this;
  220. }
  221. public function getLastname(): ?string
  222. {
  223. return $this->lastname;
  224. }
  225. public function setLastname(?string $lastname): self
  226. {
  227. $this->lastname = $lastname;
  228. return $this;
  229. }
  230. public function getGender(): ?bool
  231. {
  232. return $this->gender;
  233. }
  234. public function setGender(?bool $gender): self
  235. {
  236. $this->gender = $gender;
  237. return $this;
  238. }
  239. /**
  240. * @return Collection|Newsletter[]
  241. */
  242. public function getNewsletters(): Collection
  243. {
  244. return $this->newsletters;
  245. }
  246. public function addNewsletter(Newsletter $newsletter): self
  247. {
  248. if (!$this->newsletters->contains($newsletter)) {
  249. $this->newsletters[] = $newsletter;
  250. }
  251. return $this;
  252. }
  253. public function removeNewsletter(Newsletter $newsletter): self
  254. {
  255. if ($this->newsletters->contains($newsletter)) {
  256. $this->newsletters->removeElement($newsletter);
  257. }
  258. return $this;
  259. }
  260. /**
  261. * @return Collection|GroupUser[]
  262. */
  263. public function getGroupUsers(): Collection
  264. {
  265. return $this->groupUsers;
  266. }
  267. public function addGroupUser(GroupUser $groupUser): self
  268. {
  269. if (!$this->groupUsers->contains($groupUser)) {
  270. $this->groupUsers[] = $groupUser;
  271. $groupUser->addUser($this);
  272. }
  273. return $this;
  274. }
  275. public function removeGroupUser(GroupUser $groupUser): self
  276. {
  277. if ($this->groupUsers->contains($groupUser)) {
  278. $this->groupUsers->removeElement($groupUser);
  279. $groupUser->removeUser($this);
  280. }
  281. return $this;
  282. }
  283. /**
  284. * @return Collection|ProductFamily[]
  285. */
  286. public function getFavoriteProductFamilies(): Collection
  287. {
  288. return $this->favoriteProductFamilies;
  289. }
  290. public function addFavoriteProductFamily(ProductFamily $favoriteProductFamily): self
  291. {
  292. if (!$this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  293. $this->favoriteProductFamilies[] = $favoriteProductFamily;
  294. }
  295. return $this;
  296. }
  297. public function removeFavoriteProductFamily(ProductFamily $favoriteProductFamily): self
  298. {
  299. if ($this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  300. $this->favoriteProductFamilies->removeElement($favoriteProductFamily);
  301. }
  302. return $this;
  303. }
  304. /**
  305. * @return Collection|UserPointSale[]
  306. */
  307. public function getUserPointSales(): Collection
  308. {
  309. return $this->userPointSales;
  310. }
  311. public function addUserPointSale(UserPointSale $userPointSale): self
  312. {
  313. if (!$this->userPointSales->contains($userPointSale)) {
  314. $this->userPointSales[] = $userPointSale;
  315. $userPointSale->setUser($this);
  316. }
  317. return $this;
  318. }
  319. public function removeUserPointSale(UserPointSale $userPointSale): self
  320. {
  321. if ($this->userPointSales->contains($userPointSale)) {
  322. $this->userPointSales->removeElement($userPointSale);
  323. // set the owning side to null (unless already changed)
  324. if ($userPointSale->getUser() === $this) {
  325. $userPointSale->setUser(null);
  326. }
  327. }
  328. return $this;
  329. }
  330. /**
  331. * @return Collection|TicketInterface[]
  332. */
  333. public function getTickets(): Collection
  334. {
  335. return $this->tickets;
  336. }
  337. public function addTicket(TicketInterface $ticket): self
  338. {
  339. if (!$this->tickets->contains($ticket)) {
  340. $this->tickets[] = $ticket;
  341. $ticket->setUser($this);
  342. }
  343. return $this;
  344. }
  345. public function removeTicket(TicketInterface $ticket): self
  346. {
  347. if ($this->tickets->contains($ticket)) {
  348. $this->tickets->removeElement($ticket);
  349. // set the owning side to null (unless already changed)
  350. if ($ticket->getUser() === $this) {
  351. $ticket->setUser(null);
  352. }
  353. }
  354. return $this;
  355. }
  356. public function getCreatedAt(): ?\DateTimeInterface
  357. {
  358. return $this->createdAt;
  359. }
  360. public function setCreatedAt(\DateTimeInterface $createdAt): self
  361. {
  362. $this->createdAt = $createdAt;
  363. return $this;
  364. }
  365. public function getUpdatedAt(): ?\DateTimeInterface
  366. {
  367. return $this->updatedAt;
  368. }
  369. public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  370. {
  371. $this->updatedAt = $updatedAt;
  372. return $this;
  373. }
  374. public function getTicketTypesNotification(): ?array
  375. {
  376. return $this->ticketTypesNotification;
  377. }
  378. public function setTicketTypesNotification(?array $ticketTypesNotification): self
  379. {
  380. $this->ticketTypesNotification = $ticketTypesNotification;
  381. return $this;
  382. }
  383. /**
  384. * @return Collection|ReductionCredit[]
  385. */
  386. public function getReductionCredits(): Collection
  387. {
  388. return $this->reductionCredits;
  389. }
  390. public function addReductionCredit(ReductionCredit $reductionCredit): self
  391. {
  392. if (!$this->reductionCredits->contains($reductionCredit)) {
  393. $this->reductionCredits[] = $reductionCredit;
  394. $reductionCredit->addUser($this);
  395. }
  396. return $this;
  397. }
  398. public function removeReductionCredit(ReductionCredit $reductionCredit): self
  399. {
  400. if ($this->reductionCredits->contains($reductionCredit)) {
  401. $this->reductionCredits->removeElement($reductionCredit);
  402. $reductionCredit->removeUser($this);
  403. }
  404. return $this;
  405. }
  406. }