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 removeRole(string $role): void {
  120.         $role $this->profils->filter(function (Role $roleItem) use ($role) {
  121.             return $roleItem->getRole() == $role;
  122.         })->filter();
  123.         if ($role) {
  124.             $this->profils->removeElement($role);
  125.         }
  126.     }
  127.     public function setRoles(array $roles): self {
  128.         $this->profils->clear();
  129.         foreach ($roles as $roleName) {
  130.             $this->addRole(new Role($roleName));
  131.         }
  132.         $this->roles $roles;
  133.         return $this;
  134.     }
  135.     public function addRole(Role $role) {
  136.         if ($this->hasRole($role->getRole())) {
  137.             $this->profils->add($role);
  138.         }
  139.     }
  140.     public function getRole(string $role): ?string {
  141.         foreach ($this->getRoles() as $roleItem) {
  142.             if ($role == $roleItem) {
  143.                 return $roleItem;
  144.             }
  145.         }
  146.         return null;
  147.     }
  148.     public function hasRole(string $role): bool {
  149.         if ($this->getRole($role)) {
  150.             return true;
  151.         }
  152.         return false;
  153.     }
  154.     /**
  155.      * @see PasswordAuthenticatedUserInterface
  156.      */
  157.     public function getPassword(): ?string {
  158.         return $this->password;
  159.     }
  160.     public function setPassword(?string $password): self {
  161.         $this->password $password;
  162.         return $this;
  163.     }
  164.     public function getPlainPassword(): ?string {
  165.         return $this->plainPassword;
  166.     }
  167.     /**
  168.      * @param string $plainPassword
  169.      */
  170.     public function setPlainPassword(string $plainPassword): void {
  171.         $this->plainPassword $plainPassword;
  172.     }
  173.     /**
  174.      * @see UserInterface
  175.      */
  176.     public function eraseCredentials() {
  177.         // If you store any temporary, sensitive data on the user, clear it here
  178.         // $this->plainPassword = null;
  179.     }
  180.     public function addProfil(Role $profil): self {
  181.         $this->profils->add($profil);
  182.         return $this;
  183.     }
  184.     public function removeProfil(Role $profil): void {
  185.         $this->profils->removeElement($profil);
  186.     }
  187.     public function getProfils(): Collection {
  188.         return $this->profils;
  189.     }
  190.     public function getPersonDegree(): ?PersonDegree {
  191.         return $this->personDegree;
  192.     }
  193.     public function getPhone(): ?string {
  194.         return $this->phone;
  195.     }
  196.     public function setPhone(?string $phone): self {
  197.         $this->phone $phone;
  198.         return $this;
  199.     }
  200.     public function getImageName(): ?string {
  201.         return $this->imageName;
  202.     }
  203.     public function setImageName(?string $imageName): void {
  204.         $this->imageName $imageName;
  205.     }
  206.     public function getEmail(): string {
  207.         return $this->email;
  208.     }
  209.     /**
  210.      * @param string|null $email
  211.      * @return User
  212.      */
  213.     public function setEmail(?string $email): self {
  214.         $this->email $email;
  215.         return $this;
  216.     }
  217.     public function getValidCode(): ?string {
  218.         return $this->validCode;
  219.     }
  220.     public function setValidCode(?string $validCode): void {
  221.         $this->validCode $validCode;
  222.     }
  223.     public function getApiToken(): ?string {
  224.         return $this->apiToken;
  225.     }
  226.     public function setApiToken(?string $apiToken): self {
  227.         $this->apiToken $apiToken;
  228.         return $this;
  229.     }
  230.     public function getCountry(): ?Country {
  231.         return $this->country;
  232.     }
  233.     public function setCountry(Country $country): void {
  234.         $this->country $country;
  235.     }
  236.     public function getSchool(): ?School {
  237.         return $this->school;
  238.     }
  239.     public function setSchool(School $school): void {
  240.         $this->school $school;
  241.     }
  242.     public function getCompany(): ?Company {
  243.         return $this->company;
  244.     }
  245.     public function setCompany(Company $company): self {
  246.         $this->company $company;
  247.         return $this;
  248.     }
  249.     public function isEnabled(): bool {
  250.         return $this->enabled;
  251.     }
  252.     /**
  253.      * @param bool $enabled
  254.      * @return User
  255.      */
  256.     public function setEnabled(bool $enabled): self {
  257.         $this->enabled $enabled;
  258.         return $this;
  259.     }
  260.     public function lastLogin(): ?\DateTime {
  261.         return $this->lastLogin;
  262.     }
  263.     public function setLastLogin(?\DateTime $lastLogin): self {
  264.         $this->lastLogin $lastLogin;
  265.         return $this;
  266.     }
  267.     public function passwordRequestedAt(): ?\DateTime {
  268.         return $this->passwordRequestedAt;
  269.     }
  270.     public function setPasswordRequestedAt(?\DateTime $passwordRequestedAt): self {
  271.         $this->passwordRequestedAt $passwordRequestedAt;
  272.         return $this;
  273.     }
  274.     public function salt(): ?string {
  275.         return $this->salt;
  276.     }
  277.     public function setSalt(?string $salt): self {
  278.         $this->salt $salt;
  279.         return $this;
  280.     }
  281.     public function emailCanonical(): ?string {
  282.         return $this->emailCanonical;
  283.     }
  284.     public function setEmailCanonical(?string $emailCanonical): self {
  285.         $this->emailCanonical $emailCanonical;
  286.         return $this;
  287.     }
  288.     public function usernameCanonical(): ?string {
  289.         return $this->usernameCanonical;
  290.     }
  291.     public function setUsernameCanonical(?string $usernameCanonical): self {
  292.         $this->usernameCanonical $usernameCanonical;
  293.         return $this;
  294.     }
  295.     public function confirmationToken(): ?string {
  296.         return $this->confirmationToken;
  297.     }
  298.     public function setConfirmationToken(?string $confirmationToken): self {
  299.         $this->confirmationToken $confirmationToken;
  300.         return $this;
  301.     }
  302.     /**
  303.      * @return Country|null
  304.      */
  305.     public function getResidenceCountry(): ?Country
  306.     {
  307.         return $this->residenceCountry;
  308.     }
  309.     /**
  310.      * @param Country|null $residenceCountry
  311.      */
  312.     public function setResidenceCountry(?Country $residenceCountry): void
  313.     {
  314.         $this->residenceCountry $residenceCountry;
  315.     }
  316.     /**
  317.      * @return bool
  318.      */
  319.     public function isDiaspora(): bool
  320.     {
  321.         return $this->diaspora;
  322.     }
  323.     /**
  324.      * @param bool $diaspora
  325.      */
  326.     public function setDiaspora(bool $diaspora): void
  327.     {
  328.         $this->diaspora $diaspora;
  329.     }
  330.     /**
  331.      * @return Region|null
  332.      */
  333.     public function getRegion(): ?Region
  334.     {
  335.         return $this->region;
  336.     }
  337.     /**
  338.      * @param Region|null $region
  339.      * @return User
  340.      */
  341.     public function setRegion(?Region $region): User
  342.     {
  343.         $this->region $region;
  344.         return $this;
  345.     }
  346.     /**
  347.      * @return Region|null
  348.      */
  349.     public function getResidenceRegion(): ?Region
  350.     {
  351.         return $this->residenceRegion;
  352.     }
  353.     /**
  354.      * @param Region|null $residenceRegion
  355.      * @return User
  356.      */
  357.     public function setResidenceRegion(?Region $residenceRegion): User
  358.     {
  359.         $this->residenceRegion $residenceRegion;
  360.         return $this;
  361.     }
  362.     public function getAdminRegions(): Collection
  363.     {
  364.         return $this->adminRegions;
  365.     }
  366.     public function setAdminRegions(Collection $adminRegions): User
  367.     {
  368.         $this->adminRegions $adminRegions;
  369.         return $this;
  370.     }
  371.     public function addAdminRegion(Region $region): self {
  372.         $this->adminRegions->add($region);
  373.         return $this;
  374.     }
  375.     public function removeAdminRegion(Region $region): void {
  376.         $this->adminRegions->removeElement($region);
  377.     }
  378.     public function getAdminCities(): Collection
  379.     {
  380.         return $this->adminCities;
  381.     }
  382.     public function setAdminCities(Collection $adminCities): User
  383.     {
  384.         $this->adminCities $adminCities;
  385.         return $this;
  386.     }
  387.     public function addAdminCity(City $city): self {
  388.         $this->adminCities->add($city);
  389.         return $this;
  390.     }
  391.     public function removeAdminCity(City $city): void {
  392.         $this->adminCities->removeElement($city);
  393.     }
  394.     /**
  395.      * @return int|null
  396.      */
  397.     public function getPrincipalSchool(): ?int
  398.     {
  399.         return $this->principalSchool;
  400.     }
  401.     /**
  402.      * @param int|null $principalSchool
  403.      */
  404.     public function setPrincipalSchool(?int $principalSchool): void
  405.     {
  406.         $this->principalSchool $principalSchool;
  407.     }
  408. }