<?php
namespace App\Entity;
use App\Config\SpeakerTimeSlotSettings;
use App\Repository\SpeakerConsultationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Intl\Timezones;
/**
* @ORM\Entity(repositoryClass=SpeakerConsultationRepository::class)
*/
class SpeakerConsultation
{
const STATUS_FREE = 0;
const STATUS_PLANNED = 1;
const STATUS_COMPLETED = 2;
const STATUS_CANCELED = 9;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Speaker::class, inversedBy="consultations")
* @ORM\JoinColumn(nullable=false)
*/
private $speaker;
/**
* @ORM\Column(type="integer")
*/
private $price = 0;
/**
* @ORM\Column(type="integer")
*/
private $groupPrice = 0;
/**
* @ORM\Column(type="datetime")
*/
private $startDate;
/**
* @ORM\Column(type="datetime")
*/
private $endDate;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $freezeDate;
/**
* @ORM\ManyToOne(targetEntity=SpeakerConsultationRepeat::class, inversedBy="speakerConsultations")
*/
private $repeatSettings;
/**
* @ORM\OneToMany(targetEntity=OrderConsultation::class, mappedBy="consultation")
*/
private $orderConsultation;
/**
* @ORM\Column(type="integer")
*/
private $status = self::STATUS_FREE;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $zoomMeetingNumber;
/**
* @ORM\ManyToMany(targetEntity=User::class, inversedBy="consultations")
*/
private $participants;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $googleEventsData;
/**
* @ORM\OneToMany(targetEntity=Review::class, mappedBy="consultation")
*/
private $reviews;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $trueConfCallId;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $videoMostConferenceId;
/**
* @ORM\ManyToOne(targetEntity=Charity::class, inversedBy="consultations")
* @ORM\JoinColumn(nullable=true)
*/
private $charity;
public function __construct()
{
$this->orderConsultation = new ArrayCollection();
$this->participants = new ArrayCollection();
$this->reviews = new ArrayCollection();
}
public function __clone()
{
$this->id = null;
$this->freezeDate = null;
$this->repeatSettings = null;
$this->orderConsultation = new ArrayCollection();
$this->participants = new ArrayCollection();
$this->reviews = new ArrayCollection();
$this->status = self::STATUS_FREE;
$this->zoomMeetingNumber = null;
$this->googleEventsData = null;
}
public function getId(): ?int
{
return $this->id;
}
public function getSpeaker(): ?Speaker
{
return $this->speaker;
}
public function setSpeaker(?Speaker $speaker): self
{
$this->speaker = $speaker;
return $this;
}
public function getPrice(): ?int
{
return $this->price;
}
public function setPrice(int $price): self
{
$this->price = $price;
return $this;
}
public function getGroupPrice(): ?int
{
return $this->groupPrice;
}
public function setGroupPrice(int $groupPrice): self
{
$this->groupPrice = $groupPrice;
return $this;
}
public function getStartDate(): ?\DateTimeInterface
{
return $this->startDate;
}
public function setStartDate(\DateTimeInterface $startDate): self
{
$this->startDate = $startDate;
return $this;
}
public function isStarted(): bool
{
return $this->getStartDate() < new \DateTime('+15 MINUTES');
}
public function getEndDate(): ?\DateTimeInterface
{
return $this->endDate;
}
public function setEndDate(\DateTimeInterface $endDate): self
{
$this->endDate = $endDate;
return $this;
}
public function getFreezeDate(): ?\DateTimeInterface
{
return $this->freezeDate;
}
public function setFreezeDate(?\DateTimeInterface $freezeDate): self
{
$this->freezeDate = $freezeDate;
return $this;
}
public function getStartDateBasedOnTimeZone(?string $timeZone): ?\DateTimeInterface
{
if (!$timeZone) {
return $this->getStartDate();
}
$offset = Timezones::getRawOffset($timeZone);
if (!empty($offset)) {
return (clone $this->getStartDate())->modify($offset . ' seconds');
}
return $this->getStartDate();
}
public function getEndDateBasedOnTimeZone(?string $timeZone): ?\DateTimeInterface
{
if (!$timeZone) {
return $this->getEndDate();
}
$offset = Timezones::getRawOffset($timeZone);
if (!empty($offset)) {
return (clone $this->getEndDate())->modify($offset . ' seconds');
}
return $this->getEndDate();
}
public function getRepeatSettings(): ?SpeakerConsultationRepeat
{
return $this->repeatSettings;
}
public function setRepeatSettings(?SpeakerConsultationRepeat $repeatSettings): self
{
$this->repeatSettings = $repeatSettings;
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getOrderConsultations()
{
return $this->orderConsultation;
}
public function getOrderConsultation()
{
return $this->orderConsultation->last();
}
public function getZoomMeetingNumber(): ?string
{
return $this->zoomMeetingNumber;
}
public function setZoomMeetingNumber(?string $zoomMeetingNumber): self
{
$this->zoomMeetingNumber = $zoomMeetingNumber;
return $this;
}
/**
* @return Collection|User[]
*/
public function getParticipants(): Collection
{
return $this->participants;
}
public function addParticipant(User $participant): self
{
if (!$this->participants->contains($participant)) {
$this->participants[] = $participant;
}
return $this;
}
public function removeParticipant(User $participant): self
{
$this->participants->removeElement($participant);
return $this;
}
public function getGoogleEventsData(): array
{
if (empty($this->googleEventsData)) {
return [];
}
$data = @json_decode($this->googleEventsData, true);
return empty($data) ? [] : $data;
}
public function setGoogleEventsData(array $googleEventsData): self
{
$this->googleEventsData = json_encode($googleEventsData);
return $this;
}
/**
* @return Collection<int, Review>
*/
public function getReviews(): Collection
{
return $this->reviews;
}
public function addReview(Review $review): self
{
if (!$this->reviews->contains($review)) {
$this->reviews[] = $review;
$review->setConsultation($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->getConsultation() === $this) {
$review->setConsultation(null);
}
}
return $this;
}
public function isCancelable($timezone = null): bool
{
if ($timezone) {
return $this->getStatus() == self::STATUS_PLANNED && $this->getStartDateBasedOnTimeZone($timezone) > (new \DateTime());
}
return $this->getStatus() == self::STATUS_PLANNED && $this->getStartDate() > (new \DateTime());
}
public function __toString()
{
return $this->getSpeaker() . ': ' . $this->getStartDate()->format('d.m.Y H:i') . ' - ' . $this->getEndDate()->format('d.m.Y H:i');
}
public function toStringTzBased($timezone)
{
return $this->getSpeaker() . ': ' . $this->getStartDateBasedOnTimeZone($timezone)->format('d.m.Y H:i') . ' - ' . $this->getEndDateBasedOnTimeZone($timezone)->format('d.m.Y H:i');
}
public function getTrueConfCallId(): ?string
{
return $this->trueConfCallId;
}
public function setTrueConfCallId(?string $trueConfCallId): self
{
$this->trueConfCallId = $trueConfCallId;
return $this;
}
public function getVideoMostConferenceId(): ?string
{
return $this->videoMostConferenceId;
}
public function setVideoMostConferenceId(?string $videoMostConferenceId): self
{
$this->videoMostConferenceId = $videoMostConferenceId;
return $this;
}
public function getCharity(): ?Charity
{
return $this->charity;
}
public function setCharity(?Charity $charity): self
{
$this->charity = $charity;
return $this;
}
}