<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Gedmo\Timestampable\Traits\TimestampableEntity;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @ORM\Table(name="`user`")
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="boolean")
*/
private $isVerified = false;
/**
* @ORM\Column(type="boolean")
*/
private $isEnabled = true;
/**
* @ORM\OneToOne(targetEntity=UserInfo::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $info;
/**
* @ORM\OneToOne(targetEntity=UserAddress::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $address;
/**
* @ORM\OneToMany(targetEntity=Order::class, mappedBy="user")
* @ORM\OrderBy({"createdAt" = "DESC"})
*/
private $orders;
/**
* @ORM\OneToMany(targetEntity=UserCertificate::class, mappedBy="user")
*/
private $userCertificates;
/**
* @ORM\OneToMany(targetEntity=UserCardToken::class, mappedBy="user")
*/
private $userCardTokens;
/**
* @ORM\OneToMany(targetEntity=UserCourse::class, mappedBy="user")
*/
private $userCourses;
/**
* @ORM\OneToMany(targetEntity=Course::class, mappedBy="user")
*/
private $courses;
/**
* @ORM\OneToMany(targetEntity=UserCareerPath::class, mappedBy="user", orphanRemoval=true)
*/
private $userCareerPaths;
/**
* @ORM\Column(type="boolean")
*/
private $hasEmailSubscribed = false;
public function __construct()
{
$this->orders = new ArrayCollection();
$this->userCertificates = new ArrayCollection();
$this->userCardTokens = new ArrayCollection();
$this->userCourses = new ArrayCollection();
$this->courses = new ArrayCollection();
$this->userCareerPaths = new ArrayCollection();
$this->hasEmailSubscribed = false;
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getIsEnabled(): ?bool
{
return $this->isEnabled;
}
public function setIsEnabled(bool $isEnabled): self
{
$this->isEnabled = $isEnabled;
return $this;
}
public function getInfo(): ?UserInfo
{
return $this->info;
}
public function setInfo(UserInfo $info): self
{
// set the owning side of the relation if necessary
if ($info->getUser() !== $this) {
$info->setUser($this);
}
$this->info = $info;
return $this;
}
public function getAddress(): ?UserAddress
{
return $this->address;
}
public function setAddress(UserAddress $address): self
{
// set the owning side of the relation if necessary
if ($address->getUser() !== $this) {
$address->setUser($this);
}
$this->address = $address;
return $this;
}
/**
* @return Collection|OrderHistory[]
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setUser($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getUser() === $this) {
$order->setUser(null);
}
}
return $this;
}
/**
* @return Collection|UserCertificate[]
*/
public function getUserCertificates(): Collection
{
return $this->userCertificates;
}
public function addUserCertificate(UserCertificate $userCertificate): self
{
if (!$this->userCertificates->contains($userCertificate)) {
$this->userCertificates[] = $userCertificate;
$userCertificate->setUser($this);
}
return $this;
}
public function removeUserCertificate(UserCertificate $userCertificate): self
{
if ($this->userCertificates->removeElement($userCertificate)) {
// set the owning side to null (unless already changed)
if ($userCertificate->getUser() === $this) {
$userCertificate->setUser(null);
}
}
return $this;
}
/**
* @return Collection|UserCardToken[]
*/
public function getUserCardTokens(): Collection
{
return $this->userCardTokens;
}
public function addUserCardToken(UserCardToken $userCardToken): self
{
if (!$this->userCardTokens->contains($userCardToken)) {
$this->userCardTokens[] = $userCardToken;
$userCardToken->setUser($this);
}
return $this;
}
public function removeUserCardToken(UserCardToken $userCardToken): self
{
if ($this->userCardTokens->removeElement($userCardToken)) {
// set the owning side to null (unless already changed)
if ($userCardToken->getUser() === $this) {
$userCardToken->setUser(null);
}
}
return $this;
}
/**
* @return Collection|UserCourse[]
*/
public function getUserCourses(): Collection
{
return $this->userCourses;
}
public function addUserCourse(UserCourse $userCourse): self
{
if (!$this->userCourses->contains($userCourse)) {
$this->userCourses[] = $userCourse;
$userCourse->setUser($this);
}
return $this;
}
public function removeUserCourse(UserCourse $userCourse): self
{
if ($this->userCourses->removeElement($userCourse)) {
// set the owning side to null (unless already changed)
if ($userCourse->getUser() === $this) {
$userCourse->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Course>
*/
public function getCourses(): Collection
{
return $this->courses;
}
public function addCourse(Course $course): self
{
if (!$this->courses->contains($course)) {
$this->courses[] = $course;
$course->setUser($this);
}
return $this;
}
public function removeCourse(Course $course): self
{
if ($this->courses->removeElement($course)) {
// set the owning side to null (unless already changed)
if ($course->getUser() === $this) {
$course->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, UserCareerPath>
*/
public function getUserCareerPaths(): Collection
{
return $this->userCareerPaths;
}
public function addUserCareerPath(UserCareerPath $userCareerPath): self
{
if (!$this->userCareerPaths->contains($userCareerPath)) {
$this->userCareerPaths[] = $userCareerPath;
$userCareerPath->setUser($this);
}
return $this;
}
public function removeUserCareerPath(UserCareerPath $userCareerPath): self
{
if ($this->userCareerPaths->removeElement($userCareerPath)) {
// set the owning side to null (unless already changed)
if ($userCareerPath->getUser() === $this) {
$userCareerPath->setUser(null);
}
}
return $this;
}
public function getHasEmailSubscribed(): ?bool
{
return $this->hasEmailSubscribed;
}
public function setHasEmailSubscribed(bool $hasEmailSubscribed): self
{
$this->hasEmailSubscribed = $hasEmailSubscribed;
return $this;
}
}