hesabixCore/src/Entity/User.php

272 lines
6.5 KiB
PHP
Raw Normal View History

2023-01-19 16:04:55 +03:30
<?php
namespace App\Entity;
use App\Repository\UserRepository;
2023-01-26 19:43:53 +03:30
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
2023-01-19 16:04:55 +03:30
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
private ?string $email = null;
#[ORM\Column]
2023-02-11 22:58:54 +03:30
private array $roles = ['ROLE_ADMIN'];
2023-01-19 16:04:55 +03:30
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
2023-01-26 19:43:53 +03:30
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserToken::class, orphanRemoval: true)]
private Collection $userTokens;
#[ORM\Column(length: 255)]
private ?string $fullName = null;
#[ORM\Column(length: 50)]
private ?string $dateRegister = null;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Business::class, orphanRemoval: true)]
private Collection $businesses;
2023-02-11 22:58:54 +03:30
#[ORM\OneToMany(mappedBy: 'submiter', targetEntity: GuideContent::class, orphanRemoval: true)]
private Collection $guideContents;
#[ORM\OneToMany(mappedBy: 'submitter', targetEntity: StackContent::class, orphanRemoval: true)]
private Collection $stackContents;
2023-01-26 19:43:53 +03:30
public function __construct()
{
$this->userTokens = new ArrayCollection();
$this->businesses = new ArrayCollection();
2023-02-11 22:58:54 +03:30
$this->guideContents = new ArrayCollection();
$this->stackContents = new ArrayCollection();
2023-01-26 19:43:53 +03:30
}
2023-01-19 16:04:55 +03:30
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;
}
/**
* 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);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
2023-01-26 19:43:53 +03:30
/**
* @return Collection<int, UserToken>
*/
public function getUserTokens(): Collection
{
return $this->userTokens;
}
public function addUserToken(UserToken $userToken): self
{
if (!$this->userTokens->contains($userToken)) {
$this->userTokens->add($userToken);
$userToken->setUser($this);
}
return $this;
}
public function removeUserToken(UserToken $userToken): self
{
if ($this->userTokens->removeElement($userToken)) {
// set the owning side to null (unless already changed)
if ($userToken->getUser() === $this) {
$userToken->setUser(null);
}
}
return $this;
}
public function getFullName(): ?string
{
return $this->fullName;
}
public function setFullName(string $fullName): self
{
$this->fullName = $fullName;
return $this;
}
public function getDateRegister(): ?string
{
return $this->dateRegister;
}
public function setDateRegister(string $dateRegister): self
{
$this->dateRegister = $dateRegister;
return $this;
}
/**
* @return Collection<int, Business>
*/
public function getBusinesses(): Collection
{
return $this->businesses;
}
public function addBusiness(Business $business): self
{
if (!$this->businesses->contains($business)) {
$this->businesses->add($business);
$business->setOwner($this);
}
return $this;
}
public function removeBusiness(Business $business): self
{
if ($this->businesses->removeElement($business)) {
// set the owning side to null (unless already changed)
if ($business->getOwner() === $this) {
$business->setOwner(null);
}
}
return $this;
}
2023-02-11 22:58:54 +03:30
/**
* @return Collection<int, GuideContent>
*/
public function getGuideContents(): Collection
{
return $this->guideContents;
}
public function addGuideContent(GuideContent $guideContent): self
{
if (!$this->guideContents->contains($guideContent)) {
$this->guideContents->add($guideContent);
$guideContent->setSubmiter($this);
}
return $this;
}
public function removeGuideContent(GuideContent $guideContent): self
{
if ($this->guideContents->removeElement($guideContent)) {
// set the owning side to null (unless already changed)
if ($guideContent->getSubmiter() === $this) {
$guideContent->setSubmiter(null);
}
}
return $this;
}
/**
* @return Collection<int, StackContent>
*/
public function getStackContents(): Collection
{
return $this->stackContents;
}
public function addStackContent(StackContent $stackContent): self
{
if (!$this->stackContents->contains($stackContent)) {
$this->stackContents->add($stackContent);
$stackContent->setSubmitter($this);
}
return $this;
}
public function removeStackContent(StackContent $stackContent): self
{
if ($this->stackContents->removeElement($stackContent)) {
// set the owning side to null (unless already changed)
if ($stackContent->getSubmitter() === $this) {
$stackContent->setSubmitter(null);
}
}
return $this;
}
2023-01-19 16:04:55 +03:30
}