<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"email"}, message="Il y a déjà un compte associé à cette adresse mail.")
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="boolean")
*/
private $isVerified = false;
public function isRelanceProfile(): ?bool
{
return $this->relanceProfile;
}
public function setRelanceProfile(?bool $relanceProfile): void
{
$this->relanceProfile = $relanceProfile;
}
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private $relanceProfile = false;
/**
* @ORM\Column(type="string", length=255)
*/
private $firstname;
/**
* @ORM\Column(type="string", length=255)
*/
private $lastname;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="string", length=255)
*/
public $type = 'freelance';
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $photo;
/**
* @ORM\Column(type="string", length=255, nullable=true, name="subscription_id")
*/
private $subscriptionId;
/**
* @return mixed
*/
public function getSubscriptionId()
{
return $this->subscriptionId;
}
/**
* @param mixed $subscriptionId
*/
public function setSubscriptionId($subscriptionId): void
{
$this->subscriptionId = $subscriptionId;
}
/**
* @ORM\OneToOne(targetEntity=Society::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $society;
/**
* @ORM\OneToMany(targetEntity=Profile::class, mappedBy="user", orphanRemoval=true)
*/
private $profiles;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $deleteAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastConnection;
/**
* @ORM\OneToMany(targetEntity=Message::class, mappedBy="writer")
*/
private $messages;
/**
* @ORM\OneToMany(targetEntity=Room::class, mappedBy="caller")
*/
private $rooms;
/**
* @ORM\OneToMany(targetEntity=OfferFavorite::class, mappedBy="user", orphanRemoval=true)
*/
private $offerFavorites;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\OneToMany(targetEntity=AuthLog::class, mappedBy="user", orphanRemoval=true)
*/
private $authLogs;
/**
* @ORM\OneToMany(targetEntity=OfferVisit::class, mappedBy="user", orphanRemoval=true)
*/
private $offerVisits;
/**
* @ORM\OneToMany(targetEntity=Report::class, mappedBy="user", orphanRemoval=true)
*/
private $reports;
/**
* @ORM\OneToMany(targetEntity=OfferAlert::class, mappedBy="user", orphanRemoval=true)
*/
private $offerAlerts;
/**
* @ORM\OneToMany(targetEntity=ProfileFavorite::class, mappedBy="user")
*/
private $profileFavorites;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $civility;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $jobSociety;
/**
* @ORM\ManyToOne(targetEntity=Society::class)
*/
private $CompteSociety;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $compteTestIsNotActive;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $googleSubId;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isBlocked;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $mailRelance;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastLoginTime;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $expoPushTokens = [];
public function getExpoPushTokens(): array
{
return $this->expoPushTokens ?: [];
}
public function addExpoPushToken(string $token): self
{
if (!is_array($this->expoPushTokens)) {
$this->expoPushTokens = [];
}
if (!in_array($token, $this->expoPushTokens, true)) {
$this->expoPushTokens[] = $token;
}
return $this;
}
public function removeExpoPushToken(string $token): self
{
if (($key = array_search($token, $this->expoPushTokens, true)) !== false) {
unset($this->expoPushTokens[$key]);
$this->expoPushTokens = array_values($this->expoPushTokens);
}
return $this;
}
/**
* @return \DateTimeInterface|null
*/
public function getLastLoginTime(): ?\DateTimeInterface
{
return $this->lastLoginTime;
}
/**
*
* @param \DateTimeInterface|null $lastLoginTime
* @return void
*/
public function setLastLoginTime(?\DateTimeInterface $lastLoginTime): void
{
$this->lastLoginTime = $lastLoginTime;
}
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastLougoutTime;
/**
* @return \DateTimeInterface|null
*/
public function getLastLougoutTime(): ?\DateTimeInterface
{
return $this->lastLougoutTime;
}
public function setLastLougoutTime(?\DateTimeInterface $lastLougoutTime): void
{
$this->lastLougoutTime = $lastLougoutTime;
}
/**
* @return \DateTimeInterface|null
*/
public function getLastReminderTime(): ?\DateTimeInterface
{
return $this->lastReminderTime;
}
public function setLastReminderTime(?\DateTimeInterface $lastReminderTime): void
{
$this->lastReminderTime = $lastReminderTime;
}
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastReminderTime;
public function getMailRelance(): ?int
{
return $this->mailRelance;
}
public function setMailRelance(int $mailRelance): void
{
$this->mailRelance = $mailRelance;
}
public function getIsBlocked()
{
return $this->isBlocked;
}
public function setIsBlocked($isBlocked): void
{
$this->isBlocked = $isBlocked;
}
public function __construct()
{
$this->profiles = new ArrayCollection();
$this->messages = new ArrayCollection();
$this->rooms = new ArrayCollection();
$this->offerFavorites = new ArrayCollection();
$this->authLogs = new ArrayCollection();
$this->offerVisits = new ArrayCollection();
$this->reports = new ArrayCollection();
$this->offerAlerts = new ArrayCollection();
$this->profileFavorites = new ArrayCollection();
}
// ---------------------------------
public function getCivilityString(): string
{
if ($this->civility == 1) {
return "Mr.";
}
if ($this->civility == 2) {
return "Mme.";
}
return "";
}
public function isRole(string $role)
{
if (in_array($role, $this->roles)) {
return true;
}
return false;
}
// ---------------------------------
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
$roles[] = '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 isVerified(): bool
{
return $this->isVerified;
}
public function hasProfile(): bool
{
return $this->getUniqueProfile()->getId() !== null;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getPhoto(): ?string
{
if ($this->getCompteSociety()) {
$societe = $this->getCompteSociety();
return $societe->getUser()->getPhoto();
}
return $this->photo;
}
public function setPhoto(?string $photo): self
{
$this->photo = $photo;
return $this;
}
public function getFullName(): string
{
return $this->firstname . ' ' . $this->lastname;
}
public function getSociety(): ?Society
{
if ($this->getCompteSociety() && in_array("ROLE_RECRUTEUR", $this->roles)) {
return $this->getCompteSociety();
}
return $this->society;
}
public function setSociety(Society $society): self
{
// set the owning side of the relation if necessary
if ($society->getUser() !== $this) {
$society->setUser($this);
}
$this->society = $society;
return $this;
}
public function isFreelance(): bool
{
return $this->type === 'freelance';
}
public function isSociety(): bool
{
if ($this->getCompteSociety()) {
return true;
}
return $this->type === 'society';
}
public function isAdmin(): bool
{
return $this->type == 'admin';
}
/**
* @return Collection|Profile[]
*/
public function getProfiles(): Collection
{
return $this->profiles;
}
public function addProfile(Profile $profile): self
{
if (!$this->profiles->contains($profile)) {
$this->profiles[] = $profile;
$profile->setUser($this);
}
return $this;
}
public function removeProfile(Profile $profile): self
{
if ($this->profiles->removeElement($profile)) {
// set the owning side to null (unless already changed)
if ($profile->getUser() === $this) {
$profile->setUser(null);
}
}
return $this;
}
public function getUniqueProfile(): Profile
{
return $this->getProfiles()->isEmpty()
? (new Profile())
->setUser($this)
->setIsIntercontrat($this->isSociety())
->setName($this->isFreelance() ? $this->getLastname() : 'Intercontrat')
->setPhone($this->getPhone() ?? '')
->setFirstname($this->isFreelance() ? $this->getFirstname() : 'Intercontrat')
: $this->getProfiles()->first();
}
public function getDeleteAt(): ?\DateTimeInterface
{
return $this->deleteAt;
}
public function setDeleteAt(?\DateTimeInterface $deleteAt): self
{
$this->deleteAt = $deleteAt;
return $this;
}
public function getLastConnection(): ?\DateTimeInterface
{
return $this->lastConnection;
}
public function setLastConnection(?\DateTimeInterface $lastConnection): self
{
$this->lastConnection = $lastConnection;
return $this;
}
/**
* @return Collection|Message[]
*/
public function getMessages(): Collection
{
return $this->messages;
}
public function addMessage(Message $message): self
{
if (!$this->messages->contains($message)) {
$this->messages[] = $message;
$message->setWriter($this);
}
return $this;
}
public function removeMessage(Message $message): self
{
if ($this->messages->removeElement($message)) {
// set the owning side to null (unless already changed)
if ($message->getWriter() === $this) {
$message->setWriter(null);
}
}
return $this;
}
/**
* @return Collection|Room[]
*/
public function getRooms(): Collection
{
return $this->rooms;
}
public function addRoom(Room $room): self
{
if (!$this->rooms->contains($room)) {
$this->rooms[] = $room;
$room->setCaller($this);
}
return $this;
}
public function removeRoom(Room $room): self
{
if ($this->rooms->removeElement($room)) {
// set the owning side to null (unless already changed)
if ($room->getCaller() === $this) {
$room->setCaller(null);
}
}
return $this;
}
/**
* @return Collection|OfferFavorite[]
*/
public function getOfferFavorites(): Collection
{
return $this->offerFavorites;
}
public function addOfferFavorite(OfferFavorite $offerFavorite): self
{
if (!$this->offerFavorites->contains($offerFavorite)) {
$this->offerFavorites[] = $offerFavorite;
$offerFavorite->setUser($this);
}
return $this;
}
public function removeOfferFavorite(OfferFavorite $offerFavorite): self
{
if ($this->offerFavorites->removeElement($offerFavorite)) {
// set the owning side to null (unless already changed)
if ($offerFavorite->getUser() === $this) {
$offerFavorite->setUser(null);
}
}
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection|AuthLog[]
*/
public function getAuthLogs(): Collection
{
return $this->authLogs;
}
public function addAuthLog(AuthLog $authLog): self
{
if (!$this->authLogs->contains($authLog)) {
$this->authLogs[] = $authLog;
$authLog->setUser($this);
}
return $this;
}
public function removeAuthLog(AuthLog $authLog): self
{
if ($this->authLogs->removeElement($authLog)) {
// set the owning side to null (unless already changed)
if ($authLog->getUser() === $this) {
$authLog->setUser(null);
}
}
return $this;
}
/**
* @return Collection|OfferVisit[]
*/
public function getOfferVisits(): Collection
{
return $this->offerVisits;
}
public function addOfferVisit(OfferVisit $offerVisit): self
{
if (!$this->offerVisits->contains($offerVisit)) {
$this->offerVisits[] = $offerVisit;
$offerVisit->setUser($this);
}
return $this;
}
public function removeOfferVisit(OfferVisit $offerVisit): self
{
if ($this->offerVisits->removeElement($offerVisit)) {
// set the owning side to null (unless already changed)
if ($offerVisit->getUser() === $this) {
$offerVisit->setUser(null);
}
}
return $this;
}
public function getPublicName(): ?string
{
return $this->isSociety()
? $this->getSociety()->getName()
: $this->getUniqueProfile()->getPublicName();
}
/**
* @return Collection|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|OfferAlert[]
*/
public function getOfferAlerts(): Collection
{
return $this->offerAlerts;
}
public function addOfferAlert(OfferAlert $offerAlert): self
{
if (!$this->offerAlerts->contains($offerAlert)) {
$this->offerAlerts[] = $offerAlert;
$offerAlert->setUser($this);
}
return $this;
}
public function removeOfferAlert(OfferAlert $offerAlert): self
{
if ($this->offerAlerts->removeElement($offerAlert)) {
// set the owning side to null (unless already changed)
if ($offerAlert->getUser() === $this) {
$offerAlert->setUser(null);
}
}
return $this;
}
public function isOauth(): bool
{
return $this->password == 'nopass';
}
/**
* @return Collection<int, ProfileFavorite>
*/
public function getProfileFavorites(): Collection
{
return $this->profileFavorites;
}
public function addProfileFavorite(ProfileFavorite $profileFavorite): self
{
if (!$this->profileFavorites->contains($profileFavorite)) {
$this->profileFavorites[] = $profileFavorite;
$profileFavorite->setUser($this);
}
return $this;
}
public function removeProfileFavorite(ProfileFavorite $profileFavorite): self
{
if ($this->profileFavorites->removeElement($profileFavorite)) {
// set the owning side to null (unless already changed)
if ($profileFavorite->getUser() === $this) {
$profileFavorite->setUser(null);
}
}
return $this;
}
public function isIsVerified(): ?bool
{
return $this->isVerified;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getCivility(): ?int
{
return $this->civility;
}
public function setCivility(?int $civility): self
{
$this->civility = $civility;
return $this;
}
public function getJobSociety(): ?string
{
return $this->jobSociety;
}
public function setJobSociety(?string $jobSociety): self
{
$this->jobSociety = $jobSociety;
return $this;
}
public function getCompteSociety(): ?Society
{
return $this->CompteSociety;
}
public function setCompteSociety(?Society $CompteSociety): self
{
$this->CompteSociety = $CompteSociety;
return $this;
}
public function isCompteTestIsNotActive(): ?bool
{
return $this->compteTestIsNotActive;
}
public function setCompteTestIsNotActive(?bool $compteTestIsNotActive): self
{
$this->compteTestIsNotActive = $compteTestIsNotActive;
return $this;
}
public function getGoogleSubId(): ?string
{
return $this->googleSubId;
}
public function setGoogleSubId(?string $googleSubId): self
{
$this->googleSubId = $googleSubId;
return $this;
}
public function isProfileCompleted(): bool
{
return !$this->profiles->isEmpty();
}
}