src/Entity/CalendarEvent.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\CalendarEvent\Status;
  4. use App\Enum\CalendarEvent\Type;
  5. use App\Enum\Student\VirtualStatus;
  6. use App\Library\Utils\DateUtils;
  7. use App\Repository\CalendarEventRepository;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. /**
  12.  * @ORM\Entity(repositoryClass=CalendarEventRepository::class)
  13.  */
  14. class CalendarEvent
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=255, nullable=true)
  24.      */
  25.     private $name;
  26.     /**
  27.      * @ORM\Column(type="date")
  28.      */
  29.     private $startDate;
  30.     /**
  31.      * @ORM\Column(type="date")
  32.      */
  33.     private $endDate;
  34.     /**
  35.      * @ORM\Column(type="integer", nullable=true)
  36.      */
  37.     private $price;
  38.     /**
  39.      * @ORM\Column(type="smallint", nullable=true)
  40.      */
  41.     private $fromLevel;
  42.     /**
  43.      * @ORM\Column(type="smallint", nullable=true)
  44.      */
  45.     private $earnLevel;
  46.     /**
  47.      * @ORM\Column(type="time")
  48.      */
  49.     private $startTime;
  50.     /**
  51.      * @ORM\Column(type="time")
  52.      */
  53.     private $endTime;
  54.     /**
  55.      * @ORM\Column(type="enum", options={"values"="calendar_event_enum"})
  56.      */
  57.     private $type Type::TYPE_COURSE;
  58.     /**
  59.      * @ORM\Column(type="boolean", nullable=true)
  60.      */
  61.     private $isCandidateReviewRequired true;
  62.     /**
  63.     * @ORM\ManyToOne(targetEntity=PaymentRequisites::class)
  64.     * @ORM\JoinColumn(nullable=true)
  65.      */
  66.     private $paymentRequisites;
  67.     /**
  68.      * @ORM\Column(type="string", length=255, nullable=true)
  69.      */
  70.     private $telegramChannelUrl;
  71.     /**
  72.      * @ORM\Column(type="string", length=100, nullable=true)
  73.      */
  74.     private $telegramChannelId;
  75.     /**
  76.      * @ORM\ManyToMany(targetEntity=CalendarEvent::class)
  77.      */
  78.     private $requireCalendarEventsParticipations;
  79.     /**
  80.      * @ORM\Column(type="boolean", nullable=true)
  81.      */
  82.     private $eventDatesApproximate;
  83.     /**
  84.      * @ORM\Column(type="enum", options={"values"="calendar_event_enum", "default"="active"}))
  85.      */
  86.     private $status Status::STATUS_ACTIVE;
  87.     /**
  88.      * @ORM\ManyToMany(targetEntity=CalendarEvent::class)
  89.      * @ORM\JoinTable(name="calendar_event_deny_participations",
  90.      *       joinColumns={@ORM\JoinColumn(name="calendar_event_id", referencedColumnName="id")},
  91.      *       inverseJoinColumns={@ORM\JoinColumn(name="deny_calendar_event_id", referencedColumnName="id")}
  92.      *  )
  93.      */
  94.     private $denyCalendarEventsParticipations;
  95.     /**
  96.      * @ORM\Column(type="smallint", nullable=true)
  97.      */
  98.     private $toLevel;
  99.     /**
  100.      * @ORM\Column(nullable=true)
  101.      */
  102.     private $requireStudentStatus;
  103.     /**
  104.      * @ORM\ManyToOne(targetEntity=CalendarEvent::class, inversedBy="connectedCalendarEvents")
  105.      * @ORM\JoinColumn(nullable=true)
  106.      */
  107.     private $connectingCalendarEvent;
  108.     /**
  109.      * @ORM\OneToMany(targetEntity=CalendarEvent::class, mappedBy="connectingCalendarEvent")
  110.      */
  111.     private $connectedCalendarEvents;
  112.     /**
  113.      * @ORM\ManyToMany(targetEntity=TelegramCampaignMessage::class)
  114.      */
  115.     private $approvedCandidatesCampaignMessages;
  116.     /**
  117.      * @ORM\ManyToOne(targetEntity=CalendarEventKind::class)
  118.      */
  119.     private $kind;
  120.     /**
  121.      * @ORM\Column(type="boolean", nullable=true)
  122.      */
  123.     private $connectingEventForAccountant;
  124.     /**
  125.      * @var bool|null
  126.      */
  127.     private $isEndDateSame;
  128.     /**
  129.      * @ORM\Column(type="boolean", nullable=true)
  130.      */
  131.     private $isTelegramChannelConfigurated;
  132.     /**
  133.      * @ORM\Column(type="datetime", nullable=true)
  134.      */
  135.     private $createdAt;
  136.     /**
  137.      * @ORM\Column(type="datetime", nullable=true)
  138.      */
  139.     private $updatedAt;
  140.     public function __construct()
  141.     {
  142.         $this->createdAt = new \DateTime();
  143.         $this->updatedAt = new \DateTime();
  144.         $this->startDate = new \DateTime();
  145.         $this->endDate = new \DateTime();
  146.         $this->startTime = new \DateTime('10:00:00');
  147.         $this->endTime = new \DateTime('13:00:00');
  148.         $this->requireCalendarEventsParticipations = new ArrayCollection();
  149.         $this->approvedCandidatesCampaignMessages = new ArrayCollection();
  150.         $this->denyCalendarEventsParticipations = new ArrayCollection();
  151.         $this->connectedCalendarEvents = new ArrayCollection();
  152.     }
  153.     public function __toString()
  154.     {
  155.         return $this->getNameText();
  156.     }
  157.     public function getShortInfo(): string
  158.     {
  159.         return $this->getName() . " " . ($this->getStartDate() ? $this->getStartDate()->format('d.m.Y') : "") .
  160.             ($this->getFromLevel() ? " (с " $this->getFromLevel() . " ур.)" " (все ур.)");
  161.     }
  162.     public function getText(array $options null)
  163.     {
  164.         $options array_merge([
  165.             "quotes" => false,
  166.         ], $options ?? []);
  167.         $result = ($options['quotes'] ? $this->getNameText() : $this->getName());
  168.         return $result;
  169.     }
  170.     public function getNameText(): string
  171.     {
  172.         return $this->getTypeText() . " «" $this->getName() . "»";
  173.     }
  174.     public function getOnTypeText(): string
  175.     {
  176.         $typeText null;
  177.         switch ($this->getType()) {
  178.             case Type::TYPE_COURSE:
  179.                 $typeText "курс";
  180.                 break;
  181.             case Type::TYPE_OPEN_MEETING:
  182.                 $typeText "открытую встречу";
  183.                 break;
  184.             case Type::TYPE_MEETING:
  185.                 $typeText "конференцию";
  186.                 break;
  187.             case Type::TYPE_PERSONAL_CONSULTATION:
  188.                 $typeText "личную консультациию";
  189.                 break;
  190.             default:
  191.                 $typeText $this->getTypeText();
  192.                 break;
  193.         }
  194.         return $typeText;
  195.     }
  196.     public function getOfTypeText(): string
  197.     {
  198.         $typeText null;
  199.         switch ($this->getType()) {
  200.             case Type::TYPE_COURSE:
  201.                 $typeText "курса";
  202.                 break;
  203.                 case Type::TYPE_OPEN_MEETING:
  204.                 $typeText "открытой встречи";
  205.                 break;
  206.             case Type::TYPE_MEETING:
  207.                 $typeText "конференции";
  208.                 break;
  209.             case Type::TYPE_PERSONAL_CONSULTATION:
  210.                 $typeText "личной консультации";
  211.                 break;
  212.             default:
  213.                 $typeText $this->getTypeText();
  214.                 break;
  215.         }
  216.         return $typeText;
  217.     }
  218.     public function getOnNameText(): string
  219.     {
  220.         $typeText $this->getOnTypeText();
  221.         return $typeText " «" $this->getName() . "»";
  222.     }
  223.     public function getOfNameText(): string
  224.     {
  225.         $typeText $this->getOfTypeText();
  226.         return $typeText " «" $this->getName() . "»";
  227.     }
  228.     public function getId(): ?int
  229.     {
  230.         return $this->id;
  231.     }
  232.     public function getName(): ?string
  233.     {
  234.         return $this->name;
  235.     }
  236.     public function setName(?string $name): self
  237.     {
  238.         $this->name $name;
  239.         return $this;
  240.     }
  241.     public function getStartDate(): ?\DateTimeInterface
  242.     {
  243.         return $this->startDate;
  244.     }
  245.     public function setStartDate(\DateTimeInterface $startDate): self
  246.     {
  247.         $this->startDate $startDate;
  248.         return $this;
  249.     }
  250.     public function getEndDate(): ?\DateTimeInterface
  251.     {
  252.         return $this->endDate;
  253.     }
  254.     public function setEndDate(\DateTimeInterface $endDate): self
  255.     {
  256.         $this->endDate $endDate;
  257.         return $this;
  258.     }
  259.     private function _getPrice($isFirstCall false): ?int
  260.     {
  261.         if ($isFirstCall) {
  262.             if (!$this->_getPrice() && $this->getConnectedCalendarEvents()->count()) {
  263.                 $isAllPricesEqual true;
  264.                 $price null;
  265.                 foreach ($this->getConnectedCalendarEvents() as $connectedEvent) {
  266.                     if ($connectedEvent->_getPrice()) {
  267.                         if ($price === null) {
  268.                             $price $connectedEvent->_getPrice();
  269.                         } elseif ($price != $connectedEvent->_getPrice()) {
  270.                             $isAllPricesEqual false;
  271.                             break;
  272.                         }
  273.                     }
  274.                 }
  275.                 if ($isAllPricesEqual) {
  276.                     return $price;
  277.                 }
  278.             }
  279.         }
  280.         return $this->price;
  281.     }
  282.     public function getPrice(): ?int
  283.     {
  284.       return $this->_getPrice(true);
  285.     }
  286.     public function isPriceNotNull(): bool
  287.     {
  288.         return $this->getPrice() === || $this->getPrice();
  289.     }
  290.     public function setPrice(?int $price): self
  291.     {
  292.         $this->price $price;
  293.         return $this;
  294.     }
  295.     public function getFromLevel(): ?int
  296.     {
  297.         return $this->fromLevel;
  298.     }
  299.     public function getFromLevelEmoji(): string
  300.     {
  301.         $level $this->getFromLevel();
  302.         if ($level === null || $level === 0) {
  303.             return "🔢";
  304.         }
  305.         $emojiNumbers = [
  306.             '0' => '0️⃣',
  307.             '1' => '1️⃣',
  308.             '2' => '2️⃣',
  309.             '3' => '3️⃣',
  310.             '4' => '4️⃣',
  311.             '5' => '5️⃣',
  312.             '6' => '6️⃣',
  313.             '7' => '7️⃣',
  314.             '8' => '8️⃣',
  315.             '9' => '9️⃣',
  316.         ];
  317.         $levelStr = (string)$level;
  318.         return $emojiNumbers[$levelStr[0]] . ($levelStr[1] ?? '');
  319.     }
  320.     public function getFromLevelText(): string
  321.     {
  322.         if ($this->getFromLevel() === null) {
  323.             return "";
  324.         }
  325.         if ($this->getFromLevel() === && $this->getToLevel() === null) {
  326.             return "все ур.";
  327.         }
  328.         return ($this->getFromLevel() === $this->getToLevel() ? "для " "с")
  329. //            . StringUtils::getEnding($this->getFromLevel(),
  330. //                "", "о", "",
  331. //                "")
  332.             " " $this->getFromLevelNumberText()
  333.             . ($this->getToLevel() === null || $this->getFromLevel() === $this->getToLevel() ? "" "–" $this->getToLevelNumberText())
  334.             . " ур.";
  335.     }
  336.     public function getFromLevelNumberText(): ?string
  337.     {
  338.         if ($this->getFromLevel() === 0) {
  339.             return "баз.";
  340.         }
  341.         return $this->getFromLevel();
  342.     }
  343.     public function getToLevelNumberText(): ?string
  344.     {
  345.         if ($this->getToLevel() === 0) {
  346.             return "баз.";
  347.         }
  348.         return $this->getToLevel();
  349.     }
  350.     public function setFromLevel(?int $fromLevel): self
  351.     {
  352.         $this->fromLevel $fromLevel;
  353.         return $this;
  354.     }
  355.     public function getEarnLevel(): ?int
  356.     {
  357.         return $this->earnLevel;
  358.     }
  359.     public function setEarnLevel(?int $level): self
  360.     {
  361.         $this->earnLevel $level;
  362.         return $this;
  363.     }
  364.     public function getStartTime(): ?\DateTimeInterface
  365.     {
  366.         return $this->startTime;
  367.     }
  368.     public function setStartTime(\DateTimeInterface $startTime): self
  369.     {
  370.         $this->startTime $startTime;
  371.         return $this;
  372.     }
  373.     public function getEndTime(): ?\DateTimeInterface
  374.     {
  375.         return $this->endTime;
  376.     }
  377.     public function setEndTime(\DateTimeInterface $endTime): self
  378.     {
  379.         $this->endTime $endTime;
  380.         return $this;
  381.     }
  382.     public function getType()
  383.     {
  384.         return $this->type;
  385.     }
  386.     public function getTypeText(): string
  387.     {
  388.         return Type::getText($this->getType());
  389.     }
  390.     public function setType($type): self
  391.     {
  392.         $this->type $type;
  393.         return $this;
  394.     }
  395.     public function getTopic(): string
  396.     {
  397.         if ($this->type === Type::TYPE_COURSE) {
  398.             return "Курс «" $this->getName() . "»";
  399.         } elseif ($this->type === Type::TYPE_MEETING) {
  400.             return "Конференция «" $this->getName() . "»";
  401.         } elseif ($this->type === Type::TYPE_OPEN_MEETING) {
  402.             return "Открытая встреча «" $this->getName() . "»";
  403.         } else {
  404.             return $this->getTypeText() . " «" $this->getName() . "»";
  405.         }
  406.     }
  407.     public function isIsCandidateReviewRequired(): ?bool
  408.     {
  409.         return $this->isCandidateReviewRequired;
  410.     }
  411.     public function setIsCandidateReviewRequired(?bool $isCandidateReviewRequired): self
  412.     {
  413.         $this->isCandidateReviewRequired $isCandidateReviewRequired;
  414.         return $this;
  415.     }
  416.     public function getPaymentRequisites(): ?PaymentRequisites
  417.     {
  418.         return $this->paymentRequisites;
  419.     }
  420.     public function isForFree(): bool
  421.     {
  422.         return $this->getPrice() === 0;
  423.     }
  424.     public function checkPaymentRequisites(): bool
  425.     {
  426.         return $this->isPriceNotNull() && ($this->isForFree() || $this->getPaymentRequisites());
  427.     }
  428.     public function canCreateTelegramCampaign(): bool
  429.     {
  430.         return $this->isPriceNotNull() && $this->checkPaymentRequisites();
  431.     }
  432.     public function setPaymentRequisites(?PaymentRequisites $paymentRequisites): self
  433.     {
  434.         $this->paymentRequisites $paymentRequisites;
  435.         return $this;
  436.     }
  437.     public function getNameWithCode(): string
  438.     {
  439.         return "Код " $this->getPrice() . " – " $this->getShortInfo();
  440.     }
  441.     public function isFinished(): bool
  442.     {
  443.         if (!$this->getFullEndDate()) {
  444.             return true;
  445.         }
  446.         $now = new \DateTime();
  447.         return $this->getFullEndDate() < $now;
  448.     }
  449.     public function isInProgress(): bool
  450.     {
  451.         return $this->isStarted() && !$this->isFinished();
  452.     }
  453.     public function isUpcoming(): bool
  454.     {
  455.         if (!$this->getFullStartDate()) {
  456.             return false;
  457.         }
  458.         $now = new \DateTime();
  459.         return $this->getFullStartDate() > $now;
  460.     }
  461.     public function getFullStartDate(): ?\DateTime
  462.     {
  463.         $startDate $this->getStartDate();
  464.         if (!$startDate) {
  465.             return null;
  466.         }
  467.         $startTime $this->getStartTime();
  468.         if ($startTime) {
  469.             $startDate = (clone $startDate)->setTime($startTime->format('H'), $startTime->format('i'), $startTime->format('s'));
  470.         }
  471.         return $startDate;
  472.     }
  473.     public function getFullEndDate(): ?\DateTime
  474.     {
  475.         $endDate $this->getEndDate();
  476.         if (!$endDate) {
  477.             return null;
  478.         }
  479.         $endTime $this->getEndTime();
  480.         if ($endTime) {
  481.             $endDate = (clone $endDate)->setTime($endTime->format('H'), $endTime->format('i'), $endTime->format('s'));
  482.         }
  483.         return $endDate;
  484.     }
  485.     public function isStarted(int $addDaysToStartDate null): bool
  486.     {
  487.         if (!$this->getStartDate() || $this->isFinished()) {
  488.             return false;
  489.         }
  490.         $now = (new \DateTime())->setTime(000);
  491.         $startDate = (clone $this->getStartDate())->setTime(000);
  492.         if ($addDaysToStartDate) {
  493.             $startDate $startDate->modify("+$addDaysToStartDate days");
  494.         }
  495.         return $startDate <= $now;
  496.     }
  497.     public function isRegistrationOpen(): bool
  498.     {
  499.         return !$this->isStarted(-2);
  500.     }
  501.     public function getLastRegistrationDate(): ?\DateTime
  502.     {
  503.         if (!$this->getStartDate()) {
  504.             return null;
  505.         }
  506.         $lastRegistrationDate = (clone $this->getStartDate())->modify("-3 days");
  507.         $weekendDays 0;
  508.         if (in_array((int)$lastRegistrationDate->format('N'), [67])) {
  509.             $weekendDays = (int)$lastRegistrationDate->format('N') - 5;
  510.         }
  511.         if ($weekendDays 0) {
  512.             $lastRegistrationDate $lastRegistrationDate->modify("-$weekendDays days");
  513.         }
  514.         return $lastRegistrationDate;
  515.     }
  516.     public function getHoursLeftBeforeStart(): int
  517.     {
  518.         return (int)ceil((($this->getStartDate()->getTimestamp() - (new \DateTime())->getTimestamp()) / 3600));
  519.     }
  520.     public function getTelegramChannelUrl(): ?string
  521.     {
  522.         return $this->telegramChannelUrl;
  523.     }
  524.     public function setTelegramChannelUrl(?string $telegramChannelUrl): self
  525.     {
  526.         $this->telegramChannelUrl $telegramChannelUrl;
  527.         if (!$telegramChannelUrl) {
  528.             $this->setIsTelegramChannelConfigurated(false);
  529.         }
  530.         return $this;
  531.     }
  532.     public function getTelegramChannelId(): ?string
  533.     {
  534.         return $this->telegramChannelId;
  535.     }
  536.     public function setTelegramChannelId(?string $telegramChannelId): self
  537.     {
  538.         $this->telegramChannelId $telegramChannelId;
  539.         if (!$telegramChannelId) {
  540.             $this->setIsTelegramChannelConfigurated(false);
  541.         }
  542.         return $this;
  543.     }
  544.     /**
  545.      * @return Collection<int, self>
  546.      */
  547.     public function getRequireCalendarEventsParticipations(): Collection
  548.     {
  549.         return $this->requireCalendarEventsParticipations;
  550.     }
  551.     public function getRequireCalendarEventsParticipationsText(): string
  552.     {
  553.         $texts = [];
  554.         foreach ($this->getRequireCalendarEventsParticipations() as $event) {
  555.             $texts[] = mb_lcfirst($event->getNameText(), 'UTF-8');
  556.         }
  557.         return implode(", "$texts);
  558.     }
  559.     public function getDenyCalendarEventsParticipationsText(): string
  560.     {
  561.         $texts = [];
  562.         foreach ($this->getDenyCalendarEventsParticipations() as $event) {
  563.             $texts[] = mb_lcfirst($event->getNameText(), 'UTF-8');
  564.         }
  565.         return implode(", "$texts);
  566.     }
  567.     public function addRequireCalendarEventsParticipation(self $requireCalendarEventsParticipation): self
  568.     {
  569.         if (!$this->requireCalendarEventsParticipations->contains($requireCalendarEventsParticipation)) {
  570.             $this->requireCalendarEventsParticipations[] = $requireCalendarEventsParticipation;
  571.         }
  572.         return $this;
  573.     }
  574.     public function removeRequireCalendarEventsParticipation(self $requireCalendarEventsParticipation): self
  575.     {
  576.         $this->requireCalendarEventsParticipations->removeElement($requireCalendarEventsParticipation);
  577.         return $this;
  578.     }
  579.     public function isStudentLevelCorrespond(?Person $person): bool
  580.     {
  581.         if (!$person) {
  582.             return false;
  583.         }
  584.         $eventLevel $this->getFromLevel();
  585.         if ($eventLevel === null) {
  586.             return true;
  587.         }
  588.         if (!$person->getStudent() || $person->getStudent()->getLevel() === null) {
  589.             return false;
  590.         }
  591.         return $person->getStudent()->getLevel() >= $eventLevel;
  592.     }
  593.     public function isEventDatesApproximate(): ?bool
  594.     {
  595.         return $this->eventDatesApproximate;
  596.     }
  597.     public function setEventDatesApproximate(?bool $eventDatesApproximate): self
  598.     {
  599.         $this->eventDatesApproximate $eventDatesApproximate;
  600.         return $this;
  601.     }
  602. //    /**
  603. //     * @return Collection<int, TelegramCampaignMessage>
  604. //     */
  605. //    public function getApprovedCandidatesCampaignMessages(): Collection
  606. //    {
  607. //        return $this->approvedCandidatesCampaignMessages;
  608. //    }
  609. //
  610. //    public function addApprovedCandidatesCampaignMessage(TelegramCampaignMessage $approvedCandidatesCampaignMessage): self
  611. //    {
  612. //        if (!$this->approvedCandidatesCampaignMessages->contains($approvedCandidatesCampaignMessage)) {
  613. //            $this->approvedCandidatesCampaignMessages[] = $approvedCandidatesCampaignMessage;
  614. //        }
  615. //
  616. //        return $this;
  617. //    }
  618. //
  619. //    public function removeApprovedCandidatesCampaignMessage(TelegramCampaignMessage $approvedCandidatesCampaignMessage): self
  620. //    {
  621. //        $this->approvedCandidatesCampaignMessages->removeElement($approvedCandidatesCampaignMessage);
  622. //
  623. //        return $this;
  624. //    }
  625.     public function getStatus()
  626.     {
  627.         return $this->status;
  628.     }
  629.     public function setStatus($status): self
  630.     {
  631.         $this->status $status;
  632.         return $this;
  633.     }
  634.     public function getStatusText(): ?string
  635.     {
  636.         return Status::getText($this->getStatus());
  637.     }
  638.     public function getStatusCssClass($prefix null): ?string
  639.     {
  640.         return Status::getCssClass($this->getStatus(), $prefix);
  641.     }
  642.     /**
  643.      * @return Collection<int, self>
  644.      */
  645.     public function getDenyCalendarEventsParticipations(): Collection
  646.     {
  647.         return $this->denyCalendarEventsParticipations;
  648.     }
  649.     public function addDenyCalendarEventsParticipation(self $denyCalendarEventsParticipation): self
  650.     {
  651.         if (!$this->denyCalendarEventsParticipations->contains($denyCalendarEventsParticipation)) {
  652.             $this->denyCalendarEventsParticipations[] = $denyCalendarEventsParticipation;
  653.         }
  654.         return $this;
  655.     }
  656.     public function removeDenyCalendarEventsParticipation(self $denyCalendarEventsParticipation): self
  657.     {
  658.         $this->denyCalendarEventsParticipations->removeElement($denyCalendarEventsParticipation);
  659.         return $this;
  660.     }
  661.     public function getToLevel(): ?int
  662.     {
  663.         return $this->toLevel;
  664.     }
  665.     public function setToLevel(?int $toLevel): self
  666.     {
  667.         $this->toLevel $toLevel;
  668.         return $this;
  669.     }
  670.     public function getRequireStudentStatus()
  671.     {
  672.         return $this->requireStudentStatus;
  673.     }
  674.     public function getRequireStudentStatusText(): string
  675.     {
  676.         return VirtualStatus::getText($this->getRequireStudentStatus());
  677.     }
  678.     public function setRequireStudentStatus($requireStudentStatus): self
  679.     {
  680.         $this->requireStudentStatus $requireStudentStatus;
  681.         return $this;
  682.     }
  683.     public function getConnectingCalendarEvent(): ?self
  684.     {
  685.         return $this->connectingCalendarEvent;
  686.     }
  687.     public function setConnectingCalendarEvent(?self $connectingCalendarEvent): self
  688.     {
  689.         $this->connectingCalendarEvent $connectingCalendarEvent;
  690.         return $this;
  691.     }
  692.     /**
  693.      * @return Collection<int, self>
  694.      */
  695.     public function getConnectedCalendarEvents(): Collection
  696.     {
  697.         return $this->connectedCalendarEvents;
  698.     }
  699.     public function addConnectedCalendarEvent(self $connectedCalendarEvent): self
  700.     {
  701.         if (!$this->connectedCalendarEvents->contains($connectedCalendarEvent)) {
  702.             $this->connectedCalendarEvents[] = $connectedCalendarEvent;
  703.             $connectedCalendarEvent->setConnectingCalendarEvent($this);
  704.         }
  705.         return $this;
  706.     }
  707.     public function removeConnectedCalendarEvent(self $connectedCalendarEvent): self
  708.     {
  709.         if ($this->connectedCalendarEvents->removeElement($connectedCalendarEvent)) {
  710.             // set the owning side to null (unless already changed)
  711.             if ($connectedCalendarEvent->getConnectingCalendarEvent() === $this) {
  712.                 $connectedCalendarEvent->setConnectingCalendarEvent(null);
  713.             }
  714.         }
  715.         return $this;
  716.     }
  717.     public function getKind(): ?CalendarEventKind
  718.     {
  719.         return $this->kind;
  720.     }
  721.     public function setKind(?CalendarEventKind $kind): self
  722.     {
  723.         $this->kind $kind;
  724.         return $this;
  725.     }
  726.     public function getFinanceCategory(): ?FinanceCategory
  727.     {
  728.         $ceKind $this->getKind();
  729.         return $ceKind $ceKind->getFinanceCategory() : null;
  730.     }
  731.     public function isSameFinanceCategory(FinanceCategory $financeCategory): bool
  732.     {
  733.         $ceFinanceCategory $this->getFinanceCategory();
  734.         if (!$ceFinanceCategory) {
  735.             return false;
  736.         }
  737.         return $ceFinanceCategory->getId() === $financeCategory->getId();
  738.     }
  739.     public function isConnectingType(): bool
  740.     {
  741.         return $this->getType() == Type::TYPE_CONNECTING_EVENT;
  742.     }
  743.     public function isConnectingEventForAccountant(): ?bool
  744.     {
  745.         return $this->connectingEventForAccountant;
  746.     }
  747.     public function setConnectingEventForAccountant(?bool $connectingEventForAccountant): self
  748.     {
  749.         $this->connectingEventForAccountant $connectingEventForAccountant;
  750.         return $this;
  751.     }
  752.     public function getIsEndDateSame(): ?bool
  753.     {
  754.         $result $this->getStartDate()->format("d.m.Y") == $this->getEndDate()->format("d.m.Y");
  755.         return $result;
  756.     }
  757.     public function setIsEndDateSame(?bool $isEndDateSame): self
  758.     {
  759.         $this->isEndDateSame $isEndDateSame;
  760.         return $this;
  761.     }
  762.     public function isIsTelegramChannelConfigurated(): ?bool
  763.     {
  764.         return $this->isTelegramChannelConfigurated;
  765.     }
  766.     public function setIsTelegramChannelConfigurated(?bool $isTelegramChannelConfigurated): self
  767.     {
  768.         $this->isTelegramChannelConfigurated $isTelegramChannelConfigurated;
  769.         return $this;
  770.     }
  771.     public function getDaysUntilStart(): int
  772.     {
  773.         if (!$this->getStartDate()) {
  774.             throw new \Exception("Start date is not set");
  775.         }
  776.         if (new \DateTime() >= $this->getStartDate()) {
  777.             return 0;
  778.         } else {
  779.             return floor(DateUtils::getDateDiff($this->getStartDate(), null"d"));
  780.         }
  781.     }
  782.     public function shouldAskReceipt(): bool
  783.     {
  784.         return $this->getDaysUntilStart() <= 1;
  785.     }
  786.     public function getCreatedAt(): ?\DateTimeInterface
  787.     {
  788.         return $this->createdAt;
  789.     }
  790.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  791.     {
  792.         $this->createdAt $createdAt;
  793.         return $this;
  794.     }
  795.     public function getUpdatedAt(): ?\DateTime
  796.     {
  797.         return $this->updatedAt;
  798.     }
  799.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  800.     {
  801.         $this->updatedAt $updatedAt;
  802.         return $this;
  803.     }
  804.     public function isUpdatedRecently(): bool
  805.     {
  806.         if (!$this->getUpdatedAt()) {
  807.             return false;
  808.         }
  809.         if (new \DateTime() < (clone $this->getUpdatedAt())->modify("+3 minutes")) {
  810.             return true;
  811.         }
  812.         return false;
  813.     }
  814. }