src/Entity/User.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Traits\EntityDateTimeAbleTrait;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. #[ORM\Entity(repositoryClass'App\Repository\UserRepository')]
  12. #[ORM\HasLifecycleCallbacks]
  13. #[UniqueEntity(fields: ['email'], errorPath'email'message'This email is already in use.')]
  14. class User implements UserInterface
  15. {
  16.     use EntityDateTimeAbleTrait;
  17.     const ADMIN_ROLE 1;
  18.     const CLIENT_ROLE 3;
  19.     const STATUS_INACTIVE 0;
  20.     const STATUS_ACTIVE 1;
  21.     // Remember update func getListRoleIdsThatNotAdmin
  22.     const ROLE_ADMINISTRATOR_SUPER 1;
  23.     const ROLE_USER 2;
  24.     const ROLE_CLIENT 3;
  25.     const ROLE_COMMERCIAL 19;
  26.     const ROLE_PARTENAIRE 20;
  27.     const GENDER_MALE 0;
  28.     const GENDER_FEMALE 1;
  29.     #[ORM\Id]
  30.     #[ORM\GeneratedValue]
  31.     #[ORM\Column(type'integer')]
  32.     private $id;
  33.     #[ORM\Column(type'string'length191uniquetrue)]
  34.     #[Assert\Length(max191)]
  35.     #[Assert\NotBlank]
  36.     private ?string $email null;
  37.     #[ORM\Column(type'string'length255)]
  38.     #[Assert\Length(max255)]
  39.     #[Groups(['excludeFrontend''excludeBackend'])]
  40.     private ?string $password null;
  41.     #[ORM\Column(type'boolean')]
  42.     private ?bool $authPermitted null;
  43.     #[ORM\ManyToMany(targetEntity'App\Entity\Role'cascade: ['persist'])]
  44.     private Collection $subRoles;
  45.     #[ORM\Column(type'string'length255nullabletrue)]
  46.     private ?string $phone null;
  47.     #[ORM\Column(type'smallint'nullabletrue)]
  48.     private ?int $status null;
  49.     #[ORM\Column(type'string'length150nullabletrue)]
  50.     private ?string $resetPasswordToken null;
  51.     #[ORM\Column(type'string'length255nullabletrue)]
  52.     private ?string $firstName null;
  53.     #[ORM\Column(type'string'length255nullabletrue)]
  54.     private ?string $lastName null;
  55.     #[ORM\Column(type'boolean'nullabletrue)]
  56.     private ?bool $gender null;
  57.     #[ORM\Column(type'date'nullabletrue)]
  58.     private ?\DateTimeInterface $birthDay null;
  59.     #[ORM\OneToOne(targetEntityMedia::class, orphanRemovaltruecascade: ['persist'])]
  60.     #[ORM\JoinColumn(nullabletrue)]
  61.     private ?\App\Entity\Media $media null;
  62.     #[ORM\OneToMany(targetEntityProfile::class, mappedBy'user')]
  63.     private Collection $profiles;
  64.     #[ORM\OneToMany(targetEntityProfileNote::class, mappedBy'user')]
  65.     private Collection $profileNotes;
  66.     #[ORM\Column(type'string'length255nullabletrue)]
  67.     private ?string $birthPlace null;
  68.     #[ORM\ManyToOne(targetEntityCountry::class, inversedBy'users')]
  69.     private ?\App\Entity\Country $country null;
  70.     #[ORM\ManyToOne(targetEntityCountry::class, inversedBy'users')]
  71.     private ?\App\Entity\Country $nationality null;
  72.     #[ORM\ManyToMany(targetEntityCampus::class, inversedBy'users')]
  73.     private Collection $campuses;
  74.     #[ORM\Column(type'string'length255nullabletrue)]
  75.     private ?string $department null;
  76.     #[ORM\ManyToOne(inversedBy'users')]
  77.     private ?Landingpage $landingpage null;
  78.     public function __construct()
  79.     {
  80.         $this->subRoles = new ArrayCollection();
  81.         $this->profiles = new ArrayCollection();
  82.         $this->profileNotes = new ArrayCollection();
  83.         $this->campuses = new ArrayCollection();
  84.     }
  85.     public function getId(): ?int
  86.     {
  87.         return $this->id;
  88.     }
  89.     /**
  90.      * @see UserInterface
  91.      */
  92.     public function getSalt()
  93.     {
  94.         // not needed when using the "bcrypt" algorithm in security.yaml
  95.     }
  96.     /**
  97.      * @see UserInterface
  98.      */
  99.     public function eraseCredentials()
  100.     {
  101.         // If you location any temporary, sensitive data on the user, clear it here
  102.         // $this->plainPassword = null;
  103.     }
  104.     /**
  105.      * @see UserInterface
  106.      */
  107.     public function getRoles()
  108.     {
  109.         return $this->getSubRoleNames();
  110.     }
  111.     public function getEmail(): ?string
  112.     {
  113.         return $this->email;
  114.     }
  115.     public function getUsername(): ?string
  116.     {
  117.         return $this->email;
  118.     }
  119.     public function setEmail(string $email): self
  120.     {
  121.         $this->email $email;
  122.         return $this;
  123.     }
  124.     public function getPassword(): ?string
  125.     {
  126.         return $this->password;
  127.     }
  128.     public function setPassword(string $password): self
  129.     {
  130.         $this->password $password;
  131.         return $this;
  132.     }
  133.     public function getAuthPermitted(): ?bool
  134.     {
  135.         return $this->authPermitted;
  136.     }
  137.     public function setAuthPermitted(bool $authPermitted): self
  138.     {
  139.         $this->authPermitted $authPermitted;
  140.         return $this;
  141.     }
  142.     /**
  143.      * @return Collection|Role[]
  144.      */
  145.     public function getSubRoles(): Collection
  146.     {
  147.         return $this->subRoles;
  148.     }
  149.     public function getSubRoleNames()
  150.     {
  151.         $names = [];
  152.         foreach ($this->subRoles as $subRole) {
  153.             $names[] = $subRole->getName();
  154.         }
  155.         return $names;
  156.     }
  157.     public function addSubRole(Role $subRole): self
  158.     {
  159.         if (!$this->subRoles->contains($subRole)) {
  160.             $this->subRoles[] = $subRole;
  161.         }
  162.         return $this;
  163.     }
  164.     public function removeSubRole(Role $subRole): self
  165.     {
  166.         if ($this->subRoles->contains($subRole)) {
  167.             $this->subRoles->removeElement($subRole);
  168.         }
  169.         return $this;
  170.     }
  171.     public static function getListRoleIdsThatNotAdmin()
  172.     {
  173.         return [
  174.             self::ROLE_CLIENT,
  175.             self::ROLE_USER
  176.         ];
  177.     }
  178.     public function getPhone(): ?string
  179.     {
  180.         return $this->phone;
  181.     }
  182.     public function setPhone(?string $phone): self
  183.     {
  184.         $this->phone $phone;
  185.         return $this;
  186.     }
  187.     public function getFullName()
  188.     {
  189.         return $this->getFirstName() . ' ' $this->getLastName();
  190.     }
  191.     public function getStatus(): ?int
  192.     {
  193.         return $this->status;
  194.     }
  195.     public function setStatus(?int $status): self
  196.     {
  197.         $this->status $status;
  198.         return $this;
  199.     }
  200.     public function getResetPasswordToken(): ?string
  201.     {
  202.         return $this->resetPasswordToken;
  203.     }
  204.     public function setResetPasswordToken(?string $resetPasswordToken): self
  205.     {
  206.         $this->resetPasswordToken $resetPasswordToken;
  207.         return $this;
  208.     }
  209.     public function getFirstName(): ?string
  210.     {
  211.         return $this->firstName;
  212.     }
  213.     public function setFirstName(?string $firstName): self
  214.     {
  215.         $this->firstName $firstName;
  216.         return $this;
  217.     }
  218.     public function getLastName(): ?string
  219.     {
  220.         return $this->lastName;
  221.     }
  222.     public function setLastName(?string $lastName): self
  223.     {
  224.         $this->lastName $lastName;
  225.         return $this;
  226.     }
  227.     public function getGender(): ?bool
  228.     {
  229.         return $this->gender;
  230.     }
  231.     public function setGender(?bool $gender): self
  232.     {
  233.         $this->gender $gender;
  234.         return $this;
  235.     }
  236.     public function getBirthDay(): ?\DateTimeInterface
  237.     {
  238.         return $this->birthDay;
  239.     }
  240.     public function setBirthDay(?\DateTimeInterface $birthDay): self
  241.     {
  242.         $this->birthDay $birthDay;
  243.         return $this;
  244.     }
  245.     public function getMedia(): ?Media
  246.     {
  247.         return $this->media;
  248.     }
  249.     public function setMedia(Media $media): self
  250.     {
  251.         $this->media $media;
  252.         return $this;
  253.     }
  254.     /**
  255.      * @return Collection<int, Profile>
  256.      */
  257.     public function getProfiles(): Collection
  258.     {
  259.         return $this->profiles;
  260.     }
  261.     public function addProfile(Profile $profile): self
  262.     {
  263.         if (!$this->profiles->contains($profile)) {
  264.             $this->profiles[] = $profile;
  265.             $profile->setUser($this);
  266.         }
  267.         return $this;
  268.     }
  269.     public function removeProfile(Profile $profile): self
  270.     {
  271.         if ($this->profiles->removeElement($profile)) {
  272.             // set the owning side to null (unless already changed)
  273.             if ($profile->getUser() === $this) {
  274.                 $profile->setUser(null);
  275.             }
  276.         }
  277.         return $this;
  278.     }
  279.     /**
  280.      * @return Collection<int, ProfileNote>
  281.      */
  282.     public function getProfileNotes(): Collection
  283.     {
  284.         return $this->profileNotes;
  285.     }
  286.     public function addProfileNote(ProfileNote $profileNote): self
  287.     {
  288.         if (!$this->profileNotes->contains($profileNote)) {
  289.             $this->profileNotes[] = $profileNote;
  290.             $profileNote->setUser($this);
  291.         }
  292.         return $this;
  293.     }
  294.     public function removeProfileNote(ProfileNote $profileNote): self
  295.     {
  296.         if ($this->profileNotes->removeElement($profileNote)) {
  297.             // set the owning side to null (unless already changed)
  298.             if ($profileNote->getUser() === $this) {
  299.                 $profileNote->setUser(null);
  300.             }
  301.         }
  302.         return $this;
  303.     }
  304.     public function getBirthPlace(): ?string
  305.     {
  306.         return $this->birthPlace;
  307.     }
  308.     public function setBirthPlace(?string $birthPlace): self
  309.     {
  310.         $this->birthPlace $birthPlace;
  311.         return $this;
  312.     }
  313.     public function getCountry(): ?Country
  314.     {
  315.         return $this->country;
  316.     }
  317.     public function setCountry(?Country $country): self
  318.     {
  319.         $this->country $country;
  320.         return $this;
  321.     }
  322.     public function getNationality(): ?Country
  323.     {
  324.         return $this->nationality;
  325.     }
  326.     public function setNationality(?Country $nationality): self
  327.     {
  328.         $this->nationality $nationality;
  329.         return $this;
  330.     }
  331.     /**
  332.      * @return Collection<int, campus>
  333.      */
  334.     public function getCampuses(): Collection
  335.     {
  336.         return $this->campuses;
  337.     }
  338.     public function addCampus(Campus $campus): self
  339.     {
  340.         if (!$this->campuses->contains($campus)) {
  341.             $this->campuses[] = $campus;
  342.         }
  343.         return $this;
  344.     }
  345.     public function removeCampus(Campus $campus): self
  346.     {
  347.         $this->campuses->removeElement($campus);
  348.         return $this;
  349.     }
  350.     public function getDepartment(): ?string
  351.     {
  352.         return $this->department;
  353.     }
  354.     public function setDepartment(?string $department): self
  355.     {
  356.         $this->department $department;
  357.         return $this;
  358.     }
  359.     public function getLandingpage(): ?Landingpage
  360.     {
  361.         return $this->landingpage;
  362.     }
  363.     public function setLandingpage(?Landingpage $landingpage): static
  364.     {
  365.         $this->landingpage $landingpage;
  366.         return $this;
  367.     }
  368. }