src/Entity/User.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTimeImmutable;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Repository\UserRepository;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Symfony\Component\Uid\Uuid;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  13. use App\Entity\Instance;
  14. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  15. use League\OAuth2\Server\Entities\UserEntityInterface;
  16. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  17. /**
  18.  * @ORM\Entity(repositoryClass=UserRepository::class)
  19.  * @UniqueEntity(fields={"email"}, message="Cette adresse email est déjà utilisé")
  20.  * @ORM\HasLifecycleCallbacks
  21.  */
  22. class User implements UserInterfacePasswordAuthenticatedUserInterfaceUserEntityInterface
  23. {
  24.     public const ROLE_SUPER_ADMIN 'ROLE_SUPER_ADMIN';
  25.     public const ROLE_ADMIN 'ROLE_ADMIN';
  26.     public const ROLE_DIRECTEUR 'ROLE_DIRECTEUR';
  27.     public const ROLE_CHEF_REDACTEUR 'ROLE_CHEF_REDACTEUR';
  28.     public const ROLE_ADJOINT_REDACTEUR 'ROLE_ADJOINT_REDACTEUR';
  29.     public const ROLE_CHEF_RUBRIQUE 'ROLE_CHEF_RUBRIQUE';
  30.     public const ROLE_REDACTEUR 'ROLE_REDACTEUR';
  31.     public const ROLE_USER 'ROLE_USER';
  32.     /**
  33.      * @ORM\Id
  34.      * @ORM\GeneratedValue
  35.      * @ORM\Column(type="integer")
  36.      */
  37.     private $id;
  38.     /**
  39.      * @ORM\Column(type="string", length=180, unique=true)
  40.      * @Assert\NotBlank()
  41.      * @Assert\Email()
  42.      */
  43.     private $email;
  44.     /**
  45.      * @ORM\Column(type="json")
  46.      */
  47.     private $roles = [];
  48.     /**
  49.      * @var string The hashed password
  50.      * @ORM\Column(type="string")
  51.      * @Assert\NotBlank(message="Veuillez entrer un mot de passe")
  52.      * @Assert\Length(min="8", minMessage="Le mot de passe doit faire au moins 8 caratères")
  53.      */
  54.     private $password;
  55.     /**
  56.      * @Assert\EqualTo(propertyPath="password", message="Les mots de passes ne correspondent pas")
  57.      */
  58.     private $passwordConfirm;
  59.     /**
  60.      * @ORM\OneToMany(targetEntity=BlogPostLike::class, mappedBy="user")
  61.      */
  62.     private $blogPostLikes;
  63.     /**
  64.      * @ORM\Column(type="datetime", nullable=true)
  65.      */
  66.     private $createdAt;
  67.     /**
  68.      * @ORM\Column(type="datetime", nullable=true)
  69.      */
  70.     private ?\DateTimeInterface $updatedAt null;
  71.     /**
  72.      * @ORM\Column(type="boolean", options={"default": false}, nullable=true)
  73.      */
  74.     private $isItmConnect;
  75.     /**
  76.      * @ORM\Column(type="text", nullable=true)
  77.      */
  78.     private $refreshToken;
  79.     /**
  80.      * @ORM\ManyToMany(targetEntity="BlogPostCategory", inversedBy="users")
  81.      * @ORM\JoinColumn(nullable=true,onDelete="SET NULL")
  82.      * )
  83.      */
  84.     private $blogPostCategories;
  85.     /**
  86.      * @ORM\OneToMany(targetEntity=UserNotificationEntry::class, mappedBy="user", orphanRemoval=true)
  87.      */
  88.     private $userNotificationEntries;
  89.     /**
  90.      * @ORM\ManyToMany(targetEntity=Preference::class)
  91.      */
  92.     private $preference;
  93.     /**
  94.      * @ORM\OneToMany(targetEntity=Contributor::class, mappedBy="user")
  95.      */
  96.     private $contributors;
  97.     /**
  98.      * @ORM\Column(type="string", length=255, nullable=true)
  99.      */
  100.     private $tokenFirebase;
  101.     /**
  102.      * @ORM\Column(type="boolean", nullable=true)
  103.      */
  104.     private $acceptCgu;
  105.     /**
  106.      * @ORM\Column(type="uuid", unique=true, nullable=true)
  107.      */
  108.     private ?Uuid $uuid null;
  109.     /**
  110.      * @ORM\OneToMany(mappedBy="user", targetEntity=OAuth2UserConsent::class, orphanRemoval=true)
  111.      */
  112.     private Collection $oAuth2UserConsents;
  113.     /**
  114.      * @ORM\OneToMany(targetEntity=BlogPost::class, mappedBy="author")
  115.      */
  116.     private $blogPosts;
  117.     /**
  118.      * @ORM\ManyToMany(targetEntity=Criteria1Item::class)
  119.      */
  120.     private $criteria1Items;
  121.     /**
  122.      * @ORM\ManyToMany(targetEntity=Criteria2Item::class)
  123.      */
  124.     private $criteria2Items;
  125.     /**
  126.      * @ORM\ManyToMany(targetEntity=Criteria3Item::class)
  127.      */
  128.     private $criteria3Items;
  129.     /**
  130.      * @ORM\ManyToMany(targetEntity=Criteria4Item::class)
  131.      */
  132.     private $criteria4Items;
  133.     /**
  134.      * @ORM\ManyToMany(targetEntity=Criteria5Item::class)
  135.      */
  136.     private $criteria5Items;
  137.     /**
  138.      * @ORM\Column(type="datetime", nullable=true)
  139.      */
  140.     private $firebaseTokenGeneratedAt;
  141.     /**
  142.      * @ORM\OneToMany(targetEntity=Scoring::class, mappedBy="user", orphanRemoval=true)
  143.      */
  144.     private $scorings;
  145.     /**
  146.      * @ORM\ManyToMany(targetEntity=Instance::class, inversedBy="users")
  147.      */
  148.     private Collection $instances;
  149.     /**
  150.      * @ORM\Column(type="boolean", options={"default": false})
  151.      */
  152.     private bool $allowSelfEdit false;
  153.     /**
  154.      * @ORM\Column(type="boolean", options={"default": false})
  155.      */
  156.     private bool $anonymizationEnabled false;
  157.     /**
  158.      * Indique si l'utilisateur a confirmé la popup d'anonymisation
  159.      * @ORM\Column(type="boolean", options={"default": false})
  160.      */
  161.     private bool $isAnonymisationConfirmed false;
  162.     /**
  163.      * Retourne vrai si l'utilisateur a confirmé la popup d'anonymisation
  164.      */
  165.     public function isAnonymisationConfirmed(): bool
  166.     {
  167.         return $this->isAnonymisationConfirmed;
  168.     }
  169.     /**
  170.      * Définit la confirmation d'anonymisation
  171.      */
  172.     public function setAnonymisationConfirmed(bool $confirmed): self
  173.     {
  174.         $this->isAnonymisationConfirmed $confirmed;
  175.         return $this;
  176.     }
  177.     /**
  178.      * @ORM\Column(type="string", length=512, nullable=true)
  179.      */
  180.     private ?string $firstName null;
  181.     /**
  182.      * @ORM\Column(type="string", length=512, nullable=true)
  183.      */
  184.     private ?string $lastName null;
  185.     /**
  186.      * @ORM\Column(type="string", length=512, nullable=true)
  187.      */
  188.     private ?string $entityCode null;
  189.     /**
  190.      * @ORM\Column(type="string", length=512, nullable=true)
  191.      * @Assert\Email(message="Veuillez saisir un email professionnel valide")
  192.      */
  193.     private ?string $proEmail null;
  194.     /**
  195.      * @ORM\Column(type="string", length=512, nullable=true)
  196.      * @Assert\Regex(
  197.      *     pattern="/^\d*$/",
  198.      *     message="Le téléphone professionnel doit contenir uniquement des chiffres."
  199.      * )
  200.      */
  201.     private ?string $proPhone null;
  202.     /**
  203.      * @ORM\Column(type="string", length=255, nullable=true)
  204.      */
  205.     private ?string $photoPath null;
  206.     /**
  207.      * @ORM\Column(type="boolean", options={"default": 0})
  208.      */
  209.     private bool $acceptPrivacy false;
  210.     /**
  211.      * @ORM\Column(type="datetime_immutable", nullable=true)
  212.      */
  213.     private ?DateTimeImmutable $acceptPrivacyAt null;
  214.     /**
  215.      * @ORM\Column(type="string", length=32, nullable=true)
  216.      */
  217.     private ?string $acceptPrivacyVersion null;
  218.     /**
  219.      * @ORM\Column(type="boolean", options={"default": 0})
  220.      */
  221.     private bool $privacyChecked false;
  222.     public function __construct()
  223.     {
  224.         $this->blogPostLikes = new ArrayCollection();
  225.         $this->createdAt = new \DateTime();
  226.         $this->blogPostCategories = new ArrayCollection();
  227.         $this->userNotificationEntries = new ArrayCollection();
  228.         $this->preference = new ArrayCollection();
  229.         $this->contributors = new ArrayCollection();
  230.         $this->oAuth2UserConsents = new ArrayCollection();
  231.         $this->blogPosts = new ArrayCollection();
  232.         $this->criteria1Items = new ArrayCollection();
  233.         $this->criteria2Items = new ArrayCollection();
  234.         $this->criteria3Items = new ArrayCollection();
  235.         $this->criteria4Items = new ArrayCollection();
  236.         $this->criteria5Items = new ArrayCollection();
  237.         $this->scorings = new ArrayCollection();
  238.         $this->instances = new ArrayCollection();
  239.         // Init updatedAt with the same value as createdAt at creation time
  240.         $this->updatedAt $this->createdAt;
  241.     }
  242.     /**
  243.      * @return int|null
  244.      */
  245.     public function getId(): ?int
  246.     {
  247.         return $this->id;
  248.     }
  249.     /**
  250.      * @return string|null
  251.      */
  252.     public function getEmail(): ?string
  253.     {
  254.         return $this->email;
  255.     }
  256.     /**
  257.      * @param string $email
  258.      * @return $this
  259.      */
  260.     public function setEmail(string $email): self
  261.     {
  262.         $this->email $email;
  263.         return $this;
  264.     }
  265.     public function getCreatedAt(): ?\DateTimeInterface
  266.     {
  267.         return $this->createdAt;
  268.     }
  269.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  270.     {
  271.         $this->createdAt $createdAt;
  272.         // Keep updatedAt in sync initially if it's not set yet
  273.         if ($this->updatedAt === null) {
  274.             $this->updatedAt $createdAt;
  275.         }
  276.         return $this;
  277.     }
  278.     public function getUpdatedAt(): ?\DateTimeInterface
  279.     {
  280.         return $this->updatedAt;
  281.     }
  282.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  283.     {
  284.         $this->updatedAt $updatedAt;
  285.         return $this;
  286.     }
  287.     /**
  288.      * Met à jour automatiquement la date de modification avant insert
  289.      * @ORM\PrePersist
  290.      */
  291.     public function onPrePersist(): void
  292.     {
  293.         $now = new \DateTime();
  294.         if ($this->createdAt === null) {
  295.             $this->createdAt $now;
  296.         }
  297.         $this->updatedAt $this->createdAt ?? $now;
  298.     }
  299.     /**
  300.      * Met à jour automatiquement la date de modification avant update
  301.      * @ORM\PreUpdate
  302.      */
  303.     public function onPreUpdate(): void
  304.     {
  305.         $this->updatedAt = new \DateTime();
  306.     }
  307.     /**
  308.      * A visual identifier that represents this user.
  309.      *
  310.      * @see UserInterface
  311.      */
  312.     public function getUserIdentifier(): string
  313.     {
  314.         return (string) $this->email;
  315.     }
  316.     /**
  317.      * Required by UserEntityInterface for OAuth2 server
  318.      *
  319.      * @see UserEntityInterface
  320.      */
  321.     public function getIdentifier(): ?string
  322.     {
  323.         return (string) $this->id;
  324.     }
  325.     /**
  326.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  327.      */
  328.     public function getUsername(): string
  329.     {
  330.         return (string) $this->email;
  331.     }
  332.     public function __toString(): string
  333.     {
  334.         return (string) $this->email;
  335.     }
  336.     /**
  337.      * @see UserInterface
  338.      */
  339.     public function getRoles(): array
  340.     {
  341.         $roles $this->roles;
  342.         // guarantee every user at least has ROLE_USER
  343.         $roles[] = User::ROLE_USER;
  344.         return array_unique($roles);
  345.     }
  346.     public function getRolesList(): string
  347.     {
  348.         return implode(", "$this->roles);
  349.     }
  350.     public function getRolesString(): string
  351.     {
  352.         $roleString "[";
  353.         foreach ($this->roles as $key => $role) {
  354.             $roleString .= '"' $role '"';
  355.             if ($key count($this->roles) - 1)
  356.                 $roleString .= ',';
  357.         }
  358.         $roleString .= "]";
  359.         return $roleString;
  360.     }
  361.     public function hasRole(string $role): bool
  362.     {
  363.         return in_array($role$this->getRoles());
  364.     }
  365.     /**
  366.      * @param array $roles
  367.      * @return $this
  368.      */
  369.     public function setRoles(array $roles): self
  370.     {
  371.         $this->roles $roles;
  372.         return $this;
  373.     }
  374.     public function getPasswordConfirm(): ?string
  375.     {
  376.         return $this->passwordConfirm;
  377.     }
  378.     public function setPasswordConfirm(string $passwordConfirm): self
  379.     {
  380.         $this->passwordConfirm $passwordConfirm;
  381.         return $this;
  382.     }
  383.     /**
  384.      * @see PasswordAuthenticatedUserInterface
  385.      */
  386.     public function getPassword(): ?string
  387.     {
  388.         return $this->password;
  389.     }
  390.     public function setPassword(string $password): self
  391.     {
  392.         $this->password $password;
  393.         return $this;
  394.     }
  395.     /**
  396.      * Returning a salt is only needed, if you are not using a modern
  397.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  398.      *
  399.      * @see UserInterface
  400.      */
  401.     public function getSalt(): ?string
  402.     {
  403.         return null;
  404.     }
  405.     /**
  406.      * @see UserInterface
  407.      */
  408.     public function eraseCredentials()
  409.     {
  410.         // If you store any temporary, sensitive data on the user, clear it here
  411.         // $this->plainPassword = null;
  412.     }
  413.     /**
  414.      * @return Collection|BlogPostLike[]
  415.      */
  416.     public function getBlogPostLikes(): Collection
  417.     {
  418.         return $this->blogPostLikes;
  419.     }
  420.     public function addBlogPostLike(BlogPostLike $blogPostLike): self
  421.     {
  422.         if (!$this->blogPostLikes->contains($blogPostLike)) {
  423.             $this->blogPostLikes[] = $blogPostLike;
  424.             $blogPostLike->setUser($this);
  425.         }
  426.         return $this;
  427.     }
  428.     public function removeBlogPostLike(BlogPostLike $blogPostLike): self
  429.     {
  430.         if ($this->blogPostLikes->removeElement($blogPostLike)) {
  431.             // set the owning side to null (unless already changed)
  432.             if ($blogPostLike->getUser() === $this) {
  433.                 $blogPostLike->setUser(null);
  434.             }
  435.         }
  436.         return $this;
  437.     }
  438.     /**
  439.      * @return Collection|BlogPostCategory[]
  440.      */
  441.     public function getBlogPostCategories(): Collection
  442.     {
  443.         return $this->blogPostCategories;
  444.     }
  445.     public function addBlogPostCategory(BlogPostCategory $blogPostCategory): self
  446.     {
  447.         if (!$this->blogPostCategories->contains($blogPostCategory)) {
  448.             $this->blogPostCategories[] = $blogPostCategory;
  449.             $blogPostCategory->addUser($this);
  450.         }
  451.         return $this;
  452.     }
  453.     public function removeBlogPostCategory(BlogPostCategory $rubrique): self
  454.     {
  455.         $this->blogPostCategories->removeElement($rubrique);
  456.         return $this;
  457.     }
  458.     /**
  459.      * @return Collection<int, UserNotificationEntry>
  460.      */
  461.     public function getUserNotificationEntries(): Collection
  462.     {
  463.         return $this->userNotificationEntries;
  464.     }
  465.     public function addUserNotificationEntry(UserNotificationEntry $userNotificationEntry): self
  466.     {
  467.         if (!$this->userNotificationEntries->contains($userNotificationEntry)) {
  468.             $this->userNotificationEntries[] = $userNotificationEntry;
  469.             $userNotificationEntry->setUser($this);
  470.         }
  471.         return $this;
  472.     }
  473.     public function removeUserNotificationEntry(UserNotificationEntry $userNotificationEntry): self
  474.     {
  475.         if ($this->userNotificationEntries->removeElement($userNotificationEntry)) {
  476.             // set the owning side to null (unless already changed)
  477.             if ($userNotificationEntry->getUser() === $this) {
  478.                 $userNotificationEntry->setUser(null);
  479.             }
  480.         }
  481.         return $this;
  482.     }
  483.     public function isItmConnect(): ?bool
  484.     {
  485.         return $this->isItmConnect;
  486.     }
  487.     public function getIsItmConnect(): bool
  488.     {
  489.         return $this->isItmConnect;
  490.     }
  491.     public function setIsItmConnect(bool $ItmConnect): self
  492.     {
  493.         $this->isItmConnect $ItmConnect;
  494.         return $this;
  495.     }
  496.     /**
  497.      * @return Collection<int, Preference>
  498.      */
  499.     public function getPreference(): Collection
  500.     {
  501.         return $this->preference;
  502.     }
  503.     public function getPreferenceString(): string
  504.     {
  505.         $preferences $this->preference;
  506.         $preferenceString "";
  507.         if (count($preferences) > 0) {
  508.             for ($i 0$i count($preferences); $i++) {
  509.                 if ($i == count($preferences) - 1) {
  510.                     $preferenceString $preferenceString "" $preferences[$i]->getId();
  511.                 } else {
  512.                     $preferenceString $preferenceString "" $preferences[$i]->getId() . ",";
  513.                 }
  514.             }
  515.         }
  516.         return $preferenceString;
  517.     }
  518.     public function addPreference(Preference $preference): self
  519.     {
  520.         if (!$this->preference->contains($preference)) {
  521.             $this->preference[] = $preference;
  522.         }
  523.         return $this;
  524.     }
  525.     public function removePreference(Preference $preference): self
  526.     {
  527.         $this->preference->removeElement($preference);
  528.         return $this;
  529.     }
  530.     public function getRefreshToken(): ?string
  531.     {
  532.         return $this->refreshToken;
  533.     }
  534.     public function setRefreshToken(string $refreshToken): self
  535.     {
  536.         $this->refreshToken $refreshToken;
  537.         return $this;
  538.     }
  539.     /**
  540.      * @return Collection<int, Contributor>
  541.      */
  542.     public function getContributors(): Collection
  543.     {
  544.         return $this->contributors;
  545.     }
  546.     public function addContributor(Contributor $contributor): self
  547.     {
  548.         if (!$this->contributors->contains($contributor)) {
  549.             $this->contributors[] = $contributor;
  550.             $contributor->setUser($this);
  551.         }
  552.         return $this;
  553.     }
  554.     public function removeContributor(Contributor $contributor): self
  555.     {
  556.         if ($this->contributors->removeElement($contributor)) {
  557.             // set the owning side to null (unless already changed)
  558.             if ($contributor->getUser() === $this) {
  559.                 $contributor->setUser(null);
  560.             }
  561.         }
  562.         return $this;
  563.     }
  564.     public function getTokenFirebase(): ?string
  565.     {
  566.         return $this->tokenFirebase;
  567.     }
  568.     public function setTokenFirebase(?string $tokenFirebase): self
  569.     {
  570.         $this->tokenFirebase $tokenFirebase;
  571.         return $this;
  572.     }
  573.     public function isAcceptCgu(): ?bool
  574.     {
  575.         return $this->acceptCgu;
  576.     }
  577.     public function setAcceptCgu(?bool $acceptCgu): self
  578.     {
  579.         $this->acceptCgu $acceptCgu;
  580.         return $this;
  581.     }
  582.     public function getUuid(): ?Uuid
  583.     {
  584.         return $this->uuid;
  585.     }
  586.     public function setUuid(Uuid $uuid): self
  587.     {
  588.         $this->uuid $uuid;
  589.         return $this;
  590.     }
  591.     /**
  592.      * @return Collection<int, OAuth2UserConsent>
  593.      */
  594.     public function getOAuth2UserConsents(): Collection
  595.     {
  596.         return $this->oAuth2UserConsents;
  597.     }
  598.     public function addOAuth2UserConsent(OAuth2UserConsent $oAuth2UserConsent): self
  599.     {
  600.         if (!$this->oAuth2UserConsents->contains($oAuth2UserConsent)) {
  601.             $this->oAuth2UserConsents->add($oAuth2UserConsent);
  602.             $oAuth2UserConsent->setUser($this);
  603.         }
  604.         return $this;
  605.     }
  606.     public function removeOAuth2UserConsent(OAuth2UserConsent $oAuth2UserConsent): self
  607.     {
  608.         if ($this->oAuth2UserConsents->removeElement($oAuth2UserConsent)) {
  609.             // set the owning side to null (unless already changed)
  610.             if ($oAuth2UserConsent->getUser() === $this) {
  611.                 $oAuth2UserConsent->setUser(null);
  612.             }
  613.         }
  614.         return $this;
  615.     }
  616.     public function canAccessBO(?AuthorizationCheckerInterface $authChecker null): bool
  617.     {
  618.         // Canonical check via voter (préférable depuis BoAccessVoter)
  619.         if ($authChecker !== null) {
  620.             return $authChecker->isGranted('BO_ACCESS');
  621.         }
  622.         // Fallback legacy : tout rôle autre que ROLE_USER
  623.         // Préférer is_granted('BO_ACCESS') ou canAccessBO($authChecker) pour un check complet
  624.         if ($this->hasRole(self::ROLE_SUPER_ADMIN)) {
  625.             return true;
  626.         }
  627.         foreach ($this->getRoles() as $role) {
  628.             if ($role !== self::ROLE_USER) {
  629.                 return true;
  630.             }
  631.         }
  632.         return false;
  633.     }
  634.     /**
  635.      * @return Collection<int, BlogPost>
  636.      */
  637.     public function getBlogPosts(): Collection
  638.     {
  639.         return $this->blogPosts;
  640.     }
  641.     public function addBlogPost(BlogPost $blogPost): self
  642.     {
  643.         if (!$this->blogPosts->contains($blogPost)) {
  644.             $this->blogPosts[] = $blogPost;
  645.             $blogPost->setAuthor($this);
  646.         }
  647.         return $this;
  648.     }
  649.     public function removeBlogPost(BlogPost $blogPost): self
  650.     {
  651.         if ($this->blogPosts->removeElement($blogPost)) {
  652.             // set the owning side to null (unless already changed)
  653.             if ($blogPost->getAuthor() === $this) {
  654.                 $blogPost->setAuthor(null);
  655.             }
  656.         }
  657.         return $this;
  658.     }
  659.     /**
  660.      * @return Collection<int, Criteria1Item>
  661.      */
  662.     public function getCriteria1Items(): Collection
  663.     {
  664.         return $this->criteria1Items;
  665.     }
  666.     public function getCriteria1ItemsList(): string
  667.     {
  668.         return implode(", "$this->criteria1Items->toArray());
  669.     }
  670.     public function getCriteria1ItemsString(): string
  671.     {
  672.         $string "[";
  673.         foreach ($this->criteria1Items as $key => $criteria) {
  674.             $string .= '"' $criteria '"';
  675.             if ($key count($this->criteria1Items) - 1)
  676.                 $string .= ',';
  677.         }
  678.         $string .= "]";
  679.         return $string;
  680.     }
  681.     public function addCriteria1Item(Criteria1Item $criteria1Item): self
  682.     {
  683.         if (!$this->criteria1Items->contains($criteria1Item)) {
  684.             $this->criteria1Items[] = $criteria1Item;
  685.         }
  686.         return $this;
  687.     }
  688.     /**
  689.      * @return Collection<int, Criteria2Item>
  690.      */
  691.     public function getCriteria2Items(): Collection
  692.     {
  693.         return $this->criteria2Items;
  694.     }
  695.     public function getCriteria2ItemsList(): string
  696.     {
  697.         return implode(", "$this->criteria2Items->toArray());
  698.     }
  699.     public function getCriteria2ItemsString(): string
  700.     {
  701.         $string "[";
  702.         foreach ($this->criteria2Items as $key => $criteria) {
  703.             $string .= '"' $criteria '"';
  704.             if ($key count($this->criteria2Items) - 1)
  705.                 $string .= ',';
  706.         }
  707.         $string .= "]";
  708.         return $string;
  709.     }
  710.     public function addCriteria2Item(Criteria2Item $criteria2Item): self
  711.     {
  712.         if (!$this->criteria2Items->contains($criteria2Item)) {
  713.             $this->criteria2Items[] = $criteria2Item;
  714.         }
  715.         return $this;
  716.     }
  717.     /**
  718.      * @return Collection<int, Criteria3Item>
  719.      */
  720.     public function getCriteria3Items(): Collection
  721.     {
  722.         return $this->criteria3Items;
  723.     }
  724.     public function getCriteria3ItemsList(): string
  725.     {
  726.         return implode(", "$this->criteria3Items->toArray());
  727.     }
  728.     public function getCriteria3ItemsString(): string
  729.     {
  730.         $string "[";
  731.         foreach ($this->criteria3Items as $key => $criteria) {
  732.             $string .= '"' $criteria '"';
  733.             if ($key count($this->criteria3Items) - 1)
  734.                 $string .= ',';
  735.         }
  736.         $string .= "]";
  737.         return $string;
  738.     }
  739.     public function addCriteria3Item(Criteria3Item $criteria3Item): self
  740.     {
  741.         if (!$this->criteria3Items->contains($criteria3Item)) {
  742.             $this->criteria3Items[] = $criteria3Item;
  743.         }
  744.         return $this;
  745.     }
  746.     /**
  747.      * @return Collection<int, Criteria4Item>
  748.      */
  749.     public function getCriteria4Items(): Collection
  750.     {
  751.         return $this->criteria4Items;
  752.     }
  753.     public function getCriteria4ItemsList(): string
  754.     {
  755.         return implode(", "$this->criteria4Items->toArray());
  756.     }
  757.     public function getCriteria4ItemsString(): string
  758.     {
  759.         $string "[";
  760.         foreach ($this->criteria4Items as $key => $criteria) {
  761.             $string .= '"' $criteria '"';
  762.             if ($key count($this->criteria4Items) - 1)
  763.                 $string .= ',';
  764.         }
  765.         $string .= "]";
  766.         return $string;
  767.     }
  768.     public function addCriteria4Item(Criteria4Item $criteria4Item): self
  769.     {
  770.         if (!$this->criteria4Items->contains($criteria4Item)) {
  771.             $this->criteria4Items[] = $criteria4Item;
  772.         }
  773.         return $this;
  774.     }
  775.     /**
  776.      * @return Collection<int, Criteria5Item>
  777.      */
  778.     public function getCriteria5Items(): Collection
  779.     {
  780.         return $this->criteria5Items;
  781.     }
  782.     public function getCriteria5ItemsList(): string
  783.     {
  784.         return implode(", "$this->criteria5Items->toArray());
  785.     }
  786.     public function getCriteria5ItemsString(): string
  787.     {
  788.         $string "[";
  789.         foreach ($this->criteria5Items as $key => $criteria) {
  790.             $string .= '"' $criteria '"';
  791.             if ($key count($this->criteria5Items) - 1)
  792.                 $string .= ',';
  793.         }
  794.         $string .= "]";
  795.         return $string;
  796.     }
  797.     // AVANT (bug) : public function addCriteria5Item(Criteria4Item $criteria5Item): self
  798.     public function addCriteria5Item(Criteria5Item $criteria5Item): self
  799.     {
  800.         if (!$this->criteria5Items->contains($criteria5Item)) {
  801.             $this->criteria5Items[] = $criteria5Item;
  802.         }
  803.         return $this;
  804.     }
  805.     public function getTokenFirebaseGeneratedAt(): ?\DateTimeInterface
  806.     {
  807.         return $this->firebaseTokenGeneratedAt;
  808.     }
  809.     public function setTokenFirebaseGeneratedAt(?\DateTimeInterface $firebaseTokenGeneratedAt): self
  810.     {
  811.         $this->firebaseTokenGeneratedAt $firebaseTokenGeneratedAt;
  812.         return $this;
  813.     }
  814.     /**
  815.      * @return Collection<int, Scoring>
  816.      */
  817.     public function getScorings(): Collection
  818.     {
  819.         return $this->scorings;
  820.     }
  821.     public function addScoring(Scoring $scoring): self
  822.     {
  823.         if (!$this->scorings->contains($scoring)) {
  824.             $this->scorings[] = $scoring;
  825.             $scoring->setUser($this);
  826.         }
  827.         return $this;
  828.     }
  829.     public function removeScoring(Scoring $scoring): self
  830.     {
  831.         if ($this->scorings->removeElement($scoring)) {
  832.             if ($scoring->getUser() === $this) {
  833.                 $scoring->setUser(null);
  834.             }
  835.         }
  836.         return $this;
  837.     }
  838.     /**
  839.      * @return Collection<int, Instance>
  840.      */
  841.     public function getInstances(): Collection
  842.     {
  843.         return $this->instances;
  844.     }
  845.     public function getInstancesList(): string
  846.     {
  847.         return implode(", "$this->instances->toArray());
  848.     }
  849.     public function getInstancesString(): string
  850.     {
  851.         $string "[";
  852.         foreach ($this->instances as $key => $instance) {
  853.             $string .= '"' $instance->getName() . '"';
  854.             if ($key count($this->instances) - 1) {
  855.                 $string .= ',';
  856.             }
  857.         }
  858.         $string .= "]";
  859.         return $string;
  860.     }
  861.     public function addInstance(Instance $instance): self
  862.     {
  863.         if (!$this->instances->contains($instance)) {
  864.             $this->instances[] = $instance;
  865.         }
  866.         return $this;
  867.     }
  868.     public function removeInstance(Instance $instance): self
  869.     {
  870.         $this->instances->removeElement($instance);
  871.         return $this;
  872.     }
  873.     public function hasInstance(Instance $instance): bool
  874.     {
  875.         return $this->instances->contains($instance);
  876.     }
  877.     /**
  878.      * @return bool
  879.      */
  880.     public function isAllowSelfEdit(): bool
  881.     {
  882.         return (bool) $this->allowSelfEdit;
  883.     }
  884.     /**
  885.      * @param bool $allowSelfEdit 
  886.      * @return self
  887.      */
  888.     public function setAllowSelfEdit(bool $allowSelfEdit): self
  889.     {
  890.         $this->allowSelfEdit $allowSelfEdit;
  891.         return $this;
  892.     }
  893.     /**
  894.      * @return bool
  895.      */
  896.     public function isAnonymizationEnabled(): bool
  897.     {
  898.         return $this->anonymizationEnabled;
  899.     }
  900.     /**
  901.      * @param bool $anonymizationEnabled 
  902.      * @return self
  903.      */
  904.     public function setAnonymizationEnabled(bool $anonymizationEnabled): self
  905.     {
  906.         $this->anonymizationEnabled $anonymizationEnabled;
  907.         return $this;
  908.     }
  909.     /**
  910.      * @return 
  911.      */
  912.     public function getFirstName(): ?string
  913.     {
  914.         return $this->firstName;
  915.     }
  916.     /**
  917.      * @param  $firstName 
  918.      * @return self
  919.      */
  920.     public function setFirstName(?string $firstName): self
  921.     {
  922.         $this->firstName $firstName;
  923.         return $this;
  924.     }
  925.     /**
  926.      * @return 
  927.      */
  928.     public function getLastName(): ?string
  929.     {
  930.         return $this->lastName;
  931.     }
  932.     /**
  933.      * @param  $lastName 
  934.      * @return self
  935.      */
  936.     public function setLastName(?string $lastName): self
  937.     {
  938.         $this->lastName $lastName;
  939.         return $this;
  940.     }
  941.     /**
  942.      * @return 
  943.      */
  944.     public function getEntityCode(): ?string
  945.     {
  946.         return $this->entityCode;
  947.     }
  948.     /**
  949.      * @param  $entityCode 
  950.      * @return self
  951.      */
  952.     public function setEntityCode(?string $entityCode): self
  953.     {
  954.         $this->entityCode $entityCode;
  955.         return $this;
  956.     }
  957.     /**
  958.      * @return 
  959.      */
  960.     public function getPhotoPath(): ?string
  961.     {
  962.         return $this->photoPath;
  963.     }
  964.     /**
  965.      * @param  $photoPath 
  966.      * @return self
  967.      */
  968.     public function setPhotoPath(?string $photoPath): self
  969.     {
  970.         $this->photoPath $photoPath;
  971.         return $this;
  972.     }
  973.     /**
  974.      * @return 
  975.      */
  976.     public function getProEmail(): ?string
  977.     {
  978.         return $this->proEmail;
  979.     }
  980.     /**
  981.      * @param  $proEmail 
  982.      * @return self
  983.      */
  984.     public function setProEmail(?string $proEmail): self
  985.     {
  986.         $this->proEmail $proEmail;
  987.         return $this;
  988.     }
  989.     /**
  990.      * @return 
  991.      */
  992.     public function getProPhone(): ?string
  993.     {
  994.         return $this->proPhone;
  995.     }
  996.     /**
  997.      * @param  $proPhone 
  998.      * @return self
  999.      */
  1000.     public function setProPhone(?string $proPhone): self
  1001.     {
  1002.         $this->proPhone $proPhone;
  1003.         return $this;
  1004.     }
  1005.     public function isAcceptPrivacy(): bool
  1006.     {
  1007.         return $this->acceptPrivacy;
  1008.     }
  1009.     public function setAcceptPrivacy(bool $acceptPrivacy): self
  1010.     {
  1011.         $this->acceptPrivacy $acceptPrivacy;
  1012.         return $this;
  1013.     }
  1014.     public function getAcceptPrivacyAt(): ?DateTimeImmutable
  1015.     {
  1016.         return $this->acceptPrivacyAt;
  1017.     }
  1018.     public function setAcceptPrivacyAt(?DateTimeImmutable $acceptPrivacyAt): self
  1019.     {
  1020.         $this->acceptPrivacyAt $acceptPrivacyAt;
  1021.         return $this;
  1022.     }
  1023.     public function getAcceptPrivacyVersion(): ?string
  1024.     {
  1025.         return $this->acceptPrivacyVersion;
  1026.     }
  1027.     public function setAcceptPrivacyVersion(?string $acceptPrivacyVersion): self
  1028.     {
  1029.         $this->acceptPrivacyVersion $acceptPrivacyVersion;
  1030.         return $this;
  1031.     }
  1032.     public function isPrivacyChecked(): bool
  1033.     {
  1034.         return $this->privacyChecked;
  1035.     }
  1036.     public function setPrivacyChecked(bool $value): self
  1037.     {
  1038.         $this->privacyChecked $value;
  1039.         return $this;
  1040.     }
  1041.     #[Assert\Callback(groups: ['identity'])]
  1042.     public function validateIdentity(ExecutionContextInterface $context): void
  1043.     {
  1044.         // Si l’admin coche "Autoriser l’utilisateur à compléter/modifier ses infos"
  1045.         // => on n'impose pas les champs d’identité côté back-office.
  1046.         if ($this->isAllowSelfEdit() || $this->isAnonymizationEnabled()) {
  1047.             return;
  1048.         }
  1049.         // Sinon : ces champs deviennent obligatoires côté admin
  1050.         $lastName trim((string) $this->getLastName());
  1051.         $firstName trim((string) $this->getFirstName());
  1052.         $entity trim((string) $this->getEntityCode());
  1053.         if ($lastName === '') {
  1054.             $context->buildViolation('Le nom est obligatoire.')
  1055.                 ->atPath('lastName')
  1056.                 ->addViolation();
  1057.         }
  1058.         if ($firstName === '') {
  1059.             $context->buildViolation('Le prénom est obligatoire.')
  1060.                 ->atPath('firstName')
  1061.                 ->addViolation();
  1062.         }
  1063.         if ($entity === '') {
  1064.             $context->buildViolation('L’entité / code entité est obligatoire.')
  1065.                 ->atPath('entityCode')
  1066.                 ->addViolation();
  1067.         }
  1068.     }
  1069.     // Criteria 1
  1070.     public function removeCriteria1Item(Criteria1Item $criteria1Item): self
  1071.     {
  1072.         $this->criteria1Items->removeElement($criteria1Item);
  1073.         return $this;
  1074.     }
  1075.     // Criteria 2
  1076.     public function removeCriteria2Item(Criteria2Item $criteria2Item): self
  1077.     {
  1078.         $this->criteria2Items->removeElement($criteria2Item);
  1079.         return $this;
  1080.     }
  1081.     // Criteria 3
  1082.     public function removeCriteria3Item(Criteria3Item $criteria3Item): self
  1083.     {
  1084.         $this->criteria3Items->removeElement($criteria3Item);
  1085.         return $this;
  1086.     }
  1087.     // Criteria 4
  1088.     public function removeCriteria4Item(Criteria4Item $criteria4Item): self
  1089.     {
  1090.         $this->criteria4Items->removeElement($criteria4Item);
  1091.         return $this;
  1092.     }
  1093.     // Criteria 5
  1094.     public function removeCriteria5Item(Criteria5Item $criteria5Item): self
  1095.     {
  1096.         $this->criteria5Items->removeElement($criteria5Item);
  1097.         return $this;
  1098.     }
  1099. }