src/Entity/User.php line 22

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\UserRepository;
  5. use App\State\UserProcessor;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\DBAL\Types\Types;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. use Gedmo\Mapping\Annotation as Gedmo;
  13. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  14. #[ORM\Entity(repositoryClassUserRepository::class)]
  15. #[ApiResource(
  16.     processorUserProcessor::class
  17. )]
  18. #[Vich\Uploadable]
  19. class User implements UserInterfacePasswordAuthenticatedUserInterface
  20. {
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue]
  23.     #[ORM\Column]
  24.     private ?int $id null;
  25.     #[ORM\Column(length180uniquetrue)]
  26.     private ?string $email null;
  27.     #[ORM\Column]
  28.     private array $roles = [];
  29.     /**
  30.      * @var string The hashed password
  31.      */
  32.     #[ORM\Column]
  33.     private ?string $password null;
  34.     private ?string $plainPassword null;
  35.     #[ORM\Column(length255nullabletrue)]
  36.     private ?string $nom null;
  37.     #[ORM\Column(length255nullabletrue)]
  38.     private ?string $prenom null;
  39.     #[ORM\Column(length255nullabletrue)]
  40.     private ?string $telephone null;
  41.     #[ORM\Column(options: ['default' => false])]
  42.     private ?bool $locked false;
  43.     #[ORM\Column(length255nullabletrue)]
  44.     private ?string $telMobile null;
  45.     #[ORM\Column]
  46.     #[Gedmo\Timestampable(on'create')]
  47.     private ?\DateTimeImmutable $createdAt null;
  48.     #[ORM\Column]
  49.     #[Gedmo\Timestampable(on'update')]
  50.     private ?\DateTimeImmutable $updatedAt null;
  51.     #[ORM\ManyToOne(cascade: ['persist'])]
  52.     private ?MediaObject $photoProfil null;
  53.     #[ORM\ManyToMany(targetEntityStructure::class, inversedBy'users')]
  54.     private Collection $structures;
  55.     #[ORM\ManyToOne]
  56.     private ?Structure $selectedStructure null;
  57.     #[ORM\OneToMany(mappedBy'user'targetEntityJournal::class)]
  58.     private Collection $journals;
  59.     public function __construct()
  60.     {
  61.         $this->structures = new ArrayCollection();
  62.         $this->journals = new ArrayCollection();
  63.     }
  64.     public function getId(): ?int
  65.     {
  66.         return $this->id;
  67.     }
  68.     public function getEmail(): ?string
  69.     {
  70.         return $this->email;
  71.     }
  72.     public function setEmail(string $email): static
  73.     {
  74.         $this->email $email;
  75.         return $this;
  76.     }
  77.     /**
  78.      * A visual identifier that represents this user.
  79.      *
  80.      * @see UserInterface
  81.      */
  82.     public function getUserIdentifier(): 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): static
  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): static
  109.     {
  110.         $this->password $password;
  111.         return $this;
  112.     }
  113.     /**
  114.      * @see UserInterface
  115.      */
  116.     public function eraseCredentials(): void
  117.     {
  118.         // If you store any temporary, sensitive data on the user, clear it here
  119.         // $this->plainPassword = null;
  120.     }
  121.     public function getNom(): ?string
  122.     {
  123.         return $this->nom;
  124.     }
  125.     public function setNom(?string $nom): static
  126.     {
  127.         $this->nom $nom;
  128.         return $this;
  129.     }
  130.     public function getPrenom(): ?string
  131.     {
  132.         return $this->prenom;
  133.     }
  134.     public function setPrenom(?string $prenom): static
  135.     {
  136.         $this->prenom $prenom;
  137.         return $this;
  138.     }
  139.     public function getTelephone(): ?string
  140.     {
  141.         return $this->telephone;
  142.     }
  143.     public function setTelephone(?string $telephone): static
  144.     {
  145.         $this->telephone $telephone;
  146.         return $this;
  147.     }
  148.     public function isLocked(): ?bool
  149.     {
  150.         return $this->locked;
  151.     }
  152.     public function setLocked(bool $locked): static
  153.     {
  154.         $this->locked $locked;
  155.         return $this;
  156.     }
  157.     public function getTelMobile(): ?string
  158.     {
  159.         return $this->telMobile;
  160.     }
  161.     public function setTelMobile(?string $telMobile): static
  162.     {
  163.         $this->telMobile $telMobile;
  164.         return $this;
  165.     }
  166.     public function getDisplayName (): string
  167.     {
  168.         return implode(' 'array_filter([ucfirst(strtolower($this->getPrenom())), strtoupper($this->getNom())]));
  169.     }
  170.     public function getCreatedAt(): ?\DateTimeImmutable
  171.     {
  172.         return $this->createdAt;
  173.     }
  174.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  175.     {
  176.         $this->createdAt $createdAt;
  177.         return $this;
  178.     }
  179.     public function getUpdatedAt(): ?\DateTimeImmutable
  180.     {
  181.         return $this->updatedAt;
  182.     }
  183.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): static
  184.     {
  185.         $this->updatedAt $updatedAt;
  186.         return $this;
  187.     }
  188.     public function getPhotoProfil(): ?MediaObject
  189.     {
  190.         return $this->photoProfil;
  191.     }
  192.     public function setPhotoProfil(?MediaObject $photoProfil): static
  193.     {
  194.         $this->photoProfil $photoProfil;
  195.         return $this;
  196.     }
  197.     /**
  198.      * @return string|null
  199.      */
  200.     public function getPlainPassword(): ?string
  201.     {
  202.         return $this->plainPassword;
  203.     }
  204.     /**
  205.      * @param string|null $plainPassword
  206.      */
  207.     public function setPlainPassword(?string $plainPassword): void
  208.     {
  209.         $this->plainPassword $plainPassword;
  210.     }
  211.     /**
  212.      * @return Collection<int, Structure>
  213.      */
  214.     public function getStructures(): Collection
  215.     {
  216.         return $this->structures;
  217.     }
  218.     public function addStructure(Structure $structure): static
  219.     {
  220.         if (!$this->structures->contains($structure)) {
  221.             $this->structures->add($structure);
  222.         }
  223.         return $this;
  224.     }
  225.     public function removeStructure(Structure $structure): static
  226.     {
  227.         $this->structures->removeElement($structure);
  228.         return $this;
  229.     }
  230.     public function getSelectedStructure(): ?Structure
  231.     {
  232.         return $this->selectedStructure;
  233.     }
  234.     public function setSelectedStructure(?Structure $selectedStructure): static
  235.     {
  236.         $this->selectedStructure $selectedStructure;
  237.         return $this;
  238.     }
  239.     /**
  240.      * @return Collection<int, Journal>
  241.      */
  242.     public function getJournals(): Collection
  243.     {
  244.         return $this->journals;
  245.     }
  246.     public function addJournal(Journal $journal): static
  247.     {
  248.         if (!$this->journals->contains($journal)) {
  249.             $this->journals->add($journal);
  250.             $journal->setUser($this);
  251.         }
  252.         return $this;
  253.     }
  254.     public function removeJournal(Journal $journal): static
  255.     {
  256.         if ($this->journals->removeElement($journal)) {
  257.             // set the owning side to null (unless already changed)
  258.             if ($journal->getUser() === $this) {
  259.                 $journal->setUser(null);
  260.             }
  261.         }
  262.         return $this;
  263.     }
  264.     public function isMulti (): bool
  265.     {
  266.         return $this->getSelectedStructure()->isMulti();
  267.     }
  268. }