src/Entity/User.php line 34

Open in your IDE?
  1. <?php
  2. /*
  3.  * This event is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * event that was distributed with this source code.
  9.  */
  10. namespace App\Entity;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  15. use Symfony\Component\Security\Core\User\UserInterface;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. /**
  18.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  19.  * @ORM\Table(name="user")
  20.  *
  21.  * Defines the properties of the User entity to represent the application users.
  22.  * See https://symfony.com/doc/current/doctrine.html#creating-an-entity-class
  23.  *
  24.  * Tip: if you have an existing database, you can generate these entity class automatically.
  25.  * See https://symfony.com/doc/current/doctrine/reverse_engineering.html
  26.  *
  27.  * @author Ryan Weaver <weaverryan@gmail.com>
  28.  * @author Javier Eguiluz <javier.eguiluz@gmail.com>
  29.  */
  30. class User implements UserInterfacePasswordAuthenticatedUserInterface {
  31.     /**
  32.      * @ORM\Id
  33.      * @ORM\GeneratedValue
  34.      * @ORM\Column(type="integer")
  35.      */
  36.     private ?int $id null;
  37.     /**
  38.      * @ORM\Column(type="string")
  39.      */
  40.     #[Assert\NotBlank]
  41.     private ?string $firstname null;
  42.     /**
  43.      * @ORM\Column(type="string")
  44.      */
  45.     #[Assert\NotBlank]
  46.     private ?string $lastname null;
  47.     /**
  48.      * @ORM\Column(type="string", unique=true)
  49.      */
  50.     #[
  51.         Assert\NotBlank,
  52.         Assert\Length(min2max50)
  53.     ]
  54.     private ?string $username null;
  55.     /**
  56.      * @ORM\Column(type="string", nullable=true)
  57.      */
  58.     private ?string $bio;
  59.     /**
  60.      * @ORM\Column(type="datetime", nullable=true)
  61.      */
  62.     private \DateTime $createdAt;
  63.     
  64.     /**
  65.      * @ORM\Column(type="boolean", nullable=true)
  66.      */
  67.     private $enabled;
  68.     
  69.     /**
  70.      * @ORM\Column(type="boolean", nullable=true)
  71.      */
  72.     private $published;
  73.     
  74.     /**
  75.      * @ORM\Column(type="string", nullable=true)
  76.      */
  77.     private ?string $emailVerification "0";
  78.     /**
  79.      * @ORM\Column(type="string", unique=true)
  80.      */
  81.     #[Assert\Email]
  82.     private ?string $email null;
  83.     /**
  84.      * @ORM\Column(type="string", nullable=true)
  85.      */
  86.     private ?string $password null;
  87.     /**
  88.      * @ORM\Column(type="string", nullable=true)
  89.      */
  90.     private ?string $tokenreset null;
  91.     /**
  92.      * @ORM\Column(type="string", nullable=true)
  93.      */
  94.     private ?string $phone null;
  95.     /**
  96.      * @ORM\Column(type="string", nullable=true)
  97.      */
  98.     private ?string $country null;
  99.     /**
  100.      * @ORM\Column(type="string", nullable=true)
  101.      */
  102.     private ?string $gender null;
  103. //    1 men 0 women
  104.     /**
  105.      * @ORM\Column(type="string", nullable=true)
  106.      */
  107.     private ?string $address null;
  108.     /**
  109.      * @ORM\Column(type="json")
  110.      */
  111.     private array $roles = [];
  112.     /**
  113.      * @ORM\Column(type="string", nullable=true)
  114.      */
  115.     private ?string $image null;
  116.     /**
  117.      * @ORM\OneToMany(targetEntity="App\Entity\Experience", mappedBy="coach",orphanRemoval=true))
  118.      * @ORM\OrderBy({"id": "DESC"})
  119.      */
  120.     private Collection $experiences;
  121.     /**
  122.      * @ORM\OneToMany(targetEntity="App\Entity\Booking", mappedBy="customer",orphanRemoval=true))
  123.      * @ORM\OrderBy({"id": "DESC"})
  124.      */
  125.     private Collection $bookings;
  126.     public function __construct() {
  127.         $this->createdAt = new \DateTime('now');
  128.         $this->experiences = new ArrayCollection();
  129.         $this->bookings = new ArrayCollection();
  130.     }
  131.     public function getId(): ?int {
  132.         return $this->id;
  133.     }
  134.     public function setFullName(string $fullName): void {
  135.         $this->fullName $fullName;
  136.     }
  137.     public function getFullName(): ?string {
  138.         return $this->fullName;
  139.     }
  140.     public function getUserIdentifier(): string {
  141.         return $this->username;
  142.     }
  143.     public function getFirstname(): ?string {
  144.         return $this->firstname;
  145.     }
  146.     public function getLastname(): ?string {
  147.         return $this->lastname;
  148.     }
  149.     public function getUsername(): ?string {
  150.         return $this->username;
  151.     }
  152.     public function getBio(): ?string {
  153.         return $this->bio;
  154.     }
  155.     public function getEmail(): ?string {
  156.         return $this->email;
  157.     }
  158.     public function getPassword(): ?string {
  159.         return $this->password;
  160.     }
  161.     public function setFirstname(?string $firstname): void {
  162.         $this->firstname $firstname;
  163.     }
  164.     public function setLastname(?string $lastname): void {
  165.         $this->lastname $lastname;
  166.     }
  167.     public function setUsername(?string $username): void {
  168.         $this->username $username;
  169.     }
  170.     public function getEnabled() {
  171.         return $this->enabled;
  172.     }
  173.     public function getPublished() {
  174.         return $this->published;
  175.     }
  176.     public function setEnabled($enabled): void {
  177.         $this->enabled $enabled;
  178.     }
  179.     public function setPublished($published): void {
  180.         $this->published $published;
  181.     }
  182.     
  183.     public function setBio(?string $bio): void {
  184.         $this->bio $bio;
  185.     }
  186.     public function setEmail(?string $email): void {
  187.         $this->email $email;
  188.     }
  189.     public function setPassword(?string $password): void {
  190.         $this->password $password;
  191.     }
  192.     /**
  193.      * Returns the roles or permissions granted to the user for security.
  194.      */
  195.     public function getRoles(): array {
  196.         $roles $this->roles;
  197.         // guarantees that a user always has at least one role for security
  198.         if (empty($roles)) {
  199.             $roles[] = 'ROLE_USER';
  200.         }
  201.         return array_unique($roles);
  202.     }
  203.     public function setRoles(array $roles): void {
  204.         $this->roles $roles;
  205.     }
  206.     public function getTokenreset(): ?string {
  207.         return $this->tokenreset;
  208.     }
  209.     public function setTokenreset(?string $tokenreset): void {
  210.         $this->tokenreset $tokenreset;
  211.     }
  212.     public function getEmailVerification(): ?string {
  213.         return $this->emailVerification;
  214.     }
  215.     public function setEmailVerification(?string $emailVerification): void {
  216.         $this->emailVerification $emailVerification;
  217.     }
  218.     public function getPhone(): ?string {
  219.         return $this->phone;
  220.     }
  221.     public function setPhone(?string $phone): void {
  222.         $this->phone $phone;
  223.     }
  224.     public function getCreatedAt(): \DateTime {
  225.         return $this->createdAt;
  226.     }
  227.     public function setCreatedAt(\DateTime $createdAt): void {
  228.         $this->createdAt $createdAt;
  229.     }
  230.     /**
  231.      * Returns the salt that was originally used to encode the password.
  232.      *
  233.      * {@inheritdoc}
  234.      */
  235.     public function getSalt(): ?string {
  236.         // We're using bcrypt in security.yaml to encode the password, so
  237.         // the salt value is built-in and you don't have to generate one
  238.         // See https://en.wikipedia.org/wiki/Bcrypt
  239.         return null;
  240.     }
  241.     /**
  242.      * Removes sensitive data from the user.
  243.      *
  244.      * {@inheritdoc}
  245.      */
  246.     public function eraseCredentials(): void {
  247.         // if you had a plainPassword property, you'd nullify it here
  248.         // $this->plainPassword = null;
  249.     }
  250.     public function __serialize(): array {
  251.         // add $this->salt too if you don't use Bcrypt or Argon2i
  252.         return [$this->id$this->username$this->password];
  253.     }
  254.     public function __unserialize(array $data): void {
  255.         // add $this->salt too if you don't use Bcrypt or Argon2i
  256.         [$this->id$this->username$this->password] = $data;
  257.     }
  258.     public function getImage(): ?string {
  259.         return $this->image;
  260.     }
  261.     public function setImage(?string $image): void {
  262.         $this->image $image;
  263.     }
  264.     public function getCountry(): ?string {
  265.         return $this->country;
  266.     }
  267.     public function getAddress(): ?string {
  268.         return $this->address;
  269.     }
  270.     public function setCountry(?string $country): void {
  271.         $this->country $country;
  272.     }
  273.     public function setAddress(?string $address): void {
  274.         $this->address $address;
  275.     }
  276.     public function getGender(): ?string {
  277.         return $this->gender;
  278.     }
  279.     public function setGender(?string $gender): void {
  280.         $this->gender $gender;
  281.     }
  282.     public function setExperiences(Collection $experiences): void {
  283.         $this->experiences $experiences;
  284.     }
  285.     public function addExperience(Experience $experience): void {
  286.         $experience->setCoach($this);
  287.         if (!$this->experiences->contains($experience)) {
  288.             $this->experiences->add($experience);
  289.         }
  290.     }
  291.     public function removeExperience(Experience $experience): void {
  292.         $this->experiences->removeElement($experience);
  293.     }
  294.     
  295.     public function getBookings(): Collection {
  296.         return $this->bookings;
  297.     }
  298.     public function setBookings(Collection $bookings): void {
  299.         $this->bookings $bookings;
  300.     }
  301.     
  302.     public function addBooking(Booking $booking): void {
  303.         $booking->setCustomer($this);
  304.         if (!$this->bookings->contains($booking)) {
  305.             $this->bookings->add($booking);
  306.         }
  307.     }
  308.     public function removeBooking(Booking $booking): void {
  309.         $this->bookings->removeElement($booking);
  310.     }
  311.     public function getExperiences(): Collection {
  312.         return $this->experiences;
  313.     }
  314.     public function setId(?int $id): void {
  315.         $this->id $id;
  316.     }
  317.     
  318. }