<?php
namespace App\Entity\LearningCourses;
use App\Annotation\SiteAware;
use App\Entity\AbstractBase;
use App\Entity\Calendar\CalendarEvent;
use App\Entity\Interfaces\SiteInterface;
use App\Entity\MiniAbstractBase;
use App\Entity\Traits\LearningCourseTrait;
use App\Entity\Traits\SiteTrait;
use App\Repository\LearningCourses\LearningCourseSessionRepository;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Table(name="vulco_learning_course_session", indexes={@ORM\Index(name="learning_course_session_site_idx", columns={"site"})})
* @ORM\Entity(repositoryClass=LearningCourseSessionRepository::class)
* @Gedmo\SoftDeleteable(fieldName="removedAt", timeAware=false)
* @SiteAware(siteFieldName="site")
*/
class LearningCourseSession extends AbstractBase implements SiteInterface
{
use LearningCourseTrait;
use SiteTrait;
/**
* @ORM\ManyToOne(targetEntity="LearningCourse", inversedBy="sessions")
*/
private LearningCourse $course;
/**
* @ORM\Column(type="date", nullable=false)
*/
private DateTimeInterface $date;
/**
* @ORM\Column(type="date", nullable=true)
*/
private ?DateTimeInterface $endDate = null;
/**
* @ORM\Column(type="time", nullable=true)
*/
private ?DateTimeInterface $beginHour;
/**
* @ORM\Column(type="time", nullable=true)
*/
private ?DateTimeInterface $endHour;
/**
* @ORM\Column(type="text", length=10000, nullable=true)
*/
private ?string $location = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $title;
/**
* @ORM\Column(type="text", length=10000, nullable=true)
*/
private ?string $description = null;
/**
* @ORM\OneToMany(targetEntity="App\Entity\LearningCourses\LearningCourseRegistration", mappedBy="session")
*/
private ?Collection $registrations;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Calendar\CalendarEvent", cascade={"persist", "remove"})
*/
private ?CalendarEvent $calendarEvent = null;
public function __construct()
{
$this->registrations = new ArrayCollection();
}
public function getDateString(): string
{
return $this->getDateAsString($this->getDate());
}
public function getDate(): DateTimeInterface
{
return $this->date;
}
public function getDateWithBeginHour(): DateTimeInterface
{
$date = clone $this->getDate();
if ($this->getBeginHour()) {
$hours = $this->getBeginHour()->format('H');
$minutes = $this->getBeginHour()->format('i');
$date->setTime($hours, $minutes);
}
return $date;
}
public function getDateWithEndHour(): DateTimeInterface
{
$date = clone $this->getDate();
if ($this->getEndHour()) {
$hours = $this->getEndHour()->format('H');
$minutes = $this->getEndHour()->format('i');
$date->setTime($hours, $minutes);
}
return $date;
}
public function setDate(DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function getEndDateString(): string
{
return $this->getDateAsString($this->getEndDate());
}
public function getEndDate(): ?DateTimeInterface
{
return $this->endDate;
}
public function getEndDateWithEndHour(): DateTimeInterface
{
$date = clone $this->getEndDate();
if ($this->getEndHour()) {
$hours = $this->getEndHour()->format('H');
$minutes = $this->getEndHour()->format('i');
$date->setTime($hours, $minutes);
}
return $date;
}
public function setEndDate(?DateTimeInterface $endDate): self
{
$this->endDate = $endDate;
return $this;
}
public function getBeginHour(): ?DateTimeInterface
{
return $this->beginHour;
}
public function getBeginHourAsTimeString(): string
{
return $this->getTimeAsString($this->getBeginHour());
}
public function setBeginHour(?DateTimeInterface $beginHour): self
{
$this->beginHour = $beginHour;
return $this;
}
public function getEndHour(): ?DateTimeInterface
{
return $this->endHour;
}
public function getEndHourAsTimeString(): string
{
return $this->getTimeAsString($this->getEndHour());
}
public function setEndHour(?DateTimeInterface $endHour): self
{
$this->endHour = $endHour;
return $this;
}
public function getLocation(): ?string
{
return $this->location;
}
public function setLocation(?string $location): self
{
$this->location = $location;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getRegistrations(): ?Collection
{
return $this->registrations;
}
public function getCalendarEvent(): ?CalendarEvent
{
return $this->calendarEvent;
}
public function setCalendarEvent(?CalendarEvent $calendarEvent): self
{
$this->calendarEvent = $calendarEvent;
return $this;
}
public function __toString(): string
{
$string = ($this->getDateString());
$string .= ($this->getEndDate() ? ' - '.$this->getEndDateString() : '');
$string .= ($this->getBeginHour() ? ', '.$this->getBeginHourAsTimeString().'h' : '');
$string .= ($this->getEndHour() ? ' - '.$this->getEndHourAsTimeString().'h' : '');
$string .= ($this->getLocation() ? ', '.$this->getLocation() : '');
$string .= ($this->getTitle() ? ', '.$this->getTitle() : '');
$string .= ($this->getDescription() ? ', '.$this->getDescription() : '');
return $this->id ? $string : MiniAbstractBase::DEFAULT_EMPTY_STRING;
}
}