src/Entity/User.php line 14

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\Length;
  10. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. class User implements UserInterfacePasswordAuthenticatedUserInterface
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\Column(length180uniquetrue)]
  18.     private ?string $userName null;
  19.     #[ORM\Column]
  20.     private array $roles = [];
  21.     /**
  22.      * @var string The hashed password
  23.      */
  24.     #[ORM\Column]
  25.     private ?string $password null;
  26.     #[ORM\OneToMany(mappedBy'user'targetEntityMarchePublic::class)]
  27.     private Collection $marchePublics;
  28.     #[ORM\OneToMany(mappedBy'user'targetEntityConcession::class)]
  29.     private Collection $concessions;
  30.     #[ORM\Column(length255nullabletrue)]
  31.     #[Length(
  32.         exactly14,
  33.         exactMessage'L\'identifiant SIRET doit comporter exactement 14 chiffres.'
  34.     )]
  35.     private ?string $siret null;
  36.     #[ORM\Column(length255nullabletrue)]
  37.     private ?string $name null;
  38.     public function __construct()
  39.     {
  40.         $this->marchePublics = new ArrayCollection();
  41.         $this->concessions = new ArrayCollection();
  42.     }
  43.     public function getId(): ?int
  44.     {
  45.         return $this->id;
  46.     }
  47.     public function getUserName(): ?string
  48.     {
  49.         return $this->userName;
  50.     }
  51.     public function setUserName(string $userName): static
  52.     {
  53.         $this->userName $userName;
  54.         return $this;
  55.     }
  56.     /**
  57.      * A visual identifier that represents this user.
  58.      *
  59.      * @see UserInterface
  60.      */
  61.     public function getUserIdentifier(): string
  62.     {
  63.         return (string) $this->userName;
  64.     }
  65.     /**
  66.      * @see UserInterface
  67.      */
  68.     public function getRoles(): array
  69.     {
  70.         $roles $this->roles;
  71.         // guarantee every user at least has ROLE_USER
  72.         $roles[] = 'ROLE_SUPER_USER';
  73.         return array_unique($roles);
  74.     }
  75.     public function setRoles(array $roles): static
  76.     {
  77.         $this->roles $roles;
  78.         return $this;
  79.     }
  80.     /**
  81.      * @see PasswordAuthenticatedUserInterface
  82.      */
  83.     public function getPassword(): string
  84.     {
  85.         return $this->password;
  86.     }
  87.     public function setPassword(string $password): static
  88.     {
  89.         $this->password $password;
  90.         return $this;
  91.     }
  92.     /**
  93.      * @see UserInterface
  94.      */
  95.     public function eraseCredentials(): void
  96.     {
  97.         // If you store any temporary, sensitive data on the user, clear it here
  98.         // $this->plainPassword = null;
  99.     }
  100.     /**
  101.      * @return Collection<int, MarchePublic>
  102.      */
  103.     public function getMarchePublics(): Collection
  104.     {
  105.         return $this->marchePublics;
  106.     }
  107.     public function addMarchePublic(MarchePublic $marchePublic): static
  108.     {
  109.         if (!$this->marchePublics->contains($marchePublic)) {
  110.             $this->marchePublics->add($marchePublic);
  111.             $marchePublic->setUser($this);
  112.         }
  113.         return $this;
  114.     }
  115.     public function removeMarchePublic(MarchePublic $marchePublic): static
  116.     {
  117.         if ($this->marchePublics->removeElement($marchePublic)) {
  118.             // set the owning side to null (unless already changed)
  119.             if ($marchePublic->getUser() === $this) {
  120.                 $marchePublic->setUser(null);
  121.             }
  122.         }
  123.         return $this;
  124.     }
  125.     /**
  126.      * @return Collection<int, Concession>
  127.      */
  128.     public function getConcessions(): Collection
  129.     {
  130.         return $this->concessions;
  131.     }
  132.     public function addConcession(Concession $concession): static
  133.     {
  134.         if (!$this->concessions->contains($concession)) {
  135.             $this->concessions->add($concession);
  136.             $concession->setUser($this);
  137.         }
  138.         return $this;
  139.     }
  140.     public function removeConcession(Concession $concession): static
  141.     {
  142.         if ($this->concessions->removeElement($concession)) {
  143.             // set the owning side to null (unless already changed)
  144.             if ($concession->getUser() === $this) {
  145.                 $concession->setUser(null);
  146.             }
  147.         }
  148.         return $this;
  149.     }
  150.     public function getSiret(): ?string
  151.     {
  152.         return $this->siret;
  153.     }
  154.     public function setSiret(string $siret): static
  155.     {
  156.         $this->siret $siret;
  157.         return $this;
  158.     }
  159.     public function getName(): ?string
  160.     {
  161.         return $this->name;
  162.     }
  163.     public function setName(?string $name): static
  164.     {
  165.         $this->name $name;
  166.         return $this;
  167.     }
  168. }