ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilECSTimePlace.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
31 {
32  private ilLogger $logger;
33  private string $room = '';
34  private string $begin = '';
35  private string $end = '';
36  private string $cycle = '';
37 
38  public function __construct()
39  {
40  global $DIC;
41  $this->logger = $DIC->logger()->wsrv();
42  }
43 
44  public function __toString()
45  {
46  return "ECS Time and Place";
47  }
48 
56  public function loadFromJson($a_json): void
57  {
58  if (!is_object($a_json)) {
59  $this->logger->error(__METHOD__ . ': Cannot load from JSON. No object given.');
60  throw new ilException('Cannot parse ECSContent.');
61  }
62 
63  $this->logger->debug(__METHOD__ . ': ' . print_r($a_json, true));
64 
65  $this->room = $a_json->room ?? "";
66  $this->begin = $a_json->begin ?? "";
67  $this->end = $a_json->end ?? "";
68  $this->cycle = $a_json->cycle ?? "";
69 
70  $two = new ilDate('2000-01-02', IL_CAL_DATE);
71  if (ilDate::_before(new ilDateTime($this->getUTBegin(), IL_CAL_UNIX), $two)) {
72  $this->begin = '';
73  }
74  if (ilDate::_before(new ilDateTime($this->getUTEnd(), IL_CAL_UNIX), $two)) {
75  $this->end = '';
76  }
77  }
78 
82  public function setBegin($a_begin): void
83  {
84  // is it unix time ?
85  if (is_numeric($a_begin) && $a_begin) {
86  $dt = new ilDateTime($a_begin, IL_CAL_UNIX, ilTimeZone::UTC);
87  $this->end = $dt->get(IL_CAL_DATE);
88  } else {
89  $this->begin = $a_begin;
90  }
91  }
92 
96  public function getBegin(): string
97  {
98  return $this->begin;
99  }
100 
104  public function getUTBegin()
105  {
106  return (new ilDateTime($this->begin, IL_CAL_DATE, ilTimeZone::UTC))->get(IL_CAL_UNIX);
107  }
108 
112  public function setEnd(string $a_end): void
113  {
114  // is it unix time ?
115  if (is_numeric($a_end) && $a_end) {
116  $dt = new ilDateTime($a_end, IL_CAL_UNIX, ilTimeZone::UTC);
117  $this->end = $dt->get(IL_CAL_DATE);
118  } else {
119  $this->end = $a_end;
120  }
121  }
122 
126  public function getEnd(): string
127  {
128  return $this->end;
129  }
130 
134  public function getUTEnd()
135  {
136  return (new ilDateTime($this->end, IL_CAL_DATE, ilTimeZone::UTC))->get(IL_CAL_UNIX);
137  }
138 
142  public function setRoom(string $a_room): void
143  {
144  $this->room = $a_room;
145  }
146 
150  public function getRoom(): string
151  {
152  return $this->room;
153  }
154 
158  public function setCycle($a_cycle): void
159  {
160  $this->cycle = $a_cycle;
161  }
162 
166  public function getCycle(): string
167  {
168  return $this->cycle;
169  }
170 }
Representation of ECS EContent Time Place.
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.
setRoom(string $a_room)
set room
setCycle($a_cycle)
set cycle
const IL_CAL_UNIX
global $DIC
Definition: shib_login.php:26
loadFromJson($a_json)
load from json
getUTBegin()
get begin as unix time
setBegin($a_begin)
set begin
const IL_CAL_DATE
setEnd(string $a_end)
set end
getUTEnd()
get end as unix time