src/Entity/User.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  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\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * @ORM\Entity(repositoryClass=UserRepository::class)
  12.  */
  13. class User implements UserInterfacePasswordAuthenticatedUserInterface
  14. {
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\Column(type="string", length=180, unique=true)
  23.      *
  24.      * @Assert\NotBlank(message="Veuillez entrer l'adresse mail")
  25.      * @Assert\Email(message="Adresse mail non valide")
  26.      */
  27.     private $email;
  28.     /**
  29.      * @ORM\Column(type="json")
  30.      */
  31.     private $roles = [];
  32.     /**
  33.      * @var string The hashed password
  34.      * @ORM\Column(type="string")
  35.      */
  36.     private $password;
  37.     /**
  38.      * @ORM\Column(type="string", length=255, nullable=true)
  39.      *
  40.      * @Assert\NotBlank(message="Veuillez entrer le prĂ©nom")
  41.      */
  42.     private $firstname;
  43.     /**
  44.      * @ORM\Column(type="string", length=255, nullable=true)
  45.      *
  46.      * @Assert\NotBlank(message="Veuillez entrer le nom")
  47.      */
  48.     private $lastname;
  49.     /**
  50.      * @ORM\OneToMany(targetEntity=UserContent::class, mappedBy="user", orphanRemoval=true)
  51.      */
  52.     private $userContents;
  53.     public function __construct()
  54.     {
  55.         $this->userContents = new ArrayCollection();
  56.     }
  57.     public function getId(): ?int
  58.     {
  59.         return $this->id;
  60.     }
  61.     public function getEmail(): ?string
  62.     {
  63.         return $this->email;
  64.     }
  65.     public function setEmail(string $email): self
  66.     {
  67.         $this->email $email;
  68.         return $this;
  69.     }
  70.     /**
  71.      * A visual identifier that represents this user.
  72.      *
  73.      * @see UserInterface
  74.      */
  75.     public function getUserIdentifier(): string
  76.     {
  77.         return (string) $this->email;
  78.     }
  79.     /**
  80.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  81.      */
  82.     public function getUsername(): string
  83.     {
  84.         return (string) $this->email;
  85.     }
  86.     /**
  87.      * @see UserInterface
  88.      */
  89.     public function getRoles(): array
  90.     {
  91.         $roles $this->roles;
  92.         // guarantee every user at least has ROLE_USER
  93.         $roles[] = 'ROLE_USER';
  94.         return array_unique($roles);
  95.     }
  96.     public function setRoles(array $roles): self
  97.     {
  98.         $this->roles $roles;
  99.         return $this;
  100.     }
  101.     /**
  102.      * @see PasswordAuthenticatedUserInterface
  103.      */
  104.     public function getPassword(): string
  105.     {
  106.         return $this->password;
  107.     }
  108.     public function setPassword(string $password): self
  109.     {
  110.         $this->password $password;
  111.         return $this;
  112.     }
  113.     /**
  114.      * Returning a salt is only needed, if you are not using a modern
  115.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  116.      *
  117.      * @see UserInterface
  118.      */
  119.     public function getSalt(): ?string
  120.     {
  121.         return null;
  122.     }
  123.     /**
  124.      * @see UserInterface
  125.      */
  126.     public function eraseCredentials()
  127.     {
  128.         // If you store any temporary, sensitive data on the user, clear it here
  129.         // $this->plainPassword = null;
  130.     }
  131.     public function getFirstname(): ?string
  132.     {
  133.         return $this->firstname;
  134.     }
  135.     public function setFirstname(?string $firstname): self
  136.     {
  137.         $this->firstname $firstname;
  138.         return $this;
  139.     }
  140.     public function getLastname(): ?string
  141.     {
  142.         return $this->lastname;
  143.     }
  144.     public function setLastname(?string $lastname): self
  145.     {
  146.         $this->lastname $lastname;
  147.         return $this;
  148.     }
  149.     /**
  150.      * @return Collection|UserContent[]
  151.      */
  152.     public function getUserContents(): Collection
  153.     {
  154.         return $this->userContents;
  155.     }
  156.     public function addUserContent(UserContent $userContent): self
  157.     {
  158.         if (!$this->userContents->contains($userContent)) {
  159.             $this->userContents[] = $userContent;
  160.             $userContent->setUser($this);
  161.         }
  162.         return $this;
  163.     }
  164.     public function removeUserContent(UserContent $userContent): self
  165.     {
  166.         if ($this->userContents->removeElement($userContent)) {
  167.             // set the owning side to null (unless already changed)
  168.             if ($userContent->getUser() === $this) {
  169.                 $userContent->setUser(null);
  170.             }
  171.         }
  172.         return $this;
  173.     }
  174. }