src/Entity/CalendarEvent.php line 16

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