src/Entity/User.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use DateTimeInterface;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13.  * @ORM\Entity(repositoryClass=UserRepository::class)
  14.  * @UniqueEntity("username")
  15.  * @UniqueEntity("email", ignoreNull=true)
  16.  */
  17. class User implements UserInterfacePasswordAuthenticatedUserInterface
  18. {
  19.     /**
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private ?int $id null;
  25.     /**
  26.      * @ORM\Column(type="string", length=180, unique=true)
  27.      */
  28.     private ?string $username null;
  29.     /**
  30.      * @ORM\Column(type="json")
  31.      * @Assert\NotNull()
  32.      */
  33.     private array $roles = [];
  34.     /**
  35.      * @var string|null The hashed password
  36.      * @ORM\Column(type="string")
  37.      */
  38.     private ?string $password;
  39.     /**
  40.      * @Assert\NotNull(groups={"create"})
  41.      * @Assert\Length(min=8, max=4096)
  42.      */
  43.     private ?string $rawPassword null;
  44.     /**
  45.      * @ORM\Column(type="string", length=255, nullable=true)
  46.      * @Assert\NotNull(groups={"porteur", "drci", "girci", "other"})
  47.      * @Assert\Blank(groups={"expert"})
  48.      */
  49.     private ?string $email;
  50.     /**
  51.      * @ORM\Column(type="string", length=10, nullable=true)
  52.      */
  53.     private ?string $title;
  54.     /**
  55.      * @ORM\Column(type="string", length=10, nullable=true)
  56.      * @Assert\NotNull(groups={"porteur"})
  57.      */
  58.     private ?string $civility;
  59.     /**
  60.      * @ORM\Column(type="string", length=255, nullable=true)
  61.      * @Assert\NotNull(groups={"porteur"})
  62.      */
  63.     private ?string $name;
  64.     /**
  65.      * @ORM\Column(type="string", length=255, nullable=true)
  66.      * @Assert\NotNull(groups={"porteur"})
  67.      */
  68.     private ?string $firstname;
  69.     /**
  70.      * @ORM\Column(type="string", length=25, nullable=true)
  71.      * @Assert\NotNull(groups={"porteur"})
  72.      */
  73.     private ?string $phone;
  74.     /**
  75.      * @ORM\ManyToOne(targetEntity=Drci::class)
  76.      * @Assert\NotNull(groups={"porteur", "drci"})
  77.      */
  78.     private ?Drci $drci;
  79.     /**
  80.      * @ORM\ManyToOne(targetEntity=Girci::class)
  81.      * @Assert\NotNull(groups={"girci"})
  82.      */
  83.     private ?Girci $girci;
  84.     /**
  85.      * @ORM\Column(type="string", length=255, nullable=true)
  86.      * @Assert\NotNull(groups={"porteur"})
  87.      */
  88.     private ?string $service;
  89.     /**
  90.      * @ORM\Column(type="string", length=255, nullable=true)
  91.      * @Assert\NotNull(groups={"porteur"})
  92.      */
  93.     private ?string $street;
  94.     /**
  95.      * @ORM\Column(type="string", length=10, nullable=true)
  96.      * @Assert\NotNull(groups={"porteur"})
  97.      */
  98.     private ?string $postalCode;
  99.     /**
  100.      * @ORM\Column(type="string", length=255, nullable=true)
  101.      * @Assert\NotNull(groups={"porteur"})
  102.      */
  103.     private ?string $city;
  104.     /**
  105.      * @ORM\OneToMany(targetEntity=Project::class, mappedBy="author")
  106.      */
  107.     private $projects;
  108.     /**
  109.      * @ORM\Column(type="datetime", nullable=true)
  110.      */
  111.     private $lastLoginDate;
  112.     /**
  113.      * @ORM\Column(type="datetime")
  114.      */
  115.     private $creationDate;
  116.     /**
  117.      * @ORM\OneToMany(targetEntity=UserProject::class, mappedBy="user")
  118.      */
  119.     private $userProjects;
  120.     /**
  121.      * @ORM\Column(type="boolean")
  122.      */
  123.     private $enabled;
  124.     /**
  125.      * @ORM\Column(type="boolean")
  126.      */
  127.     private $isVerified false;
  128.     public function __construct()
  129.     {
  130.         $this->projects = new ArrayCollection();
  131.         $this->userProjects = new ArrayCollection();
  132.         $this->enabled false;
  133.     }
  134.     public function getId(): ?int
  135.     {
  136.         return $this->id;
  137.     }
  138.     /**
  139.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  140.      */
  141.     public function getUsername(): ?string
  142.     {
  143.         return $this->username;
  144.     }
  145.     public function setUsername(string $username): self
  146.     {
  147.         $this->username $username;
  148.         return $this;
  149.     }
  150.     /**
  151.      * A visual identifier that represents this user.
  152.      *
  153.      * @see UserInterface
  154.      */
  155.     public function getUserIdentifier(): string
  156.     {
  157.         return $this->username;
  158.     }
  159.     /**
  160.      * @see UserInterface
  161.      */
  162.     public function getRoles(): array
  163.     {
  164.         $roles $this->roles;
  165.         // guarantee every user at least has ROLE_USER
  166.         $roles[] = 'ROLE_USER';
  167.         return array_unique($roles);
  168.     }
  169.     public function setRoles(array $roles): self
  170.     {
  171.         $this->roles $roles;
  172.         return $this;
  173.     }
  174.     public function addRole($role): self
  175.     {
  176.         $role strtoupper($role);
  177.         if ($role === 'ROLE_USER') {
  178.             return $this;
  179.         }
  180.         if (!in_array($role$this->rolestrue)) {
  181.             $this->roles[] = $role;
  182.         }
  183.         return $this;
  184.     }
  185.     public function removeRole($role): self
  186.     {
  187.         if (false !== $key array_search(strtoupper($role), $this->rolestrue)) {
  188.             unset($this->roles[$key]);
  189.             $this->roles array_values($this->roles);
  190.         }
  191.         return $this;
  192.     }
  193.     public function hasRole(string $role)
  194.     {
  195.         if (in_array($role$this->rolestrue)) {
  196.             return true;
  197.         }
  198.         return false;
  199.     }
  200.     /**
  201.      * @see PasswordAuthenticatedUserInterface
  202.      */
  203.     public function getPassword(): string
  204.     {
  205.         return $this->password;
  206.     }
  207.     public function setPassword(string $password): self
  208.     {
  209.         $this->password $password;
  210.         return $this;
  211.     }
  212.     public function getRawPassword(): ?string
  213.     {
  214.         return $this->rawPassword;
  215.     }
  216.     public function setRawPassword(string $rawPassword): self
  217.     {
  218.         $this->rawPassword $rawPassword;
  219.         $this->password null;
  220.         return $this;
  221.     }
  222.     /**
  223.      * Returning a salt is only needed, if you are not using a modern
  224.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  225.      *
  226.      * @see UserInterface
  227.      */
  228.     public function getSalt(): ?string
  229.     {
  230.         return null;
  231.     }
  232.     /**
  233.      * @see UserInterface
  234.      */
  235.     public function eraseCredentials()
  236.     {
  237.         // If you store any temporary, sensitive data on the user, clear it here
  238.          $this->rawPassword null;
  239.     }
  240.     public function getEmail(): ?string
  241.     {
  242.         return $this->email;
  243.     }
  244.     public function setEmail(?string $email): self
  245.     {
  246.         $this->email $email;
  247.         return $this;
  248.     }
  249.     public function getTitle(): ?string
  250.     {
  251.         return $this->title;
  252.     }
  253.     public function setTitle(?string $title): self
  254.     {
  255.         $this->title $title;
  256.         return $this;
  257.     }
  258.     public function getCivility(): ?string
  259.     {
  260.         return $this->civility;
  261.     }
  262.     public function setCivility(?string $civility): self
  263.     {
  264.         $this->civility $civility;
  265.         return $this;
  266.     }
  267.     public function getName(): ?string
  268.     {
  269.         return $this->name;
  270.     }
  271.     public function setName(?string $name): self
  272.     {
  273.         $this->name $name;
  274.         return $this;
  275.     }
  276.     public function getFirstname(): ?string
  277.     {
  278.         return $this->firstname;
  279.     }
  280.     public function setFirstname(?string $firstname): self
  281.     {
  282.         $this->firstname $firstname;
  283.         return $this;
  284.     }
  285.     public function getPhone(): ?string
  286.     {
  287.         return $this->phone;
  288.     }
  289.     public function setPhone(?string $phone): self
  290.     {
  291.         $this->phone $phone;
  292.         return $this;
  293.     }
  294.     public function getDrci(): ?Drci
  295.     {
  296.         return $this->drci;
  297.     }
  298.     public function setDrci(?Drci $drci): self
  299.     {
  300.         $this->drci $drci;
  301.         return $this;
  302.     }
  303.     public function getGirci(): ?Girci
  304.     {
  305.         return $this->girci;
  306.     }
  307.     public function setGirci(?Girci $girci): self
  308.     {
  309.         $this->girci $girci;
  310.         return $this;
  311.     }
  312.     public function getService(): ?string
  313.     {
  314.         return $this->service;
  315.     }
  316.     public function setService(?string $service): self
  317.     {
  318.         $this->service $service;
  319.         return $this;
  320.     }
  321.     public function getStreet(): ?string
  322.     {
  323.         return $this->street;
  324.     }
  325.     public function setStreet(?string $street): self
  326.     {
  327.         $this->street $street;
  328.         return $this;
  329.     }
  330.     public function getPostalCode(): ?string
  331.     {
  332.         return $this->postalCode;
  333.     }
  334.     public function setPostalCode(?string $postalCode): self
  335.     {
  336.         $this->postalCode $postalCode;
  337.         return $this;
  338.     }
  339.     public function getCity(): ?string
  340.     {
  341.         return $this->city;
  342.     }
  343.     public function setCity(?string $city): self
  344.     {
  345.         $this->city $city;
  346.         return $this;
  347.     }
  348.     /**
  349.      * @return Collection|Project[]
  350.      */
  351.     public function getProjects(): Collection
  352.     {
  353.         return $this->projects;
  354.     }
  355.     public function addProject(Project $project): self
  356.     {
  357.         if (!$this->projects->contains($project)) {
  358.             $this->projects[] = $project;
  359.             $project->setAuthor($this);
  360.         }
  361.         return $this;
  362.     }
  363.     public function removeProject(Project $project): self
  364.     {
  365.         if ($this->projects->removeElement($project)) {
  366.             // set the owning side to null (unless already changed)
  367.             if ($project->getAuthor() === $this) {
  368.                 $project->setAuthor(null);
  369.             }
  370.         }
  371.         return $this;
  372.     }
  373.     public function getLastLoginDate(): ?DateTimeInterface
  374.     {
  375.         return $this->lastLoginDate;
  376.     }
  377.     public function setLastLoginDate(?DateTimeInterface $lastLoginDate): self
  378.     {
  379.         $this->lastLoginDate $lastLoginDate;
  380.         return $this;
  381.     }
  382.     public function getCreationDate(): ?DateTimeInterface
  383.     {
  384.         return $this->creationDate;
  385.     }
  386.     public function setCreationDate(DateTimeInterface $creationDate): self
  387.     {
  388.         $this->creationDate $creationDate;
  389.         return $this;
  390.     }
  391.     /**
  392.      * @return Collection|UserProject[]
  393.      */
  394.     public function getUserProjects(): Collection
  395.     {
  396.         return $this->userProjects;
  397.     }
  398.     public function addUserProject(UserProject $userProject) {
  399.         if (!$this->userProjects->contains($userProject)) {
  400.             $this->userProjects[] = $userProject;
  401.             $userProject->setUser($this);
  402.         }
  403.         return $this;
  404.     }
  405.     public function removeUserProject(UserProject $userproject): self
  406.     {
  407.         if ($this->userProjects->removeElement($userproject)) {
  408.             // set the owning side to null (unless already changed)
  409.             if ($userproject->getUser() === $this) {
  410.                 $userproject->setUser(null);
  411.             }
  412.         }
  413.         return $this;
  414.     }
  415.     public function isEnabled(): ?bool
  416.     {
  417.         return $this->enabled;
  418.     }
  419.     public function setEnabled(bool $enabled): self
  420.     {
  421.         $this->enabled $enabled;
  422.         return $this;
  423.     }
  424.     public function isVerified(): bool
  425.     {
  426.         return $this->isVerified;
  427.     }
  428.     public function setIsVerified(bool $isVerified): self
  429.     {
  430.         $this->isVerified $isVerified;
  431.         return $this;
  432.     }
  433. }