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.

457 satır
13KB

  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. public function __construct()
  90. {
  91. parent::__construct();
  92. $this->addresses = new ArrayCollection();
  93. $this->orders = new ArrayCollection();
  94. $this->groupUsers = new ArrayCollection();
  95. $this->newsletters = new ArrayCollection();
  96. $this->favoriteProductFamilies = new ArrayCollection();
  97. $this->userPointSales = new ArrayCollection();
  98. $this->userMerchants = new ArrayCollection();
  99. }
  100. public function __toString()
  101. {
  102. return $this->getSummary();
  103. }
  104. public function getSummary()
  105. {
  106. return '#'.$this->getId().' '.strtoupper($this->getLastname()).' '.$this->getFirstname(). ' ('.$this->getEmail().')';
  107. }
  108. public function getName()
  109. {
  110. return (string) ucfirst(strtolower($this->getFirstname())). ' '.strtoupper($this->getLastname());
  111. }
  112. public function setEmail($email)
  113. {
  114. $this->setUsername($email);
  115. return parent::setEmail($email);
  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 getMerchant(): ?MerchantInterface
  136. {
  137. return $this->merchant;
  138. }
  139. public function setMerchant(?MerchantInterface $merchant): self
  140. {
  141. $this->merchant = $merchant;
  142. return $this;
  143. }
  144. /**
  145. * @return Collection|Address[]
  146. */
  147. public function getAddresses(): Collection
  148. {
  149. return $this->addresses;
  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|GroupUser[]
  246. */
  247. public function getGroupUsers(): Collection
  248. {
  249. return $this->groupUsers;
  250. }
  251. public function addGroupUser(GroupUser $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(GroupUser $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|UserPointSale[]
  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. }