<?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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @ORM\Table(name="`user`")
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
* @UniqueEntity(fields={"username"}, message="There is already an account with this username")
*/
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 = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="string", length=255, unique=true)
*/
private $username;
/**
* @ORM\OneToMany(targetEntity=DeployPackages::class, mappedBy="executedBy")
*/
private $executedBy;
/**
* @ORM\OneToMany(targetEntity=DeployPackages::class, mappedBy="createdBy")
*/
private $createdBy;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $deleted;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $deletedAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $name;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $locked;
/**
* @ORM\OneToMany(targetEntity=DeployPackages::class, mappedBy="deletedBy")
*/
private $deployPackages;
public function __construct()
{
$this->executedBy = new ArrayCollection();
$this->createdBy = new ArrayCollection();
$this->deployPackages = new ArrayCollection();
}
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 getUsername(): string
{
return (string) $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
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(string $roles): self
{
$this->roles[] = $roles;
return $this;
}
public function hasRole($role)
{
return in_array($role, $this->getRoles(), true);
}
public function addRole($role)
{
if (!in_array($role, $this->roles, true)) {
$this->roles[] = $role;
}
return $this;
}
public function removeRole($role)
{
if (false !== $key = array_search($role, $this->roles, true)) {
unset($this->roles[$key]);
$this->roles = array_values($this->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;
}
/**
* @return Collection<int, DeployPackages>
*/
public function getExecutedBy(): Collection
{
return $this->executedBy;
}
public function addExecutedBy(DeployPackages $executedBy): self
{
if (!$this->executedBy->contains($executedBy)) {
$this->executedBy[] = $executedBy;
$executedBy->setExecutedBy($this);
}
return $this;
}
public function removeExecutedBy(DeployPackages $executedBy): self
{
if ($this->executedBy->removeElement($executedBy)) {
// set the owning side to null (unless already changed)
if ($executedBy->getExecutedBy() === $this) {
$executedBy->setExecutedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, DeployPackages>
*/
public function getCreatedBy(): Collection
{
return $this->createdBy;
}
public function addCreatedBy(DeployPackages $createdBy): self
{
if (!$this->createdBy->contains($createdBy)) {
$this->createdBy[] = $createdBy;
$createdBy->setCreatedBy($this);
}
return $this;
}
public function removeCreatedBy(DeployPackages $createdBy): self
{
if ($this->createdBy->removeElement($createdBy)) {
// set the owning side to null (unless already changed)
if ($createdBy->getCreatedBy() === $this) {
$createdBy->setCreatedBy(null);
}
}
return $this;
}
public function isDeleted(): ?bool
{
return $this->deleted;
}
public function setDeleted(?bool $deleted): self
{
$this->deleted = $deleted;
return $this;
}
public function getDeletedAt(): ?\DateTimeInterface
{
return $this->deletedAt;
}
public function setDeletedAt(?\DateTimeInterface $deletedAt): self
{
$this->deletedAt = $deletedAt;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function isLocked(): ?bool
{
return $this->locked;
}
public function setLocked(?bool $locked): self
{
$this->locked = $locked;
return $this;
}
/**
* @return Collection<int, DeployPackages>
*/
public function getDeployPackages(): Collection
{
return $this->deployPackages;
}
public function addDeployPackage(DeployPackages $deployPackage): self
{
if (!$this->deployPackages->contains($deployPackage)) {
$this->deployPackages[] = $deployPackage;
$deployPackage->setDeletedBy($this);
}
return $this;
}
public function removeDeployPackage(DeployPackages $deployPackage): self
{
if ($this->deployPackages->removeElement($deployPackage)) {
// set the owning side to null (unless already changed)
if ($deployPackage->getDeletedBy() === $this) {
$deployPackage->setDeletedBy(null);
}
}
return $this;
}
}