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 Symfony\Component\Uid\Uuid;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Repository\UserRepository;
  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 UserInterfacePasswordAuthenticatedUserInterface
  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, nullable=true)
  29.      */
  30.     private ?string $email null;
  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\OneToMany(targetEntity=Sujet::class, mappedBy="user")
  87.      */
  88.     private $sujets;
  89.     /**
  90.      * @ORM\OneToMany(targetEntity=Message::class, mappedBy="user")
  91.      */
  92.     private $messages;
  93.     /**
  94.      * @ORM\OneToMany(targetEntity=Post::class, mappedBy="user")
  95.      */
  96.     private $posts;
  97.     /**
  98.      * @ORM\OneToMany(targetEntity=Astuce::class, mappedBy="user")
  99.      */
  100.     private $astuces;
  101.     /**
  102.      * @ORM\OneToMany(targetEntity=Droit::class, mappedBy="user")
  103.      */
  104.     private $droits;
  105.     /**
  106.      * @ORM\OneToMany(targetEntity=Cv::class, mappedBy="user")
  107.      */
  108.     private $cvs;
  109.     /**
  110.      * @ORM\OneToMany(targetEntity=Agora::class, mappedBy="user")
  111.      */
  112.     private $agoras;
  113.     /**
  114.      * @ORM\OneToMany(targetEntity=Messagerie::class, mappedBy="emetteur")
  115.      */
  116.     private $emetteur;
  117.     /**
  118.      * @ORM\OneToMany(targetEntity=Messagerie::class, mappedBy="destinataire")
  119.      */
  120.     private $destinataire;
  121.     /**
  122.      * @ORM\OneToMany(targetEntity=Conversation::class, mappedBy="interlocuteur")
  123.      */
  124.     private $conversations;
  125.     /**
  126.      * @ORM\OneToMany(targetEntity=Conversation::class, mappedBy="user")
  127.      */
  128.     private $conversationsUser;
  129.     public function __construct()
  130.     {
  131.         $this->uuid Uuid::v4();
  132.         $this->sujets = new ArrayCollection();
  133.         $this->messages = new ArrayCollection();
  134.         $this->posts = new ArrayCollection();
  135.         $this->astuces = new ArrayCollection();
  136.         $this->droits = new ArrayCollection();
  137.         $this->cvs = new ArrayCollection();
  138.         $this->agoras = new ArrayCollection();
  139.         $this->emetteur = new ArrayCollection();
  140.         $this->destinataire = new ArrayCollection();
  141.         $this->conversations = new ArrayCollection();
  142.         $this->conversationsUser = new ArrayCollection();
  143.     }
  144.     /**
  145.      * getId
  146.      *
  147.      * @return int
  148.      */
  149.     public function getId(): ?int
  150.     {
  151.         return $this->id;
  152.     }
  153.     
  154.     /**
  155.      * getUuid
  156.      *
  157.      * @return void
  158.      */
  159.     public function getUuid()
  160.     {
  161.         return $this->uuid;
  162.     }
  163.     
  164.     /**
  165.      * setUuid
  166.      *
  167.      * @param  mixed $uuid
  168.      * @return self
  169.      */
  170.     public function setUuid($uuid): self
  171.     {
  172.         $this->uuid $uuid;
  173.         return $this;
  174.     }
  175.     
  176.     /**
  177.      * getEmail
  178.      *
  179.      * @return ?string
  180.      */
  181.     public function getEmail(): ?string
  182.     {
  183.         return $this->email;
  184.     }
  185.     
  186.     /**
  187.      * setEmail
  188.      *
  189.      * @param  mixed $email
  190.      * @return self
  191.      */
  192.     public function setEmail(?string $email): self
  193.     {
  194.         $this->email $email;
  195.         return $this;
  196.     }
  197.     /**
  198.      * A visual identifier that represents this user.
  199.      *
  200.      * @see UserInterface
  201.      */
  202.     public function getUserIdentifier(): string
  203.     {
  204.         return (string) $this->email;
  205.     }
  206.     /**
  207.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  208.      */
  209.     public function getUsername(): string
  210.     {
  211.         return (string) $this->email;
  212.     }
  213.     /**
  214.      * @see UserInterface
  215.      */
  216.     public function getRoles(): array
  217.     {
  218.         $roles $this->roles;
  219.         // guarantee every user at least has ROLE_USER
  220.         // $roles[] = 'ROLE_USER';
  221.         return array_unique($roles);
  222.     }
  223.     
  224.     /**
  225.      * setRoles
  226.      *
  227.      * @param  mixed $roles
  228.      * @return self
  229.      */
  230.     public function setRoles(array $roles): self
  231.     {
  232.         $this->roles $roles;
  233.         return $this;
  234.     }
  235.     /**
  236.      * @see PasswordAuthenticatedUserInterface
  237.      */
  238.     public function getPassword(): ?string
  239.     {
  240.         return $this->password;
  241.     }
  242.     
  243.     /**
  244.      * setPassword
  245.      *
  246.      * @param  mixed $password
  247.      * @return self
  248.      */
  249.     public function setPassword(?string $password): self
  250.     {
  251.         $this->password $password;
  252.         return $this;
  253.     }
  254.     /**
  255.      * Returning a salt is only needed, if you are not using a modern
  256.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  257.      *
  258.      * @see UserInterface
  259.      */
  260.     public function getSalt(): ?string
  261.     {
  262.         return null;
  263.     }
  264.     /**
  265.      * @see UserInterface
  266.      */
  267.     public function eraseCredentials()
  268.     {
  269.         // If you store any temporary, sensitive data on the user, clear it here
  270.         // $this->plainPassword = null;
  271.     }
  272.     
  273.     /**
  274.      * getNom
  275.      *
  276.      * @return string
  277.      */
  278.     public function getNom(): ?string
  279.     {
  280.         return $this->nom;
  281.     }
  282.     
  283.     /**
  284.      * setNom
  285.      *
  286.      * @param  mixed $nom
  287.      * @return self
  288.      */
  289.     public function setNom(?string $nom): self
  290.     {
  291.         $this->nom $nom;
  292.         return $this;
  293.     }
  294.     
  295.     /**
  296.      * getPrenom
  297.      *
  298.      * @return string
  299.      */
  300.     public function getPrenom(): ?string
  301.     {
  302.         return $this->prenom;
  303.     }
  304.     
  305.     /**
  306.      * setPrenom
  307.      *
  308.      * @param  mixed $prenom
  309.      * @return self
  310.      */
  311.     public function setPrenom(?string $prenom): self
  312.     {
  313.         $this->prenom $prenom;
  314.         return $this;
  315.     }
  316.     
  317.     /**
  318.      * isStatut
  319.      *
  320.      * @return bool
  321.      */
  322.     public function isStatut(): ?bool
  323.     {
  324.         return $this->statut;
  325.     }
  326.     
  327.     /**
  328.      * setStatut
  329.      *
  330.      * @param  mixed $statut
  331.      * @return self
  332.      */
  333.     public function setStatut(?bool $statut): self
  334.     {
  335.         $this->statut $statut;
  336.         return $this;
  337.     }
  338.     
  339.     /**
  340.      * getActivation
  341.      *
  342.      * @return string
  343.      */
  344.     public function getActivation(): ?string
  345.     {
  346.         return $this->activation;
  347.     }
  348.     
  349.     /**
  350.      * setActivation
  351.      *
  352.      * @param  mixed $activation
  353.      * @return self
  354.      */
  355.     public function setActivation(?string $activation): self
  356.     {
  357.         $this->activation $activation;
  358.         return $this;
  359.     }
  360.     
  361.     /**
  362.      * getCreatedAt
  363.      *
  364.      * @return DateTimeImmutable
  365.      */
  366.     public function getCreatedAt(): ?\DateTimeImmutable
  367.     {
  368.         return $this->createdAt;
  369.     }
  370.     
  371.     /**
  372.      * setCreatedAt
  373.      *
  374.      * @param  mixed $createdAt
  375.      * @return self
  376.      */
  377.     public function setCreatedAt(?\DateTimeImmutable $createdAt): self
  378.     {
  379.         $this->createdAt $createdAt;
  380.         return $this;
  381.     }
  382.     
  383.     /**
  384.      * getUpdatedAt
  385.      *
  386.      * @return DateTimeInterface
  387.      */
  388.     public function getUpdatedAt(): ?\DateTimeInterface
  389.     {
  390.         return $this->updatedAt;
  391.     }
  392.     
  393.     /**
  394.      * setUpdatedAt
  395.      *
  396.      * @param  mixed $updatedAt
  397.      * @return self
  398.      */
  399.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  400.     {
  401.         $this->updatedAt $updatedAt;
  402.         return $this;
  403.     }
  404.     
  405.     /**
  406.      * getToken
  407.      *
  408.      * @return string
  409.      */
  410.     public function getToken(): ?string
  411.     {
  412.         return $this->token;
  413.     }
  414.     
  415.     /**
  416.      * setToken
  417.      *
  418.      * @param  mixed $token
  419.      * @return self
  420.      */
  421.     public function setToken(?string $token): self
  422.     {
  423.         $this->token $token;
  424.         return $this;
  425.     }
  426.     
  427.     /**
  428.      * isOnline
  429.      *
  430.      * @return bool
  431.      */
  432.     public function isOnline(): ?bool
  433.     {
  434.         return $this->online;
  435.     }
  436.     
  437.     /**
  438.      * setOnline
  439.      *
  440.      * @param  mixed $online
  441.      * @return self
  442.      */
  443.     public function setOnline(?bool $online): self
  444.     {
  445.         $this->online $online;
  446.         return $this;
  447.     }
  448.     
  449.     /**
  450.      * getLoginAt
  451.      *
  452.      * @return DateTimeInterface
  453.      */
  454.     public function getLoginAt(): ?\DateTimeInterface
  455.     {
  456.         return $this->loginAt;
  457.     }
  458.     
  459.     /**
  460.      * setLoginAt
  461.      *
  462.      * @param  mixed $loginAt
  463.      * @return self
  464.      */
  465.     public function setLoginAt(?\DateTimeInterface $loginAt): self
  466.     {
  467.         $this->loginAt $loginAt;
  468.         return $this;
  469.     }
  470.     
  471.     /**
  472.      * getProvider
  473.      *
  474.      * @return string
  475.      */
  476.     public function getProvider(): ?string
  477.     {
  478.         return $this->provider;
  479.     }
  480.     
  481.     /**
  482.      * setProvider
  483.      *
  484.      * @param  mixed $provider
  485.      * @return self
  486.      */
  487.     public function setProvider(?string $provider): self
  488.     {
  489.         $this->provider $provider;
  490.         return $this;
  491.     }
  492.     
  493.     /**
  494.      * getSexe
  495.      *
  496.      * @return string
  497.      */
  498.     public function getSexe(): ?string
  499.     {
  500.         return $this->sexe;
  501.     }
  502.     
  503.     /**
  504.      * setSexe
  505.      *
  506.      * @param  mixed $sexe
  507.      * @return self
  508.      */
  509.     public function setSexe(?string $sexe): self
  510.     {
  511.         $this->sexe $sexe;
  512.         return $this;
  513.     }
  514.     /**
  515.      * @return Collection<int, Sujet>
  516.      */
  517.     public function getSujets(): Collection
  518.     {
  519.         return $this->sujets;
  520.     }
  521.     public function addSujet(Sujet $sujet): self
  522.     {
  523.         if (!$this->sujets->contains($sujet)) {
  524.             $this->sujets[] = $sujet;
  525.             $sujet->setUser($this);
  526.         }
  527.         return $this;
  528.     }
  529.     public function removeSujet(Sujet $sujet): self
  530.     {
  531.         if ($this->sujets->removeElement($sujet)) {
  532.             // set the owning side to null (unless already changed)
  533.             if ($sujet->getUser() === $this) {
  534.                 $sujet->setUser(null);
  535.             }
  536.         }
  537.         return $this;
  538.     }
  539.     /**
  540.      * @return Collection<int, Message>
  541.      */
  542.     public function getMessages(): Collection
  543.     {
  544.         return $this->messages;
  545.     }
  546.     public function addMessage(Message $message): self
  547.     {
  548.         if (!$this->messages->contains($message)) {
  549.             $this->messages[] = $message;
  550.             $message->setUser($this);
  551.         }
  552.         return $this;
  553.     }
  554.     public function removeMessage(Message $message): self
  555.     {
  556.         if ($this->messages->removeElement($message)) {
  557.             // set the owning side to null (unless already changed)
  558.             if ($message->getUser() === $this) {
  559.                 $message->setUser(null);
  560.             }
  561.         }
  562.         return $this;
  563.     }
  564.     /**
  565.      * @return Collection<int, Post>
  566.      */
  567.     public function getPosts(): Collection
  568.     {
  569.         return $this->posts;
  570.     }
  571.     public function addPost(Post $post): self
  572.     {
  573.         if (!$this->posts->contains($post)) {
  574.             $this->posts[] = $post;
  575.             $post->setUser($this);
  576.         }
  577.         return $this;
  578.     }
  579.     public function removePost(Post $post): self
  580.     {
  581.         if ($this->posts->removeElement($post)) {
  582.             // set the owning side to null (unless already changed)
  583.             if ($post->getUser() === $this) {
  584.                 $post->setUser(null);
  585.             }
  586.         }
  587.         return $this;
  588.     }
  589.     /**
  590.      * @return Collection<int, Astuce>
  591.      */
  592.     public function getAstuces(): Collection
  593.     {
  594.         return $this->astuces;
  595.     }
  596.     public function addAstuce(Astuce $astuce): self
  597.     {
  598.         if (!$this->astuces->contains($astuce)) {
  599.             $this->astuces[] = $astuce;
  600.             $astuce->setUser($this);
  601.         }
  602.         return $this;
  603.     }
  604.     public function removeAstuce(Astuce $astuce): self
  605.     {
  606.         if ($this->astuces->removeElement($astuce)) {
  607.             // set the owning side to null (unless already changed)
  608.             if ($astuce->getUser() === $this) {
  609.                 $astuce->setUser(null);
  610.             }
  611.         }
  612.         return $this;
  613.     }
  614.     /**
  615.      * @return Collection<int, Droit>
  616.      */
  617.     public function getDroits(): Collection
  618.     {
  619.         return $this->droits;
  620.     }
  621.     public function addDroit(Droit $droit): self
  622.     {
  623.         if (!$this->droits->contains($droit)) {
  624.             $this->droits[] = $droit;
  625.             $droit->setUser($this);
  626.         }
  627.         return $this;
  628.     }
  629.     public function removeDroit(Droit $droit): self
  630.     {
  631.         if ($this->droits->removeElement($droit)) {
  632.             // set the owning side to null (unless already changed)
  633.             if ($droit->getUser() === $this) {
  634.                 $droit->setUser(null);
  635.             }
  636.         }
  637.         return $this;
  638.     }
  639.     /**
  640.      * @return Collection<int, Cv>
  641.      */
  642.     public function getCvs(): Collection
  643.     {
  644.         return $this->cvs;
  645.     }
  646.     public function addCv(Cv $cv): self
  647.     {
  648.         if (!$this->cvs->contains($cv)) {
  649.             $this->cvs[] = $cv;
  650.             $cv->setUser($this);
  651.         }
  652.         return $this;
  653.     }
  654.     public function removeCv(Cv $cv): self
  655.     {
  656.         if ($this->cvs->removeElement($cv)) {
  657.             // set the owning side to null (unless already changed)
  658.             if ($cv->getUser() === $this) {
  659.                 $cv->setUser(null);
  660.             }
  661.         }
  662.         return $this;
  663.     }
  664.     /**
  665.      * @return Collection<int, Agora>
  666.      */
  667.     public function getAgoras(): Collection
  668.     {
  669.         return $this->agoras;
  670.     }
  671.     public function addAgora(Agora $agora): self
  672.     {
  673.         if (!$this->agoras->contains($agora)) {
  674.             $this->agoras[] = $agora;
  675.             $agora->setUser($this);
  676.         }
  677.         return $this;
  678.     }
  679.     public function removeAgora(Agora $agora): self
  680.     {
  681.         if ($this->agoras->removeElement($agora)) {
  682.             // set the owning side to null (unless already changed)
  683.             if ($agora->getUser() === $this) {
  684.                 $agora->setUser(null);
  685.             }
  686.         }
  687.         return $this;
  688.     }
  689.     /**
  690.      * @return Collection<int, Messagerie>
  691.      */
  692.     public function getEmetteur(): Collection
  693.     {
  694.         return $this->emetteur;
  695.     }
  696.     public function addEmetteur(Messagerie $emetteur): self
  697.     {
  698.         if (!$this->emetteur->contains($emetteur)) {
  699.             $this->emetteur[] = $emetteur;
  700.             $emetteur->setEmetteur($this);
  701.         }
  702.         return $this;
  703.     }
  704.     public function removeEmetteur(Messagerie $emetteur): self
  705.     {
  706.         if ($this->emetteur->removeElement($emetteur)) {
  707.             // set the owning side to null (unless already changed)
  708.             if ($emetteur->getEmetteur() === $this) {
  709.                 $emetteur->setEmetteur(null);
  710.             }
  711.         }
  712.         return $this;
  713.     }
  714.     /**
  715.      * @return Collection<int, Messagerie>
  716.      */
  717.     public function getDestinataire(): Collection
  718.     {
  719.         return $this->destinataire;
  720.     }
  721.     public function addDestinataire(Messagerie $destinataire): self
  722.     {
  723.         if (!$this->destinataire->contains($destinataire)) {
  724.             $this->destinataire[] = $destinataire;
  725.             $destinataire->setDestinataire($this);
  726.         }
  727.         return $this;
  728.     }
  729.     public function removeDestinataire(Messagerie $destinataire): self
  730.     {
  731.         if ($this->destinataire->removeElement($destinataire)) {
  732.             // set the owning side to null (unless already changed)
  733.             if ($destinataire->getDestinataire() === $this) {
  734.                 $destinataire->setDestinataire(null);
  735.             }
  736.         }
  737.         return $this;
  738.     }
  739.     /**
  740.      * @return Collection<int, Conversation>
  741.      */
  742.     public function getConversations(): Collection
  743.     {
  744.         return $this->conversations;
  745.     }
  746.     public function addConversation(Conversation $conversation): self
  747.     {
  748.         if (!$this->conversations->contains($conversation)) {
  749.             $this->conversations[] = $conversation;
  750.             $conversation->setInterlocuteur($this);
  751.         }
  752.         return $this;
  753.     }
  754.     public function removeConversation(Conversation $conversation): self
  755.     {
  756.         if ($this->conversations->removeElement($conversation)) {
  757.             // set the owning side to null (unless already changed)
  758.             if ($conversation->getInterlocuteur() === $this) {
  759.                 $conversation->setInterlocuteur(null);
  760.             }
  761.         }
  762.         return $this;
  763.     }
  764.     /**
  765.      * @return Collection<int, Conversation>
  766.      */
  767.     public function getConversationsUser(): Collection
  768.     {
  769.         return $this->conversationsUser;
  770.     }
  771.     public function addConversationsUser(Conversation $conversationsUser): self
  772.     {
  773.         if (!$this->conversationsUser->contains($conversationsUser)) {
  774.             $this->conversationsUser[] = $conversationsUser;
  775.             $conversationsUser->setUser($this);
  776.         }
  777.         return $this;
  778.     }
  779.     public function removeConversationsUser(Conversation $conversationsUser): self
  780.     {
  781.         if ($this->conversationsUser->removeElement($conversationsUser)) {
  782.             // set the owning side to null (unless already changed)
  783.             if ($conversationsUser->getUser() === $this) {
  784.                 $conversationsUser->setUser(null);
  785.             }
  786.         }
  787.         return $this;
  788.     }
  789.     
  790. }