<?php
namespace App\Entity;
use Serializable;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\UserRepository;
use Doctrine\ORM\Mapping\InheritanceType;
use Doctrine\ORM\Mapping\DiscriminatorMap;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\DiscriminatorColumn;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[UniqueEntity(fields: ['email'], message: 'Un compte existe déjà avec cet email')]
#[InheritanceType('JOINED')]
#[DiscriminatorColumn(name: 'type', type: 'string')]
#[DiscriminatorMap(['coach' => 'Coach', 'club' => 'Club', 'operator' => 'Operator', 'user' => 'User', 'trainee' => 'Trainee', 'admin' => 'Admin'])]
abstract class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $firstname;
#[ORM\Column(type: 'string', length: 255)]
private $lastname;
#[ORM\Column(type: 'string', length: 50, nullable: true)]
private $telephone;
#[ORM\Column(type: 'string', length: 180, unique: true)]
private $email;
/**
* @var string The hashed password
*/
#[ORM\Column(type: 'string')]
private $password;
#[ORM\Column(type: 'boolean')]
private $activated;
#[ORM\Column(type: 'boolean')]
private $notification;
#[ORM\OneToOne(targetEntity: Address::class, inversedBy: 'owner', cascade: ['persist', 'remove'])]
private $address;
#[ORM\Column(type: 'datetime', nullable: true)]
private $registeredAt;
#[ORM\Column(type: 'string', length: 255)]
private $token;
#[ORM\ManyToMany(targetEntity: Role::class, inversedBy: 'users')]
private $userRoles;
#[ORM\Column(type: 'string', length: 255)]
private $photo;
#[ORM\Column(type: 'string', length: 255)]
private $slug;
#[ORM\Column(type: 'boolean')]
private $isPro;
#[ORM\OneToMany(targetEntity: Subscription::class, mappedBy: 'pro')]
private $subscriptions;
#[ORM\OneToMany(targetEntity: Course::class, mappedBy: 'owner')]
private $courses;
#[ORM\OneToOne(targetEntity: ProInfo::class, inversedBy: 'pro', cascade: ['persist', 'remove'])]
private $proInfo;
#[ORM\Column(type: 'boolean', nullable: true)]
private $hasAccess;
#[ORM\ManyToMany(targetEntity: Language::class, inversedBy: 'users')]
private $languages;
#[ORM\OneToOne(targetEntity: StripeInfo::class, inversedBy: 'user', cascade: ['persist', 'remove'])]
private $stripeInfo;
#[ORM\OneToMany(targetEntity: Message::class, mappedBy: 'sender')]
private $sentMessages;
#[ORM\OneToMany(targetEntity: Participant::class, mappedBy: 'user')]
private $participations;
#[ORM\OneToMany(targetEntity: Conversation::class, mappedBy: 'trainee')]
private $traineeConversations;
#[ORM\OneToMany(targetEntity: Conversation::class, mappedBy: 'pro')]
private $proConversations;
#[ORM\OneToMany(targetEntity: ProViewsStat::class, mappedBy: 'pro', orphanRemoval: true)]
private $proViewsStats;
#[ORM\Column(type: 'string', length: 255)]
private $status;
#[ORM\Column(type: 'boolean')]
private $hasAcceptedTerms;
#[ORM\ManyToMany(targetEntity: Trainee::class, mappedBy: 'proFavorites')]
private $traineesFavorites;
#[ORM\OneToMany(targetEntity: Invoice::class, mappedBy: 'pro')]
private $invoices;
#[ORM\Column(type: 'boolean', nullable: true)]
private $isAmbassador;
#[ORM\Column(type: 'string', length: 255)]
private $language;
#[ORM\OneToMany(targetEntity: Address::class, mappedBy: 'pro', orphanRemoval: true)]
private $areas;
#[ORM\Column(length: 255, nullable: true)]
private ?string $timezone = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $phoneCode = null;
#[ORM\Column(nullable: true)]
private ?bool $newsletter = null;
#[ORM\OneToMany(mappedBy: 'pro', targetEntity: ProDescription::class)]
private Collection $proDescriptions;
#[ORM\ManyToMany(targetEntity: Note::class, mappedBy: 'associatedPros')]
private Collection $notes;
#[ORM\OneToMany(mappedBy: 'pro', targetEntity: NoteRequest::class)]
private Collection $noteRequests;
public function __construct()
{
$this->userRoles = new ArrayCollection();
$this->subscriptions = new ArrayCollection();
$this->courses = new ArrayCollection();
$this->languages = new ArrayCollection();
$this->sentMessages = new ArrayCollection();
$this->participations = new ArrayCollection();
$this->traineeConversations = new ArrayCollection();
$this->proConversations = new ArrayCollection();
$this->proViewsStats = new ArrayCollection();
$this->traineesFavorites = new ArrayCollection();
$this->invoices = new ArrayCollection();
$this->areas = new ArrayCollection();
$this->proDescriptions = new ArrayCollection();
$this->notes = new ArrayCollection();
$this->noteRequests = new ArrayCollection();
}
//Getters and Setters
public function getId(): ?int
{
return $this->id;
}
public function fullname() {
return $this->firstname . ' ' . $this->lastname;
}
public function getProType() {
if ($this instanceof Coach) {
$type = 'coach';
} else if ($this instanceof Club) {
$type = 'club';
} else {
$type = 'operator';
}
return $type;
}
public function getCurrentSubscription() {
return $this->subscriptions->last() ?? null;
}
/**
* Get the value of firstname
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* Set the value of firstname
*
* @return self
*/
public function setFirstname($firstname)
{
$this->firstname = $firstname;
return $this;
}
/**
* Get the value of lastname
*/
public function getLastname()
{
return $this->lastname;
}
/**
* Set the value of lastname
*
* @return self
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
return $this;
}
/**
* Get the value of telephone
*/
public function getTelephone()
{
return $this->telephone;
}
/**
* Set the value of telephone
*
* @return self
*/
public function setTelephone($telephone)
{
$this->telephone = $telephone;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* @see UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Get the value of activated
*/
public function getActivated()
{
return $this->activated;
}
/**
* Set the value of activated
*
* @return self
*/
public function setActivated($activated)
{
$this->activated = $activated;
return $this;
}
/**
* Get the value of notification
*/
public function getNotification()
{
return $this->notification;
}
/**
* Set the value of notification
*
* @return self
*/
public function setNotification($notification)
{
$this->notification = $notification;
return $this;
}
public function getAddress(): ?Address
{
return $this->address;
}
public function setAddress(?Address $address): self
{
$this->address = $address;
return $this;
}
public function getRegisteredAt(): ?\DateTimeInterface
{
return $this->registeredAt;
}
public function setRegisteredAt(?\DateTimeInterface $registeredAt): self
{
$this->registeredAt = $registeredAt;
return $this;
}
public function getToken(): ?string
{
return $this->token;
}
public function setToken(string $token): self
{
$this->token = $token;
return $this;
}
public function getSalt(){}
public function eraseCredentials(){}
public function getRoles()
{
$roles = $this->userRoles->map(function($role){
return $role->getTitle();
})->toArray();
$roles[] = 'ROLE_USER';
return $roles;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername()
{
return $this->email;
}
/**
* @return Collection|Role[]
*/
public function getUserRoles(): Collection
{
return $this->userRoles;
}
public function addUserRole(Role $userRole): self
{
if ($this->userRoles == null || !$this->userRoles->contains($userRole)) {
$this->userRoles[] = $userRole;
}
return $this;
}
public function removeUserRole(Role $userRole): self
{
$this->userRoles->removeElement($userRole);
return $this;
}
public function getPhoto()
{
return $this->photo;
}
public function setPhoto($photo): self
{
$this->photo = $photo;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getIsPro(): ?bool
{
return $this->isPro;
}
public function setIsPro(bool $isPro): self
{
$this->isPro = $isPro;
return $this;
}
/**
* @return Collection|Subscription[]
*/
public function getSubscriptions(): Collection
{
return $this->subscriptions;
}
public function addSubscription(Subscription $subscription): self
{
if (!$this->subscriptions->contains($subscription)) {
$this->subscriptions[] = $subscription;
$subscription->setPro($this);
}
return $this;
}
public function removeSubscription(Subscription $subscription): self
{
if ($this->subscriptions->removeElement($subscription)) {
// set the owning side to null (unless already changed)
if ($subscription->getPro() === $this) {
$subscription->setPro(null);
}
}
return $this;
}
/**
* @return Collection|Course[]
*/
public function getCourses(): Collection
{
return $this->courses;
}
public function addCourse(Course $course): self
{
if (!$this->courses->contains($course)) {
$this->courses[] = $course;
$course->setOwner($this);
}
return $this;
}
public function removeCourse(Course $course): self
{
if ($this->courses->removeElement($course)) {
// set the owning side to null (unless already changed)
if ($course->getOwner() === $this) {
$course->setOwner(null);
}
}
return $this;
}
public function getProInfo(): ?ProInfo
{
return $this->proInfo;
}
public function setProInfo(?ProInfo $proInfo): self
{
$this->proInfo = $proInfo;
return $this;
}
public function getHasAccess(): ?bool
{
return $this->hasAccess;
}
public function setHasAccess(bool $hasAccess): self
{
$this->hasAccess = $hasAccess;
return $this;
}
/**
* @return Collection|Language[]
*/
public function getLanguages(): Collection
{
return $this->languages;
}
public function addLanguage(Language $language): self
{
if (!$this->languages->contains($language)) {
$this->languages[] = $language;
}
return $this;
}
public function removeLanguage(Language $language): self
{
$this->languages->removeElement($language);
return $this;
}
public function getStripeInfo(): ?StripeInfo
{
return $this->stripeInfo;
}
public function setStripeInfo(?StripeInfo $stripeInfo): self
{
$this->stripeInfo = $stripeInfo;
return $this;
}
/**
* @return Collection|Message[]
*/
public function getSentMessages(): Collection
{
return $this->sentMessages;
}
public function addSentMessage(Message $sentMessage): self
{
if (!$this->sentMessages->contains($sentMessage)) {
$this->sentMessages[] = $sentMessage;
$sentMessage->setSender($this);
}
return $this;
}
public function removeSentMessage(Message $sentMessage): self
{
if ($this->sentMessages->removeElement($sentMessage)) {
// set the owning side to null (unless already changed)
if ($sentMessage->getSender() === $this) {
$sentMessage->setSender(null);
}
}
return $this;
}
/**
* @return Collection|Participant[]
*/
public function getParticipations(): Collection
{
return $this->participations;
}
public function addParticipation(Participant $participation): self
{
if (!$this->participations->contains($participation)) {
$this->participations[] = $participation;
$participation->setUser($this);
}
return $this;
}
public function removeParticipation(Participant $participation): self
{
if ($this->participations->removeElement($participation)) {
// set the owning side to null (unless already changed)
if ($participation->getUser() === $this) {
$participation->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Conversation[]
*/
public function getTraineeConversations(): Collection
{
return $this->traineeConversations;
}
public function addTraineeConversation(Conversation $traineeConversation): self
{
if (!$this->traineeConversations->contains($traineeConversation)) {
$this->traineeConversations[] = $traineeConversation;
$traineeConversation->setTrainee($this);
}
return $this;
}
public function removeTraineeConversation(Conversation $traineeConversation): self
{
if ($this->traineeConversations->removeElement($traineeConversation)) {
// set the owning side to null (unless already changed)
if ($traineeConversation->getTrainee() === $this) {
$traineeConversation->setTrainee(null);
}
}
return $this;
}
/**
* @return Collection|Conversation[]
*/
public function getProConversations(): Collection
{
return $this->proConversations;
}
public function addProConversation(Conversation $proConversation): self
{
if (!$this->proConversations->contains($proConversation)) {
$this->proConversations[] = $proConversation;
$proConversation->setPro($this);
}
return $this;
}
public function removeProConversation(Conversation $proConversation): self
{
if ($this->proConversations->removeElement($proConversation)) {
// set the owning side to null (unless already changed)
if ($proConversation->getPro() === $this) {
$proConversation->setPro(null);
}
}
return $this;
}
/**
* @return Collection|ProViewsStat[]
*/
public function getProViewsStats(): Collection
{
return $this->proViewsStats;
}
public function addProViewsStat(ProViewsStat $proViewsStat): self
{
if (!$this->proViewsStats->contains($proViewsStat)) {
$this->proViewsStats[] = $proViewsStat;
$proViewsStat->setPro($this);
}
return $this;
}
public function removeProViewsStat(ProViewsStat $proViewsStat): self
{
if ($this->proViewsStats->removeElement($proViewsStat)) {
// set the owning side to null (unless already changed)
if ($proViewsStat->getPro() === $this) {
$proViewsStat->setPro(null);
}
}
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getHasAcceptedTerms(): ?bool
{
return $this->hasAcceptedTerms;
}
public function setHasAcceptedTerms(bool $hasAcceptedTerms): self
{
$this->hasAcceptedTerms = $hasAcceptedTerms;
return $this;
}
/**
* @return Collection|Trainee[]
*/
public function getTraineesFavorites(): Collection
{
return $this->traineesFavorites;
}
public function addTraineesFavorite(Trainee $traineesFavorite): self
{
if (!$this->traineesFavorites->contains($traineesFavorite)) {
$this->traineesFavorites[] = $traineesFavorite;
$traineesFavorite->addProFavorite($this);
}
return $this;
}
public function removeTraineesFavorite(Trainee $traineesFavorite): self
{
if ($this->traineesFavorites->removeElement($traineesFavorite)) {
$traineesFavorite->removeProFavorite($this);
}
return $this;
}
/**
* @return Collection|Invoice[]
*/
public function getInvoices(): Collection
{
return $this->invoices;
}
public function addInvoice(Invoice $invoice): self
{
if (!$this->invoices->contains($invoice)) {
$this->invoices[] = $invoice;
$invoice->setPro($this);
}
return $this;
}
public function removeInvoice(Invoice $invoice): self
{
if ($this->invoices->removeElement($invoice)) {
// set the owning side to null (unless already changed)
if ($invoice->getPro() === $this) {
$invoice->setPro(null);
}
}
return $this;
}
public function getIsAmbassador(): ?bool
{
return $this->isAmbassador;
}
public function setIsAmbassador(?bool $isAmbassador): self
{
$this->isAmbassador = $isAmbassador;
return $this;
}
public function getLanguage(): ?string
{
return $this->language;
}
public function setLanguage(string $language): self
{
$this->language = $language;
return $this;
}
/**
* @return Collection<int, Address>
*/
public function getAreas(): Collection
{
return $this->areas;
}
public function addArea(Address $area): self
{
if (!$this->areas->contains($area)) {
$this->areas[] = $area;
$area->setPro($this);
}
return $this;
}
public function removeArea(Address $area): self
{
if ($this->areas->removeElement($area)) {
// set the owning side to null (unless already changed)
if ($area->getPro() === $this) {
$area->setPro(null);
}
}
return $this;
}
public function getTimezone(): ?string
{
return $this->timezone;
}
public function setTimezone(?string $timezone): static
{
$this->timezone = $timezone;
return $this;
}
public function getPhoneCode(): ?string
{
return $this->phoneCode;
}
public function setPhoneCode(?string $phoneCode): static
{
$this->phoneCode = $phoneCode;
return $this;
}
public function getNewsletter(): ?bool
{
return $this->newsletter;
}
public function setNewsletter(?bool $newsletter): static
{
$this->newsletter = $newsletter;
return $this;
}
/**
* @return Collection<int, ProDescription>
*/
public function getProDescriptions(): Collection
{
return $this->proDescriptions;
}
public function addProDescription(ProDescription $proDescription): static
{
if (!$this->proDescriptions->contains($proDescription)) {
$this->proDescriptions->add($proDescription);
$proDescription->setPro($this);
}
return $this;
}
public function removeProDescription(ProDescription $proDescription): static
{
if ($this->proDescriptions->removeElement($proDescription)) {
// set the owning side to null (unless already changed)
if ($proDescription->getPro() === $this) {
$proDescription->setPro(null);
}
}
return $this;
}
/**
* @return Collection<int, Note>
*/
public function getNotes(): Collection
{
return $this->notes;
}
public function addNote(Note $note): static
{
if (!$this->notes->contains($note)) {
$this->notes->add($note);
$note->addAssociatedPro($this);
}
return $this;
}
public function removeNote(Note $note): static
{
if ($this->notes->removeElement($note)) {
$note->removeAssociatedPro($this);
}
return $this;
}
/**
* @return Collection<int, NoteRequest>
*/
public function getNoteRequests(): Collection
{
return $this->noteRequests;
}
public function addNoteRequest(NoteRequest $noteRequest): static
{
if (!$this->noteRequests->contains($noteRequest)) {
$this->noteRequests->add($noteRequest);
$noteRequest->setPro($this);
}
return $this;
}
public function removeNoteRequest(NoteRequest $noteRequest): static
{
if ($this->noteRequests->removeElement($noteRequest)) {
// set the owning side to null (unless already changed)
if ($noteRequest->getPro() === $this) {
$noteRequest->setPro(null);
}
}
return $this;
}
}