ILIAS  release_8 Revision v8.24
TimePeriod.php
Go to the documentation of this file.
1<?php
2
20
29{
35 private ?int $startDateTime = null;
36
42 private ?int $endDateTime = null;
43
49 public function __construct(int $startDateTime, int $endDateTime)
50 {
51 $this->startDateTime = $startDateTime;
52 $this->endDateTime = $endDateTime;
53 }
54
60 public function toJsonldObject()
61 {
62 return $this->toJsonObject();
63 }
64
70 public function toJsonObject(): \stdClass
71 {
72 $timePeriod = new \stdClass();
73 if (!is_null($this->startDateTime)) {
74 $timePeriod->startDateTime = gmdate('Y-m-d\TH:i:s\Z', $this->startDateTime);
75 }
76 if (!is_null($this->endDateTime)) {
77 $timePeriod->endDateTime = gmdate('Y-m-d\TH:i:s\Z', $this->endDateTime);
78 }
79
80 return $timePeriod;
81 }
82
88 public static function fromJsonObject(object $item): ?TimePeriod
89 {
90 $obj = null;
91 $startDateTime = null;
92 $endDateTime = null;
93 if (is_object($item)) {
94 $url = null;
95 foreach (get_object_vars($item) as $name => $value) {
96 switch ($name) {
97 case 'startDateTime':
98 $startDateTime = strtotime($item->startDateTime);
99 break;
100 case 'endDateTime':
101 $endDateTime = strtotime($item->endDateTime);
102 break;
103 }
104 }
105 } else {
106 $url = $item;
107 }
110 }
111
112 return $obj;
113 }
114}
Class to represent a time period object.
Definition: TimePeriod.php:29
static fromJsonObject(object $item)
Generate a LineItem object from its JSON or JSON-LD representation.
Definition: TimePeriod.php:88
toJsonldObject()
Generate the JSON-LD object representation of the time period.
Definition: TimePeriod.php:60
toJsonObject()
Generate the JSON object representation of the image.
Definition: TimePeriod.php:70
__construct(int $startDateTime, int $endDateTime)
Class constructor.
Definition: TimePeriod.php:49
if($format !==null) $name
Definition: metadata.php:247
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: FileItem.php:19
$url