1 <?php 2 3 namespace Packback\Lti1p3; 4 5 use DateTime; 6 7 class LtiDeepLinkDateTimeInterval 8 { 9 private ?DateTime $start; 10 private ?DateTime $end; 11 12 public function __construct(DateTime $start = null, DateTime $end = null) 13 { 14 if ($start !== null && $end !== null && $end < $start) { 15 throw new LtiException('Interval start time cannot be greater than end time'); 16 } 17 18 $this->start = $start ?? null; 19 $this->end = $end ?? null; 20 } 21 22 public static function new(): LtiDeepLinkDateTimeInterval 23 { 24 return new LtiDeepLinkDateTimeInterval(); 25 } 26 27 public function setStart(?DateTime $start): LtiDeepLinkDateTimeInterval 28 { 29 $this->start = $start; 30 31 return $this; 32 } 33 34 public function getStart(): ?DateTime 35 { 36 return $this->start; 37 } 38 39 public function setEnd(?DateTime $end): LtiDeepLinkDateTimeInterval 40 { 41 $this->end = $end; 42 43 return $this; 44 } 45 46 public function getEnd(): ?DateTime 47 { 48 return $this->end; 49 } 50 51 public function toArray(): array 52 { 53 if (!isset($this->start) && !isset($this->end)) { 54 throw new LtiException('At least one of the interval bounds must be specified on the object instance'); 55 } 56 57 if ($this->start !== null && $this->end !== null && $this->end < $this->start) { 58 throw new LtiException('Interval start time cannot be greater than end time'); 59 } 60 61 $dateTimeInterval = []; 62 63 if (isset($this->start)) { 64 $dateTimeInterval['startDateTime'] = $this->start->format(DateTime::ATOM); 65 } 66 if (isset($this->end)) { 67 $dateTimeInterval['endDateTime'] = $this->end->format(DateTime::ATOM); 68 } 69 70 return $dateTimeInterval; 71 } 72 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body