/** * Renders a property in accordance with rfc 2445 * @todo $proptype is created below and never used... wtf? */ protected function renderProperty(qCal_Property $property) { $propval = $property->getValue(); $params = $property->getParams(); $paramreturn = ""; foreach ($params as $paramname => $paramval) { $paramreturn .= $this->renderParam($paramname, $paramval); } // if property has a "value" param, then use it as the type instead $proptype = isset($params['VALUE']) ? $params['VALUE'] : $property->getType(); if ($property instanceof qCal_Property_MultiValue) { $values = array(); foreach ($property->getValue() as $value) { $values[] = $this->renderValue($property->getValue(), $proptype); } $value = implode(chr(44), $values); } else { $value = $this->renderValue($property->getValue(), $proptype); } $content = $property->getName() . $paramreturn . ":" . $value . self::LINE_ENDING; return $this->fold($content); }
/** * Override doParse in a child class if necessary */ protected function doParse($tokens) { $properties = array(); foreach ($tokens['properties'] as $propertytoken) { $params = array(); foreach ($propertytoken['params'] as $paramtoken) { $params[$paramtoken['param']] = $paramtoken['value']; } try { $properties[] = qCal_Property::factory($propertytoken['property'], $propertytoken['value'], $params); } catch (qCal_Exception $e) { // @todo There should be a better way of determining what went wrong during parsing/lexing than this // do nothing... // pr($e); } } $component = qCal_Component::factory($tokens['component'], $properties); foreach ($tokens['children'] as $child) { $childcmpnt = $this->doParse($child); $component->attach($childcmpnt); } return $component; }
/** * Allows for components to get and set property values by calling * qCal_Component::getPropertyName() and qCal_Component::setPropertyName('2.0') where propertyName is the property name * to be set and $val is the property value. * This is just a convenience facade, it isn't going to be used within the library as much as by end-users * @todo I can't decided whether to maybe get rid of the facade methods at least for now since some properties * can potentially return multiple values and that makes the interface inconsistent */ public function __call($method, $params) { $firstthree = substr($method, 0, 3); $name = substr($method, 3); if ($firstthree == "get") { // if property is allowed multiple times, an array is returned, otherwise just the one component if ($this->hasProperty($name)) { $property = $this->getProperty($name); if (!$property[0]->allowMultiple()) { return $property[0]; } else { return $property; } } } elseif ($firstthree == "set") { $value = isset($params[0]) ? $params[0] : null; $params = isset($params[1]) ? $params[1] : array(); $property = qCal_Property::factory($name, $value, $params); $this->addProperty($property); } elseif ($firstthree == "add") { // add property type $property = qCal_Property::factory($name, $params); $this->addProperty($property); return $this; } // throw exception here? // throw new qCal_Exception(); }
public function __construct($value, $params, $name) { parent::__construct($value, $params); $this->name = strtoupper($name); }