Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

468 rindas
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($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(Address $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(Address $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|OrderShop[]
  182. */
  183. public function getOrders(): Collection
  184. {
  185. return $this->orders;
  186. }
  187. public function addOrder(OrderShop $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(OrderShop $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|Newsletter[]
  235. */
  236. public function getNewsletters(): Collection
  237. {
  238. return $this->newsletters;
  239. }
  240. public function addNewsletter(Newsletter $newsletter): self
  241. {
  242. if (!$this->newsletters->contains($newsletter)) {
  243. $this->newsletters[] = $newsletter;
  244. }
  245. return $this;
  246. }
  247. public function removeNewsletter(Newsletter $newsletter): self
  248. {
  249. if ($this->newsletters->contains($newsletter)) {
  250. $this->newsletters->removeElement($newsletter);
  251. }
  252. return $this;
  253. }
  254. /**
  255. * @return Collection|GroupUser[]
  256. */
  257. public function getGroupUsers(): Collection
  258. {
  259. return $this->groupUsers;
  260. }
  261. public function addGroupUser(GroupUser $groupUser): self
  262. {
  263. if (!$this->groupUsers->contains($groupUser)) {
  264. $this->groupUsers[] = $groupUser;
  265. $groupUser->addUser($this);
  266. }
  267. return $this;
  268. }
  269. public function removeGroupUser(GroupUser $groupUser): self
  270. {
  271. if ($this->groupUsers->contains($groupUser)) {
  272. $this->groupUsers->removeElement($groupUser);
  273. $groupUser->removeUser($this);
  274. }
  275. return $this;
  276. }
  277. /**
  278. * @return Collection|ProductFamily[]
  279. */
  280. public function getFavoriteProductFamilies(): Collection
  281. {
  282. return $this->favoriteProductFamilies;
  283. }
  284. public function addFavoriteProductFamily(ProductFamily $favoriteProductFamily): self
  285. {
  286. if (!$this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  287. $this->favoriteProductFamilies[] = $favoriteProductFamily;
  288. }
  289. return $this;
  290. }
  291. public function removeFavoriteProductFamily(ProductFamily $favoriteProductFamily): self
  292. {
  293. if ($this->favoriteProductFamilies->contains($favoriteProductFamily)) {
  294. $this->favoriteProductFamilies->removeElement($favoriteProductFamily);
  295. }
  296. return $this;
  297. }
  298. /**
  299. * @return Collection|UserPointSale[]
  300. */
  301. public function getUserPointSales(): Collection
  302. {
  303. return $this->userPointSales;
  304. }
  305. public function addUserPointSale(UserPointSale $userPointSale): self
  306. {
  307. if (!$this->userPointSales->contains($userPointSale)) {
  308. $this->userPointSales[] = $userPointSale;
  309. $userPointSale->setUser($this);
  310. }
  311. return $this;
  312. }
  313. public function removeUserPointSale(UserPointSale $userPointSale): self
  314. {
  315. if ($this->userPointSales->contains($userPointSale)) {
  316. $this->userPointSales->removeElement($userPointSale);
  317. // set the owning side to null (unless already changed)
  318. if ($userPointSale->getUser() === $this) {
  319. $userPointSale->setUser(null);
  320. }
  321. }
  322. return $this;
  323. }
  324. /**
  325. * @return Collection|TicketInterface[]
  326. */
  327. public function getTickets(): Collection
  328. {
  329. return $this->tickets;
  330. }
  331. public function addTicket(TicketInterface $ticket): self
  332. {
  333. if (!$this->tickets->contains($ticket)) {
  334. $this->tickets[] = $ticket;
  335. $ticket->setUser($this);
  336. }
  337. return $this;
  338. }
  339. public function removeTicket(TicketInterface $ticket): self
  340. {
  341. if ($this->tickets->contains($ticket)) {
  342. $this->tickets->removeElement($ticket);
  343. // set the owning side to null (unless already changed)
  344. if ($ticket->getUser() === $this) {
  345. $ticket->setUser(null);
  346. }
  347. }
  348. return $this;
  349. }
  350. public function getCreatedAt(): ?\DateTimeInterface
  351. {
  352. return $this->createdAt;
  353. }
  354. public function setCreatedAt(\DateTimeInterface $createdAt): self
  355. {
  356. $this->createdAt = $createdAt;
  357. return $this;
  358. }
  359. public function getUpdatedAt(): ?\DateTimeInterface
  360. {
  361. return $this->updatedAt;
  362. }
  363. public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  364. {
  365. $this->updatedAt = $updatedAt;
  366. return $this;
  367. }
  368. public function getTicketTypesNotification(): ?array
  369. {
  370. return $this->ticketTypesNotification;
  371. }
  372. public function setTicketTypesNotification(?array $ticketTypesNotification): self
  373. {
  374. $this->ticketTypesNotification = $ticketTypesNotification;
  375. return $this;
  376. }
  377. }