<?php
namespace App\Entity\Kernel;
use App\Repository\Kernel\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Gedmo\Mapping\Annotation as Gedmo;
use App\Entity\Kernel\UserFunction;
use App\Entity\HR\Employee;
/**
* @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=255, unique=true)
*/
private $uuid;
/**
* @ORM\Column(type="string", length=255)
*/
private $email;
/**
* @ORM\Column(type="string", length=255)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=255)
*/
private $lastName;
/**
* @ORM\OneToOne(targetEntity=KernelFile::class, cascade={"remove"})
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*/
private $picture;
/**
* @ORM\Column(type="string", length=55, nullable=true)
*/
private $phone;
/**
*
* @ORM\Column(type="integer", nullable=true)
*/
private $type; //0 normal user, 1 azure user, 2 facebook user
/**
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastLogin;
/**
*
* @ORM\Column(type="integer")
*/
private $failedLoginAttempts;
/**
* @ORM\Column(type="boolean")
*/
private $enabled;
/**
* @ORM\Column(type="boolean")
*/
private $locked;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\ManyToOne(targetEntity=UserFunction::class)
*/
private $userfunction;
/**
* @ORM\ManyToOne(targetEntity=ListItem::class)
*/
private $timezone;
/**
* @ORM\ManyToOne(targetEntity=ListItem::class)
*/
private $locale;
/**
* @ORM\OneToOne(targetEntity=Employee::class, inversedBy="user")
*/
private $employee;
/**
* @ORM\ManyToMany(targetEntity=App\Entity\Kernel\Contact::class, mappedBy="users")
*/
private $contacts;
/**
* @ORM\Column(type="integer")
*/
private $state;
/**
* @var datetime $created
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private $created;
/**
* @ORM\ManyToOne(targetEntity=Organization::class)
*/
private $organization;
/**
* @var string $createdBy
*
* @Gedmo\Blameable(on="create")
* @ORM\ManyToOne(targetEntity="App\Entity\Kernel\User")
* @ORM\JoinColumn(name="created_by", referencedColumnName="id")
*/
private $createdBy;
/**
* @var datetime $updated
*
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="update")
*/
private $updated;
/**
* @var string $updatedBy
*
* @Gedmo\Blameable(on="update")
* @ORM\ManyToOne(targetEntity="App\Entity\Kernel\User")
* @ORM\JoinColumn(name="updated_by", referencedColumnName="id")
*/
private $updatedBy;
public function getUserIdentifier():string
{
return $this->uuid;
}
public function __construct()
{
$this->users = new ArrayCollection();
$this->contacts = new ArrayCollection();
}
public function getName()
{
return "".$this->firstName. " " .$this->lastName;
}
public function __toString()
{
return "".$this->email;
}
public function getId(): ?int
{
return $this->id;
}
public function getUuid(): ?string
{
return $this->uuid;
}
public function setUuid(string $uuid): self
{
$this->uuid = $uuid;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string) $this->email;
}
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
/**
* @see UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @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 getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getLastLogin(): ?\DateTimeInterface
{
return $this->lastLogin;
}
public function setLastLogin(?\DateTimeInterface $lastLogin): self
{
$this->lastLogin = $lastLogin;
return $this;
}
public function getFailedLoginAttempts(): ?int
{
return $this->failedLoginAttempts;
}
public function setFailedLoginAttempts(int $failedLoginAttempts): self
{
$this->failedLoginAttempts = $failedLoginAttempts;
return $this;
}
public function getEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function getLocked(): ?bool
{
return $this->locked;
}
public function setLocked(bool $locked): self
{
$this->locked = $locked;
return $this;
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function getState(): ?int
{
return $this->state;
}
public function setState(int $state): self
{
$this->state = $state;
return $this;
}
public function getCreated(): ?\DateTimeInterface
{
return $this->created;
}
public function setCreated(\DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
public function getUpdated(): ?\DateTimeInterface
{
return $this->updated;
}
public function setUpdated(\DateTimeInterface $updated): self
{
$this->updated = $updated;
return $this;
}
public function getCreatedBy(): ?self
{
return $this->createdBy;
}
public function setCreatedBy(?self $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getUpdatedBy(): ?self
{
return $this->updatedBy;
}
public function setUpdatedBy(?self $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
public function getUserfunction(): ?UserFunction
{
return $this->userfunction;
}
public function setUserfunction(?UserFunction $userfunction): self
{
$this->userfunction = $userfunction;
return $this;
}
public function getOrganization(): ?Organization
{
return $this->organization;
}
public function setOrganization(?Organization $organization): self
{
$this->organization = $organization;
return $this;
}
public function getTimezone(): ?ListItem
{
return $this->timezone;
}
public function setTimezone(?ListItem $timezone): self
{
$this->timezone = $timezone;
return $this;
}
public function getLocale(): ?ListItem
{
return $this->locale;
}
public function setLocale(?ListItem $locale): self
{
$this->locale = $locale;
return $this;
}
public function getPicture(): ?KernelFile
{
return $this->picture;
}
public function setPicture(?KernelFile $picture): self
{
$this->picture = $picture;
return $this;
}
public function getType(): ?int
{
return $this->type;
}
public function setType(?int $type): self
{
$this->type = $type;
return $this;
}
public function getEmployee(): ?Employee
{
return $this->employee;
}
public function setEmployee(?Employee $employee): self
{
$this->employee = $employee;
return $this;
}
/**
* @return Collection|Contact[]
*/
public function getContacts(): Collection
{
return $this->contacts;
}
public function addContact(Contact $contact): self
{
if (!$this->contacts->contains($contact)) {
$this->contacts[] = $contact;
$contact->addUser($this);
}
return $this;
}
public function removeContact(Contact $contact): self
{
if ($this->contacts->removeElement($contact)) {
$contact->removeUser($this);
}
return $this;
}
}