ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Period.php
Go to the documentation of this file.
1 <?php
2 
4 
7 use Sabre\Xml;
8 
20 class Period extends Property {
21 
28  public $delimiter = ',';
29 
40  function setRawMimeDirValue($val) {
41 
42  $this->setValue(explode($this->delimiter, $val));
43 
44  }
45 
51  function getRawMimeDirValue() {
52 
53  return implode($this->delimiter, $this->getParts());
54 
55  }
56 
65  function getValueType() {
66 
67  return 'PERIOD';
68 
69  }
70 
80  function setJsonValue(array $value) {
81 
82  $value = array_map(
83  function($item) {
84 
85  return strtr(implode('/', $item), [':' => '', '-' => '']);
86 
87  },
88  $value
89  );
90  parent::setJsonValue($value);
91 
92  }
93 
101  function getJsonValue() {
102 
103  $return = [];
104  foreach ($this->getParts() as $item) {
105 
106  list($start, $end) = explode('/', $item, 2);
107 
109 
110  // This is a duration value.
111  if ($end[0] === 'P') {
112  $return[] = [
113  $start->format('Y-m-d\\TH:i:s'),
114  $end
115  ];
116  } else {
118  $return[] = [
119  $start->format('Y-m-d\\TH:i:s'),
120  $end->format('Y-m-d\\TH:i:s'),
121  ];
122  }
123 
124  }
125 
126  return $return;
127 
128  }
129 
138  protected function xmlSerializeValue(Xml\Writer $writer) {
139 
140  $writer->startElement(strtolower($this->getValueType()));
141  $value = $this->getJsonValue();
142  $writer->writeElement('start', $value[0][0]);
143 
144  if ($value[0][1][0] === 'P') {
145  $writer->writeElement('duration', $value[0][1]);
146  }
147  else {
148  $writer->writeElement('end', $value[0][1]);
149  }
150 
151  $writer->endElement();
152 
153  }
154 
155 }
setValue($value)
Updates the current value.
Definition: Property.php:98
static parseDateTime($dt, DateTimeZone $tz=null)
Parses an iCalendar (rfc5545) formatted datetime and returns a DateTimeImmutable object.
getRawMimeDirValue()
Returns a raw mime-dir representation of the value.
Definition: Period.php:51
getValueType()
Returns the type of value.
Definition: Period.php:65
setRawMimeDirValue($val)
Sets a raw value coming from a mimedir (iCalendar/vCard) file.
Definition: Period.php:40
$start
Definition: bench.php:8
getJsonValue()
Returns the value, in the format it should be encoded for json.
Definition: Period.php:101
getParts()
Returns a multi-valued property.
Definition: Property.php:152
setJsonValue(array $value)
Sets the json value, as it would appear in a jCard or jCal object.
Definition: Period.php:80
xmlSerializeValue(Xml\Writer $writer)
This method serializes only the value of a property.
Definition: Period.php:138
The XML Writer class.
Definition: Writer.php:31