<?php
namespace App\Entity;
use App\Repository\UserRepository;
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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
*/
class User implements UserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $username;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="boolean")
*/
private $isActive;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastLogin;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $confirmToken;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private $created_by;
/**
* @ORM\Column(type="datetime")
*/
private $created_at;
/**
* @ORM\Column(type="integer")
*/
private $status;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\UserGroup", inversedBy="users")
*/
private $userGroup;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $photo;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="string", length=255)
*/
private $position;
/**
* @ORM\Column(type="string", length=255)
*/
private $full_name;
/**
* @ORM\ManyToOne(targetEntity=OrganizationUnit::class, inversedBy="users")
* @ORM\JoinColumn(nullable=false)
*/
private $unit;
/**
* @ORM\Column(type="string", unique=true, nullable=true)
*/
private $apiToken;
public function __construct()
{
}
public function getId(): ?int
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
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->username;
}
/**
* @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 (string) $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()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function __toString()
{
return $this->full_name;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getLastLogin(): ?\DateTimeInterface
{
return $this->lastLogin;
}
public function setLastLogin(?\DateTimeInterface $lastLogin): self
{
$this->lastLogin = $lastLogin;
return $this;
}
public function getConfirmToken(): ?string
{
return $this->confirmToken;
}
public function setConfirmToken(?string $confirmToken): self
{
$this->confirmToken = $confirmToken;
return $this;
}
public function getCreatedBy(): ?self
{
return $this->created_by;
}
public function setCreatedBy(?self $created_by): self
{
$this->created_by = $created_by;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
/**
* @return Collection|UserGroup[]
*/
public function getUserGroup(): Collection
{
return $this->userGroup;
}
public function addUserGroup(UserGroup $userGroup): self
{
if (!$this->userGroup->contains($userGroup)) {
$this->userGroup[] = $userGroup;
}
return $this;
}
public function removeUserGroup(UserGroup $userGroup): self
{
if ($this->userGroup->contains($userGroup)) {
$this->userGroup->removeElement($userGroup);
}
return $this;
}
public function getPhoto(): ?string
{
return $this->photo;
}
public function setPhoto(?string $photo): self
{
$this->photo = $photo;
return $this;
}
public function getPhone(): ?int
{
return $this->phone;
}
public function setPhone(int $phone): self
{
$this->phone = $phone;
return $this;
}
public function getPosition(): ?string
{
return $this->position;
}
public function setPosition(string $position): self
{
$this->position = $position;
return $this;
}
public function getFullName(): ?string
{
return $this->full_name;
}
public function setFullName(string $full_name): self
{
$this->full_name = $full_name;
return $this;
}
public function getUnit(): ?OrganizationUnit
{
return $this->unit;
}
public function setUnit(?OrganizationUnit $unit): self
{
$this->unit = $unit;
return $this;
}
public function getApiToken(): ?string
{
return $this->apiToken;
}
public function setApiToken(?string $apiToken): self
{
$this->apiToken = $apiToken;
return $this;
}
public function getAllFields()
{
return get_object_vars($this);
}
}