LTI Integration Library 4.10.3
PHP class library for building LTI integrations
 
Loading...
Searching...
No Matches
TimePeriod.php
1<?php
2
3namespace ceLTIc\LTI\Content;
4
13{
14
20 private $startDateTime = null;
21
27 private $endDateTime = null;
28
35 function __construct($startDateTime, $endDateTime)
36 {
37 if (is_int($startDateTime)) {
38 $this->startDateTime = $startDateTime;
39 }
40 if (is_int($endDateTime)) {
41 $this->endDateTime = $endDateTime;
42 }
43 }
44
50 public function toJsonldObject()
51 {
52 return $this->toJsonObject();
53 }
54
60 public function toJsonObject()
61 {
62 $timePeriod = new \stdClass();
63 if (!is_null($this->startDateTime)) {
64 $timePeriod->startDateTime = gmdate('Y-m-d\TH:i:s\Z', $this->startDateTime);
65 } else {
66 $timePeriod->startDateTime = null;
67 }
68 if (!is_null($this->endDateTime)) {
69 $timePeriod->endDateTime = gmdate('Y-m-d\TH:i:s\Z', $this->endDateTime);
70 } else {
71 $timePeriod->endDateTime = null;
72 }
73
74 return $timePeriod;
75 }
76
84 public static function fromJsonObject($item)
85 {
86 $obj = null;
87 $startDateTime = null;
88 $endDateTime = null;
89 if (is_object($item)) {
90 $url = null;
91 foreach (get_object_vars($item) as $name => $value) {
92 switch ($name) {
93 case 'startDateTime':
94 $startDateTime = strtotime($item->startDateTime);
95 break;
96 case 'endDateTime':
97 $endDateTime = strtotime($item->endDateTime);
98 break;
99 }
100 }
101 } else {
102 $url = $item;
103 }
104 if ($startDateTime || $endDateTime) {
105 $obj = new TimePeriod($startDateTime, $endDateTime);
106 }
107
108 return $obj;
109 }
110
111}
Class to represent a time period object.
static fromJsonObject($item)
Generate a LineItem object from its JSON or JSON-LD representation.
__construct($startDateTime, $endDateTime)
Class constructor.
toJsonObject()
Generate the JSON object representation of the image.
toJsonldObject()
Generate the JSON-LD object representation of the time period.