<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Ignore;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @ORM\ManyToOne(targetEntity=UserRole::class, inversedBy="users")
*/
private $user_role;
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="boolean")
*/
private $active;
/**
* @var string
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $googleId;
/**
* @Vich\UploadableField(mapping="avatars", fileNameProperty="avatarName")
* @var File|null
* @Ignore()
*/
private ?File $avatarFile = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $avatarName = null;
/**
* @ORM\OneToOne(targetEntity=Employee::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $employee;
/**
* @return File|null
*/
public function getAvatarFile(): ?File
{
return $this->avatarFile;
}
/**
* @param File|null $avatarFile
* @return User
*/
public function setAvatarFile(?File $avatarFile): User
{
$this->avatarFile = $avatarFile;
return $this;
}
/**
* @return string|null
*/
public function getAvatarName(): ?string
{
return $this->avatarName;
}
/**
* @param string|null $avatarName
* @return User
*/
public function setAvatarName(?string $avatarName): User
{
$this->avatarName = $avatarName;
return $this;
}
/**
* @return string
*/
public function getGoogleId(): string
{
return (string)$this->googleId;
}
/**
* @param string $googleId
* @return User
*/
public function setGoogleId(string $googleId): User
{
$this->googleId = $googleId;
return $this;
}
/**
* @return mixed
*/
public function getActive()
{
return $this->active;
}
/**
* @param mixed $active
* @return User
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
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;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string)$this->email;
}
/**
* @return UserRole
*/
public function getUserRole()
{
return $this->user_role;
}
/**
* @param mixed $user_role
* @return User
*/
public function setUserRole($user_role): User
{
$this->user_role = $user_role;
return $this;
}
/**
* @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;
}
/**
* 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;
}
public function getEmployee(): ?Employee
{
return $this->employee;
}
public function setEmployee(?Employee $employee): self
{
// unset the owning side of the relation if necessary
if ($employee === null && $this->employee !== null) {
$this->employee->setUser(null);
}
// set the owning side of the relation if necessary
if ($employee !== null && $employee->getUser() !== $this) {
$employee->setUser($this);
}
$this->employee = $employee;
return $this;
}
}