src/Entity/User.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use App\Repository\UserRepository;
  7. use Symfony\Component\Uid\Uuid;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  11. /**
  12.  * @ORM\Entity(repositoryClass=UserRepository::class)
  13.  * @UniqueEntity(fields={"email"}, message="Cet email est déjà associé à un compte")
  14.  */
  15. class User implements UserInterface, PasswordAuthenticatedUserInterface
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private int $id;
  23.     /**
  24.      * @ORM\Column(type="string", nullable=true)
  25.      */
  26.     private ?string $uuid;
  27.     /**
  28.      * @ORM\Column(type="string", length=180, unique=true)
  29.      */
  30.     private string $email;
  31.     /**
  32.      * @ORM\Column(type="json")
  33.      */
  34.     private array $roles = [];
  35.     public string $role;
  36.     /**
  37.      * @var string The hashed password
  38.      * @ORM\Column(type="string", nullable=true)
  39.      */
  40.     private ?string $password;
  41.     /**
  42.      * @ORM\Column(type="string", length=255, nullable=true)
  43.      */
  44.     private ?string $nom;
  45.     /**
  46.      * @ORM\Column(type="string", length=255, nullable=true)
  47.      */
  48.     private ?string $prenom;
  49.     /**
  50.      * @ORM\Column(type="boolean", nullable=true)
  51.      */
  52.     private ?bool $statut = false;
  53.     /**
  54.      * @ORM\Column(type="string", length=255, nullable=true)
  55.      */
  56.     private ?string $activation;
  57.     /**
  58.      * @ORM\Column(type="datetime_immutable", nullable=true)
  59.      */
  60.     private ?\DateTimeImmutable $createdAt;
  61.     /**
  62.      * @ORM\Column(type="datetime", nullable=true)
  63.      */
  64.     private ?\DateTime $updatedAt;
  65.     /**
  66.      * @ORM\Column(type="string", length=255, nullable=true)
  67.      */
  68.     private ?string $token;
  69.     /**
  70.      * @ORM\Column(type="boolean", nullable=true)
  71.      */
  72.     private ?bool $online = false;
  73.     /**
  74.      * @ORM\Column(type="datetime", nullable=true)
  75.      */
  76.     private ?\DateTime $loginAt;
  77.     /**
  78.      * @ORM\Column(type="string", length=255, nullable=true)
  79.      */
  80.     private ?string $provider;
  81.     /**
  82.      * @ORM\Column(type="string", length=255, nullable=true)
  83.      */
  84.     private ?string $sexe;
  85.     /**
  86.      * @ORM\Column(type="string", length=255, nullable=true)
  87.      */
  88.     private ?string $src;
  89.     /**
  90.      * @ORM\Column(type="text", nullable=true)
  91.      */
  92.     private ?string $alt;
  93.     /**
  94.      * @ORM\Column(type="string", length=255, nullable=true)
  95.      */
  96.     private ?string $title;
  97.     /**
  98.      * @ORM\OneToMany(targetEntity=Arbre::class, mappedBy="user", cascade={"persist", "remove"})
  99.      */
  100.     private $arbres;
  101.     public function __construct()
  102.     {
  103.         $this->uuid = Uuid::v4();
  104.         $this->arbres = new ArrayCollection();
  105.     }
  106.     
  107.     /**
  108.      * getId
  109.      *
  110.      * @return int
  111.      */
  112.     public function getId(): int
  113.     {
  114.         return $this->id;
  115.     }
  116.     
  117.     /**
  118.      * getUuid
  119.      *
  120.      * @return void
  121.      */
  122.     public function getUuid()
  123.     {
  124.         return $this->uuid;
  125.     }
  126.     
  127.     /**
  128.      * setUuid
  129.      *
  130.      * @param  mixed $uuid
  131.      * @return self
  132.      */
  133.     public function setUuid($uuid): self
  134.     {
  135.         $this->uuid = $uuid;
  136.         return $this;
  137.     }
  138.     
  139.     /**
  140.      * getEmail
  141.      *
  142.      * @return string
  143.      */
  144.     public function getEmail(): ?string
  145.     {
  146.         return $this->email;
  147.     }
  148.     
  149.     /**
  150.      * setEmail
  151.      *
  152.      * @param  mixed $email
  153.      * @return self
  154.      */
  155.     public function setEmail(string $email): self
  156.     {
  157.         $this->email = $email;
  158.         return $this;
  159.     }
  160.     /**
  161.      * A visual identifier that represents this user.
  162.      *
  163.      * @see UserInterface
  164.      */
  165.     public function getUserIdentifier(): string
  166.     {
  167.         return (string) $this->email;
  168.     }
  169.     /**
  170.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  171.      */
  172.     public function getUsername(): string
  173.     {
  174.         return (string) $this->email;
  175.     }
  176.     /**
  177.      * @see UserInterface
  178.      */
  179.     public function getRoles(): array
  180.     {
  181.         $roles = $this->roles;
  182.         // guarantee every user at least has ROLE_USER
  183.         // $roles[] = 'ROLE_USER';
  184.         return array_unique($roles);
  185.     }
  186.     
  187.     /**
  188.      * setRoles
  189.      *
  190.      * @param  mixed $roles
  191.      * @return self
  192.      */
  193.     public function setRoles(array $roles): self
  194.     {
  195.         $this->roles = $roles;
  196.         return $this;
  197.     }
  198.     /**
  199.      * @see PasswordAuthenticatedUserInterface
  200.      */
  201.     public function getPassword(): ?string
  202.     {
  203.         return $this->password;
  204.     }
  205.     
  206.     /**
  207.      * setPassword
  208.      *
  209.      * @param  mixed $password
  210.      * @return self
  211.      */
  212.     public function setPassword(?string $password): self
  213.     {
  214.         $this->password = $password;
  215.         return $this;
  216.     }
  217.     /**
  218.      * Returning a salt is only needed, if you are not using a modern
  219.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  220.      *
  221.      * @see UserInterface
  222.      */
  223.     public function getSalt(): ?string
  224.     {
  225.         return null;
  226.     }
  227.     /**
  228.      * @see UserInterface
  229.      */
  230.     public function eraseCredentials()
  231.     {
  232.         // If you store any temporary, sensitive data on the user, clear it here
  233.         // $this->plainPassword = null;
  234.     }
  235.     
  236.     /**
  237.      * getNom
  238.      *
  239.      * @return string
  240.      */
  241.     public function getNom(): ?string
  242.     {
  243.         return $this->nom;
  244.     }
  245.     
  246.     /**
  247.      * setNom
  248.      *
  249.      * @param  mixed $nom
  250.      * @return self
  251.      */
  252.     public function setNom(?string $nom): self
  253.     {
  254.         $this->nom = $nom;
  255.         return $this;
  256.     }
  257.     
  258.     /**
  259.      * getPrenom
  260.      *
  261.      * @return string
  262.      */
  263.     public function getPrenom(): ?string
  264.     {
  265.         return $this->prenom;
  266.     }
  267.     
  268.     /**
  269.      * setPrenom
  270.      *
  271.      * @param  mixed $prenom
  272.      * @return self
  273.      */
  274.     public function setPrenom(?string $prenom): self
  275.     {
  276.         $this->prenom = $prenom;
  277.         return $this;
  278.     }
  279.     
  280.     /**
  281.      * isStatut
  282.      *
  283.      * @return bool
  284.      */
  285.     public function isStatut(): ?bool
  286.     {
  287.         return $this->statut;
  288.     }
  289.     
  290.     /**
  291.      * setStatut
  292.      *
  293.      * @param  mixed $statut
  294.      * @return self
  295.      */
  296.     public function setStatut(?bool $statut): self
  297.     {
  298.         $this->statut = $statut;
  299.         return $this;
  300.     }
  301.     
  302.     /**
  303.      * getActivation
  304.      *
  305.      * @return string
  306.      */
  307.     public function getActivation(): ?string
  308.     {
  309.         return $this->activation;
  310.     }
  311.     
  312.     /**
  313.      * setActivation
  314.      *
  315.      * @param  mixed $activation
  316.      * @return self
  317.      */
  318.     public function setActivation(?string $activation): self
  319.     {
  320.         $this->activation = $activation;
  321.         return $this;
  322.     }
  323.     
  324.     /**
  325.      * getCreatedAt
  326.      *
  327.      * @return DateTimeImmutable
  328.      */
  329.     public function getCreatedAt(): ?\DateTimeImmutable
  330.     {
  331.         return $this->createdAt;
  332.     }
  333.     
  334.     /**
  335.      * setCreatedAt
  336.      *
  337.      * @param  mixed $createdAt
  338.      * @return self
  339.      */
  340.     public function setCreatedAt(?\DateTimeImmutable $createdAt): self
  341.     {
  342.         $this->createdAt = $createdAt;
  343.         return $this;
  344.     }
  345.     
  346.     /**
  347.      * getUpdatedAt
  348.      *
  349.      * @return DateTimeInterface
  350.      */
  351.     public function getUpdatedAt(): ?\DateTimeInterface
  352.     {
  353.         return $this->updatedAt;
  354.     }
  355.     
  356.     /**
  357.      * setUpdatedAt
  358.      *
  359.      * @param  mixed $updatedAt
  360.      * @return self
  361.      */
  362.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  363.     {
  364.         $this->updatedAt = $updatedAt;
  365.         return $this;
  366.     }
  367.     
  368.     /**
  369.      * getToken
  370.      *
  371.      * @return string
  372.      */
  373.     public function getToken(): ?string
  374.     {
  375.         return $this->token;
  376.     }
  377.     
  378.     /**
  379.      * setToken
  380.      *
  381.      * @param  mixed $token
  382.      * @return self
  383.      */
  384.     public function setToken(?string $token): self
  385.     {
  386.         $this->token = $token;
  387.         return $this;
  388.     }
  389.     
  390.     /**
  391.      * isOnline
  392.      *
  393.      * @return bool
  394.      */
  395.     public function isOnline(): ?bool
  396.     {
  397.         return $this->online;
  398.     }
  399.     
  400.     /**
  401.      * setOnline
  402.      *
  403.      * @param  mixed $online
  404.      * @return self
  405.      */
  406.     public function setOnline(?bool $online): self
  407.     {
  408.         $this->online = $online;
  409.         return $this;
  410.     }
  411.     
  412.     /**
  413.      * getLoginAt
  414.      *
  415.      * @return DateTimeInterface
  416.      */
  417.     public function getLoginAt(): ?\DateTimeInterface
  418.     {
  419.         return $this->loginAt;
  420.     }
  421.     
  422.     /**
  423.      * setLoginAt
  424.      *
  425.      * @param  mixed $loginAt
  426.      * @return self
  427.      */
  428.     public function setLoginAt(?\DateTimeInterface $loginAt): self
  429.     {
  430.         $this->loginAt = $loginAt;
  431.         return $this;
  432.     }
  433.     
  434.     /**
  435.      * getProvider
  436.      *
  437.      * @return string
  438.      */
  439.     public function getProvider(): ?string
  440.     {
  441.         return $this->provider;
  442.     }
  443.     
  444.     /**
  445.      * setProvider
  446.      *
  447.      * @param  mixed $provider
  448.      * @return self
  449.      */
  450.     public function setProvider(?string $provider): self
  451.     {
  452.         $this->provider = $provider;
  453.         return $this;
  454.     }
  455.     
  456.     /**
  457.      * getSexe
  458.      *
  459.      * @return string
  460.      */
  461.     public function getSexe(): ?string
  462.     {
  463.         return $this->sexe;
  464.     }
  465.     
  466.     /**
  467.      * setSexe
  468.      *
  469.      * @param  mixed $sexe
  470.      * @return self
  471.      */
  472.     public function setSexe(?string $sexe): self
  473.     {
  474.         $this->sexe = $sexe;
  475.         return $this;
  476.     }
  477.     
  478.     /**
  479.      * getSrc
  480.      *
  481.      * @return string
  482.      */
  483.     public function getSrc(): ?string
  484.     {
  485.         return $this->src;
  486.     }
  487.     
  488.     /**
  489.      * setSrc
  490.      *
  491.      * @param  mixed $src
  492.      * @return self
  493.      */
  494.     public function setSrc(?string $src): self
  495.     {
  496.         $this->src = $src;
  497.         return $this;
  498.     }
  499.     
  500.     /**
  501.      * getAlt
  502.      *
  503.      * @return string
  504.      */
  505.     public function getAlt(): ?string
  506.     {
  507.         return $this->alt;
  508.     }
  509.     
  510.     /**
  511.      * setAlt
  512.      *
  513.      * @param  mixed $alt
  514.      * @return self
  515.      */
  516.     public function setAlt(?string $alt): self
  517.     {
  518.         $this->alt = $alt;
  519.         return $this;
  520.     }
  521.     
  522.     /**
  523.      * getTitle
  524.      *
  525.      * @return string
  526.      */
  527.     public function getTitle(): ?string
  528.     {
  529.         return $this->title;
  530.     }
  531.     
  532.     /**
  533.      * setTitle
  534.      *
  535.      * @param  mixed $title
  536.      * @return self
  537.      */
  538.     public function setTitle(?string $title): self
  539.     {
  540.         $this->title = $title;
  541.         return $this;
  542.     }
  543.     /**
  544.      * @return Collection<int, Arbre>
  545.      */
  546.     public function getArbres(): Collection
  547.     {
  548.         return $this->arbres;
  549.     }
  550.     public function addArbre(Arbre $arbre): self
  551.     {
  552.         if (!$this->arbres->contains($arbre)) {
  553.             $this->arbres[] = $arbre;
  554.             $arbre->setUser($this);
  555.         }
  556.         return $this;
  557.     }
  558.     public function removeArbre(Arbre $arbre): self
  559.     {
  560.         if ($this->arbres->removeElement($arbre)) {
  561.             // set the owning side to null (unless already changed)
  562.             if ($arbre->getUser() === $this) {
  563.                 $arbre->setUser(null);
  564.             }
  565.         }
  566.         return $this;
  567.     }
  568. }