ILIAS  release_8 Revision v8.24
class.ilECSTimePlace.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
30{
32 private string $room = '';
33 private string $begin = '';
34 private string $end = '';
35 private string $cycle = '';
36
37 public function __construct()
38 {
39 global $DIC;
40 $this->logger = $DIC->logger()->wsrv();
41 }
42
43 public function __toString()
44 {
45 return "ECS Time and Place";
46 }
47
55 public function loadFromJson($a_json): void
56 {
57 if (!is_object($a_json)) {
58 $this->logger->error(__METHOD__ . ': Cannot load from JSON. No object given.');
59 throw new ilException('Cannot parse ECSContent.');
60 }
61
62 $this->logger->debug(__METHOD__ . ': ' . print_r($a_json, true));
63
64 $this->room = $a_json->room ?? "";
65 $this->begin = $a_json->begin ?? "";
66 $this->end = $a_json->end ?? "";
67 $this->cycle = $a_json->cycle ?? "";
68
69 $two = new ilDate('2000-01-02', IL_CAL_DATE);
70 if (ilDate::_before(new ilDateTime($this->getUTBegin(), IL_CAL_UNIX), $two)) {
71 $this->begin = '';
72 }
73 if (ilDate::_before(new ilDateTime($this->getUTEnd(), IL_CAL_UNIX), $two)) {
74 $this->end = '';
75 }
76 }
77
81 public function setBegin($a_begin): void
82 {
83 // is it unix time ?
84 if (is_numeric($a_begin) && $a_begin) {
85 $dt = new ilDateTime($a_begin, IL_CAL_UNIX, ilTimeZone::UTC);
86 $this->end = $dt->get(IL_CAL_DATE);
87 } else {
88 $this->begin = $a_begin;
89 }
90 }
91
95 public function getBegin(): string
96 {
97 return $this->begin;
98 }
99
103 public function getUTBegin()
104 {
105 return (new ilDateTime($this->begin, IL_CAL_DATE, ilTimeZone::UTC))->get(IL_CAL_UNIX);
106 }
107
111 public function setEnd(string $a_end): void
112 {
113 // is it unix time ?
114 if (is_numeric($a_end) && $a_end) {
115 $dt = new ilDateTime($a_end, IL_CAL_UNIX, ilTimeZone::UTC);
116 $this->end = $dt->get(IL_CAL_DATE);
117 } else {
118 $this->end = $a_end;
119 }
120 }
121
125 public function getEnd(): string
126 {
127 return $this->end;
128 }
129
133 public function getUTEnd()
134 {
135 return (new ilDateTime($this->end, IL_CAL_DATE, ilTimeZone::UTC))->get(IL_CAL_UNIX);
136 }
137
141 public function setRoom(string $a_room): void
142 {
143 $this->room = $a_room;
144 }
145
149 public function getRoom(): string
150 {
151 return $this->room;
152 }
153
157 public function setCycle($a_cycle): void
158 {
159 $this->cycle = $a_cycle;
160 }
161
165 public function getCycle(): string
166 {
167 return $this->cycle;
168 }
169}
const IL_CAL_DATE
const IL_CAL_UNIX
@classDescription Date and time handling
static _before(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
Class for single dates.
Representation of ECS EContent Time Place.
setBegin($a_begin)
set begin
getUTBegin()
get begin as unix time
setRoom(string $a_room)
set room
setCycle($a_cycle)
set cycle
setEnd(string $a_end)
set end
getUTEnd()
get end as unix time
loadFromJson($a_json)
load from json
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Component logger with individual log levels by component id.
global $DIC
Definition: feed.php:28