Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

User.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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 FOS\UserBundle\Model\User as UserModelFOS;
  10. use Lc\ShopBundle\Context\MerchantInterface;
  11. use Lc\ShopBundle\Context\TicketInterface;
  12. /**
  13. * @ORM\MappedSuperclass()
  14. *
  15. */
  16. abstract class User extends UserModelFOS
  17. {
  18. /**
  19. * @ORM\Column(type="string", length=20, nullable=true)
  20. */
  21. protected $phone;
  22. /**
  23. * @ORM\Column(type="string", length=64, nullable=true)
  24. */
  25. protected $behaviorDisplayPrice;
  26. /**
  27. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface")
  28. */
  29. protected $merchant;
  30. /**
  31. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\AddressInterface", mappedBy="user", cascade={"persist"})
  32. */
  33. protected $addresses;
  34. /**
  35. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderShopInterface", mappedBy="user")
  36. */
  37. protected $orders;
  38. /**
  39. * @ORM\Column(type="string", length=64, nullable=true)
  40. */
  41. protected $firstname;
  42. /**
  43. * @ORM\Column(type="string", length=64, nullable=true)
  44. */
  45. protected $lastname;
  46. /**
  47. * @ORM\Column(type="boolean", nullable=true)
  48. */
  49. protected $gender;
  50. /**
  51. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\NewsletterInterface", inversedBy="users")
  52. */
  53. protected $newsletters;
  54. /**
  55. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\GroupUserInterface", inversedBy="users")
  56. */
  57. protected $groupUsers;
  58. /**
  59. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\ProductFamilyInterface")
  60. */
  61. protected $favoriteProductFamilies;
  62. /**
  63. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\UserPointSaleInterface", mappedBy="user", orphanRemoval=true)
  64. */
  65. protected $userPointSales;
  66. /**
  67. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\UserMerchantInterface", mappedBy="user", orphanRemoval=true)
  68. */
  69. protected $userMerchants;
  70. /**
  71. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\TicketInterface", mappedBy="user")
  72. */
  73. protected $tickets;
  74. public function __construct()
  75. {
  76. parent::__construct();
  77. $this->addresses = new ArrayCollection();
  78. $this->orders = new ArrayCollection();
  79. $this->groupUsers = new ArrayCollection();
  80. $this->newsletters = new ArrayCollection();
  81. $this->favoriteProductFamilies = new ArrayCollection();
  82. $this->userPointSales = new ArrayCollection();
  83. $this->userMerchants = new ArrayCollection();
  84. }
  85. public function __toString()
  86. {
  87. return $this->getName();
  88. }
  89. public function getSummary()
  90. {
  91. return '#'.$this->getId().' '.strtoupper($this->getLastname()).' '.$this->getFirstname(). ' ('.$this->getEmail().')';
  92. }
  93. public function getName()
  94. {
  95. return (string) ucfirst(strtolower($this->getFirstname())). ' '.strtoupper($this->getLastname());
  96. }
  97. public function setEmail($email)
  98. {
  99. $this->setUsername($email);
  100. return parent::setEmail($email);
  101. }
  102. public function getPhone(): ?string
  103. {
  104. return $this->phone;
  105. }
  106. public function setPhone(?string $phone): self
  107. {
  108. $this->phone = $phone;
  109. return $this;
  110. }
  111. public function getBehaviorDisplayPrice(): ?string
  112. {
  113. return $this->behaviorDisplayPrice;
  114. }
  115. public function setBehaviorDisplayPrice(?string $behaviorDisplayPrice): self
  116. {
  117. $this->behaviorDisplayPrice = $behaviorDisplayPrice;
  118. return $this;
  119. }
  120. public function getMerchant(): ?MerchantInterface
  121. {
  122. return $this->merchant;
  123. }
  124. public function setMerchant(?MerchantInterface $merchant): self
  125. {
  126. $this->merchant = $merchant;
  127. return $this;
  128. }
  129. /**
  130. * @return Collection|Address[]
  131. */
  132. public function getAddresses(): Collection
  133. {
  134. return $this->addresses;
  135. }
  136. public function addAddress(Address $address): self
  137. {
  138. if (!$this->addresses->contains($address)) {
  139. $this->addresses[] = $address;
  140. $address->setUser($this);
  141. }
  142. return $this;
  143. }
  144. public function removeAddress(Address $address): self
  145. {
  146. if ($this->addresses->contains($address)) {
  147. $this->addresses->removeElement($address);
  148. // set the owning side to null (unless already changed)
  149. if ($address->getUser() === $this) {
  150. $address->setUser(null);
  151. }
  152. }
  153. return $this;
  154. }
  155. /**
  156. * @return Collection|ShopOrder[]
  157. */
  158. public function getOrders(): Collection
  159. {
  160. return $this->orders;
  161. }
  162. public function addOrder(OrderShop $order): self
  163. {
  164. if (!$this->orders->contains($order)) {
  165. $this->orders[] = $order;
  166. $order->setUser($this);
  167. }
  168. return $this;
  169. }
  170. public function removeOrder(OrderShop $order): self
  171. {
  172. if ($this->orders->contains($order)) {
  173. $this->orders->removeElement($order);
  174. // set the owning side to null (unless already changed)
  175. if ($order->getUser() === $this) {
  176. $order->setUser(null);
  177. }
  178. }
  179. return $this;
  180. }
  181. public function getFirstname(): ?string
  182. {
  183. return $this->firstname;
  184. }
  185. public function setFirstname(?string $firstname): self
  186. {
  187. $this->firstname = $firstname;
  188. return $this;
  189. }
  190. public function getLastname(): ?string
  191. {
  192. return $this->lastname;
  193. }
  194. public function setLastname(?string $lastname): self
  195. {
  196. $this->lastname = $lastname;
  197. return $this;
  198. }
  199. public function getGender(): ?bool
  200. {
  201. return $this->gender;
  202. }
  203. public function setGender(?bool $gender): self
  204. {
  205. $this->gender = $gender;
  206. return $this;
  207. }
  208. /**
  209. * @return Collection|Newsletter[]
  210. */
  211. public function getNewsletters(): Collection
  212. {
  213. return $this->newsletters;
  214. }
  215. public function addNewsletter(Newsletter $newsletter): self
  216. {
  217. if (!$this->newsletters->contains($newsletter)) {
  218. $this->newsletters[] = $newsletter;
  219. }
  220. return $this;
  221. }
  222. public function removeNewsletter(Newsletter $newsletter): self
  223. {
  224. if ($this->newsletters->contains($newsletter)) {
  225. $this->newsletters->removeElement($newsletter);
  226. }
  227. return $this;
  228. }
  229. /**
  230. * @return Collection|GroupUser[]
  231. */
  232. public function getGroupUsers(): Collection
  233. {
  234. return $this->groupUsers;
  235. }
  236. public function addGroupUser(GroupUser $groupUser): self
  237. {
  238. if (!$this->groupUsers->contains($groupUser)) {
  239. $this->groupUsers[] = $groupUser;
  240. $groupUser->addUser($this);
  241. }
  242. return $this;
  243. }
  244. public function removeGroupUser(GroupUser $groupUser): self
  245. {
  246. if ($this->groupUsers->contains($groupUser)) {
  247. $this->groupUsers->removeElement($groupUser);
  248. $groupUser->removeUser($this);
  249. }
  250. return $this;
  251. }
  252. /**
  253. * @return Collection|ProductFamily[]
  254. */
  255. public function getFavoriteProductFamilies(): Collection
  256. {
  257. return $this->favoriteProductFamilies;
  258. }
  259. public function addFavoriteProductFamily(ProductFamily $favoriteProductFamily): self
  260. {
  261. if (!$this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  262. $this->favoriteProductFamilies[] = $favoriteProductFamily;
  263. }
  264. return $this;
  265. }
  266. public function removeFavoriteProductFamily(ProductFamily $favoriteProductFamily): self
  267. {
  268. if ($this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  269. $this->favoriteProductFamilies->removeElement($favoriteProductFamily);
  270. }
  271. return $this;
  272. }
  273. /**
  274. * @return Collection|UserPointSale[]
  275. */
  276. public function getUserPointSales(): Collection
  277. {
  278. return $this->userPointSales;
  279. }
  280. public function addUserPointSale(UserPointSale $userPointSale): self
  281. {
  282. if (!$this->userPointSales->contains($userPointSale)) {
  283. $this->userPointSales[] = $userPointSale;
  284. $userPointSale->setUser($this);
  285. }
  286. return $this;
  287. }
  288. public function removeUserPointSale(UserPointSale $userPointSale): self
  289. {
  290. if ($this->userPointSales->contains($userPointSale)) {
  291. $this->userPointSales->removeElement($userPointSale);
  292. // set the owning side to null (unless already changed)
  293. if ($userPointSale->getUser() === $this) {
  294. $userPointSale->setUser(null);
  295. }
  296. }
  297. return $this;
  298. }
  299. /**
  300. * @return Collection|TicketInterface[]
  301. */
  302. public function getTickets(): Collection
  303. {
  304. return $this->tickets;
  305. }
  306. public function addTicket(TicketInterface $ticket): self
  307. {
  308. if (!$this->tickets->contains($ticket)) {
  309. $this->tickets[] = $ticket;
  310. $ticket->setUser($this);
  311. }
  312. return $this;
  313. }
  314. public function removeTicket(TicketInterface $ticket): self
  315. {
  316. if ($this->tickets->contains($ticket)) {
  317. $this->tickets->removeElement($ticket);
  318. // set the owning side to null (unless already changed)
  319. if ($ticket->getUser() === $this) {
  320. $ticket->setUser(null);
  321. }
  322. }
  323. return $this;
  324. }
  325. }