<?php
namespace App\Entity;
use App\Traits\EntityDateTimeAbleTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[ORM\Entity(repositoryClass: 'App\Repository\UserRepository')]
#[ORM\HasLifecycleCallbacks]
#[UniqueEntity(fields: ['email'], errorPath: 'email', message: 'This email is already in use.')]
class User implements UserInterface
{
use EntityDateTimeAbleTrait;
const ADMIN_ROLE = 1;
const CLIENT_ROLE = 3;
const STATUS_INACTIVE = 0;
const STATUS_ACTIVE = 1;
// Remember update func getListRoleIdsThatNotAdmin
const ROLE_ADMINISTRATOR_SUPER = 1;
const ROLE_USER = 2;
const ROLE_CLIENT = 3;
const ROLE_COMMERCIAL = 19;
const GENDER_MALE = 0;
const GENDER_FEMALE = 1;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 191, unique: true)]
#[Assert\Length(max: 191)]
#[Assert\NotBlank]
private ?string $email = null;
#[ORM\Column(type: 'string', length: 255)]
#[Assert\Length(max: 255)]
#[Groups(['excludeFrontend', 'excludeBackend'])]
private ?string $password = null;
#[ORM\Column(type: 'boolean')]
private ?bool $authPermitted = null;
#[ORM\ManyToMany(targetEntity: 'App\Entity\Role', cascade: ['persist'])]
private Collection $subRoles;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $phone = null;
#[ORM\Column(type: 'smallint', nullable: true)]
private ?int $status = null;
#[ORM\Column(type: 'string', length: 150, nullable: true)]
private ?string $resetPasswordToken = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $firstName = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $lastName = null;
#[ORM\Column(type: 'boolean', nullable: true)]
private ?bool $gender = null;
#[ORM\Column(type: 'date', nullable: true)]
private ?\DateTimeInterface $birthDay = null;
#[ORM\OneToOne(targetEntity: Media::class, orphanRemoval: true, cascade: ['persist'])]
#[ORM\JoinColumn(nullable: true)]
private ?\App\Entity\Media $media = null;
#[ORM\OneToMany(targetEntity: Profile::class, mappedBy: 'user')]
private Collection $profiles;
#[ORM\OneToMany(targetEntity: ProfileNote::class, mappedBy: 'user')]
private Collection $profileNotes;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $birthPlace = null;
#[ORM\ManyToOne(targetEntity: Country::class, inversedBy: 'users')]
private ?\App\Entity\Country $country = null;
#[ORM\ManyToOne(targetEntity: Country::class, inversedBy: 'users')]
private ?\App\Entity\Country $nationality = null;
#[ORM\ManyToMany(targetEntity: Campus::class, inversedBy: 'users')]
private Collection $campuses;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $department = null;
public function __construct()
{
$this->subRoles = new ArrayCollection();
$this->profiles = new ArrayCollection();
$this->profileNotes = new ArrayCollection();
$this->campuses = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you location any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
/**
* @see UserInterface
*/
public function getRoles()
{
return $this->getSubRoleNames();
}
public function getEmail(): ?string
{
return $this->email;
}
public function getUsername(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getAuthPermitted(): ?bool
{
return $this->authPermitted;
}
public function setAuthPermitted(bool $authPermitted): self
{
$this->authPermitted = $authPermitted;
return $this;
}
/**
* @return Collection|Role[]
*/
public function getSubRoles(): Collection
{
return $this->subRoles;
}
public function getSubRoleNames()
{
$names = [];
foreach ($this->subRoles as $subRole) {
$names[] = $subRole->getName();
}
return $names;
}
public function addSubRole(Role $subRole): self
{
if (!$this->subRoles->contains($subRole)) {
$this->subRoles[] = $subRole;
}
return $this;
}
public function removeSubRole(Role $subRole): self
{
if ($this->subRoles->contains($subRole)) {
$this->subRoles->removeElement($subRole);
}
return $this;
}
public static function getListRoleIdsThatNotAdmin()
{
return [
self::ROLE_CLIENT,
self::ROLE_USER
];
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getFullName()
{
return $this->getFirstName() . ' ' . $this->getLastName();
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(?int $status): self
{
$this->status = $status;
return $this;
}
public function getResetPasswordToken(): ?string
{
return $this->resetPasswordToken;
}
public function setResetPasswordToken(?string $resetPasswordToken): self
{
$this->resetPasswordToken = $resetPasswordToken;
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(?string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getGender(): ?bool
{
return $this->gender;
}
public function setGender(?bool $gender): self
{
$this->gender = $gender;
return $this;
}
public function getBirthDay(): ?\DateTimeInterface
{
return $this->birthDay;
}
public function setBirthDay(?\DateTimeInterface $birthDay): self
{
$this->birthDay = $birthDay;
return $this;
}
public function getMedia(): ?Media
{
return $this->media;
}
public function setMedia(Media $media): self
{
$this->media = $media;
return $this;
}
/**
* @return Collection<int, Profile>
*/
public function getProfiles(): Collection
{
return $this->profiles;
}
public function addProfile(Profile $profile): self
{
if (!$this->profiles->contains($profile)) {
$this->profiles[] = $profile;
$profile->setUser($this);
}
return $this;
}
public function removeProfile(Profile $profile): self
{
if ($this->profiles->removeElement($profile)) {
// set the owning side to null (unless already changed)
if ($profile->getUser() === $this) {
$profile->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, ProfileNote>
*/
public function getProfileNotes(): Collection
{
return $this->profileNotes;
}
public function addProfileNote(ProfileNote $profileNote): self
{
if (!$this->profileNotes->contains($profileNote)) {
$this->profileNotes[] = $profileNote;
$profileNote->setUser($this);
}
return $this;
}
public function removeProfileNote(ProfileNote $profileNote): self
{
if ($this->profileNotes->removeElement($profileNote)) {
// set the owning side to null (unless already changed)
if ($profileNote->getUser() === $this) {
$profileNote->setUser(null);
}
}
return $this;
}
public function getBirthPlace(): ?string
{
return $this->birthPlace;
}
public function setBirthPlace(?string $birthPlace): self
{
$this->birthPlace = $birthPlace;
return $this;
}
public function getCountry(): ?Country
{
return $this->country;
}
public function setCountry(?Country $country): self
{
$this->country = $country;
return $this;
}
public function getNationality(): ?Country
{
return $this->nationality;
}
public function setNationality(?Country $nationality): self
{
$this->nationality = $nationality;
return $this;
}
/**
* @return Collection<int, campus>
*/
public function getCampuses(): Collection
{
return $this->campuses;
}
public function addCampus(Campus $campus): self
{
if (!$this->campuses->contains($campus)) {
$this->campuses[] = $campus;
}
return $this;
}
public function removeCampus(Campus $campus): self
{
$this->campuses->removeElement($campus);
return $this;
}
public function getDepartment(): ?string
{
return $this->department;
}
public function setDepartment(?string $department): self
{
$this->department = $department;
return $this;
}
}