src/Entity/Client.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Application\Points;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use JMS\Serializer\Annotation as Serializer;
  9. use Symfony\Component\HttpFoundation\File\File;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13. * @ORM\Entity(repositoryClass="App\Repository\ClientRepository")
  14. * @ORM\EntityListeners({"App\Listener\EntityListener"})
  15. * @Vich\Uploadable()
  16. */
  17. class Client implements UserInterface
  18. {
  19. /**
  20. * @ORM\Id()
  21. * @ORM\GeneratedValue()
  22. * @ORM\Column(type="integer")
  23. */
  24. protected $id;
  25. /**
  26. *
  27. * @Serializer\Groups({"api","min"})
  28. * @Serializer\SerializedName("email")
  29. * @ORM\Column(type="string", length=180, unique=true)
  30. */
  31. private $email;
  32. /**
  33. * @var string The hashed password
  34. * @ORM\Column(type="string")
  35. */
  36. private $password;
  37. /**
  38. * @ORM\Column(type="datetime", nullable=true)
  39. */
  40. private $lastLogin;
  41. /**
  42. * @ORM\Column(type="json")
  43. */
  44. private $roles = [];
  45. /**
  46. * @ORM\Column(type="string", length=100, nullable=true)
  47. */
  48. protected $type;
  49. /**
  50. * @Serializer\Groups({"api","min"})
  51. * @Serializer\SerializedName("firstName")
  52. * @ORM\Column(type="string", length=100, nullable=true)
  53. */
  54. protected $firstName;
  55. /**
  56. * @Serializer\Groups({"api","min"})
  57. * @Serializer\SerializedName("lastName")
  58. * @ORM\Column(type="string", length=100, nullable=true)
  59. */
  60. protected $lastName;
  61. /**
  62. * @Serializer\Groups({"api","min"})
  63. * @Serializer\SerializedName("zip")
  64. * @ORM\Column(type="string", length=7, nullable=true)
  65. */
  66. protected $zip;
  67. /**
  68. * @ORM\OneToMany(targetEntity="App\Entity\Order", mappedBy="client")
  69. */
  70. protected $orders;
  71. /**
  72. * @ORM\Column(type="datetime")
  73. */
  74. protected $createts;
  75. /**
  76. * @ORM\Column(type="datetime", nullable=true)
  77. */
  78. protected $registerApp;
  79. /**
  80. * @ORM\Column(type="string", nullable=true, length=2)
  81. */
  82. protected $locale;
  83. /**
  84. * @ORM\Column(type="datetime", nullable=true)
  85. */
  86. protected $editts;
  87. /**
  88. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  89. */
  90. protected $editUser;
  91. /**
  92. * @ORM\OneToMany(targetEntity=ClientAddress::class, cascade={"persist"}, mappedBy="client", orphanRemoval=true)
  93. */
  94. private $clientAddresses;
  95. /**
  96. * @ORM\OneToOne(targetEntity=ClientAddress::class, cascade={"persist"})
  97. */
  98. private $billingAddress;
  99. /**
  100. * @ORM\OneToOne(targetEntity=ClientAddress::class, cascade={"persist"})
  101. */
  102. private $deliveryAddress;
  103. /**
  104. * @ORM\Column(type="boolean", nullable=true)
  105. */
  106. private $hasDeliveryAddress = false;
  107. /**
  108. * @ORM\OneToMany(targetEntity="App\Entity\RecentlyProduct", mappedBy="client")
  109. * @ORM\OrderBy({"createts"="DESC"})
  110. */
  111. private $recentlyProducts;
  112. /**
  113. * @ORM\OneToMany(targetEntity=Cart::class, mappedBy="client")
  114. */
  115. private $carts;
  116. /**
  117. * @var string Tokeny
  118. * @ORM\Column(type="string", nullable=true)
  119. */
  120. private $confirmToken;
  121. /**
  122. * @ORM\Column(type="boolean")
  123. */
  124. private $isVerified = true;
  125. /**
  126. * @ORM\Column(type="boolean")
  127. */
  128. private $isBlocked = false;
  129. /**
  130. * @ORM\OneToMany(targetEntity=ClientToken::class, mappedBy="client", orphanRemoval=true, cascade={"all"})
  131. */
  132. private $clientTokens;
  133. /**
  134. * @Vich\UploadableField(mapping="avatar_image", fileNameProperty="avatar")
  135. * @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
  136. * @var File|null
  137. */
  138. private $avatarFile;
  139. /**
  140. * @Serializer\Groups({"api","min"})
  141. * @Serializer\SerializedName("avatar")
  142. * @ORM\Column(type="string", length=255, nullable=true)
  143. */
  144. private $avatar;
  145. /**
  146. * @Serializer\Groups({"api","min"})
  147. * @Serializer\SerializedName("birthdate")
  148. * @ORM\Column(type="datetime", nullable=true)
  149. */
  150. protected $birthdate;
  151. /**
  152. * Telefon z Appky
  153. *
  154. * @Serializer\Groups({"api","min"})
  155. * @Serializer\SerializedName("phone")
  156. * @ORM\Column(type="text", nullable=true)
  157. */
  158. protected $phone;
  159. /**
  160. * Body
  161. *
  162. * @Serializer\Groups({"api","min"})
  163. * @Serializer\SerializedName("points")
  164. * @ORM\Column(type="integer", nullable=true)
  165. */
  166. protected $points = 0;
  167. /**
  168. * @Serializer\Groups({"pointsHistory"})
  169. * @Serializer\SerializedName("pointsHistory")
  170. * @ORM\OneToMany(targetEntity=Points::class, mappedBy="client", orphanRemoval=true)
  171. * @ORM\OrderBy({"createts"="DESC"})
  172. */
  173. private $pointsHistory;
  174. public function __construct()
  175. {
  176. $this->orders = new ArrayCollection();
  177. $this->clientAddresses = new ArrayCollection();
  178. $this->recentlyProducts = new ArrayCollection();
  179. $this->carts = new ArrayCollection();
  180. $this->clientTokens = new ArrayCollection();
  181. $this->pointsHistory = new ArrayCollection();
  182. }
  183. public function getId(): ?int
  184. {
  185. return $this->id;
  186. }
  187. public function createApiToken( )
  188. {
  189. return new ClientToken($this);
  190. }
  191. /**
  192. * Get Email
  193. *
  194. * @return mixed
  195. */
  196. public function getEmail()
  197. {
  198. return $this->email;
  199. }
  200. /**
  201. * Set Email
  202. *
  203. * @param mixed $email
  204. */
  205. public function setEmail( $email )
  206. {
  207. $this->email = $email;
  208. }
  209. public function getFullName()
  210. {
  211. return sprintf( '%s %s', $this->getLastName(), $this->getFirstName() );
  212. }
  213. public function getFirstName(): ?string
  214. {
  215. return $this->firstName;
  216. }
  217. public function setFirstName( ?string $firstName ): self
  218. {
  219. $this->firstName = $firstName;
  220. return $this;
  221. }
  222. public function getLastName(): ?string
  223. {
  224. return $this->lastName;
  225. }
  226. public function setLastName( ?string $lastName ): self
  227. {
  228. $this->lastName = $lastName;
  229. return $this;
  230. }
  231. /**
  232. * @return Collection|Order[]
  233. */
  234. public function getOrders(): Collection
  235. {
  236. return $this->orders;
  237. }
  238. public function addOrder( Order $order ): self
  239. {
  240. if ( !$this->orders->contains( $order ) ) {
  241. $this->orders[] = $order;
  242. $order->setClient( $this );
  243. }
  244. return $this;
  245. }
  246. public function removeOrder( Order $order ): self
  247. {
  248. if ( $this->orders->contains( $order ) ) {
  249. $this->orders->removeElement( $order );
  250. // set the owning side to null (unless already changed)
  251. if ( $order->getClient() === $this ) {
  252. $order->setClient( null );
  253. }
  254. }
  255. return $this;
  256. }
  257. public function getCreatets(): ?\DateTimeInterface
  258. {
  259. return $this->createts;
  260. }
  261. public function setCreatets( \DateTimeInterface $createts ): self
  262. {
  263. $this->createts = $createts;
  264. return $this;
  265. }
  266. public function getEditts(): ?\DateTimeInterface
  267. {
  268. return $this->editts;
  269. }
  270. public function setEditts( ?\DateTimeInterface $editts ): self
  271. {
  272. $this->editts = $editts;
  273. return $this;
  274. }
  275. public function getEditUser(): ?User
  276. {
  277. return $this->editUser;
  278. }
  279. public function setEditUser( ?User $editUser ): self
  280. {
  281. $this->editUser = $editUser;
  282. return $this;
  283. }
  284. /**
  285. * Get Type
  286. *
  287. * @return mixed
  288. */
  289. public function getType()
  290. {
  291. return $this->type;
  292. }
  293. /**
  294. * Set Type
  295. *
  296. * @param mixed $type
  297. */
  298. public function setType( $type )
  299. {
  300. $this->type = $type;
  301. }
  302. /**
  303. * @return Collection|ClientAddress[]
  304. */
  305. public function getClientAddresses(): Collection
  306. {
  307. return $this->clientAddresses;
  308. }
  309. public function addClientAddress(ClientAddress $clientAddress): self
  310. {
  311. if (!$this->clientAddresses->contains($clientAddress)) {
  312. $this->clientAddresses[] = $clientAddress;
  313. $clientAddress->setClient($this);
  314. }
  315. return $this;
  316. }
  317. public function removeClientAddress(ClientAddress $clientAddress): self
  318. {
  319. if ($this->clientAddresses->contains($clientAddress)) {
  320. $this->clientAddresses->removeElement($clientAddress);
  321. // set the owning side to null (unless already changed)
  322. if ($clientAddress->getClient() === $this) {
  323. $clientAddress->setClient(null);
  324. }
  325. }
  326. return $this;
  327. }
  328. public function getBillingAddress(): ?ClientAddress
  329. {
  330. return $this->billingAddress;
  331. }
  332. public function setBillingAddress( ?ClientAddress $billingAddress ): self
  333. {
  334. $this->billingAddress = $billingAddress;
  335. return $this;
  336. }
  337. public function getDeliveryAddress(): ?ClientAddress
  338. {
  339. return $this->deliveryAddress;
  340. }
  341. public function setDeliveryAddress( ?ClientAddress $deliveryAddress ): self
  342. {
  343. $this->deliveryAddress = $deliveryAddress;
  344. return $this;
  345. }
  346. /**
  347. * @return Collection|RecentlyProduct[]
  348. */
  349. public function getRecentlyProducts(): Collection
  350. {
  351. return $this->recentlyProducts->slice( 0, 10 );
  352. }
  353. public function addRecentlyProduct( RecentlyProduct $recentlyProduct ): self
  354. {
  355. if ( !$this->recentlyProducts->contains( $recentlyProduct ) ) {
  356. $this->recentlyProducts[] = $recentlyProduct;
  357. $recentlyProduct->setClient( $this );
  358. }
  359. return $this;
  360. }
  361. public function removeRecentlyProduct( RecentlyProduct $recentlyProduct ): self
  362. {
  363. if ( $this->recentlyProducts->contains( $recentlyProduct ) ) {
  364. $this->recentlyProducts->removeElement( $recentlyProduct );
  365. // set the owning side to null (unless already changed)
  366. if ( $recentlyProduct->getClient() === $this ) {
  367. $recentlyProduct->setClient( null );
  368. }
  369. }
  370. return $this;
  371. }
  372. /**
  373. * @return Collection|Cart[]
  374. */
  375. public function getCarts(): Collection
  376. {
  377. return $this->carts;
  378. }
  379. public function addCart( Cart $cart ): self
  380. {
  381. if ( !$this->carts->contains( $cart ) ) {
  382. $this->carts[] = $cart;
  383. $cart->setClient( $this );
  384. }
  385. return $this;
  386. }
  387. public function removeCart( Cart $cart ): self
  388. {
  389. if ( $this->carts->contains( $cart ) ) {
  390. $this->carts->removeElement( $cart );
  391. // set the owning side to null (unless already changed)
  392. if ( $cart->getClient() === $this ) {
  393. $cart->setClient( null );
  394. }
  395. }
  396. return $this;
  397. }
  398. /**
  399. * addRoles -
  400. *
  401. * @param $role
  402. */
  403. public function addRoles( $role )
  404. {
  405. $roles = $this->roles;
  406. $roles[] = $role;
  407. $this->setRoles( array_unique( $roles ) );
  408. }
  409. public function getRoles(): array
  410. {
  411. $roles = $this->roles;
  412. // guarantee every user at least has ROLE_USER
  413. $roles[] = 'ROLE_USER';
  414. return array_unique( $roles );
  415. }
  416. public function setRoles( array $roles ): self
  417. {
  418. $this->roles = $roles;
  419. return $this;
  420. }
  421. /**
  422. * @see UserInterface
  423. */
  424. public function getPassword(): string
  425. {
  426. return (string)$this->password;
  427. }
  428. public function setPassword( string $password ): self
  429. {
  430. $this->password = $password;
  431. return $this;
  432. }
  433. /**
  434. * @see UserInterface
  435. */
  436. public function getSalt()
  437. {
  438. // not needed when using the "bcrypt" algorithm in security.yaml
  439. }
  440. /**
  441. * @see UserInterface
  442. */
  443. public function eraseCredentials()
  444. {
  445. // If you store any temporary, sensitive data on the user, clear it here
  446. // $this->plainPassword = null;
  447. }
  448. /**
  449. * Returns the username used to authenticate the user.
  450. *
  451. * @return string The username
  452. */
  453. public function getUsername()
  454. {
  455. return $this->email;
  456. }
  457. /**
  458. * Get LastLogin
  459. *
  460. * @return mixed
  461. */
  462. public function getLastLogin()
  463. {
  464. return $this->lastLogin;
  465. }
  466. /**
  467. * Set LastLogin
  468. *
  469. * @param mixed $lastLogin
  470. */
  471. public function setLastLogin( $lastLogin )
  472. {
  473. $this->lastLogin = $lastLogin;
  474. }
  475. public function isVerified(): bool
  476. {
  477. return $this->isVerified;
  478. }
  479. public function setIsVerified( bool $isVerified ): self
  480. {
  481. $this->isVerified = $isVerified;
  482. return $this;
  483. }
  484. /**
  485. * Get ConfirmToken
  486. *
  487. * @return string
  488. */
  489. public function getConfirmToken()
  490. {
  491. return $this->confirmToken;
  492. }
  493. /**
  494. * Set ConfirmToken
  495. *
  496. * @param string $confirmToken
  497. */
  498. public function setConfirmToken( $confirmToken )
  499. {
  500. $this->confirmToken = $confirmToken;
  501. }
  502. /**
  503. * Get HasDeliveryAddress
  504. *
  505. * @return mixed
  506. */
  507. public function getHasDeliveryAddress()
  508. {
  509. return $this->hasDeliveryAddress;
  510. }
  511. /**
  512. * Set HasDeliveryAddress
  513. *
  514. * @param mixed $hasDeliveryAddress
  515. */
  516. public function setHasDeliveryAddress( $hasDeliveryAddress )
  517. {
  518. $this->hasDeliveryAddress = $hasDeliveryAddress;
  519. }
  520. /**
  521. * @return Collection|ClientToken[]
  522. */
  523. public function getClientTokens(): Collection
  524. {
  525. return $this->clientTokens;
  526. }
  527. public function addClientToken(ClientToken $clientToken): self
  528. {
  529. if (!$this->clientTokens->contains($clientToken)) {
  530. $this->clientTokens[] = $clientToken;
  531. $clientToken->setClient($this);
  532. }
  533. return $this;
  534. }
  535. public function removeClientToken(ClientToken $clientToken): self
  536. {
  537. if ($this->clientTokens->removeElement($clientToken)) {
  538. // set the owning side to null (unless already changed)
  539. if ($clientToken->getClient() === $this) {
  540. $clientToken->setClient(null);
  541. }
  542. }
  543. return $this;
  544. }
  545. /**
  546. * Get Avatar
  547. *
  548. * @return mixed
  549. */
  550. public function getAvatar()
  551. {
  552. return $this->avatar;
  553. }
  554. /**
  555. * Set Avatar
  556. *
  557. * @param mixed $avatar
  558. */
  559. public function setAvatar( $avatar )
  560. {
  561. $this->avatar = $avatar;
  562. }
  563. /**
  564. * Get AvatarFile
  565. *
  566. * @return null|File
  567. */
  568. public function getAvatarFile(): ?File
  569. {
  570. return $this->avatarFile;
  571. }
  572. /**
  573. * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $avatarFile
  574. */
  575. public function setAvatarFile(?File $avatarFile = null): void
  576. {
  577. $this->avatarFile = $avatarFile;
  578. if (null !== $avatarFile) {
  579. $this->editts = new \DateTime();
  580. }
  581. }
  582. /**
  583. * Get Birthdate
  584. *
  585. * @return mixed
  586. */
  587. public function getBirthdate()
  588. {
  589. return $this->birthdate;
  590. }
  591. /**
  592. * Set Birthdate
  593. *
  594. * @param mixed $birthdate
  595. */
  596. public function setBirthdate( $birthdate )
  597. {
  598. if(!$birthdate instanceof \DateTime && $birthdate !== null){
  599. $birthdate = (new \DateTime($birthdate))->setTime(12,12,12);
  600. }
  601. $this->birthdate = $birthdate;
  602. }
  603. /**
  604. * Get Phone
  605. *
  606. * @return mixed
  607. */
  608. public function getPhone()
  609. {
  610. return $this->phone;
  611. }
  612. /**
  613. * Set Phone
  614. *
  615. * @param mixed $phone
  616. */
  617. public function setPhone( $phone )
  618. {
  619. $this->phone = $phone;
  620. }
  621. /**
  622. * Get Points
  623. *
  624. * @return mixed
  625. */
  626. public function getPoints()
  627. {
  628. return $this->points;
  629. }
  630. /**
  631. * Set Points
  632. *
  633. * @param mixed $points
  634. */
  635. public function setPoints( $points )
  636. {
  637. $this->points = $points;
  638. }
  639. /**
  640. * Add Points
  641. *
  642. * @param mixed $points
  643. */
  644. public function addPoints( $points )
  645. {
  646. $this->points = $this->getPoints()+$points;
  647. }
  648. /**
  649. * @return Collection|Points[]
  650. */
  651. public function getPointsHistory(): Collection
  652. {
  653. return $this->pointsHistory;
  654. }
  655. public function addPointsHistory(Points $pointsHistory): self
  656. {
  657. if (!$this->pointsHistory->contains($pointsHistory)) {
  658. $this->pointsHistory[] = $pointsHistory;
  659. $pointsHistory->setClient($this);
  660. }
  661. return $this;
  662. }
  663. public function removePointsHistory(Points $pointsHistory): self
  664. {
  665. if ($this->pointsHistory->removeElement($pointsHistory)) {
  666. // set the owning side to null (unless already changed)
  667. if ($pointsHistory->getClient() === $this) {
  668. $pointsHistory->setClient(null);
  669. }
  670. }
  671. return $this;
  672. }
  673. /**
  674. * Get RegisterApp
  675. *
  676. * @return mixed
  677. */
  678. public function getRegisterApp()
  679. {
  680. return $this->registerApp;
  681. }
  682. /**
  683. * Set RegisterApp
  684. *
  685. * @param mixed $registerApp
  686. */
  687. public function setRegisterApp( $registerApp )
  688. {
  689. $this->registerApp = $registerApp;
  690. }
  691. /**
  692. * @return bool
  693. */
  694. public function isBlocked(): bool
  695. {
  696. return $this->isBlocked;
  697. }
  698. /**
  699. * @param bool $isBlocked
  700. */
  701. public function setIsBlocked(bool $isBlocked): void
  702. {
  703. $this->isBlocked = $isBlocked;
  704. }
  705. /**
  706. * @return mixed
  707. */
  708. public function getZip()
  709. {
  710. return $this->zip;
  711. }
  712. /**
  713. * @param mixed $zip
  714. */
  715. public function setZip($zip): void
  716. {
  717. $this->zip = $zip;
  718. }
  719. /**
  720. * @return mixed
  721. */
  722. public function getLocale()
  723. {
  724. return $this->locale;
  725. }
  726. /**
  727. * @param mixed $locale
  728. */
  729. public function setLocale($locale): void
  730. {
  731. $this->locale = $locale;
  732. }
  733. }