<?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\JoinTable;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
private ?string $email = null;
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
#[ORM\Column(length: 100)]
private ?string $name = null;
#[ORM\Column(length: 200)]
private ?string $firstname = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $logo = null;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $updatedAt = null;
#[ORM\ManyToOne(inversedBy: 'users')]
private ?Company $company = null;
#[ORM\ManyToMany(targetEntity: Project::class, mappedBy: 'user')]
#[ORM\OrderBy(["id"=>'DESC'])]
private Collection $projects;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Logs::class, cascade:['remove'])]
#[ORM\OrderBy(['id'=>'DESC'])]
private Collection $logs;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Notification::class, cascade:['remove'])]
private Collection $notifications;
#[ORM\ManyToMany(targetEntity: Project::class, mappedBy: 'admin')]
private Collection $adminProjects;
#[ORM\OneToOne(mappedBy: 'user', cascade: ['persist', 'remove'])]
private ?UpdatePassword $updatePassword = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: ConnectionHistory::class, cascade:['remove'])]
private Collection $connectionHistories;
#[ORM\Column(nullable: true)]
private ?string $phone_number = null;
#[ORM\ManyToMany(targetEntity: Project::class, mappedBy: 'contact')]
private Collection $contact;
#[ORM\Column]
private ?bool $isPasswordChanged = null;
public function __construct()
{
$this->projects = new ArrayCollection();
$this->logs = new ArrayCollection();
$this->notifications = new ArrayCollection();
$this->adminProjects = new ArrayCollection();
$this->connectionHistories = new ArrayCollection();
$this->contact = 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;
// guarantee every user at least has ROLE_USER
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 getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLogo(): ?string
{
return $this->logo;
}
public function setLogo(?string $logo): self
{
$this->logo = $logo;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function __toString()
{
return $this->name . $this->firstname . '|';
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
/**
* @return Collection<int, Project>
*/
public function getProjects(): Collection
{
return $this->projects;
}
public function addProject(Project $project): self
{
if (!$this->projects->contains($project)) {
$this->projects->add($project);
$project->addUser($this);
}
return $this;
}
public function removeProject(Project $project): self
{
if ($this->projects->removeElement($project)) {
$project->removeUser($this);
}
return $this;
}
/**
* @return Collection<int, Logs>
*/
public function getLogs(): Collection
{
return $this->logs;
}
public function addLog(Logs $log): self
{
if (!$this->logs->contains($log)) {
$this->logs->add($log);
$log->setUser($this);
}
return $this;
}
public function removeLog(Logs $log): self
{
if ($this->logs->removeElement($log)) {
// set the owning side to null (unless already changed)
if ($log->getUser() === $this) {
$log->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Notification>
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notification $notification): self
{
if (!$this->notifications->contains($notification)) {
$this->notifications->add($notification);
$notification->setUser($this);
}
return $this;
}
public function removeNotification(Notification $notification): self
{
if ($this->notifications->removeElement($notification)) {
// set the owning side to null (unless already changed)
if ($notification->getUser() === $this) {
$notification->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Project>
*/
public function getAdminProjects(): Collection
{
return $this->adminProjects;
}
public function addAdminProject(Project $adminProject): self
{
if (!$this->adminProjects->contains($adminProject)) {
$this->adminProjects->add($adminProject);
$adminProject->addAdmin($this);
}
return $this;
}
public function removeAdminProject(Project $adminProject): self
{
if ($this->adminProjects->removeElement($adminProject)) {
$adminProject->removeAdmin($this);
}
return $this;
}
public function getUpdatePassword(): ?UpdatePassword
{
return $this->updatePassword;
}
public function setUpdatePassword(UpdatePassword $updatePassword): self
{
// set the owning side of the relation if necessary
if ($updatePassword->getUser() !== $this) {
$updatePassword->setUser($this);
}
$this->updatePassword = $updatePassword;
return $this;
}
/**
* @return Collection<int, ConnectionHistory>
*/
public function getConnectionHistories(): Collection
{
return $this->connectionHistories;
}
public function addConnectionHistory(ConnectionHistory $connectionHistory): self
{
if (!$this->connectionHistories->contains($connectionHistory)) {
$this->connectionHistories->add($connectionHistory);
$connectionHistory->setUser($this);
}
return $this;
}
public function removeConnectionHistory(ConnectionHistory $connectionHistory): self
{
if ($this->connectionHistories->removeElement($connectionHistory)) {
// set the owning side to null (unless already changed)
if ($connectionHistory->getUser() === $this) {
$connectionHistory->setUser(null);
}
}
return $this;
}
public function getPhoneNumber(): ?string
{
return $this->phone_number;
}
public function setPhoneNumber(?string $phone_number): self
{
$this->phone_number = $phone_number;
return $this;
}
/**
* @return Collection<int, Project>
*/
public function getContact(): Collection
{
return $this->contact;
}
public function addContact(Project $contact): self
{
if (!$this->contact->contains($contact)) {
$this->contact->add($contact);
$contact->addContact($this);
}
return $this;
}
public function removeContact(Project $contact): self
{
if ($this->contact->removeElement($contact)) {
$contact->removeContact($this);
}
return $this;
}
public function isIsPasswordChanged(): ?bool
{
return $this->isPasswordChanged;
}
public function setIsPasswordChanged(bool $isPasswordChanged): self
{
$this->isPasswordChanged = $isPasswordChanged;
return $this;
}
}