public function setData($xml) { $this->_data_array = array(); if (!empty($xml)) { $xml = YXML::loadString($xml); foreach ($xml->children() as $xml_element) { if ((string) $xml_element->attributes()->identifier == $this->identifier) { $data = ElementData::newInstance($this); $data->decodeXML($xml_element); $this->_data_array[] = $data; } } } if (empty($this->_data_array)) { $this->_data_array[0] = ElementData::newInstance($this); } $this->_data = $this->_data_array[0]; }
public function render() { // create html $html = '<ul>'; foreach ($this->_root->getChildren() as $child) { $html .= $child->render($this); } $html .= '</ul>'; // decorator callbacks ? if (func_num_args()) { // parse html if ($xml = YXML::loadString($html)) { foreach (func_get_args() as $callback) { if (is_callable($callback)) { $xml->map($callback); } } $html = $xml->asXML(true); } } return $html; }
public function setData($xml) { $this->_data = ElementData::newInstance($this); if (!empty($xml)) { $xml = YXML::loadString($xml); foreach ($xml->children() as $xml_element) { if ((string) $xml_element->attributes()->identifier == $this->identifier) { $this->_data->decodeXML($xml_element); break; } } } return $this; }
public static function createElementsFromXML($xml_string, Type $type) { $i = 0; $results = array(); $xml = YXML::loadString($xml_string); $params = $xml->xpath('params/param'); if ($params) { foreach ($params as $param) { if ($element = self::_getElementFromXMLNode($param, $type)) { $results[$element->identifier] = $element; $results[$element->identifier]->setOrdering($i++); } } } return $results; }
public function save() { $old_identifier = $this->id; $rename = false; if (empty($this->id)) { // check identifier if (file_exists($this->getXMLFile($this->identifier))) { throw new TypeException('Identifier already exists'); } // set xml $this->setXML(YXMLElement::create('type')->addAttribute('version', '1.0.0')->asXML(true, true)); } else { if ($old_identifier != $this->identifier) { // check identifier if (file_exists($this->getXMLFile($this->identifier))) { throw new TypeException('Identifier already exists'); } // rename xml file if (!JFile::move($this->getXMLFile(), $this->getXMLFile($this->identifier))) { throw new TypeException('Renaming xml file failed'); } $rename = true; } } // update id $this->id = $this->identifier; // set data $this->setXML(YXML::loadString($this->getXML())->addAttribute('name', $this->name)->asXML(true, true)); // save xml file if ($file = $this->getXMLFile()) { if (!JFile::write($file, $this->getXML())) { throw new TypeException('Writing type xml file failed'); } } // rename related items if ($rename) { $table = YTable::getInstance('item'); // get database $db = $table->getDBO(); // update childrens parent category $query = "UPDATE " . $table->getTableName() . " SET type=" . $db->quote($this->identifier) . " WHERE type=" . $db->quote($old_identifier); $db->query($query); } return $this; }
protected function _itemToXML(Item $item) { $attributes = array(); foreach (self::$item_attributes as $attribute) { if (isset($item->{$attribute})) { $attributes[$attribute] = $item->{$attribute}; } } $attributes['author'] = JFactory::getUser($item->created_by)->username; $item_xml = $this->_buildItem($item->alias, $item->name, $attributes); foreach ($item->getRelatedCategoryIds() as $category_id) { $alias = ''; if (empty($category_id)) { $alias = '_root'; } else { if (isset($this->categories[$category_id])) { $alias = $this->categories[$category_id]->alias; } } if (!empty($alias)) { $this->_addItemCategory($item_xml, $alias); } } foreach ($item->getTags() as $tag) { $this->_addItemTag($item_xml, $tag); } foreach ($item->getElements() as $element) { $xml = YXML::loadString('<wrapper>' . $element->toXML() . '</wrapper>'); foreach ($xml->children() as $element_xml) { $element_xml->addAttribute('name', $element->getConfig()->get('name')); $this->_addItemData($item_xml, $element_xml); } } $metadata = array(); foreach ($item->getParams()->get('metadata.', array()) as $key => $value) { $metadata[preg_replace('/^metadata\\./', '', $key)] = $value; } if (!empty($metadata)) { $this->_addItemMetadata($item_xml, $metadata); } // sanitize relateditems elements $related_item_xmls = $item_xml->xpath('data/relateditems/item'); if ($related_item_xmls) { foreach ($related_item_xmls as $related_item_xml) { $item_xml->replaceChild(YXMLElement::create('item', ItemHelper::translateIDToAlias((string) $related_item_xml), true), $related_item_xml); } } return $item_xml; }