src/Entity/LearningCourses/LearningCourseSession.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity\LearningCourses;
  3. use App\Annotation\SiteAware;
  4. use App\Entity\AbstractBase;
  5. use App\Entity\Calendar\CalendarEvent;
  6. use App\Entity\Interfaces\SiteInterface;
  7. use App\Entity\MiniAbstractBase;
  8. use App\Entity\Traits\LearningCourseTrait;
  9. use App\Entity\Traits\SiteTrait;
  10. use App\Repository\LearningCourses\LearningCourseSessionRepository;
  11. use DateTimeInterface;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Gedmo\Mapping\Annotation as Gedmo;
  16. /**
  17.  * @ORM\Table(name="vulco_learning_course_session", indexes={@ORM\Index(name="learning_course_session_site_idx", columns={"site"})})
  18.  * @ORM\Entity(repositoryClass=LearningCourseSessionRepository::class)
  19.  * @Gedmo\SoftDeleteable(fieldName="removedAt", timeAware=false)
  20.  * @SiteAware(siteFieldName="site")
  21.  */
  22. class LearningCourseSession extends AbstractBase implements SiteInterface
  23. {
  24.     use LearningCourseTrait;
  25.     use SiteTrait;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity="LearningCourse", inversedBy="sessions")
  28.      */
  29.     private LearningCourse $course;
  30.     /**
  31.      * @ORM\Column(type="date", nullable=false)
  32.      */
  33.     private DateTimeInterface $date;
  34.     /**
  35.      * @ORM\Column(type="date", nullable=true)
  36.      */
  37.     private ?DateTimeInterface $endDate null;
  38.     /**
  39.      * @ORM\Column(type="time", nullable=true)
  40.      */
  41.     private ?DateTimeInterface $beginHour;
  42.     /**
  43.      * @ORM\Column(type="time", nullable=true)
  44.      */
  45.     private ?DateTimeInterface $endHour;
  46.     /**
  47.      * @ORM\Column(type="text", length=10000, nullable=true)
  48.      */
  49.     private ?string $location null;
  50.     /**
  51.      * @ORM\Column(type="string", length=255, nullable=true)
  52.      */
  53.     private ?string $title;
  54.     /**
  55.      * @ORM\Column(type="text", length=10000, nullable=true)
  56.      */
  57.     private ?string $description null;
  58.     /**
  59.      * @ORM\OneToMany(targetEntity="App\Entity\LearningCourses\LearningCourseRegistration", mappedBy="session")
  60.      */
  61.     private ?Collection $registrations;
  62.     /**
  63.      * @ORM\OneToOne(targetEntity="App\Entity\Calendar\CalendarEvent", cascade={"persist", "remove"})
  64.      */
  65.     private ?CalendarEvent $calendarEvent null;
  66.     public function __construct()
  67.     {
  68.         $this->registrations = new ArrayCollection();
  69.     }
  70.     public function getDateString(): string
  71.     {
  72.         return $this->getDateAsString($this->getDate());
  73.     }
  74.     public function getDate(): DateTimeInterface
  75.     {
  76.         return $this->date;
  77.     }
  78.     public function getDateWithBeginHour(): DateTimeInterface
  79.     {
  80.         $date = clone $this->getDate();
  81.         if ($this->getBeginHour()) {
  82.             $hours $this->getBeginHour()->format('H');
  83.             $minutes $this->getBeginHour()->format('i');
  84.             $date->setTime($hours$minutes);
  85.         }
  86.         return $date;
  87.     }
  88.     public function getDateWithEndHour(): DateTimeInterface
  89.     {
  90.         $date = clone $this->getDate();
  91.         if ($this->getEndHour()) {
  92.             $hours $this->getEndHour()->format('H');
  93.             $minutes $this->getEndHour()->format('i');
  94.             $date->setTime($hours$minutes);
  95.         }
  96.         return $date;
  97.     }
  98.     public function setDate(DateTimeInterface $date): self
  99.     {
  100.         $this->date $date;
  101.         return $this;
  102.     }
  103.     public function getEndDateString(): string
  104.     {
  105.         return $this->getDateAsString($this->getEndDate());
  106.     }
  107.     public function getEndDate(): ?DateTimeInterface
  108.     {
  109.         return $this->endDate;
  110.     }
  111.     public function getEndDateWithEndHour(): DateTimeInterface
  112.     {
  113.         $date = clone $this->getEndDate();
  114.         if ($this->getEndHour()) {
  115.             $hours $this->getEndHour()->format('H');
  116.             $minutes $this->getEndHour()->format('i');
  117.             $date->setTime($hours$minutes);
  118.         }
  119.         return $date;
  120.     }
  121.     public function setEndDate(?DateTimeInterface $endDate): self
  122.     {
  123.         $this->endDate $endDate;
  124.         return $this;
  125.     }
  126.     public function getBeginHour(): ?DateTimeInterface
  127.     {
  128.         return $this->beginHour;
  129.     }
  130.     public function getBeginHourAsTimeString(): string
  131.     {
  132.         return $this->getTimeAsString($this->getBeginHour());
  133.     }
  134.     public function setBeginHour(?DateTimeInterface $beginHour): self
  135.     {
  136.         $this->beginHour $beginHour;
  137.         return $this;
  138.     }
  139.     public function getEndHour(): ?DateTimeInterface
  140.     {
  141.         return $this->endHour;
  142.     }
  143.     public function getEndHourAsTimeString(): string
  144.     {
  145.         return $this->getTimeAsString($this->getEndHour());
  146.     }
  147.     public function setEndHour(?DateTimeInterface $endHour): self
  148.     {
  149.         $this->endHour $endHour;
  150.         return $this;
  151.     }
  152.     public function getLocation(): ?string
  153.     {
  154.         return $this->location;
  155.     }
  156.     public function setLocation(?string $location): self
  157.     {
  158.         $this->location $location;
  159.         return $this;
  160.     }
  161.     public function getTitle(): ?string
  162.     {
  163.         return $this->title;
  164.     }
  165.     public function setTitle(?string $title): self
  166.     {
  167.         $this->title $title;
  168.         return $this;
  169.     }
  170.     public function getDescription(): ?string
  171.     {
  172.         return $this->description;
  173.     }
  174.     public function setDescription(?string $description): self
  175.     {
  176.         $this->description $description;
  177.         return $this;
  178.     }
  179.     public function getRegistrations(): ?Collection
  180.     {
  181.         return $this->registrations;
  182.     }
  183.     public function getCalendarEvent(): ?CalendarEvent
  184.     {
  185.         return $this->calendarEvent;
  186.     }
  187.     public function setCalendarEvent(?CalendarEvent $calendarEvent): self
  188.     {
  189.         $this->calendarEvent $calendarEvent;
  190.         return $this;
  191.     }
  192.     public function __toString(): string
  193.     {
  194.         $string = ($this->getDateString());
  195.         $string .= ($this->getEndDate() ? ' - '.$this->getEndDateString() : '');
  196.         $string .= ($this->getBeginHour() ? ', '.$this->getBeginHourAsTimeString().'h' '');
  197.         $string .= ($this->getEndHour() ? ' - '.$this->getEndHourAsTimeString().'h' '');
  198.         $string .= ($this->getLocation() ? ', '.$this->getLocation() : '');
  199.         $string .= ($this->getTitle() ? ', '.$this->getTitle() : '');
  200.         $string .= ($this->getDescription() ? ', '.$this->getDescription() : '');
  201.         return $this->id $string MiniAbstractBase::DEFAULT_EMPTY_STRING;
  202.     }
  203. }