src/Entity/User.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use phpDocumentor\Reflection\Types\Integer;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. class User implements UserInterfacePasswordAuthenticatedUserInterface {
  12.     const ROLE_DEFAULT 'ROLE_USER';
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column(type'integer')]
  16.     protected ?int $id null;
  17.     #[ORM\Column(type'string'length180uniquetrue)]
  18.     private ?string $username;
  19.     #[ORM\Column(type'array')]
  20.     private array $roles = [];
  21.     #[ORM\Column(type'string')]
  22.     private ?string $password;
  23.     private ?string $plainPassword null;
  24.     #[ORM\Column(name'api_token'type'string'uniquetruenullabletrue)]
  25.     private ?string $apiToken;
  26.     #[ORM\ManyToOne(targetEntityCountry::class)]
  27.     private ?Country $country null;
  28.     #[ORM\ManyToOne(targetEntityRegion::class)]
  29.     private ?Region $region null;
  30.     #[ORM\Column(name'diaspora'type'boolean')]
  31.     private bool $diaspora false;
  32.     #[ORM\ManyToOne(targetEntityCountry::class)]
  33.     private ?Country $residenceCountry null;
  34.     #[ORM\ManyToOne(targetEntityRegion::class)]
  35.     private ?Region $residenceRegion null;
  36.     #[ORM\Column(name'phone'type'string'uniquetruenullablefalse)]
  37.     #[Assert\NotBlank]
  38.     protected ?string $phone;
  39.     #[ORM\Column(name'enabled'type'boolean')]
  40.     protected bool $enabled false;
  41.     #[ORM\Column(name'email'type'string'uniquetruenullablefalse)]
  42.     #[Assert\NotBlank]
  43.     protected ?string $email;
  44.     #[ORM\Column(name'valid_code'type'string'nullabletrue)]
  45.     protected ?string $validCode;
  46.     #[ORM\Column(name'last_login'type'datetime'nullabletrue)]
  47.     protected ?\DateTime $lastLogin;
  48.     #[ORM\Column(name'password_requested_at'type'datetime'nullabletrue)]
  49.     protected ?\DateTime $passwordRequestedAt;
  50.     #[ORM\Column(name'salt'type'string'nullabletrue)]
  51.     protected ?string $salt;
  52.     #[ORM\Column(name'email_canonical'type'string'nullabletrue)]
  53.     protected ?string $emailCanonical;
  54.     #[ORM\Column(name'username_canonical'type'string'nullabletrue)]
  55.     protected ?string $usernameCanonical;
  56.     #[ORM\Column(name'confirmation_token'type'string'nullabletrue)]
  57.     protected ?string $confirmationToken;
  58.     #[ORM\OneToOne(mappedBy'user'targetEntityPersonDegree::class, cascade: ['persist''remove'])]
  59.     private ?PersonDegree $personDegree;
  60.     #[ORM\OneToOne(mappedBy'user'targetEntityCompany::class, cascade: ['persist''remove'])]
  61.     private ?Company $company;
  62.     #[ORM\OneToOne(mappedBy'user'targetEntitySchool::class, cascade: ['persist''remove'])]
  63.     private ?School $school;
  64.     /**
  65.      * only used for role: "principal"
  66.      * @var int|null
  67.      */
  68.     #[ORM\Column(name'principal_school'type'integer'nullabletrue)]
  69.     private ?int $principalSchool null;
  70.     #[ORM\ManyToMany(targetEntityRole::class, cascade: ['persist'])]
  71.     #[ORM\JoinTable(name'user_role')]
  72.     #[ORM\JoinColumn(name'user_id'referencedColumnName'id')]
  73.     #[ORM\InverseJoinColumn(name'role_id'referencedColumnName'id')]
  74.     protected Collection $profils;
  75.     #[ORM\ManyToMany(targetEntityRegion::class)]
  76.     #[ORM\JoinTable(name'user_admin_regions')]
  77.     #[ORM\JoinColumn(name'user_id'referencedColumnName'id')]
  78.     #[ORM\InverseJoinColumn(name'region_id'referencedColumnName'id')]
  79.     protected Collection $adminRegions;
  80.     #[ORM\ManyToMany(targetEntityCity::class)]
  81.     #[ORM\JoinTable(name'user_admin_cities')]
  82.     #[ORM\JoinColumn(name'user_id'referencedColumnName'id')]
  83.     #[ORM\InverseJoinColumn(name'city_id'referencedColumnName'id')]
  84.     protected Collection $adminCities;
  85.     #[ORM\Column(name'image_name'type'string'nullabletrue)]
  86.     protected ?string $imageName;
  87.     public function __construct() {
  88.         $this->profils = new ArrayCollection();
  89.         $this->adminRegions = new ArrayCollection();
  90.         $this->adminCities = new ArrayCollection();
  91.     }
  92.     public function getId(): ?int {
  93.         return $this->id;
  94.     }
  95.     public function getUsername(): ?string {
  96.         return $this->username;
  97.     }
  98.     public function setUsername(?string $username): self {
  99.         $this->username $username;
  100.         return $this;
  101.     }
  102.     /**
  103.      * A visual identifier that represents this user.
  104.      *
  105.      * @see UserInterface
  106.      */
  107.     public function getUserIdentifier(): string {
  108.         return (string)$this->username;
  109.     }
  110.     /**
  111.      * @see UserInterface
  112.      */
  113.     public function getRoles(): array {
  114.         $profiles $this->profils->map(function (Role $role) {
  115.             return $role->getRole();
  116.         })->toArray();
  117.         return array_merge($profiles, [self::ROLE_DEFAULT]);
  118.     }
  119.     public function getOriginalRoles(): array {
  120.         return $this->profils->map(function (Role $role) {
  121.             return $role->getRole();
  122.         })->toArray();
  123.     }
  124.     public function removeRole(string $role): void {
  125.         $role $this->profils->filter(function (Role $roleItem) use ($role) {
  126.             return $roleItem->getRole() == $role;
  127.         })->filter();
  128.         if ($role) {
  129.             $this->profils->removeElement($role);
  130.         }
  131.     }
  132.     public function setRoles(array $roles): self {
  133.         $this->profils->clear();
  134.         foreach ($roles as $roleName) {
  135.             $this->addRole(new Role($roleName));
  136.         }
  137.         $this->roles $roles;
  138.         return $this;
  139.     }
  140.     public function addRole(Role $role) {
  141.         if ($this->hasRole($role->getRole())) {
  142.             $this->profils->add($role);
  143.         }
  144.     }
  145.     public function getRole(string $role): ?string {
  146.         foreach ($this->getRoles() as $roleItem) {
  147.             if ($role == $roleItem) {
  148.                 return $roleItem;
  149.             }
  150.         }
  151.         return null;
  152.     }
  153.     public function hasRole(string $role): bool {
  154.         if ($this->getRole($role)) {
  155.             return true;
  156.         }
  157.         return false;
  158.     }
  159.     public function hasAnyRole(string $role1string ...$roles): bool {
  160.         $roles array_merge([$role1], $roles);
  161.         foreach ($roles as $role) {
  162.             if ($this->hasRole($role)) {
  163.                 return true;
  164.             }
  165.         }
  166.         return false;
  167.     }
  168.     /**
  169.      * @see PasswordAuthenticatedUserInterface
  170.      */
  171.     public function getPassword(): ?string {
  172.         return $this->password;
  173.     }
  174.     public function setPassword(?string $password): self {
  175.         $this->password $password;
  176.         return $this;
  177.     }
  178.     public function getPlainPassword(): ?string {
  179.         return $this->plainPassword;
  180.     }
  181.     /**
  182.      * @param string $plainPassword
  183.      */
  184.     public function setPlainPassword(string $plainPassword): void {
  185.         $this->plainPassword $plainPassword;
  186.     }
  187.     /**
  188.      * @see UserInterface
  189.      */
  190.     public function eraseCredentials() {
  191.         // If you store any temporary, sensitive data on the user, clear it here
  192.         // $this->plainPassword = null;
  193.     }
  194.     public function addProfil(Role $profil): self {
  195.         $this->profils->add($profil);
  196.         return $this;
  197.     }
  198.     public function removeProfil(Role $profil): void {
  199.         $this->profils->removeElement($profil);
  200.     }
  201.     public function getProfils(): Collection {
  202.         return $this->profils;
  203.     }
  204.     public function getPersonDegree(): ?PersonDegree {
  205.         return $this->personDegree;
  206.     }
  207.     public function getPhone(): ?string {
  208.         return $this->phone;
  209.     }
  210.     public function setPhone(?string $phone): self {
  211.         $this->phone $phone;
  212.         return $this;
  213.     }
  214.     public function getImageName(): ?string {
  215.         return $this->imageName;
  216.     }
  217.     public function setImageName(?string $imageName): void {
  218.         $this->imageName $imageName;
  219.     }
  220.     public function getEmail(): string {
  221.         return $this->email;
  222.     }
  223.     /**
  224.      * @param string|null $email
  225.      * @return User
  226.      */
  227.     public function setEmail(?string $email): self {
  228.         $this->email $email;
  229.         return $this;
  230.     }
  231.     public function getValidCode(): ?string {
  232.         return $this->validCode;
  233.     }
  234.     public function setValidCode(?string $validCode): void {
  235.         $this->validCode $validCode;
  236.     }
  237.     public function getApiToken(): ?string {
  238.         return $this->apiToken;
  239.     }
  240.     public function setApiToken(?string $apiToken): self {
  241.         $this->apiToken $apiToken;
  242.         return $this;
  243.     }
  244.     public function getCountry(): ?Country {
  245.         return $this->country;
  246.     }
  247.     public function setCountry(Country $country): void {
  248.         $this->country $country;
  249.     }
  250.     public function getSchool(): ?School {
  251.         return $this->school;
  252.     }
  253.     public function setSchool(School $school): void {
  254.         $this->school $school;
  255.     }
  256.     public function getCompany(): ?Company {
  257.         return $this->company;
  258.     }
  259.     public function setCompany(Company $company): self {
  260.         $this->company $company;
  261.         return $this;
  262.     }
  263.     public function isEnabled(): bool {
  264.         return $this->enabled;
  265.     }
  266.     /**
  267.      * @param bool $enabled
  268.      * @return User
  269.      */
  270.     public function setEnabled(bool $enabled): self {
  271.         $this->enabled $enabled;
  272.         return $this;
  273.     }
  274.     public function lastLogin(): ?\DateTime {
  275.         return $this->lastLogin;
  276.     }
  277.     public function setLastLogin(?\DateTime $lastLogin): self {
  278.         $this->lastLogin $lastLogin;
  279.         return $this;
  280.     }
  281.     public function passwordRequestedAt(): ?\DateTime {
  282.         return $this->passwordRequestedAt;
  283.     }
  284.     public function setPasswordRequestedAt(?\DateTime $passwordRequestedAt): self {
  285.         $this->passwordRequestedAt $passwordRequestedAt;
  286.         return $this;
  287.     }
  288.     public function salt(): ?string {
  289.         return $this->salt;
  290.     }
  291.     public function setSalt(?string $salt): self {
  292.         $this->salt $salt;
  293.         return $this;
  294.     }
  295.     public function emailCanonical(): ?string {
  296.         return $this->emailCanonical;
  297.     }
  298.     public function setEmailCanonical(?string $emailCanonical): self {
  299.         $this->emailCanonical $emailCanonical;
  300.         return $this;
  301.     }
  302.     public function usernameCanonical(): ?string {
  303.         return $this->usernameCanonical;
  304.     }
  305.     public function setUsernameCanonical(?string $usernameCanonical): self {
  306.         $this->usernameCanonical $usernameCanonical;
  307.         return $this;
  308.     }
  309.     public function confirmationToken(): ?string {
  310.         return $this->confirmationToken;
  311.     }
  312.     public function setConfirmationToken(?string $confirmationToken): self {
  313.         $this->confirmationToken $confirmationToken;
  314.         return $this;
  315.     }
  316.     /**
  317.      * @return Country|null
  318.      */
  319.     public function getResidenceCountry(): ?Country
  320.     {
  321.         return $this->residenceCountry;
  322.     }
  323.     /**
  324.      * @param Country|null $residenceCountry
  325.      */
  326.     public function setResidenceCountry(?Country $residenceCountry): void
  327.     {
  328.         $this->residenceCountry $residenceCountry;
  329.     }
  330.     /**
  331.      * @return bool
  332.      */
  333.     public function isDiaspora(): bool
  334.     {
  335.         return $this->diaspora;
  336.     }
  337.     /**
  338.      * @param bool $diaspora
  339.      */
  340.     public function setDiaspora(bool $diaspora): void
  341.     {
  342.         $this->diaspora $diaspora;
  343.     }
  344.     /**
  345.      * @return Region|null
  346.      */
  347.     public function getRegion(): ?Region
  348.     {
  349.         return $this->region;
  350.     }
  351.     /**
  352.      * @param Region|null $region
  353.      * @return User
  354.      */
  355.     public function setRegion(?Region $region): User
  356.     {
  357.         $this->region $region;
  358.         return $this;
  359.     }
  360.     /**
  361.      * @return Region|null
  362.      */
  363.     public function getResidenceRegion(): ?Region
  364.     {
  365.         return $this->residenceRegion;
  366.     }
  367.     /**
  368.      * @param Region|null $residenceRegion
  369.      * @return User
  370.      */
  371.     public function setResidenceRegion(?Region $residenceRegion): User
  372.     {
  373.         $this->residenceRegion $residenceRegion;
  374.         return $this;
  375.     }
  376.     public function getAdminRegions(): Collection
  377.     {
  378.         return $this->adminRegions;
  379.     }
  380.     public function setAdminRegions(Collection $adminRegions): User
  381.     {
  382.         $this->adminRegions $adminRegions;
  383.         return $this;
  384.     }
  385.     public function addAdminRegion(Region $region): self {
  386.         $this->adminRegions->add($region);
  387.         return $this;
  388.     }
  389.     public function removeAdminRegion(Region $region): void {
  390.         $this->adminRegions->removeElement($region);
  391.     }
  392.     public function getAdminCities(): Collection
  393.     {
  394.         return $this->adminCities;
  395.     }
  396.     public function setAdminCities(Collection $adminCities): User
  397.     {
  398.         $this->adminCities $adminCities;
  399.         return $this;
  400.     }
  401.     public function addAdminCity(City $city): self {
  402.         $this->adminCities->add($city);
  403.         return $this;
  404.     }
  405.     public function removeAdminCity(City $city): void {
  406.         $this->adminCities->removeElement($city);
  407.     }
  408.     /**
  409.      * @return int|null
  410.      */
  411.     public function getPrincipalSchool(): ?int
  412.     {
  413.         return $this->principalSchool;
  414.     }
  415.     /**
  416.      * @param int|null $principalSchool
  417.      */
  418.     public function setPrincipalSchool(?int $principalSchool): void
  419.     {
  420.         $this->principalSchool $principalSchool;
  421.     }
  422. }