<?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 Exception;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @Vich\Uploadable
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serializable
{
const ROLE_CLIENT = 'ROLE_CLIENT';
const ROLE_USER = 'ROLE_USER';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="string", length=500, nullable=true)
*/
private $gitlabId;
/**
* @ORM\Column(type="string", length=180)
*/
private $firstname;
/**
* @ORM\Column(type="string", length=180)
*/
private $lastname;
/**
* @ORM\Column(type="string", length=180, nullable=true)
*/
private $job;
/**
* @ORM\Column(type="string", length=180, nullable=true)
*/
private $channelId;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @var string The hashed password
* @ORM\Column(type="string", nullable=true)
*/
private $locale;
/**
* @Assert\Length(min=5, max=128)
*/
private ?string $plainPassword = null;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="users", fileNameProperty="imageName", size="imageSize")
*
* @var File|null
*/
private $imageFile;
/**
* @ORM\Column(type="string",nullable=true)
*
* @var string|null
*/
private $imageName;
/**
* @ORM\Column(type="integer",nullable=true)
*
* @var int|null
*/
private $imageSize;
/**
* @ORM\Column(type="datetime",nullable=true)
*
* @var \DateTimeInterface|null
*/
private $updatedAt;
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageName(?string $imageName): void
{
$this->imageName = $imageName;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageSize(?int $imageSize): void
{
$this->imageSize = $imageSize;
}
public function getImageSize(): ?int
{
return $this->imageSize;
}
/**
* @ORM\ManyToOne(targetEntity=Company::class, inversedBy="users")
*/
private $company;
/**
* @ORM\OneToMany(targetEntity=Project::class, mappedBy="user", cascade={"persist"})
*/
private $projects;
/**
* @ORM\OneToMany(targetEntity=UserPro::class, mappedBy="user")
*/
private $userPros;
/**
* @ORM\OneToMany(targetEntity=Report::class, mappedBy="user")
*/
private $reports;
/**
* @ORM\OneToMany(targetEntity=Task::class, mappedBy="user")
*/
private $tasks;
/**
* @ORM\OneToMany(targetEntity=Task::class, mappedBy="assigne")
*/
private $tasksAssigne;
public function __toString()
{
return $this->email;
}
public function __construct()
{
$this->projects = new ArrayCollection();
$this->userPros = new ArrayCollection();
$this->reports = new ArrayCollection();
$this->tasks = new ArrayCollection();
$this->tasksAssigne = 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 getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $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;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getPlainPassword(): ?string
{
return $this->plainPassword;
}
public function setPlainPassword(string $password): void
{
$this->plainPassword = $password;
}
/**
* @return string
*/
public function getLocale(): ?string
{
return $this->locale;
}
/**
* @param string $locale
*/
public function setLocale(string $locale): void
{
$this->locale = $locale;
}
/**
* @return Collection<int, Project>
*/
public function getProjects(): Collection
{
return $this->projects;
}
public function setProjects($projets){
$this->projects = $projets;
}
public function addProject(Project $project): self
{
if (!$this->projects->contains($project)) {
$this->projects[] = $project;
$project->setUser($this);
}
return $this;
}
public function removeProject(Project $project): self
{
if ($this->projects->removeElement($project)) {
// set the owning side to null (unless already changed)
if ($project->getUser() === $this) {
$project->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, UserPro>
*/
public function getUserPros(): Collection
{
return $this->userPros;
}
public function addUserPro(UserPro $userPro): self
{
if (!$this->userPros->contains($userPro)) {
$this->userPros[] = $userPro;
$userPro->setUser($this);
}
return $this;
}
public function removeUserPro(UserPro $userPro): self
{
if ($this->userPros->removeElement($userPro)) {
// set the owning side to null (unless already changed)
if ($userPro->getUser() === $this) {
$userPro->setUser(null);
}
}
return $this;
}
public function addTaskAssigne(Task $task): self
{
if (!$this->tasksAssigne->contains($task)) {
$this->tasksAssigne[] = $task;
$task->setAssigne($this);
}
return $this;
}
public function removeTaskAssigne(Task $task): self
{
if ($this->tasksAssigne->removeElement($task)) {
// set the owning side to null (unless already changed)
if ($task->getUser() === $this) {
$task->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Report>
*/
public function getReports(): Collection
{
return $this->reports;
}
public function addReport(Report $report): self
{
if (!$this->reports->contains($report)) {
$this->reports[] = $report;
$report->setUser($this);
}
return $this;
}
public function removeReport(Report $report): self
{
if ($this->reports->removeElement($report)) {
// set the owning side to null (unless already changed)
if ($report->getUser() === $this) {
$report->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Task>
*/
public function getTasks(): Collection
{
return $this->tasks;
}
public function addTask(Task $task): self
{
if (!$this->tasks->contains($task)) {
$this->tasks[] = $task;
$task->setUser($this);
}
return $this;
}
public function removeTask(Task $task): self
{
if ($this->tasks->removeElement($task)) {
// set the owning side to null (unless already changed)
if ($task->getUser() === $this) {
$task->setUser(null);
}
}
return $this;
}
/**
* @return mixed
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* @param mixed $firstname
*/
public function setFirstname($firstname): void
{
$this->firstname = $firstname;
}
/**
* @return mixed
*/
public function getLastname()
{
return $this->lastname;
}
/**
* @param mixed $lastname
*/
public function setLastname($lastname): void
{
$this->lastname = $lastname;
}
/**
* @return mixed
*/
public function getTasksAssigne()
{
return $this->tasksAssigne;
}
/**
* @param mixed $tasksAssigne
*/
public function setTasksAssigne($tasksAssigne): void
{
$this->tasksAssigne = $tasksAssigne;
}
/**
* @return mixed
*/
public function getJob()
{
return $this->job;
}
/**
* @param mixed $job
*/
public function setJob($job): void
{
$this->job = $job;
}
/**
* @return mixed
*/
public function getChannelId()
{
return $this->channelId;
}
/**
* @param mixed $channelId
*/
public function setChannelId($channelId): void
{
$this->channelId = $channelId;
}
public function serialize()
{
return serialize(array(
$this->id,
$this->email,
$this->password,
));
}
public function unserialize($serialized)
{
list(
$this->id,
$this->email,
$this->password,
) = unserialize($serialized);
}
/**
*
* @access public
* @param string $role
* @return bool
*/
public function hasRole($role)
{
if (in_array($role, $this->roles)) {
return true;
}
return false;
}
/**
* @return mixed
*/
public function getGitlabId()
{
return $this->gitlabId;
}
/**
* @param mixed $gitlabId
*/
public function setGitlabId($gitlabId): void
{
$this->gitlabId = $gitlabId;
}
}