public function __set($property, $value)
{
$this->_validate($property, $value);
- if ($this->_properties[$property]['multiple']) {
- $this->_properties[$property]['value'] = array($value);
- $this->_properties[$property]['params'] = array();
- } else {
- $this->_properties[$property]['value'] = $value;
- $this->_properties[$property]['params'] = null;
- }
+ $this->_setProperty($property, $value);
}
/**
*/
public function setProperty($property, $value, $params = array())
{
- $this->$property = $value;
- $this->_properties[$property]['params'] = $params;
+ $this->_validate($property, $value);
+ $this->_setProperty($property, $value, $params);
}
/**
{
$this->_validate($property, $value);
if (!$this->_properties[$property]['multiple'] &&
- isset($this->_properties[$property]['value'])) {
+ !empty($this->_properties[$property]['values'])) {
throw new Horde_Icalendar_Exception($property . ' properties must not occur more than once.');
}
- if (isset($this->_properties[$property]['value'])) {
- $this->_properties[$property]['value'][] = $value;
+ $this->_setProperty($property, $value, $params, true);
+ }
+
+ /**
+ * Sets the value of a property.
+ *
+ * @param string $property The name of the property.
+ * @param string $value The value of the property.
+ * @param array $params Array containing any addition parameters for
+ * this property.
+ * @param boolean $add Whether to add (instead of replace) the value.
+ *
+ * @throws InvalidArgumentException
+ */
+ protected function _setProperty($property, $value, $params = array(), $add = false)
+ {
+ if ($add) {
+ if (!isset($this->_properties[$property]['values'])) {
+ $this->_properties[$property]['values'] = array();
+ $this->_properties[$property]['params'] = array();
+ }
+ $this->_properties[$property]['values'][] = $value;
$this->_properties[$property]['params'][] = $params;
} else {
- $this->setProperty($property, $value, $params);
+ $this->_properties[$property]['values'] = array($value);
+ $this->_properties[$property]['params'] = $params;
}
}
if (!isset($this->_properties[$property])) {
throw new InvalidArgumentException($property . ' is not a valid property');
}
- return isset ($this->_properties[$property]['value'])
- ? $this->_properties[$property]['value']
+ return isset($this->_properties[$property]['values'])
+ ? ($this->_properties[$property]['multiple']
+ ? $this->_properties[$property]['values']
+ : $this->_properties[$property]['values'][0])
: null;
}
public function validate()
{
foreach ($this->_properties as $name => $property) {
- if (!empty($property['required']) && !isset($property['value'])) {
+ if (!empty($property['required']) && !isset($property['values'])) {
switch ($name) {
case 'uid':
$this->uid = (string)new Horde_Support_Guid;
'uid' => array('required' => true,
'multiple' => false,
'type' => 'string'),
- 'start' => array('required' => false,
+ 'start' => array('required' => true,
'multiple' => false,
'class' => 'Horde_Date'),
'startDate' => array('required' => false,
parent::__construct($properties);
}
- public function validate()
+ /**
+ * Sets the value of a property.
+ *
+ * @param string $property The name of the property.
+ * @param string $value The value of the property.
+ * @param array $params Array containing any addition parameters for
+ * this property.
+ * @param boolean $add Whether to add (instead of replace) the value.
+ *
+ * @throws InvalidArgumentException
+ */
+ protected function _setProperty($property, $value, $params = array(), $add = false)
{
- parent::validate();
- if (!isset($this->_properties['start']['value']) &&
- !isset($this->_properties['startDate']['value'])) {
- throw new Horde_Icalendar_Exception('VEVENT components must have a start property set');
+ if ($property == 'startDate') {
+ $this->_validate('start', $value);
+ $property = 'start';
+ $params['value'] = 'date';
}
+ parent::_setProperty($property, $value, $params, $add);
}
}
class Horde_Icalendar_Writer_Vcalendar_20 extends Horde_Icalendar_Writer_Base
{
+ protected $_propertyMap = array('product' => 'PRODID',
+ 'start' => 'DTSTART',
+ 'stamp' => 'DTSTAMP');
+
+ protected function _exportProperty($name, $property)
+ {
+ if (!isset($property['values'])) {
+ return;
+ }
+ if (isset($property['class']) && $property['class'] == 'Horde_Date') {
+ if (isset($this->_propertyMap[$name])) {
+ $name = $this->_propertyMap[$name];
+ }
+ foreach ($property['values'] as $value) {
+ $this->_output .= Horde_String::upper($name) . ':' . $value->format('Ymd\THms\Z') . "\n";
+ }
+ } else {
+ parent::_exportProperty($name, $property);
+ }
+ }
}