src/Entity/User.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\UserRepository;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Symfony\Component\Uid\Uuid;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  12. /**
  13.  * @ORM\Entity(repositoryClass=UserRepository::class)
  14.  * @UniqueEntity(fields={"email"}, message="Cette adresse email est déjà utilisé")
  15.  */
  16. class User implements UserInterfacePasswordAuthenticatedUserInterface
  17. {
  18.     public const ROLE_ADMIN 'ROLE_ADMIN';
  19.     public const ROLE_DIRECTEUR 'ROLE_DIRECTEUR';
  20.     public const ROLE_CHEF_REDACTEUR 'ROLE_CHEF_REDACTEUR';
  21.     public const ROLE_ADJOINT_REDACTEUR 'ROLE_ADJOINT_REDACTEUR';
  22.     public const ROLE_CHEF_RUBRIQUE 'ROLE_CHEF_RUBRIQUE';
  23.     public const ROLE_REDACTEUR 'ROLE_REDACTEUR';
  24.     public const ROLE_USER 'ROLE_USER';
  25.     /**
  26.      * @ORM\Id
  27.      * @ORM\GeneratedValue
  28.      * @ORM\Column(type="integer")
  29.      */
  30.     private $id;
  31.     /**
  32.      * @ORM\Column(type="string", length=180, unique=true)
  33.      * @Assert\NotBlank()
  34.      * @Assert\Email()
  35.      */
  36.     private $email;
  37.     /**
  38.      * @ORM\Column(type="json")
  39.      */
  40.     private $roles = [];
  41.     /**
  42.      * @var string The hashed password
  43.      * @ORM\Column(type="string")
  44.      * @Assert\NotBlank(message="Veuillez entrer un mot de passe")
  45.      * @Assert\Length(min="8", minMessage="Le mot de passe doit faire au moins 8 caratères")
  46.      */
  47.     private $password;
  48.     /**
  49.      * @Assert\EqualTo(propertyPath="password", message="Les mots de passes ne correspondent pas")
  50.      */
  51.     private $passwordConfirm;
  52.     /**
  53.      * @ORM\OneToMany(targetEntity=BlogPostLike::class, mappedBy="user")
  54.      */
  55.     private $blogPostLikes;
  56.     /**
  57.      * @ORM\Column(type="datetime", nullable=true)
  58.      */
  59.     private $createdAt;
  60.     /**
  61.      * @ORM\Column(type="boolean", options={"default": false}, nullable=true)
  62.      */
  63.     private $isItmConnect;
  64.     /**
  65.      * @ORM\Column(type="text", nullable=true)
  66.      */
  67.     private $refreshToken;
  68.     /**
  69.      * @ORM\ManyToMany(targetEntity="BlogPostCategory", inversedBy="users")
  70.      * @ORM\JoinColumn(nullable=true,onDelete="SET NULL")
  71.      * )
  72.      */
  73.     private $blogPostCategories;
  74.     /**
  75.      * @ORM\OneToMany(targetEntity=UserNotificationEntry::class, mappedBy="user", orphanRemoval=true)
  76.      */
  77.     private $userNotificationEntries;
  78.     /**
  79.      * @ORM\ManyToMany(targetEntity=Preference::class)
  80.      */
  81.     private $preference;
  82.     /**
  83.      * @ORM\OneToMany(targetEntity=Contributor::class, mappedBy="user")
  84.      */
  85.     private $contributors;
  86.     /**
  87.      * @ORM\Column(type="string", length=255, nullable=true)
  88.      */
  89.     private $tokenFirebase;
  90.     /**
  91.      * @ORM\Column(type="boolean", nullable=true)
  92.      */
  93.     private $acceptCgu;
  94.     /**
  95.      * @ORM\Column(type="uuid", unique=true, nullable=true)
  96.      */
  97.     private ?Uuid $uuid null;
  98.     /**
  99.      * @ORM\OneToMany(mappedBy="user", targetEntity=OAuth2UserConsent::class, orphanRemoval=true)
  100.      */
  101.     private Collection $oAuth2UserConsents;
  102.     /**
  103.      * @ORM\OneToMany(targetEntity=BlogPost::class, mappedBy="author")
  104.      */
  105.     private $blogPosts;
  106.     /**
  107.      * @ORM\ManyToMany(targetEntity=Criteria1Item::class)
  108.      */
  109.     private $criteria1Items;
  110.     /**
  111.      * @ORM\ManyToMany(targetEntity=Criteria2Item::class)
  112.      */
  113.     private $criteria2Items;
  114.     /**
  115.      * @ORM\ManyToMany(targetEntity=Criteria3Item::class)
  116.      */
  117.     private $criteria3Items;
  118.     /**
  119.      * @ORM\Column(type="datetime", nullable=true)
  120.      */
  121.     private $firebaseTokenGeneratedAt;
  122.     /**
  123.      * @ORM\OneToMany(targetEntity=Scoring::class, mappedBy="user", orphanRemoval=true)
  124.      */
  125.     private $scorings;
  126.     public function __construct()
  127.     {
  128.         $this->blogPostLikes = new ArrayCollection();
  129.         $this->createdAt = new \DateTime();
  130.         $this->blogPostCategories = new ArrayCollection();
  131.         $this->userNotificationEntries = new ArrayCollection();
  132.         $this->preference = new ArrayCollection();
  133.         $this->contributors = new ArrayCollection();
  134.         $this->oAuth2UserConsents = new ArrayCollection();
  135.         $this->blogPosts = new ArrayCollection();
  136.         $this->criteria1Items = new ArrayCollection();
  137.         $this->criteria2Items = new ArrayCollection();
  138.         $this->criteria3Items = new ArrayCollection();
  139.         $this->scorings = new ArrayCollection();
  140.     }
  141.     /**
  142.      * @return int|null
  143.      */
  144.     public function getId(): ?int
  145.     {
  146.         return $this->id;
  147.     }
  148.     /**
  149.      * @return string|null
  150.      */
  151.     public function getEmail(): ?string
  152.     {
  153.         return $this->email;
  154.     }
  155.     /**
  156.      * @param string $email
  157.      * @return $this
  158.      */
  159.     public function setEmail(string $email): self
  160.     {
  161.         $this->email $email;
  162.         return $this;
  163.     }
  164.     public function getCreatedAt(): ?\DateTimeInterface
  165.     {
  166.         return $this->createdAt;
  167.     }
  168.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  169.     {
  170.         $this->createdAt $createdAt;
  171.         return $this;
  172.     }
  173.     /**
  174.      * A visual identifier that represents this user.
  175.      *
  176.      * @see UserInterface
  177.      */
  178.     public function getUserIdentifier(): string
  179.     {
  180.         return (string) $this->email;
  181.     }
  182.     /**
  183.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  184.      */
  185.     public function getUsername(): string
  186.     {
  187.         return (string) $this->email;
  188.     }
  189.     public function __toString(): string
  190.     {
  191.         return (string) $this->email;
  192.     }
  193.     /**
  194.      * @see UserInterface
  195.      */
  196.     public function getRoles(): array
  197.     {
  198.         $roles $this->roles;
  199.         // guarantee every user at least has ROLE_USER
  200.         $roles[] = User::ROLE_USER;
  201.         return array_unique($roles);
  202.     }
  203.     public function getRolesList(): string
  204. {
  205.         return implode(", "$this->roles);
  206. }
  207.     public function getRolesString(): string
  208.     {
  209.         $roleString "[";
  210.         foreach ($this->roles as $key => $role) {
  211.             $roleString .= '"' $role '"';
  212.             if ($key count($this->roles) - 1)
  213.                 $roleString .= ',';
  214.         }
  215.         $roleString .= "]";
  216.         return $roleString;
  217.     }
  218.     public function hasRole(string $role): bool
  219.     {
  220.         return in_array($role$this->getRoles());
  221.     }
  222.     /**
  223.      * @param array $roles
  224.      * @return $this
  225.      */
  226.     public function setRoles(array $roles): self
  227.     {
  228.         $this->roles $roles;
  229.         return $this;
  230.     }
  231.     public function getPasswordConfirm(): ?string
  232.     {
  233.         return $this->passwordConfirm;
  234.     }
  235.     public function setPasswordConfirm(string $passwordConfirm): self
  236.     {
  237.         $this->passwordConfirm $passwordConfirm;
  238.         return $this;
  239.     }
  240.     /**
  241.      * @see PasswordAuthenticatedUserInterface
  242.      */
  243.     public function getPassword(): ?string
  244.     {
  245.         return $this->password;
  246.     }
  247.     public function setPassword(string $password): self
  248.     {
  249.         $this->password $password;
  250.         return $this;
  251.     }
  252.     /**
  253.      * Returning a salt is only needed, if you are not using a modern
  254.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  255.      *
  256.      * @see UserInterface
  257.      */
  258.     public function getSalt(): ?string
  259.     {
  260.         return null;
  261.     }
  262.     /**
  263.      * @see UserInterface
  264.      */
  265.     public function eraseCredentials()
  266.     {
  267.         // If you store any temporary, sensitive data on the user, clear it here
  268.         // $this->plainPassword = null;
  269.     }
  270.     /**
  271.      * @return Collection|BlogPostLike[]
  272.      */
  273.     public function getBlogPostLikes(): Collection
  274.     {
  275.         return $this->blogPostLikes;
  276.     }
  277.     public function addBlogPostLike(BlogPostLike $blogPostLike): self
  278.     {
  279.         if (!$this->blogPostLikes->contains($blogPostLike)) {
  280.             $this->blogPostLikes[] = $blogPostLike;
  281.             $blogPostLike->setUser($this);
  282.         }
  283.         return $this;
  284.     }
  285.     public function removeBlogPostLike(BlogPostLike $blogPostLike): self
  286.     {
  287.         if ($this->blogPostLikes->removeElement($blogPostLike)) {
  288.             // set the owning side to null (unless already changed)
  289.             if ($blogPostLike->getUser() === $this) {
  290.                 $blogPostLike->setUser(null);
  291.             }
  292.         }
  293.         return $this;
  294.     }
  295.     /**
  296.      * @return Collection|BlogPostCategory[]
  297.      */
  298.     public function getBlogPostCategories(): Collection
  299.     {
  300.         return $this->blogPostCategories;
  301.     }
  302.     public function addBlogPostCategory(BlogPostCategory $blogPostCategory): self
  303.     {
  304.         if (!$this->blogPostCategories->contains($blogPostCategory)) {
  305.             $this->blogPostCategories[] = $blogPostCategory;
  306.             $blogPostCategory->addUser($this);
  307.         }
  308.         return $this;
  309.     }
  310.     public function removeBlogPostCategory(BlogPostCategory $rubrique): self
  311.     {
  312.         $this->blogPostCategories->removeElement($rubrique);
  313.         return $this;
  314.     }
  315.     /**
  316.      * @return Collection<int, UserNotificationEntry>
  317.      */
  318.     public function getUserNotificationEntries(): Collection
  319.     {
  320.         return $this->userNotificationEntries;
  321.     }
  322.     public function addUserNotificationEntry(UserNotificationEntry $userNotificationEntry): self
  323.     {
  324.         if (!$this->userNotificationEntries->contains($userNotificationEntry)) {
  325.             $this->userNotificationEntries[] = $userNotificationEntry;
  326.             $userNotificationEntry->setUser($this);
  327.         }
  328.         return $this;
  329.     }
  330.     public function removeUserNotificationEntry(UserNotificationEntry $userNotificationEntry): self
  331.     {
  332.         if ($this->userNotificationEntries->removeElement($userNotificationEntry)) {
  333.             // set the owning side to null (unless already changed)
  334.             if ($userNotificationEntry->getUser() === $this) {
  335.                 $userNotificationEntry->setUser(null);
  336.             }
  337.         }
  338.         return $this;
  339.     }
  340.     public function isItmConnect(): ?bool
  341.     {
  342.         return $this->isItmConnect;
  343.     }
  344.     public function getIsItmConnect(): bool
  345.     {
  346.         return $this->isItmConnect;
  347.     }
  348.     public function setIsItmConnect(bool $ItmConnect): self
  349.     {
  350.         $this->isItmConnect $ItmConnect;
  351.         return $this;
  352.     }
  353.     /**
  354.      * @return Collection<int, Preference>
  355.      */
  356.     public function getPreference(): Collection
  357.     {
  358.         return $this->preference;
  359.     }
  360.     public function getPreferenceString(): string
  361.     {
  362.         $preferences $this->preference;
  363.         $preferenceString "";
  364.         if (count($preferences) > 0) {
  365.             for ($i 0$i count($preferences); $i++) {
  366.                 if ($i == count($preferences) - 1) {
  367.                     $preferenceString $preferenceString "" $preferences[$i]->getId();
  368.                 } else {
  369.                     $preferenceString $preferenceString "" $preferences[$i]->getId() . ",";
  370.                 }
  371.             }
  372.         }
  373.         return $preferenceString;
  374.     }
  375.     public function addPreference(Preference $preference): self
  376.     {
  377.         if (!$this->preference->contains($preference)) {
  378.             $this->preference[] = $preference;
  379.         }
  380.         return $this;
  381.     }
  382.     public function removePreference(Preference $preference): self
  383.     {
  384.         $this->preference->removeElement($preference);
  385.         return $this;
  386.     }
  387.     public function getRefreshToken(): ?string
  388.     {
  389.         return $this->refreshToken;
  390.     }
  391.     public function setRefreshToken(string $refreshToken): self
  392.     {
  393.         $this->refreshToken $refreshToken;
  394.         return $this;
  395.     }
  396.     /**
  397.      * @return Collection<int, Contributor>
  398.      */
  399.     public function getContributors(): Collection
  400.     {
  401.         return $this->contributors;
  402.     }
  403.     public function addContributor(Contributor $contributor): self
  404.     {
  405.         if (!$this->contributors->contains($contributor)) {
  406.             $this->contributors[] = $contributor;
  407.             $contributor->setUser($this);
  408.         }
  409.         return $this;
  410.     }
  411.     public function removeContributor(Contributor $contributor): self
  412.     {
  413.         if ($this->contributors->removeElement($contributor)) {
  414.             // set the owning side to null (unless already changed)
  415.             if ($contributor->getUser() === $this) {
  416.                 $contributor->setUser(null);
  417.             }
  418.         }
  419.         return $this;
  420.     }
  421.     public function getTokenFirebase(): ?string
  422.     {
  423.         return $this->tokenFirebase;
  424.     }
  425.     public function setTokenFirebase(?string $tokenFirebase): self
  426.     {
  427.         $this->tokenFirebase $tokenFirebase;
  428.         return $this;
  429.     }
  430.     public function isAcceptCgu(): ?bool
  431.     {
  432.         return $this->acceptCgu;
  433.     }
  434.     public function setAcceptCgu(?bool $acceptCgu): self
  435.     {
  436.         $this->acceptCgu $acceptCgu;
  437.         return $this;
  438.     }
  439.     public function getUuid(): ?Uuid
  440.     {
  441.         return $this->uuid;
  442.     }
  443.     public function setUuid(Uuid $uuid): self
  444.     {
  445.         $this->uuid $uuid;
  446.         return $this;
  447.     }
  448.     /**
  449.      * @return Collection<int, OAuth2UserConsent>
  450.      */
  451.     public function getOAuth2UserConsents(): Collection
  452.     {
  453.         return $this->oAuth2UserConsents;
  454.     }
  455.     public function addOAuth2UserConsent(OAuth2UserConsent $oAuth2UserConsent): self
  456.     {
  457.         if (!$this->oAuth2UserConsents->contains($oAuth2UserConsent)) {
  458.             $this->oAuth2UserConsents->add($oAuth2UserConsent);
  459.             $oAuth2UserConsent->setUser($this);
  460.         }
  461.         return $this;
  462.     }
  463.     public function removeOAuth2UserConsent(OAuth2UserConsent $oAuth2UserConsent): self
  464.     {
  465.         if ($this->oAuth2UserConsents->removeElement($oAuth2UserConsent)) {
  466.             // set the owning side to null (unless already changed)
  467.             if ($oAuth2UserConsent->getUser() === $this) {
  468.                 $oAuth2UserConsent->setUser(null);
  469.             }
  470.         }
  471.         return $this;
  472.     }
  473.     public function canAccessBO(): bool
  474.     {
  475.         return
  476.             $this->hasRole(User::ROLE_ADMIN) ||
  477.             $this->hasRole(User::ROLE_DIRECTEUR) ||
  478.             $this->hasRole(User::ROLE_CHEF_REDACTEUR) ||
  479.             $this->hasRole(User::ROLE_ADJOINT_REDACTEUR) ||
  480.             $this->hasRole(User::ROLE_CHEF_RUBRIQUE) ||
  481.             $this->hasRole(User::ROLE_REDACTEUR);
  482.     }
  483.     /**
  484.      * @return Collection<int, BlogPost>
  485.      */
  486.     public function getBlogPosts(): Collection
  487.     {
  488.         return $this->blogPosts;
  489.     }
  490.     public function addBlogPost(BlogPost $blogPost): self
  491.     {
  492.         if (!$this->blogPosts->contains($blogPost)) {
  493.             $this->blogPosts[] = $blogPost;
  494.             $blogPost->setAuthor($this);
  495.         }
  496.         return $this;
  497.     }
  498.     public function removeBlogPost(BlogPost $blogPost): self
  499.     {
  500.         if ($this->blogPosts->removeElement($blogPost)) {
  501.             // set the owning side to null (unless already changed)
  502.             if ($blogPost->getAuthor() === $this) {
  503.                 $blogPost->setAuthor(null);
  504.             }
  505.         }
  506.         return $this;
  507.     }
  508.     /**
  509.      * @return Collection<int, Criteria1Item>
  510.      */
  511.     public function getCriteria1Items(): Collection
  512.     {
  513.         return $this->criteria1Items;
  514.     }
  515.     public function getCriteria1ItemsList(): string
  516.     {
  517.         return implode(", "$this->criteria1Items->toArray());
  518.     }
  519.     public function getCriteria1ItemsString(): string
  520.     {
  521.         $string "[";
  522.         foreach ($this->criteria1Items as $key => $criteria) {
  523.             $string .= '"' $criteria '"';
  524.             if ($key count($this->criteria1Items) - 1)
  525.                 $string .= ',';
  526.         }
  527.         $string .= "]";
  528.         return $string;
  529.     }
  530.     public function addCriteria1Item(Criteria1Item $criteria1Item): self
  531.     {
  532.         if (!$this->criteria1Items->contains($criteria1Item)) {
  533.             $this->criteria1Items[] = $criteria1Item;
  534.         }
  535.         return $this;
  536.     }
  537.     /**
  538.      * @return Collection<int, Criteria2Item>
  539.      */
  540.     public function getCriteria2Items(): Collection
  541.     {
  542.         return $this->criteria2Items;
  543.     }
  544.     public function getCriteria2ItemsList(): string
  545.     {
  546.         return implode(", "$this->criteria2Items->toArray());
  547.     }
  548.     public function getCriteria2ItemsString(): string
  549.     {
  550.         $string "[";
  551.         foreach ($this->criteria2Items as $key => $criteria) {
  552.             $string .= '"' $criteria '"';
  553.             if ($key count($this->criteria2Items) - 1)
  554.                 $string .= ',';
  555.         }
  556.         $string .= "]";
  557.         return $string;
  558.     }
  559.     public function addCriteria2Item(Criteria2Item $criteria2Item): self
  560.     {
  561.         if (!$this->criteria2Items->contains($criteria2Item)) {
  562.             $this->criteria2Items[] = $criteria2Item;
  563.         }
  564.         return $this;
  565.     }
  566.     /**
  567.      * @return Collection<int, Criteria3Item>
  568.      */
  569.     public function getCriteria3Items(): Collection
  570.     {
  571.         return $this->criteria3Items;
  572.     }
  573.     public function getCriteria3ItemsList(): string
  574.     {
  575.         return implode(", "$this->criteria3Items->toArray());
  576.     }
  577.     public function getCriteria3ItemsString(): string
  578.     {
  579.         $string "[";
  580.         foreach ($this->criteria3Items as $key => $criteria) {
  581.             $string .= '"' $criteria '"';
  582.             if ($key count($this->criteria3Items) - 1)
  583.                 $string .= ',';
  584.         }
  585.         $string .= "]";
  586.         return $string;
  587.     }
  588.     public function addCriteria3Item(Criteria3Item $criteria3Item): self
  589.     {
  590.         if (!$this->criteria3Items->contains($criteria3Item)) {
  591.             $this->criteria3Items[] = $criteria3Item;
  592.         }
  593.         return $this;
  594.     }
  595.     public function getTokenFirebaseGeneratedAt(): ?\DateTimeInterface
  596.     {
  597.         return $this->firebaseTokenGeneratedAt;
  598.     }
  599.     public function setTokenFirebaseGeneratedAt(?\DateTimeInterface $firebaseTokenGeneratedAt): self
  600.     {
  601.         $this->firebaseTokenGeneratedAt $firebaseTokenGeneratedAt;
  602.         return $this;
  603.     }
  604.     /**
  605.      * @return Collection<int, Scoring>
  606.      */
  607.     public function getScorings(): Collection
  608.     {
  609.         return $this->scorings;
  610.     }
  611.     public function addScoring(Scoring $scoring): self
  612.     {
  613.         if (!$this->scorings->contains($scoring)) {
  614.             $this->scorings[] = $scoring;
  615.             $scoring->setUser($this);
  616.         }
  617.         return $this;
  618.     }
  619.     public function removeScoring(Scoring $scoring): self
  620.     {
  621.         if ($this->scorings->removeElement($scoring)) {
  622.             // set the owning side to null (unless already changed)
  623.             if ($scoring->getUser() === $this) {
  624.                 $scoring->setUser(null);
  625.             }
  626.         }
  627.         return $this;
  628.     }
  629. }