src/Entity/User.php line 17
<?phpnamespace App\Entity;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;use App\Repository\UserRepository;use Gedmo\Mapping\Annotation as Gedmo;use Doctrine\Common\Collections\Collection;use Doctrine\Common\Collections\ArrayCollection;use Symfony\Component\Serializer\Annotation\Groups;use Symfony\Component\Security\Core\User\UserInterface;use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;#[ORM\Entity(repositoryClass: UserRepository::class)]// #[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false)]class User extends RootEntity implements UserInterface, PasswordAuthenticatedUserInterface{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column(type: 'integer')]#[Groups(['api_index', 'reg_success', 'api_user'])]private $id;#[ORM\Column(type: 'string', length: 180, unique: true)]#[Groups(['reg_success', 'api_user'])]private $email;#[ORM\Column(type: 'string', length: 180)]#[Groups(['reg_success', 'api_user'])]private $newEmail;#[ORM\Column(type: 'string', nullable: true)]#[Groups(['api_user'])]private $firstName;#[ORM\Column(type: 'string', nullable: true)]#[Groups(['api_user'])]private $lastName;#[ORM\Column(type: 'string', nullable: true)]#[Groups(['api_user'])]private $middleName;#[ORM\Column(type: 'string', nullable: true)]#[Groups(['api_index', 'api_user'])]private $phone;#[ORM\Column(type: 'date_immutable', nullable: true)]#[Groups(['api_user'])]private $birthday;#[ORM\Column(type: 'integer', nullable: true)]#[Groups(['api_user'])]private $age;#[ORM\Column(type: 'integer', nullable: true)]#[Groups(['api_user'])]private $height;#[ORM\Column(type: 'json', nullable: true)]#[Groups(['api_user'])]private $meta = [];const ALLOW_META = ['age' => 'number','height' => 'number','birthday' => 'date','phone' => 'phone',];#[Groups(['api_user'])]public $metaTemplate = [['name' => 'birthday','pattern' => 'date','label' => 'Дата рождения',],['name' => 'phone','pattern' => '+{7} 000 000-00-00','label' => 'Телефон',],['name' => 'height','pattern' => '00[0]','label' => 'Рост, см',],['name' => 'age','pattern' => '00[0]','label' => 'Возраст',],];#[ORM\Column(type: 'json')]private $roles = [];const SYS_ROLES = ['Администратор' => 'ROLE_ADMIN','Пользователь' => 'ROLE_USER',];#[Groups(['api_user'])]public function getTextRoles(){$db = array_flip($this::SYS_ROLES);$roles = array_map(function ($r) use ($db) {return isset($db[$r]) ? $db[$r] : $r;}, $this->roles);return array_values(array_filter($roles, fn ($r) => !in_array($r, ['Пользователь'])));}#[ORM\Column(type: 'string')]private $password;// Для смены пароля админомpublic $plainPassword;#[ORM\Column(type: 'string', nullable: true)]private $code;#[ORM\Column(type: 'integer')]private $status = 0;#[ORM\Column(type: 'string', nullable: true)]#[Groups(['api_user'])]private $verificationStatus = 'no';// 'no', 'pending', 'failed', 'success'const USER_STATUS = ['Новый' => 0,'Подтвержден Email' => 10,'Активен' => 20,'Забанен' => -10,];#[ORM\OneToMany(mappedBy: 'user', targetEntity: Document::class)]private Collection $documents;#[ORM\ManyToMany(targetEntity: Role::class, mappedBy: 'users')]private Collection $accessRoles;public function __construct(){$this->documents = new ArrayCollection();$this->accessRoles = new ArrayCollection();}#[Groups(['api_user'])]public function getFullName(){if ($this->firstName && $this->lastName) return $this->firstName . " " . $this->lastName;return $this->email;}public function __toString(){return '#' . $this->id . ': ' . $this->getFullName();}/*** Returning a salt is only needed, if you are not using a modern* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.** @see UserInterface*/public function getSalt(): ?string{return null;}/*** @see UserInterface*/public function eraseCredentials(){// If you store any temporary, sensitive data on the user, clear it here// $this->plainPassword = null;}/*** A visual identifier that represents this user.** @see UserInterface*/public function getUserIdentifier(): string{return (string) $this->email;}/*** @see UserInterface*/public function getRoles(): array{$roles = $this->roles;// guarantee every user at least has ROLE_USER$roles[] = 'ROLE_USER';return array_unique($roles);}/*** @see PasswordAuthenticatedUserInterface*/public function getPassword(): string{return $this->password;}public function getId(): ?int{return $this->id;}public function getEmail(): ?string{return $this->email;}public function setEmail(string $email): self{$this->email = $email;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 getMiddleName(): ?string{return $this->middleName;}public function setMiddleName(?string $middleName): self{$this->middleName = $middleName;return $this;}public function getPhone(): ?string{return $this->phone;}public function setPhone(?string $phone): self{$this->phone = $phone;return $this;}public function getAge(): ?int{return $this->age;}public function setAge(?int $age): self{$this->age = $age;return $this;}public function getHeight(): ?int{return $this->height;}public function setHeight(?int $height): self{$this->height = $height;return $this;}public function getMeta(): array{return $this->meta;}public function setMeta(?array $meta): self{$this->meta = $meta;return $this;}public function setRoles(array $roles): self{$this->roles = $roles;return $this;}public function setPassword(string $password): self{$this->password = $password;return $this;}public function getCode(): ?string{return $this->code;}public function setCode(?string $code): self{$this->code = $code;return $this;}public function getStatus(): ?int{return $this->status;}public function setStatus(int $status): self{$this->status = $status;return $this;}/*** @return Collection<int, Document>*/public function getDocuments(): Collection{return $this->documents;}public function addDocument(Document $document): self{if (!$this->documents->contains($document)) {$this->documents->add($document);$document->setUser($this);}return $this;}public function removeDocument(Document $document): self{if ($this->documents->removeElement($document)) {// set the owning side to null (unless already changed)if ($document->getUser() === $this) {$document->setUser(null);}}return $this;}/*** @return Collection<int, Role>*/public function getAccessRoles(): Collection{return $this->accessRoles;}public function addAccessRole(Role $accessRole): self{if (!$this->accessRoles->contains($accessRole)) {$this->accessRoles->add($accessRole);$accessRole->addUser($this);}return $this;}public function removeAccessRole(Role $accessRole): self{if ($this->accessRoles->removeElement($accessRole)) {$accessRole->removeUser($this);}return $this;}public function getNewEmail(): ?string{return $this->newEmail;}public function setNewEmail(string $newEmail): self{$this->newEmail = $newEmail;return $this;}public function getBirthday(): ?\DateTimeImmutable{return $this->birthday;}public function setBirthday(?\DateTimeImmutable $birthday): self{$this->birthday = $birthday;return $this;}public function getVerificationStatus(): ?string{return $this->verificationStatus;}public function setVerificationStatus(?string $verificationStatus): self{$this->verificationStatus = $verificationStatus;return $this;}}