src/Entity/User.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Repository\UserRepository;
  6. use Doctrine\Common\Collections\Collection;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Symfony\Component\Serializer\Annotation\Ignore;
  10. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. #[UniqueEntity(fields: ['email'], message'Un compte existe déjà avec cet email.')]
  12. class User implements UserInterface
  13. {
  14.     const ROLES = [
  15.         'GLOBAL' => [
  16.             'ROLE_USER' => [
  17.                 'level' => 0,
  18.                 'label' => 'Utilisateur',
  19.                 'icon' => 'user'
  20.             ],
  21.             'ROLE_ADMIN' => [
  22.                 'level' => 98,
  23.                 'label' => 'Administrateur',
  24.                 'icon' => 'tool'
  25.             ],
  26.             'ROLE_SUPER_ADMIN' => [
  27.                 'level' => 99,
  28.                 'label' => 'Super-administrateur',
  29.                 'icon' => 'key'
  30.             ]
  31.         ],
  32.         //Other roles groups by categories
  33.         /* Example
  34.         'CATEGORY' => [
  35.             'ROLE_CATEGORY_VIEW' => [
  36.                 'level' => 0,
  37.                 'label' => 'Category - View',
  38.                 'icon' => 'user'
  39.             ],
  40.             'ROLE_CATEGORY_EDIT' => [
  41.                 'level' => 0,
  42.                 'label' => 'Category - Edit',
  43.                 'icon' => 'user'
  44.             ]
  45.         ] ,*/
  46.     ];
  47.     const STATUS_INACTIVE 'Inactif';
  48.     const STATUS_ACTIVE 'Actif';
  49.     #[ORM\Id]
  50.     #[ORM\GeneratedValue]
  51.     #[ORM\Column(type'integer')]
  52.     private $id;
  53.     #[ORM\Column(type'string'length180)]
  54.     private $email;
  55.     #[ORM\Column(type'string'length55)]
  56.     private $firstname;
  57.     #[ORM\Column(type'string'length55)]
  58.     private $lastname;
  59.     #[ORM\Column(type'string'length20)]
  60.     private $status;
  61.     #[ORM\Column(type'json')]
  62.     private $roles = [];
  63.     #[ORM\Column(type'string'length255)]
  64.     private $password;
  65.     #[ORM\ManyToOne(targetEntityFile::class, fetch"EAGER")]
  66.     #[ORM\JoinColumn(nullabletrue)]
  67.     private $avatar;
  68.     #[ORM\OneToMany(mappedBy'user'targetEntityNotification::class)]
  69.     private $notifications;
  70.     #[ORM\Column(type'boolean')]
  71.     private $isVerified false;
  72.     #[ORM\OneToMany(mappedBy'user'targetEntityReponseUser::class, orphanRemovaltrue)]
  73.     private $reponseUsers;
  74.     #[ORM\Column(type'string'length55nullabletrue)]
  75.     private $entrepriseName;
  76.     #[ORM\Column(type'string'length55nullabletrue)]
  77.     private $entrepriseSiteWeb;
  78.     #[ORM\Column(type'text'nullabletrue)]
  79.     private $entrepriseDescription;
  80.     #[ORM\Column(type'text'nullabletrue)]
  81.     private $entrepriseAdresse;
  82.     #[ORM\Column(type'string'length55nullabletrue)]
  83.     private $entrepriseRCS;
  84.     #[ORM\Column(type'string'length55nullabletrue)]
  85.     private $entrepriseFormeJuridique;
  86.     #[ORM\Column(type'boolean')]
  87.     private $archive;
  88.     public function __construct()
  89.     {
  90.         $this->reponseUsers = new ArrayCollection();
  91.     }
  92.     public function getId(): ?int
  93.     {
  94.         return $this->id;
  95.     }
  96.     public function getUserIdentifier(): string
  97.     {
  98.         return $this->email;
  99.     }
  100.     public function getEmail(): ?string
  101.     {
  102.         return $this->email;
  103.     }
  104.     public function setEmail(string $email): self
  105.     {
  106.         $this->email $email;
  107.         return $this;
  108.     }
  109.     public function getFirstname(): ?string
  110.     {
  111.         return $this->firstname;
  112.     }
  113.     public function setFirstname(?string $firstname): self
  114.     {
  115.         $this->firstname $firstname;
  116.         return $this;
  117.     }
  118.     public function getLastname(): ?string
  119.     {
  120.         return $this->lastname;
  121.     }
  122.     public function setLastname(?string $lastname): self
  123.     {
  124.         $this->lastname $lastname;
  125.         return $this;
  126.     }
  127.     /**
  128.      * A visual identifier that represents this user.
  129.      *
  130.      * @see UserInterface
  131.      */
  132.     public function getUsername(): string
  133.     {
  134.         return (string) $this->email;
  135.     }
  136.     /**
  137.      * @see UserInterface
  138.      */
  139.     public function getRoles(): array
  140.     {
  141.         $roles $this->roles;
  142.         // guarantee every user at least has ROLE_USER
  143.         $roles[] = 'ROLE_USER';
  144.         return array_unique($roles);
  145.     }
  146.     public function setRoles(array $roles): self
  147.     {
  148.         $this->roles $roles;
  149.         return $this;
  150.     }
  151.     /**
  152.      * @see UserInterface
  153.      */
  154.     public function getPassword(): string
  155.     {
  156.         return (string) $this->password;
  157.     }
  158.     public function setPassword(string $password): self
  159.     {
  160.         $this->password $password;
  161.         return $this;
  162.     }
  163.     /**
  164.      * Returning a salt is only needed, if you are not using a modern
  165.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  166.      *
  167.      * @see UserInterface
  168.      */
  169.     public function getSalt(): ?string
  170.     {
  171.         return null;
  172.     }
  173.     /**
  174.      * @see UserInterface
  175.      */
  176.     public function eraseCredentials()
  177.     {
  178.         // If you store any temporary, sensitive data on the user, clear it here
  179.         // $this->plainPassword = null;
  180.     }
  181.     public function getUniqRole(): string
  182.     {
  183.         $uniqRole 'ROLE_USER';
  184.         foreach ($this->getRoles() as $role) {
  185.             if (isset(self::ROLES['GLOBAL'][$role])) if (self::ROLES['GLOBAL'][$role]['level'] > self::ROLES['GLOBAL'][$uniqRole]['level']) $uniqRole $role;
  186.         }
  187.         return $uniqRole;
  188.     }
  189.     public function getUniqRoleLabel(): string
  190.     {
  191.         return self::ROLES['GLOBAL'][$this->getUniqRole()]['label'];
  192.     }
  193.     /**
  194.      * Get the value of status
  195.      */
  196.     public function getStatus()
  197.     {
  198.         return $this->status == null self::STATUS_INACTIVE $this->status;
  199.     }
  200.     /**
  201.      * Set the value of status
  202.      *
  203.      * @return  self
  204.      */
  205.     public function setStatus($status)
  206.     {
  207.         $this->status $status;
  208.         return $this;
  209.     }
  210.     /**
  211.      * Get the value of avatar
  212.      */
  213.     public function getAvatar()
  214.     {
  215.         return $this->avatar;
  216.     }
  217.     /**
  218.      * Set the value of avatar
  219.      *
  220.      * @return  self
  221.      */
  222.     public function setAvatar($avatar)
  223.     {
  224.         $this->avatar $avatar;
  225.         return $this;
  226.     }
  227.     /**
  228.      * @return Collection|Notification[]
  229.      */
  230.     public function getNotifications(): Collection
  231.     {
  232.         return $this->notifications;
  233.     }
  234.     public function addNotification(Notification $notification): self
  235.     {
  236.         if (!$this->notifications->contains($notification)) {
  237.             $this->notifications[] = $notification;
  238.             $notification->setUser($this);
  239.         }
  240.         return $this;
  241.     }
  242.     public function isVerified(): bool
  243.     {
  244.         return $this->isVerified;
  245.     }
  246.     public function setIsVerified(bool $isVerified): self
  247.     {
  248.         $this->isVerified $isVerified;
  249.         return $this;
  250.     }
  251.     /**
  252.      * @return Collection<int, ReponseUser>
  253.      */
  254.     public function getReponseUsers(): Collection
  255.     {
  256.         return $this->reponseUsers;
  257.     }
  258.     public function addReponseUser(ReponseUser $reponseUser): self
  259.     {
  260.         if (!$this->reponseUsers->contains($reponseUser)) {
  261.             $this->reponseUsers[] = $reponseUser;
  262.             $reponseUser->setUser($this);
  263.         }
  264.         return $this;
  265.     }
  266.     public function removeReponseUser(ReponseUser $reponseUser): self
  267.     {
  268.         if ($this->reponseUsers->removeElement($reponseUser)) {
  269.             // set the owning side to null (unless already changed)
  270.             if ($reponseUser->getUser() === $this) {
  271.                 $reponseUser->setUser(null);
  272.             }
  273.         }
  274.         return $this;
  275.     }
  276.     /**
  277.      * Get the value of entrepriseName
  278.      */ 
  279.     public function getEntrepriseName()
  280.     {
  281.         return $this->entrepriseName;
  282.     }
  283.     /**
  284.      * Set the value of entrepriseName
  285.      *
  286.      * @return  self
  287.      */ 
  288.     public function setEntrepriseName($entrepriseName)
  289.     {
  290.         $this->entrepriseName $entrepriseName;
  291.         return $this;
  292.     }
  293.     /**
  294.      * Get the value of entrepriseSiteWeb
  295.      */ 
  296.     public function getEntrepriseSiteWeb()
  297.     {
  298.         return $this->entrepriseSiteWeb;
  299.     }
  300.     /**
  301.      * Set the value of entrepriseSiteWeb
  302.      *
  303.      * @return  self
  304.      */ 
  305.     public function setEntrepriseSiteWeb($entrepriseSiteWeb)
  306.     {
  307.         $this->entrepriseSiteWeb $entrepriseSiteWeb;
  308.         return $this;
  309.     }
  310.     /**
  311.      * Get the value of entrepriseDescription
  312.      */ 
  313.     public function getEntrepriseDescription()
  314.     {
  315.         return $this->entrepriseDescription;
  316.     }
  317.     /**
  318.      * Set the value of entrepriseDescription
  319.      *
  320.      * @return  self
  321.      */ 
  322.     public function setEntrepriseDescription($entrepriseDescription)
  323.     {
  324.         $this->entrepriseDescription $entrepriseDescription;
  325.         return $this;
  326.     }
  327.     /**
  328.      * Get the value of entrepriseAdresse
  329.      */ 
  330.     public function getEntrepriseAdresse()
  331.     {
  332.         return $this->entrepriseAdresse;
  333.     }
  334.     /**
  335.      * Set the value of entrepriseAdresse
  336.      *
  337.      * @return  self
  338.      */ 
  339.     public function setEntrepriseAdresse($entrepriseAdresse)
  340.     {
  341.         $this->entrepriseAdresse $entrepriseAdresse;
  342.         return $this;
  343.     }
  344.     /**
  345.      * Get the value of entrepriseRCS
  346.      */ 
  347.     public function getEntrepriseRCS()
  348.     {
  349.         return $this->entrepriseRCS;
  350.     }
  351.     /**
  352.      * Set the value of entrepriseRCS
  353.      *
  354.      * @return  self
  355.      */ 
  356.     public function setEntrepriseRCS($entrepriseRCS)
  357.     {
  358.         $this->entrepriseRCS $entrepriseRCS;
  359.         return $this;
  360.     }
  361.     /**
  362.      * Get the value of entrepriseFormeJuridique
  363.      */ 
  364.     public function getEntrepriseFormeJuridique()
  365.     {
  366.         return $this->entrepriseFormeJuridique;
  367.     }
  368.     /**
  369.      * Set the value of entrepriseFormeJuridique
  370.      *
  371.      * @return  self
  372.      */ 
  373.     public function setEntrepriseFormeJuridique($entrepriseFormeJuridique)
  374.     {
  375.         $this->entrepriseFormeJuridique $entrepriseFormeJuridique;
  376.         return $this;
  377.     }
  378.     public function isArchive(): ?bool
  379.     {
  380.         return $this->archive;
  381.     }
  382.     public function setArchive(bool $archive): self
  383.     {
  384.         $this->archive $archive;
  385.         return $this;
  386.     }
  387. }