<?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 Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\File;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\InheritanceType('JOINED')]
#[ORM\DiscriminatorColumn(name: "type", type: "string")]
#[ORM\DiscriminatorMap(['commercial' => Commercial::class, 'prescriber' => Prescriber::class, 'employee' => Employee::class])]
#[Vich\Uploadable]
abstract class User implements UserInterface, PasswordAuthenticatedUserInterface
{
use IdentifiableTrait;
#[ORM\Column(length: 180, unique: true)]
private ?string $username = null;
#[ORM\Column]
protected array $roles = [];
/**
* @var string|null The hashed password
*/
#[ORM\Column]
private ?string $password = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $email = null;
#[ORM\OneToMany(mappedBy: 'prescriberValidationUser', targetEntity: Invoice::class)]
private Collection $prescriberValidatedInvoices;
#[ORM\OneToMany(mappedBy: 'origin', targetEntity: PrescriberPoint::class)]
private Collection $prescriberPoints;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: LogHistory::class)]
private Collection $logHistory;
#[ORM\Column(nullable: true)]
private ?bool $active = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $lastConnexionDate = null;
#[ORM\OneToMany(mappedBy: 'sender', targetEntity: Message::class, orphanRemoval: true)]
private Collection $senderMessages;
#[ORM\ManyToMany(targetEntity: MessageReceiver::class, mappedBy: 'users')]
private Collection $messageReceivers;
#[ORM\Column(type: "string", length: 255, nullable: true)]
private ?string $photoFilename = '';
#[Vich\UploadableField(mapping: "user_photo", fileNameProperty: "photoFilename")]
private ?File $photoFile = null;
#[ORM\OneToMany(mappedBy: 'targetUser', targetEntity: LogHistory::class)]
private Collection $logHistories;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Booking::class)]
private Collection $bookings;
#[ORM\OneToMany(mappedBy: 'attributedTo', targetEntity: PrescriptionPad::class)]
private Collection $prescriptionPads;
#[ORM\ManyToMany(targetEntity: BookingUserGroup::class, mappedBy: 'user')]
private Collection $bookingUserGroups;
#[ORM\ManyToMany(targetEntity: BookingEvent::class, mappedBy: 'users')]
private Collection $bookingEvents;
public function __construct()
{
$this->prescriberValidatedInvoices = new ArrayCollection();
$this->prescriberPoints = new ArrayCollection();
$this->logHistory = new ArrayCollection();
$this->senderMessages = new ArrayCollection();
$this->messageReceivers = new ArrayCollection();
$this->logHistories = new ArrayCollection();
$this->bookings = new ArrayCollection();
$this->prescriptionPads = new ArrayCollection();
$this->bookingUserGroups = new ArrayCollection();
$this->bookingEvents = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string)$this->username;
}
public function getFullName(): ?string
{
return (string)$this->username;
}
public function setUsername(string $username): self
{
$this->username = strtolower($username);
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string)$this->username;
}
/**
* @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;
}
public function hasRole(string $role): bool
{
return in_array($role, $this->roles, true);
}
/**
* @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 getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = strtolower($email);
return $this;
}
/**
* @return Collection<int, Invoice>
*/
public function getPrescriberValidatedInvoices(): Collection
{
return $this->prescriberValidatedInvoices;
}
public function addPrescriberValidatedInvoice(Invoice $prescriberValidatedInvoice): self
{
if (!$this->prescriberValidatedInvoices->contains($prescriberValidatedInvoice)) {
$this->prescriberValidatedInvoices->add($prescriberValidatedInvoice);
$prescriberValidatedInvoice->setPrescriberValidationUser($this);
}
return $this;
}
public function removePrescriberValidatedInvoice(Invoice $prescriberValidatedInvoice): self
{
if ($this->prescriberValidatedInvoices->removeElement($prescriberValidatedInvoice)) {
// set the owning side to null (unless already changed)
if ($prescriberValidatedInvoice->getPrescriberValidationUser() === $this) {
$prescriberValidatedInvoice->setPrescriberValidationUser(null);
}
}
return $this;
}
/**
* @return Collection<int, PrescriberPoint>
*/
public function getPrescriberPoints(): Collection
{
return $this->prescriberPoints;
}
public function addPrescriberPoint(PrescriberPoint $prescriberPoint): self
{
if (!$this->prescriberPoints->contains($prescriberPoint)) {
$this->prescriberPoints->add($prescriberPoint);
$prescriberPoint->setOrigin($this);
}
return $this;
}
public function removePrescriberPoint(PrescriberPoint $prescriberPoint): self
{
if ($this->prescriberPoints->removeElement($prescriberPoint)) {
// set the owning side to null (unless already changed)
if ($prescriberPoint->getOrigin() === $this) {
$prescriberPoint->setOrigin(null);
}
}
return $this;
}
/**
* @return Collection<int, LogHistory>
*/
public function getLogHistory(): Collection
{
return $this->logHistory;
}
public function addLogHistory(LogHistory $logHistory): self
{
if (!$this->logHistory->contains($logHistory)) {
$this->logHistory->add($logHistory);
$logHistory->setUser($this);
}
return $this;
}
public function removeLogHistory(LogHistory $logHistory): self
{
if ($this->logHistory->removeElement($logHistory)) {
// set the owning side to null (unless already changed)
if ($logHistory->getUser() === $this) {
$logHistory->setUser(null);
}
}
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(?bool $active): self
{
$this->active = $active;
return $this;
}
public function getLastConnexionDate(): ?\DateTimeImmutable
{
return $this->lastConnexionDate;
}
public function setLastConnexionDate(?\DateTimeImmutable $lastConnexionDate): self
{
$this->lastConnexionDate = $lastConnexionDate;
return $this;
}
/**
* @return Collection<int, Message>
*/
public function getSenderMessages(): Collection
{
return $this->senderMessages;
}
public function addSenderMessage(Message $senderMessage): self
{
if (!$this->senderMessages->contains($senderMessage)) {
$this->senderMessages->add($senderMessage);
$senderMessage->setSender($this);
}
return $this;
}
public function removeSenderMessage(Message $senderMessage): self
{
if ($this->senderMessages->removeElement($senderMessage)) {
// set the owning side to null (unless already changed)
if ($senderMessage->getSender() === $this) {
$senderMessage->setSender(null);
}
}
return $this;
}
/**
* @return Collection<int, MessageReceiver>
*/
public function getMessageReceivers(): Collection
{
return $this->messageReceivers;
}
public function addMessageReceiver(MessageReceiver $messageReceiver): self
{
if (!$this->messageReceivers->contains($messageReceiver)) {
$this->messageReceivers->add($messageReceiver);
$messageReceiver->addUser($this);
}
return $this;
}
public function removeMessageReceiver(MessageReceiver $messageReceiver): self
{
if ($this->messageReceivers->removeElement($messageReceiver)) {
$messageReceiver->removeUser($this);
}
return $this;
}
public function getPhotoFilename(): ?string
{
return $this->photoFilename;
}
public function setPhotoFilename(?string $photoFilename): self
{
$this->photoFilename = $photoFilename;
return $this;
}
public function getPhotoFile(): ?File
{
return $this->photoFile;
}
public function setPhotoFile(?File $photoFile): self
{
$this->photoFile = $photoFile;
if (null !== $photoFile) {
// Ceci est nécessaire pour forcer la mise à jour de l'entité lorsque le fichier est modifié
$this->updatedAt = new \DateTimeImmutable();
}
return $this;
}
/**
* @return Collection<int, LogHistory>
*/
public function getLogHistories(): Collection
{
return $this->logHistories;
}
/**
* @return Collection<int, Booking>
*/
public function getBookings(): Collection
{
return $this->bookings;
}
public function addBooking(Booking $booking): static
{
if (!$this->bookings->contains($booking)) {
$this->bookings->add($booking);
$booking->setOwner($this);
}
return $this;
}
public function removeBooking(Booking $booking): static
{
if ($this->bookings->removeElement($booking)) {
// set the owning side to null (unless already changed)
if ($booking->getOwner() === $this) {
$booking->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, PrescriptionPad>
*/
public function getPrescriptionPads(): Collection
{
return $this->prescriptionPads;
}
public function addPrescriptionPad(PrescriptionPad $prescriptionPad): static
{
if (!$this->prescriptionPads->contains($prescriptionPad)) {
$this->prescriptionPads->add($prescriptionPad);
$prescriptionPad->setAttributedTo($this);
}
return $this;
}
public function removePrescriptionPad(PrescriptionPad $prescriptionPad): static
{
if ($this->prescriptionPads->removeElement($prescriptionPad)) {
// set the owning side to null (unless already changed)
if ($prescriptionPad->getAttributedTo() === $this) {
$prescriptionPad->setAttributedTo(null);
}
}
return $this;
}
/**
* @return Collection<int, BookingUserGroup>
*/
public function getBookingUserGroups(): Collection
{
return $this->bookingUserGroups;
}
public function addBookingUserGroup(BookingUserGroup $bookingUserGroup): static
{
if (!$this->bookingUserGroups->contains($bookingUserGroup)) {
$this->bookingUserGroups->add($bookingUserGroup);
$bookingUserGroup->addUser($this);
}
return $this;
}
public function removeBookingUserGroup(BookingUserGroup $bookingUserGroup): static
{
if ($this->bookingUserGroups->removeElement($bookingUserGroup)) {
$bookingUserGroup->removeUser($this);
}
return $this;
}
/**
* @return Collection<int, BookingEvent>
*/
public function getPrescriberSpeakersBookingEvents(): Collection
{
return $this->bookingEvents;
}
public function addBookingEvent(BookingEvent $bookingEvent): static
{
if (!$this->bookingEvents->contains($bookingEvent)) {
$this->bookingEvents->add($bookingEvent);
$bookingEvent->addUser($this);
}
return $this;
}
public function removeBookingEvent(BookingEvent $bookingEvent): static
{
if ($this->bookingEvents->removeElement($bookingEvent)) {
$bookingEvent->removeUser($this);
}
return $this;
}
}