<?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 Doctrine\ORM\Mapping\JoinColumn;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: 'tb_users')]
#[ORM\HasLifecycleCallbacks]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: "integer", unique: true)]
private ?int $id;
#[ORM\Column(type: 'string', length: 50, nullable: false)]
private ?string $code;
#[ORM\Column(type: 'string', length: 100, nullable: true)]
private $username;
#[ORM\Column(type: 'string', length: 100, nullable: true)]
private ?string $password;
#[ORM\Column(type: 'string', length: 100, nullable: true)]
private ?string $name;
#[ORM\Column(type: 'boolean', nullable: true)]
private ?bool $activated;
#[ORM\Column(type: 'datetime', nullable: false)]
private \DateTimeInterface $createdAt;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTimeInterface $modifiedAt;
#[ORM\ManyToMany(targetEntity: Role::class, inversedBy: "users")]
#[ORM\JoinTable(name: 'tb_users_roles')]
#[ORM\JoinColumn(name: 'users_id', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'roles_id', referencedColumnName: 'id')]
private Collection $rls;
#[ORM\ManyToOne(targetEntity: User::class)]
private ?User $createdBy;
#[ORM\OneToMany(mappedBy: "createdBy", targetEntity: Agency::class)]
private Collection $agencies;
#[ORM\OneToMany(mappedBy: "createdBy", targetEntity: AgencyAccountType::class)]
private Collection $agencyAccountTypes;
#[ORM\OneToMany(mappedBy: "createdBy", targetEntity: AgencyAccount::class)]
private Collection $agencyAccounts;
public function __construct()
{
$this->createdAt = new \DateTime();
$this->rls = new ArrayCollection();
$this->agencies = new ArrayCollection();
$this->agencyAccountTypes = new ArrayCollection();
$this->agencyAccounts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getActivated(): ?bool
{
return $this->activated;
}
public function setActivated(?bool $activated): self
{
$this->activated = $activated;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getModifiedAt(): ?\DateTimeInterface
{
return $this->modifiedAt;
}
public function setModifiedAt(?\DateTimeInterface $modifiedAt): self
{
$this->modifiedAt = $modifiedAt;
return $this;
}
public function getRoles()
{
$rs = array();
foreach ($this->getRls()->toArray() as $role)
$rs[] = 'ROLE_'.$role->getName();
return $rs;
}
public function addRole(Role $role): self
{
if (!$this->rls->contains($role)) {
$this->rls[] = $role;
}
return $this;
}
public function removeRole(Role $role): self
{
$this->rls->removeElement($role);
return $this;
}
/**
* @return Collection|Role[]
*/
public function getRls()
{
return $this->rls;
}
public function getCreatedBy(): ?self
{
return $this->createdBy;
}
public function setCreatedBy(?self $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getSalt()
{
return null;
}
public function eraseCredentials()
{
// TODO: Implement eraseCredentials() method.
}
public function __call($name, $arguments)
{
// TODO: Implement @method string getUserIdentifier()
}
/**
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->username;
}
/**
* @ORM\PreUpdate
*/
public function onUpdate() {
$this->modifiedAt = new \DateTime();
}
/**
* @return Collection|Agency[]
*/
public function getAgencies(): Collection
{
return $this->agencies;
}
public function addAgency(Agency $agency): self
{
if (!$this->agencies->contains($agency)) {
$this->agencies[] = $agency;
$agency->setCreatedBy($this);
}
return $this;
}
public function removeAgency(Agency $agency): self
{
if ($this->agencies->removeElement($agency)) {
// set the owning side to null (unless already changed)
if ($agency->getCreatedBy() === $this) {
$agency->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection|AgencyAccountType[]
*/
public function getAgencyAccountTypes(): Collection
{
return $this->agencyAccountTypes;
}
public function addAgencyAccountType(AgencyAccountType $agencyAccountType): self
{
if (!$this->agencyAccountTypes->contains($agencyAccountType)) {
$this->agencyAccountTypes[] = $agencyAccountType;
$agencyAccountType->setCreatedBy($this);
}
return $this;
}
public function removeAgencyAccountType(AgencyAccountType $agencyAccountType): self
{
if ($this->agencyAccountTypes->removeElement($agencyAccountType)) {
// set the owning side to null (unless already changed)
if ($agencyAccountType->getCreatedBy() === $this) {
$agencyAccountType->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection|AgencyAccount[]
*/
public function getAgencyAccounts(): Collection
{
return $this->agencyAccounts;
}
public function addAgencyAccount(AgencyAccount $agencyAccount): self
{
if (!$this->agencyAccounts->contains($agencyAccount)) {
$this->agencyAccounts[] = $agencyAccount;
$agencyAccount->setCreatedBy($this);
}
return $this;
}
public function removeAgencyAccount(AgencyAccount $agencyAccount): self
{
if ($this->agencyAccounts->removeElement($agencyAccount)) {
// set the owning side to null (unless already changed)
if ($agencyAccount->getCreatedBy() === $this) {
$agencyAccount->setCreatedBy(null);
}
}
return $this;
}
}