src/Entity/User.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Gedmo\Timestampable\Traits\TimestampableEntity;
  11. /**
  12.  * @ORM\Entity(repositoryClass=UserRepository::class)
  13.  * @ORM\Table(name="`user`")
  14.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  15.  */
  16. class User implements UserInterfacePasswordAuthenticatedUserInterface
  17. {
  18.     use TimestampableEntity;
  19.     /**
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="string", length=180, unique=true)
  27.      */
  28.     private $email;
  29.     /**
  30.      * @ORM\Column(type="json")
  31.      */
  32.     private $roles = [];
  33.     /**
  34.      * @var string The hashed password
  35.      * @ORM\Column(type="string")
  36.      */
  37.     private $password;
  38.     /**
  39.      * @ORM\Column(type="boolean")
  40.      */
  41.     private $isVerified false;
  42.     /**
  43.      * @ORM\Column(type="boolean")
  44.      */
  45.     private $isEnabled true;
  46.     /**
  47.      * @ORM\OneToOne(targetEntity=UserInfo::class, mappedBy="user", cascade={"persist", "remove"})
  48.      */
  49.     private $info;
  50.     /**
  51.      * @ORM\OneToOne(targetEntity=UserAddress::class, mappedBy="user", cascade={"persist", "remove"})
  52.      */
  53.     private $address;
  54.     /**
  55.      * @ORM\OneToMany(targetEntity=Order::class, mappedBy="user")
  56.      * @ORM\OrderBy({"createdAt" = "DESC"})
  57.      */
  58.     private $orders;
  59.     /**
  60.      * @ORM\OneToMany(targetEntity=UserCertificate::class, mappedBy="user")
  61.      */
  62.     private $userCertificates;
  63.     /**
  64.      * @ORM\OneToMany(targetEntity=UserCardToken::class, mappedBy="user")
  65.      */
  66.     private $userCardTokens;
  67.     /**
  68.      * @ORM\OneToMany(targetEntity=UserCourse::class, mappedBy="user")
  69.      */
  70.     private $userCourses;
  71.     /**
  72.      * @ORM\OneToMany(targetEntity=Course::class, mappedBy="user")
  73.      */
  74.     private $courses;
  75.     /**
  76.      * @ORM\OneToMany(targetEntity=UserCareerPath::class, mappedBy="user", orphanRemoval=true)
  77.      */
  78.     private $userCareerPaths;
  79.     /**
  80.      * @ORM\Column(type="boolean")
  81.      */
  82.     private $hasEmailSubscribed false;
  83.     public function __construct()
  84.     {
  85.         $this->orders = new ArrayCollection();
  86.         $this->userCertificates = new ArrayCollection();
  87.         $this->userCardTokens = new ArrayCollection();
  88.         $this->userCourses = new ArrayCollection();
  89.         $this->courses = new ArrayCollection();
  90.         $this->userCareerPaths = new ArrayCollection();
  91.         $this->hasEmailSubscribed false;
  92.     }
  93.     public function getId(): ?int
  94.     {
  95.         return $this->id;
  96.     }
  97.     public function getEmail(): ?string
  98.     {
  99.         return $this->email;
  100.     }
  101.     public function setEmail(string $email): self
  102.     {
  103.         $this->email $email;
  104.         return $this;
  105.     }
  106.     /**
  107.      * A visual identifier that represents this user.
  108.      *
  109.      * @see UserInterface
  110.      */
  111.     public function getUserIdentifier(): string
  112.     {
  113.         return (string) $this->email;
  114.     }
  115.     /**
  116.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  117.      */
  118.     public function getUsername(): string
  119.     {
  120.         return (string) $this->email;
  121.     }
  122.     /**
  123.      * @see UserInterface
  124.      */
  125.     public function getRoles(): array
  126.     {
  127.         $roles $this->roles;
  128.         // guarantee every user at least has ROLE_USER
  129.         $roles[] = 'ROLE_USER';
  130.         return array_unique($roles);
  131.     }
  132.     public function setRoles(array $roles): self
  133.     {
  134.         $this->roles $roles;
  135.         return $this;
  136.     }
  137.     /**
  138.      * @see PasswordAuthenticatedUserInterface
  139.      */
  140.     public function getPassword(): string
  141.     {
  142.         return $this->password;
  143.     }
  144.     public function setPassword(string $password): self
  145.     {
  146.         $this->password $password;
  147.         return $this;
  148.     }
  149.     /**
  150.      * Returning a salt is only needed, if you are not using a modern
  151.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  152.      *
  153.      * @see UserInterface
  154.      */
  155.     public function getSalt(): ?string
  156.     {
  157.         return null;
  158.     }
  159.     /**
  160.      * @see UserInterface
  161.      */
  162.     public function eraseCredentials()
  163.     {
  164.         // If you store any temporary, sensitive data on the user, clear it here
  165.         // $this->plainPassword = null;
  166.     }
  167.     public function isVerified(): bool
  168.     {
  169.         return $this->isVerified;
  170.     }
  171.     public function setIsVerified(bool $isVerified): self
  172.     {
  173.         $this->isVerified $isVerified;
  174.         return $this;
  175.     }
  176.     public function getIsEnabled(): ?bool
  177.     {
  178.         return $this->isEnabled;
  179.     }
  180.     public function setIsEnabled(bool $isEnabled): self
  181.     {
  182.         $this->isEnabled $isEnabled;
  183.         return $this;
  184.     }
  185.     public function getInfo(): ?UserInfo
  186.     {
  187.         return $this->info;
  188.     }
  189.     public function setInfo(UserInfo $info): self
  190.     {
  191.         // set the owning side of the relation if necessary
  192.         if ($info->getUser() !== $this) {
  193.             $info->setUser($this);
  194.         }
  195.         $this->info $info;
  196.         return $this;
  197.     }
  198.     public function getAddress(): ?UserAddress
  199.     {
  200.         return $this->address;
  201.     }
  202.     public function setAddress(UserAddress $address): self
  203.     {
  204.         // set the owning side of the relation if necessary
  205.         if ($address->getUser() !== $this) {
  206.             $address->setUser($this);
  207.         }
  208.         $this->address $address;
  209.         return $this;
  210.     }
  211.     /**
  212.      * @return Collection|OrderHistory[]
  213.      */
  214.     public function getOrders(): Collection
  215.     {
  216.         return $this->orders;
  217.     }
  218.     public function addOrder(Order $order): self
  219.     {
  220.         if (!$this->orders->contains($order)) {
  221.             $this->orders[] = $order;
  222.             $order->setUser($this);
  223.         }
  224.         return $this;
  225.     }
  226.     public function removeOrder(Order $order): self
  227.     {
  228.         if ($this->orders->removeElement($order)) {
  229.             // set the owning side to null (unless already changed)
  230.             if ($order->getUser() === $this) {
  231.                 $order->setUser(null);
  232.             }
  233.         }
  234.         return $this;
  235.     }
  236.     /**
  237.      * @return Collection|UserCertificate[]
  238.      */
  239.     public function getUserCertificates(): Collection
  240.     {
  241.         return $this->userCertificates;
  242.     }
  243.     public function addUserCertificate(UserCertificate $userCertificate): self
  244.     {
  245.         if (!$this->userCertificates->contains($userCertificate)) {
  246.             $this->userCertificates[] = $userCertificate;
  247.             $userCertificate->setUser($this);
  248.         }
  249.         return $this;
  250.     }
  251.     public function removeUserCertificate(UserCertificate $userCertificate): self
  252.     {
  253.         if ($this->userCertificates->removeElement($userCertificate)) {
  254.             // set the owning side to null (unless already changed)
  255.             if ($userCertificate->getUser() === $this) {
  256.                 $userCertificate->setUser(null);
  257.             }
  258.         }
  259.         return $this;
  260.     }
  261.     /**
  262.      * @return Collection|UserCardToken[]
  263.      */
  264.     public function getUserCardTokens(): Collection
  265.     {
  266.         return $this->userCardTokens;
  267.     }
  268.     public function addUserCardToken(UserCardToken $userCardToken): self
  269.     {
  270.         if (!$this->userCardTokens->contains($userCardToken)) {
  271.             $this->userCardTokens[] = $userCardToken;
  272.             $userCardToken->setUser($this);
  273.         }
  274.         return $this;
  275.     }
  276.     public function removeUserCardToken(UserCardToken $userCardToken): self
  277.     {
  278.         if ($this->userCardTokens->removeElement($userCardToken)) {
  279.             // set the owning side to null (unless already changed)
  280.             if ($userCardToken->getUser() === $this) {
  281.                 $userCardToken->setUser(null);
  282.             }
  283.         }
  284.         return $this;
  285.     }
  286.     /**
  287.      * @return Collection|UserCourse[]
  288.      */
  289.     public function getUserCourses(): Collection
  290.     {
  291.         return $this->userCourses;
  292.     }
  293.     public function addUserCourse(UserCourse $userCourse): self
  294.     {
  295.         if (!$this->userCourses->contains($userCourse)) {
  296.             $this->userCourses[] = $userCourse;
  297.             $userCourse->setUser($this);
  298.         }
  299.         return $this;
  300.     }
  301.     public function removeUserCourse(UserCourse $userCourse): self
  302.     {
  303.         if ($this->userCourses->removeElement($userCourse)) {
  304.             // set the owning side to null (unless already changed)
  305.             if ($userCourse->getUser() === $this) {
  306.                 $userCourse->setUser(null);
  307.             }
  308.         }
  309.         return $this;
  310.     }
  311.     /**
  312.      * @return Collection<int, Course>
  313.      */
  314.     public function getCourses(): Collection
  315.     {
  316.         return $this->courses;
  317.     }
  318.     public function addCourse(Course $course): self
  319.     {
  320.         if (!$this->courses->contains($course)) {
  321.             $this->courses[] = $course;
  322.             $course->setUser($this);
  323.         }
  324.         return $this;
  325.     }
  326.     public function removeCourse(Course $course): self
  327.     {
  328.         if ($this->courses->removeElement($course)) {
  329.             // set the owning side to null (unless already changed)
  330.             if ($course->getUser() === $this) {
  331.                 $course->setUser(null);
  332.             }
  333.         }
  334.         return $this;
  335.     }
  336.     /**
  337.      * @return Collection<int, UserCareerPath>
  338.      */
  339.     public function getUserCareerPaths(): Collection
  340.     {
  341.         return $this->userCareerPaths;
  342.     }
  343.     public function addUserCareerPath(UserCareerPath $userCareerPath): self
  344.     {
  345.         if (!$this->userCareerPaths->contains($userCareerPath)) {
  346.             $this->userCareerPaths[] = $userCareerPath;
  347.             $userCareerPath->setUser($this);
  348.         }
  349.         return $this;
  350.     }
  351.     public function removeUserCareerPath(UserCareerPath $userCareerPath): self
  352.     {
  353.         if ($this->userCareerPaths->removeElement($userCareerPath)) {
  354.             // set the owning side to null (unless already changed)
  355.             if ($userCareerPath->getUser() === $this) {
  356.                 $userCareerPath->setUser(null);
  357.             }
  358.         }
  359.         return $this;
  360.     }
  361.     public function getHasEmailSubscribed(): ?bool
  362.     {
  363.         return $this->hasEmailSubscribed;
  364.     }
  365.     public function setHasEmailSubscribed(bool $hasEmailSubscribed): self
  366.     {
  367.         $this->hasEmailSubscribed $hasEmailSubscribed;
  368.         return $this;
  369.     }
  370. }