<?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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity("email")
* @ORM\HasLifecycleCallbacks()
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
use RemoveImageTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Assert\NotBlank()
* @Assert\Email()
*/
private $email;
/**
* @ORM\Column(type="boolean")
*/
private $emailConfirmed = false;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\ManyToMany(targetEntity=Speaker::class, mappedBy="subscribers")
*/
private $subscribedToSpeakers;
/**
* @ORM\OneToMany(targetEntity=Review::class, mappedBy="user", orphanRemoval=true)
*/
private $reviews;
/**
* @ORM\Column(type="string", length=255)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $lastName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $phone;
/**
* @ORM\OneToMany(targetEntity=Order::class, mappedBy="user")
*/
private $orders;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $timezone;
/**
* @ORM\OneToOne(targetEntity="Speaker", mappedBy="user", cascade={"persist"})
* @Assert\Valid()
*/
private $speaker;
/**
* @ORM\Column(type="float")
*/
private $rating = 0;
/**
* @ORM\Column(type="integer")
*/
private $ratingVote = 0;
/**
* @ORM\ManyToMany(targetEntity=SpeakerConsultation::class, mappedBy="participants")
*/
private $consultations;
/**
* @ORM\OneToMany(targetEntity=Notification::class, mappedBy="user", orphanRemoval=true)
*/
private $notifications;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $zoomUserId;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $googleAccessToken;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $googleCalendarId;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $avatar;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Email()
*/
private $notificationEmail;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $notificationSms;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $rebillId;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $rebillPaymentInfo;
/**
* @ORM\OneToMany(targetEntity=Complaint::class, mappedBy="author", orphanRemoval=true)
*/
private $complaints;
/**
* @ORM\ManyToMany(targetEntity=SpeakerCourse::class, mappedBy="participants")
*/
private $courses;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $telegramId;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Speaker", mappedBy="user", cascade={"remove"})
*/
private $speakers;
public function __construct()
{
$this->speakers = new ArrayCollection();
$this->subscribedToSpeakers = new ArrayCollection();
$this->reviews = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->consultations = new ArrayCollection();
$this->notifications = new ArrayCollection();
$this->complaints = new ArrayCollection();
$this->courses = new ArrayCollection();
}
/**
* @ORM\PostRemove()
*/
public function postRemoveEvent()
{
$this->removeImage($this->getAvatar());
}
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;
}
public function getEmailConfirmed(): ?bool
{
return $this->emailConfirmed;
}
public function setEmailConfirmed(bool $emailConfirmed): self
{
$this->emailConfirmed = $emailConfirmed;
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;
}
public function addRole(string $role): self
{
$roles = $this->getRoles();
if (!in_array($role, $roles)) {
$roles[] = $role;
$this->setRoles($roles);
}
return $this;
}
public function removeRole(string $role): self
{
$roles = $this->getRoles();
$index = array_search($role, $roles);
if ($index) {
unset($roles[$index]);
$this->setRoles($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;
}
/**
* @return Collection|Speaker[]
*/
public function getSubscribedToSpeakers(): Collection
{
return $this->subscribedToSpeakers;
}
public function addSubscribedToSpeaker(Speaker $subscribedToSpeaker): self
{
if (!$this->subscribedToSpeakers->contains($subscribedToSpeaker)) {
$this->subscribedToSpeakers[] = $subscribedToSpeaker;
$subscribedToSpeaker->addSubscriber($this);
}
return $this;
}
public function removeSubscribedToSpeaker(Speaker $subscribedToSpeaker): self
{
if ($this->subscribedToSpeakers->removeElement($subscribedToSpeaker)) {
$subscribedToSpeaker->removeSubscriber($this);
}
return $this;
}
/**
* @return Collection|Review[]
*/
public function getReviews(): Collection
{
return $this->reviews;
}
public function addReview(Review $review): self
{
if (!$this->reviews->contains($review)) {
$this->reviews[] = $review;
$review->setUser($this);
}
return $this;
}
public function removeReview(Review $review): self
{
if ($this->reviews->removeElement($review)) {
// set the owning side to null (unless already changed)
if ($review->getUser() === $this) {
$review->setUser(null);
}
}
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function __toString(): string
{
return trim($this->getFirstName() . ' ' . $this->getLastName());
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
/**
* @return Collection|Order[]
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setUser($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getUser() === $this) {
$order->setUser(null);
}
}
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getTimezone(): ?string
{
return empty($this->timezone) ? date_default_timezone_get() : $this->timezone;
}
public function setTimezone(?string $timezone): self
{
$this->timezone = $timezone;
return $this;
}
/**
* @return ?Speaker
*/
public function getSpeaker(): ?Speaker
{
return $this->speaker;
}
/**
* @param Speaker $speaker
* @return User
*/
public function setSpeaker(Speaker $speaker): self
{
$this->speaker = $speaker;
$this->speaker->setUser($this);
return $this;
}
public function getRating(): ?float
{
return $this->rating;
}
public function setRating(float $rating): self
{
$this->rating = $rating;
return $this;
}
public function getRatingVote(): ?int
{
return $this->ratingVote;
}
public function setRatingVote(int $ratingVote): self
{
$this->ratingVote = $ratingVote;
return $this;
}
/**
* @return Collection|SpeakerConsultation[]
*/
public function getConsultations(): Collection
{
return $this->consultations;
}
public function addConsultation(SpeakerConsultation $consultation): self
{
if (!$this->consultations->contains($consultation)) {
$this->consultations[] = $consultation;
$consultation->addParticipant($this);
}
return $this;
}
public function removeConsultation(SpeakerConsultation $consultation): self
{
if ($this->consultations->removeElement($consultation)) {
// set the owning side to null (unless already changed)
if ($consultation->getSpeaker() === $this) {
$consultation->removeParticipant($this);
}
}
return $this;
}
/**
* @return Collection|Notification[]
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notification $notification): self
{
if (!$this->notifications->contains($notification)) {
$this->notifications[] = $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;
}
public function getZoomUserId(): ?string
{
return $this->zoomUserId;
}
public function setZoomUserId(?string $zoomUserId): self
{
$this->zoomUserId = $zoomUserId;
return $this;
}
public function getGoogleAccessToken(): ?string
{
return $this->googleAccessToken;
}
public function setGoogleAccessToken(?string $googleAccessToken): self
{
$this->googleAccessToken = $googleAccessToken;
return $this;
}
public function getGoogleCalendarId(): ?string
{
return $this->googleCalendarId;
}
public function setGoogleCalendarId(?string $googleCalendarId): self
{
$this->googleCalendarId = $googleCalendarId;
return $this;
}
public function getAvatar(): ?string
{
return $this->avatar;
}
public function setAvatar(?string $avatar): self
{
$this->avatar = $avatar;
if ($this->getSpeaker() && $this->getSpeaker()->getPhotoAvatar() != $avatar) {
$this->removeImage($this->getSpeaker()->getPhotoAvatar());
$this->getSpeaker()->setPhotoAvatar($avatar);
}
return $this;
}
public function getNotificationEmail(): ?string
{
return $this->notificationEmail;
}
public function setNotificationEmail(?string $notificationEmail): self
{
$this->notificationEmail = $notificationEmail;
return $this;
}
public function getNotificationSms(): ?string
{
return $this->notificationSms;
}
public function setNotificationSms(?string $notificationSms): self
{
$this->notificationSms = $notificationSms;
return $this;
}
public function getRebillId(): ?string
{
return $this->rebillId;
}
public function setRebillId(?string $rebillId): self
{
$this->rebillId = $rebillId;
return $this;
}
public function getRebillPaymentInfo(): ?array
{
return $this->rebillPaymentInfo;
}
public function setRebillPaymentInfo(?array $rebillPaymentInfo): self
{
$this->rebillPaymentInfo = $rebillPaymentInfo;
return $this;
}
/**
* @return Collection<int, Complaint>
*/
public function getComplaints(): Collection
{
return $this->complaints;
}
public function addComplaint(Complaint $complaint): self
{
if (!$this->complaints->contains($complaint)) {
$this->complaints[] = $complaint;
$complaint->setAuthor($this);
}
return $this;
}
public function removeComplaint(Complaint $complaint): self
{
if ($this->complaints->removeElement($complaint)) {
// set the owning side to null (unless already changed)
if ($complaint->getAuthor() === $this) {
$complaint->setAuthor(null);
}
}
return $this;
}
/**
* @return Collection<int, SpeakerCourse>
*/
public function getCourses(): Collection
{
return $this->courses;
}
public function addCourse(SpeakerCourse $course): self
{
if (!$this->courses->contains($course)) {
$this->courses[] = $course;
$course->addParticipant($this);
}
return $this;
}
public function removeCourse(SpeakerCourse $course): self
{
if ($this->courses->removeElement($course)) {
$course->removeParticipant($this);
}
return $this;
}
public function getTelegramId(): ?string
{
return $this->telegramId;
}
public function setTelegramId(?string $telegramId): self
{
$this->telegramId = $telegramId;
return $this;
}
}