src/Entity/Calendar/CalendarEvent.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Calendar;
  3. use App\Annotation\SiteAware;
  4. use App\Entity\AbstractBase;
  5. use App\Entity\Garages\Garage;
  6. use App\Entity\Interfaces\PublishedInterface;
  7. use App\Entity\Interfaces\SiteInterface;
  8. use App\Entity\LearningCourses\LearningCourseSession;
  9. use App\Entity\Traits\PublishedTrait;
  10. use App\Entity\Traits\SiteTrait;
  11. use App\Entity\Traits\TitleTrait;
  12. use App\Repository\Calendar\CalendarEventRepository;
  13. use DateTime;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Doctrine\Common\Collections\Collection;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Gedmo\Mapping\Annotation as Gedmo;
  18. use Symfony\Component\Security\Core\User\UserInterface;
  19. /**
  20.  * @ORM\Table(name="vulco_calendar_event", indexes={@ORM\Index(name="calendar_event_site_idx", columns={"site"})})
  21.  * @ORM\Entity(repositoryClass=CalendarEventRepository::class)
  22.  * @Gedmo\SoftDeleteable(fieldName="removedAt", timeAware=false)
  23.  * @SiteAware(siteFieldName="site")
  24.  */
  25. class CalendarEvent extends AbstractBase implements PublishedInterfaceSiteInterface
  26. {
  27.     use TitleTrait;
  28.     use SiteTrait;
  29.     use PublishedTrait;
  30.     /**
  31.      * @ORM\Column(type="string", length=255, nullable=false)
  32.      */
  33.     private string $title;
  34.     /**
  35.      * @ORM\Column(type="datetime")
  36.      */
  37.     private \DateTimeInterface $beginAt;
  38.     /**
  39.      * @ORM\Column(type="datetime", nullable=true)
  40.      */
  41.     private ?\DateTimeInterface $endAt null;
  42.     /**
  43.      * @ORM\Column(type="text", length=10000, nullable=true, options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"})
  44.      */
  45.     private ?string $description null;
  46.     /**
  47.      * @ORM\Column(type="text", length=10000, nullable=true)
  48.      */
  49.     private ?string $link null;
  50.     /**
  51.      * @ORM\Column(type="string", length=255, nullable=true)
  52.      */
  53.     private ?string $linkLabel null;
  54.     /**
  55.      * @ORM\ManyToOne(targetEntity="App\Entity\Calendar\CalendarEventCategory")
  56.      * @ORM\JoinColumn(name="calendar_event_category_id", referencedColumnName="id")
  57.      */
  58.     private CalendarEventCategory $calendarEventCategory;
  59.     /**
  60.      * @ORM\ManyToMany(targetEntity="App\Entity\Garages\Garage", cascade={"persist"})
  61.      *
  62.      * @ORM\JoinTable(name="vulco_calendar_event_garage",
  63.      *     joinColumns={@ORM\JoinColumn(name="calendar_event_id", referencedColumnName="id")},
  64.      *     inverseJoinColumns={@ORM\JoinColumn(name="garage_id", referencedColumnName="id")}
  65.      * )
  66.      *
  67.      * @ORM\OrderBy({"name": "ASC"})
  68.      */
  69.     private ?Collection $garages;
  70.     /**
  71.      * @ORM\ManyToOne(targetEntity="App\Entity\User", fetch="EAGER")
  72.      * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  73.      *
  74.      * User who has created the CalendarEvent
  75.      */
  76.     private ?UserInterface $user null;
  77.     public function __construct()
  78.     {
  79.         $this->garages = new ArrayCollection();
  80.     }
  81.     public function getBeginAt(): \DateTimeInterface
  82.     {
  83.         return $this->beginAt;
  84.     }
  85.     public function getBeginAtTimeAsString(): string
  86.     {
  87.         return $this->getBeginAt()->format('H:i');
  88.     }
  89.     public function setBeginAt(\DateTimeInterface $beginAt): self
  90.     {
  91.         $this->beginAt $beginAt;
  92.         return $this;
  93.     }
  94.     public function getEndAt(): ?\DateTimeInterface
  95.     {
  96.         return $this->endAt;
  97.     }
  98.     public function getEndAtTimeAsString(): ?string
  99.     {
  100.         if (!is_null($this->getEndAt())) {
  101.             return $this->getEndAt()->format('H:i');
  102.         }
  103.         return null;
  104.     }
  105.     public function setEndAt(?\DateTimeInterface $endAt): self
  106.     {
  107.         $this->endAt $endAt;
  108.         return $this;
  109.     }
  110.     public function getDescription(): ?string
  111.     {
  112.         return $this->description;
  113.     }
  114.     public function setDescription(?string $description): self
  115.     {
  116.         $this->description $description;
  117.         return $this;
  118.     }
  119.     public function getLink(): ?string
  120.     {
  121.         return $this->link;
  122.     }
  123.     public function setLink(?string $link): self
  124.     {
  125.         $this->link $link;
  126.         return $this;
  127.     }
  128.     public function getLinkLabel(): ?string
  129.     {
  130.         return $this->linkLabel;
  131.     }
  132.     public function setLinkLabel(?string $linkLabel): self
  133.     {
  134.         $this->linkLabel $linkLabel;
  135.         return $this;
  136.     }
  137.     public function getCalendarEventCategory(): CalendarEventCategory
  138.     {
  139.         return $this->calendarEventCategory;
  140.     }
  141.     public function setCalendarEventCategory(CalendarEventCategory $calendarEventCategory): self
  142.     {
  143.         $this->calendarEventCategory $calendarEventCategory;
  144.         return $this;
  145.     }
  146.     public function getGarages(): ?Collection
  147.     {
  148.         return $this->garages;
  149.     }
  150.     public function setGarages(?Collection $garages): self
  151.     {
  152.         $this->garages $garages;
  153.         return $this;
  154.     }
  155.     public function addGarage(Garage $garage): self
  156.     {
  157.         if (!$this->garages->contains($garage)) {
  158.             $this->garages->add($garage);
  159.         }
  160.         return $this;
  161.     }
  162.     public function removeGarage(Garage $garage): self
  163.     {
  164.         if ($this->garages->contains($garage)) {
  165.             $this->garages->removeElement($garage);
  166.         }
  167.         return $this;
  168.     }
  169.     public function getUser(): ?UserInterface
  170.     {
  171.         return $this->user;
  172.     }
  173.     public function setUser(UserInterface $user): self
  174.     {
  175.         $this->user $user;
  176.         return $this;
  177.     }
  178.     public function setDatesFromLearningCourseSession(LearningCourseSession $session)
  179.     {
  180.         if ($session->getEndDate()) {
  181.             // if session has a date range
  182.             if ($session->getBeginHour()) {
  183.                 $this->setBeginAt($session->getDateWithBeginHour());
  184.             } else {
  185.                 $this->setBeginAt($session->getDate());
  186.             }
  187.             if ($session->getEndHour()) {
  188.                 $this->setEndAt($session->getEndDateWithEndHour());
  189.             } else {
  190.                 $endAt = clone $session->getEndDate();
  191.                 $endAt->setTime(235959);
  192.                 $this->setEndAt($endAt);
  193.             }
  194.         } else {
  195.             // one day session
  196.             $this->setBeginAt($session->getDateWithBeginHour());
  197.             if ($session->getEndHour()) {
  198.                 $this->setEndAt($session->getDateWithEndHour());
  199.             } else {
  200.                 $endAt = clone $session->getDate();
  201.                 $endAt->setTime(235959);
  202.                 $this->setEndAt($endAt);
  203.             }
  204.         }
  205.     }
  206.     public function isAllDayEvent(): bool
  207.     {
  208.         if (is_null($this->getEndAt())) {
  209.             return true;
  210.         } else {
  211.             $beginAt = clone $this->getBeginAt();
  212.             $beginAt->setTime(000);
  213.             $endAt = clone $this->getEndAt();
  214.             $endAt->setTime(000);
  215.             if ($beginAt->format('Y-m-d') === $endAt->format('Y-m-d')) {
  216.                 // equal begin and end date
  217.                 if ('00:00' == $this->getBeginAtTimeAsString()) {
  218.                     // case for LearningCourseSessions ( see setDatesFromLearningCourseSession )
  219.                     return true;
  220.                 }
  221.             }
  222.         }
  223.         return false;
  224.     }
  225. }