src/Entity/SpeakerConsultation.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Config\SpeakerTimeSlotSettings;
  4. use App\Repository\SpeakerConsultationRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Intl\Timezones;
  9. /**
  10.  * @ORM\Entity(repositoryClass=SpeakerConsultationRepository::class)
  11.  */
  12. class SpeakerConsultation
  13. {
  14.     const STATUS_FREE 0;
  15.     const STATUS_PLANNED 1;
  16.     const STATUS_COMPLETED 2;
  17.     const STATUS_CANCELED 9;
  18.     /**
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue
  21.      * @ORM\Column(type="integer")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @ORM\ManyToOne(targetEntity=Speaker::class, inversedBy="consultations")
  26.      * @ORM\JoinColumn(nullable=false)
  27.      */
  28.     private $speaker;
  29.     /**
  30.      * @ORM\Column(type="integer")
  31.      */
  32.     private $price 0;
  33.     /**
  34.      * @ORM\Column(type="integer")
  35.      */
  36.     private $groupPrice 0;
  37.     /**
  38.      * @ORM\Column(type="datetime")
  39.      */
  40.     private $startDate;
  41.     /**
  42.      * @ORM\Column(type="datetime")
  43.      */
  44.     private $endDate;
  45.     /**
  46.      * @ORM\Column(type="datetime", nullable=true)
  47.      */
  48.     private $freezeDate;
  49.     /**
  50.      * @ORM\ManyToOne(targetEntity=SpeakerConsultationRepeat::class, inversedBy="speakerConsultations")
  51.      */
  52.     private $repeatSettings;
  53.     /**
  54.      * @ORM\OneToMany(targetEntity=OrderConsultation::class, mappedBy="consultation")
  55.      */
  56.     private $orderConsultation;
  57.     /**
  58.      * @ORM\Column(type="integer")
  59.      */
  60.     private $status self::STATUS_FREE;
  61.     /**
  62.      * @ORM\Column(type="string", length=255, nullable=true)
  63.      */
  64.     private $zoomMeetingNumber;
  65.     /**
  66.      * @ORM\ManyToMany(targetEntity=User::class, inversedBy="consultations")
  67.      */
  68.     private $participants;
  69.     /**
  70.      * @ORM\Column(type="text", nullable=true)
  71.      */
  72.     private $googleEventsData;
  73.     /**
  74.      * @ORM\OneToMany(targetEntity=Review::class, mappedBy="consultation")
  75.      */
  76.     private $reviews;
  77.     /**
  78.      * @ORM\Column(type="string", length=255, nullable=true)
  79.      */
  80.     private $trueConfCallId;
  81.     /**
  82.      * @ORM\Column(type="string", length=255, nullable=true)
  83.      */
  84.     private $videoMostConferenceId;
  85.     /**
  86.      * @ORM\ManyToOne(targetEntity=Charity::class, inversedBy="consultations")
  87.      * @ORM\JoinColumn(nullable=true)
  88.      */
  89.     private $charity;
  90.     public function __construct()
  91.     {
  92.         $this->orderConsultation = new ArrayCollection();
  93.         $this->participants = new ArrayCollection();
  94.         $this->reviews = new ArrayCollection();
  95.     }
  96.     public function __clone()
  97.     {
  98.         $this->id null;
  99.         $this->freezeDate null;
  100.         $this->repeatSettings null;
  101.         $this->orderConsultation = new ArrayCollection();
  102.         $this->participants = new ArrayCollection();
  103.         $this->reviews = new ArrayCollection();
  104.         $this->status self::STATUS_FREE;
  105.         $this->zoomMeetingNumber null;
  106.         $this->googleEventsData null;
  107.     }
  108.     public function getId(): ?int
  109.     {
  110.         return $this->id;
  111.     }
  112.     public function getSpeaker(): ?Speaker
  113.     {
  114.         return $this->speaker;
  115.     }
  116.     public function setSpeaker(?Speaker $speaker): self
  117.     {
  118.         $this->speaker $speaker;
  119.         return $this;
  120.     }
  121.     public function getPrice(): ?int
  122.     {
  123.         return $this->price;
  124.     }
  125.     public function setPrice(int $price): self
  126.     {
  127.         $this->price $price;
  128.         return $this;
  129.     }
  130.     public function getGroupPrice(): ?int
  131.     {
  132.         return $this->groupPrice;
  133.     }
  134.     public function setGroupPrice(int $groupPrice): self
  135.     {
  136.         $this->groupPrice $groupPrice;
  137.         return $this;
  138.     }
  139.     public function getStartDate(): ?\DateTimeInterface
  140.     {
  141.         return $this->startDate;
  142.     }
  143.     public function setStartDate(\DateTimeInterface $startDate): self
  144.     {
  145.         $this->startDate $startDate;
  146.         return $this;
  147.     }
  148.     public function isStarted(): bool
  149.     {
  150.         return $this->getStartDate() < new \DateTime('+15 MINUTES');
  151.     }
  152.     public function getEndDate(): ?\DateTimeInterface
  153.     {
  154.         return $this->endDate;
  155.     }
  156.     public function setEndDate(\DateTimeInterface $endDate): self
  157.     {
  158.         $this->endDate $endDate;
  159.         return $this;
  160.     }
  161.     public function getFreezeDate(): ?\DateTimeInterface
  162.     {
  163.         return $this->freezeDate;
  164.     }
  165.     public function setFreezeDate(?\DateTimeInterface $freezeDate): self
  166.     {
  167.         $this->freezeDate $freezeDate;
  168.         return $this;
  169.     }
  170.     public function getStartDateBasedOnTimeZone(?string $timeZone): ?\DateTimeInterface
  171.     {
  172.         if (!$timeZone) {
  173.             return $this->getStartDate();
  174.         }
  175.         $offset Timezones::getRawOffset($timeZone);
  176.         if (!empty($offset)) {
  177.             return (clone $this->getStartDate())->modify($offset ' seconds');
  178.         }
  179.         return $this->getStartDate();
  180.     }
  181.     public function getEndDateBasedOnTimeZone(?string $timeZone): ?\DateTimeInterface
  182.     {
  183.         if (!$timeZone) {
  184.             return $this->getEndDate();
  185.         }
  186.         $offset Timezones::getRawOffset($timeZone);
  187.         if (!empty($offset)) {
  188.             return (clone $this->getEndDate())->modify($offset ' seconds');
  189.         }
  190.         return $this->getEndDate();
  191.     }
  192.     public function getRepeatSettings(): ?SpeakerConsultationRepeat
  193.     {
  194.         return $this->repeatSettings;
  195.     }
  196.     public function setRepeatSettings(?SpeakerConsultationRepeat $repeatSettings): self
  197.     {
  198.         $this->repeatSettings $repeatSettings;
  199.         return $this;
  200.     }
  201.     public function getStatus(): ?int
  202.     {
  203.         return $this->status;
  204.     }
  205.     public function setStatus(int $status): self
  206.     {
  207.         $this->status $status;
  208.         return $this;
  209.     }
  210.     public function getOrderConsultations()
  211.     {
  212.         return $this->orderConsultation;
  213.     }
  214.     public function getOrderConsultation()
  215.     {
  216.         return $this->orderConsultation->last();
  217.     }
  218.     public function getZoomMeetingNumber(): ?string
  219.     {
  220.         return $this->zoomMeetingNumber;
  221.     }
  222.     public function setZoomMeetingNumber(?string $zoomMeetingNumber): self
  223.     {
  224.         $this->zoomMeetingNumber $zoomMeetingNumber;
  225.         return $this;
  226.     }
  227.     /**
  228.      * @return Collection|User[]
  229.      */
  230.     public function getParticipants(): Collection
  231.     {
  232.         return $this->participants;
  233.     }
  234.     public function addParticipant(User $participant): self
  235.     {
  236.         if (!$this->participants->contains($participant)) {
  237.             $this->participants[] = $participant;
  238.         }
  239.         return $this;
  240.     }
  241.     public function removeParticipant(User $participant): self
  242.     {
  243.         $this->participants->removeElement($participant);
  244.         return $this;
  245.     }
  246.     public function getGoogleEventsData(): array
  247.     {
  248.         if (empty($this->googleEventsData)) {
  249.             return [];
  250.         }
  251.         $data = @json_decode($this->googleEventsDatatrue);
  252.         return empty($data) ? [] : $data;
  253.     }
  254.     public function setGoogleEventsData(array $googleEventsData): self
  255.     {
  256.         $this->googleEventsData json_encode($googleEventsData);
  257.         return $this;
  258.     }
  259.     /**
  260.      * @return Collection<int, Review>
  261.      */
  262.     public function getReviews(): Collection
  263.     {
  264.         return $this->reviews;
  265.     }
  266.     public function addReview(Review $review): self
  267.     {
  268.         if (!$this->reviews->contains($review)) {
  269.             $this->reviews[] = $review;
  270.             $review->setConsultation($this);
  271.         }
  272.         return $this;
  273.     }
  274.     public function removeReview(Review $review): self
  275.     {
  276.         if ($this->reviews->removeElement($review)) {
  277.             // set the owning side to null (unless already changed)
  278.             if ($review->getConsultation() === $this) {
  279.                 $review->setConsultation(null);
  280.             }
  281.         }
  282.         return $this;
  283.     }
  284.     public function isCancelable($timezone null): bool
  285.     {
  286.         if ($timezone) {
  287.             return $this->getStatus() == self::STATUS_PLANNED && $this->getStartDateBasedOnTimeZone($timezone) > (new \DateTime());
  288.         }
  289.         return $this->getStatus() == self::STATUS_PLANNED && $this->getStartDate() > (new \DateTime());
  290.     }
  291.     public function __toString()
  292.     {
  293.         return $this->getSpeaker() . ': ' $this->getStartDate()->format('d.m.Y H:i') . ' - ' $this->getEndDate()->format('d.m.Y H:i');
  294.     }
  295.     public function toStringTzBased($timezone)
  296.     {
  297.         return $this->getSpeaker() . ': ' $this->getStartDateBasedOnTimeZone($timezone)->format('d.m.Y H:i') . ' - ' $this->getEndDateBasedOnTimeZone($timezone)->format('d.m.Y H:i');
  298.     }
  299.     public function getTrueConfCallId(): ?string
  300.     {
  301.         return $this->trueConfCallId;
  302.     }
  303.     public function setTrueConfCallId(?string $trueConfCallId): self
  304.     {
  305.         $this->trueConfCallId $trueConfCallId;
  306.         return $this;
  307.     }
  308.     public function getVideoMostConferenceId(): ?string
  309.     {
  310.         return $this->videoMostConferenceId;
  311.     }
  312.     public function setVideoMostConferenceId(?string $videoMostConferenceId): self
  313.     {
  314.         $this->videoMostConferenceId $videoMostConferenceId;
  315.         return $this;
  316.     }
  317.     public function getCharity(): ?Charity
  318.     {
  319.         return $this->charity;
  320.     }
  321.     public function setCharity(?Charity $charity): self
  322.     {
  323.         $this->charity $charity;
  324.         return $this;
  325.     }
  326. }