<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @ORM\Table(name="user")
* @ORM\HasLifecycleCallbacks
*/
class User implements UserInterface , PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
private $email;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @var string The hashed password
* @ORM\Column(type="string", length=5000)
*/
private $password;
/**
*
* @ORM\Column(type="text", nullable=true )
*
*/
private $avatar;
/**
* @var \DateTime $createdAt
*
*
* @ORM\Column(type="datetime", nullable=true )
*/
protected $createdAt;
/**
* @var \DateTime $createdAt
*
*
* @ORM\Column(type="datetime", nullable=true )
*/
protected $updateAt;
/**
* @var boolean
*
* @ORM\Column( type="boolean" , options={"default":"1"})
*/
private $active = 1;
/**
* @ORM\ManyToMany(targetEntity="Role", inversedBy="user")
* @ORM\JoinTable(
* name="user_role",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
* )
*/
protected $roles;
/**
* @ORM\OneToMany(targetEntity="Supplier", mappedBy="user")
*/
protected $supplier;
/**
* @ORM\OneToMany(targetEntity="EventLog", mappedBy="user")
*/
protected $eventLog;
/**
* @ORM\OneToMany(targetEntity="Documentation", mappedBy="user")
*/
protected $documentation;
/**
* @ORM\ManyToOne(targetEntity="Plant", inversedBy="user")
* @ORM\JoinColumn(name="plant_id", referencedColumnName="id" )
*/
protected $plant;
/**
* @ORM\ManyToOne(targetEntity="Position", inversedBy="user")
* @ORM\JoinColumn(name="position_id", referencedColumnName="id" )
*/
protected $position;
/**
* @ORM\OneToMany(targetEntity="Evaluation", mappedBy="user")
*/
protected $evaluation;
/**
* @ORM\OneToMany(targetEntity="Tender", mappedBy="user")
*/
protected $tender;
/**
* @ORM\OneToMany(targetEntity="DocumentType", mappedBy="qualityUser")
*/
protected $documentType;
/**
* @ORM\OneToMany(targetEntity="EvaluationUser", mappedBy="qualityUser")
*/
protected $evaluationUser;
/**
* @ORM\OneToMany(targetEntity="DescriptorType", mappedBy="qualityUser")
*/
protected $descriptorType;
/**
* @ORM\OneToMany(targetEntity="SupplierData", mappedBy="user")
*/
protected $supplierData;
/**
* @ORM\OneToMany(targetEntity="UserSupervisor", mappedBy="user")
*/
private $supervisedUsers;
/**
* @ORM\OneToMany(targetEntity="UserSupervisor", mappedBy="supervisor")
*/
private $supervisors;
/**
* Constructor
*/
public function __construct()
{
$this->roles = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return mixed
*/
public function getEmail()
{
return $this->email;
}
/**
* @param mixed $email
*/
public function setEmail($email): void
{
$this->email = $email;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string)$this->email;
}
/**
* @see UserInterface
* @return \Doctrine\Common\Collections\Collection
*/
public function getRolesArray(): array
{
// guarantee every user at least has ROLE_USER
$rolesArray = [];
foreach ($this->roles->toArray() as $role) {
$rolesArray[] = $role;
}
return array_unique($rolesArray);
}
/**
* @see UserInterface
* @return \Doctrine\Common\Collections\Collection
*/
public function getRoles(): array
{
// guarantee every user at least has ROLE_USER
$rolesArray = [];
foreach ($this->roles->toArray() as $role) {
$rolesArray[] = $role->getName();
}
return array_unique($rolesArray);
}
/**
* @see UserInterface
* @return \Doctrine\Common\Collections\Collection
*/
public function getRolesId(): array
{
// guarantee every user at least has ROLE_USER
$rolesArray = [];
foreach ($this->roles->toArray() as $role) {
$rolesArray[] = $role->getId();
}
return array_unique($rolesArray);
}
/**
* @see UserInterface
* @return \Doctrine\Common\Collections\Collection
*/
public function getRolesString(): array
{
// guarantee every user at least has ROLE_USER
$rolesArray = [];
foreach ($this->roles->toArray() as $role) {
$rolesArray[] = $role->getTextName();
}
return array_unique($rolesArray);
}
/**
* @see UserInterface
* @return \Doctrine\Common\Collections\Collection
*/
public function getRolesIcon(): array
{
$rolesArray = [];
foreach ($this->roles as $key => $role) {
$rolesArray[$key]['name'] = $role->getTextName();
$rolesArray[$key]['icon'] = $role->getIcon();
}
return $rolesArray ;
}
/**
* Add roles
*
* @param Role $roles
*
*/
public function addRole(Role $roles)
{
$this->roles[] = $roles;
return $this;
}
/**
* @param Role $roles
*/
public function removeRole(Role $roles)
{
$this->roles->removeElement($roles);
}
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): void
{
$this->password = $password;
}
/**
* 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;
}
/**
* Get isAdmin
*
* @return boolean
*/
public function getIsSuperAdmin()
{
foreach ($this->roles->toArray() as $role) {
if ($role->getName() == 'ROLE_SUPER_ADMIN') {
return true;
}
}
return false;
}
/**
* @return mixed
*/
public function getAvatar()
{
return $this->avatar;
}
/**
* @param mixed $avatar
*/
public function setAvatar($avatar): void
{
$this->avatar = $avatar;
}
/**
* @param \DateTime $createdAt
*
* @ORM\PrePersist
*/
public function setCreatedAt()
{
$this->createdAt = new \DateTime(date('Y-m-d H:i:s'));
}
/**
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @param \DateTime $updateAt
*
* @ORM\PreUpdate
*/
public function setUpdateAt()
{
$this->updateAt = new \DateTime(date('Y-m-d H:i:s'));
}
/**
* @return \DateTime
*/
public function getUpdateAt()
{
return $this->updateAt;
}
/**
* @return bool
*/
public function isActive(): bool
{
return $this->active;
}
/**
* @param bool $active
*/
public function setActive(bool $active): void
{
$this->active = $active;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
*/
public function setName($name): void
{
$this->name = $name;
}
public function __toString() {
return $this->name;
}
/**
*/
public function getUserIdentifier(): string
{
return $this->id;
}
/**
* @return mixed
*/
public function getSupplier()
{
return $this->supplier;
}
/**
* @param mixed $supplier
*/
public function setSupplier($supplier): void
{
$this->supplier = $supplier;
}
/**
* @return mixed
*/
public function getEventLog()
{
return $this->eventLog;
}
/**
* @param mixed $eventLog
*/
public function setEventLog($eventLog): void
{
$this->eventLog = $eventLog;
}
/**
* @return mixed
*/
public function getDocumentation()
{
return $this->documentation;
}
/**
* @param mixed $documentation
*/
public function setDocumentation($documentation): void
{
$this->documentation = $documentation;
}
/**
* @return mixed
*/
public function getPlant()
{
return $this->plant;
}
/**
* @param mixed $plant
*/
public function setPlant($plant): void
{
$this->plant = $plant;
}
/**
* @return mixed
*/
public function getPosition()
{
return $this->position;
}
/**
* @param mixed $position
*/
public function setPosition($position): void
{
$this->position = $position;
}
/**
* @return mixed
*/
public function getEvaluation()
{
return $this->evaluation;
}
/**
* @param mixed $evaluation
*/
public function setEvaluation($evaluation): void
{
$this->evaluation = $evaluation;
}
/**
* @return mixed
*/
public function getTender()
{
return $this->tender;
}
/**
* @param mixed $tender
*/
public function setTender($tender): void
{
$this->tender = $tender;
}
/**
* @return mixed
*/
public function getDocumentType()
{
return $this->documentType;
}
/**
* @param mixed $documentType
*/
public function setDocumentType($documentType): void
{
$this->documentType = $documentType;
}
/**
* @return mixed
*/
public function getDescriptorType()
{
return $this->descriptorType;
}
/**
* @param mixed $descriptorType
*/
public function setDescriptorType($descriptorType): void
{
$this->descriptorType = $descriptorType;
}
/**
* @return mixed
*/
public function getSupplierData()
{
return $this->supplierData;
}
/**
* @param mixed $supplierData
*/
public function setSupplierData($supplierData): void
{
$this->supplierData = $supplierData;
}
}