/** * The main function for converting to an XML document. * Pass in a multi dimensional array and this recrusively loops through and builds up an XML document. * * @param array $data * @param string $rootNodeName - what you want the root node to be - defaultsto data. * @param SimpleXMLElement $xml - should only be used recursively * @param array $namespaces - the namespaces (like $namespace[] = array('url' => 'http://....', 'name' => 'xmlns:g') */ public function toXml($data, $rootNodeName = 'data', &$xml = null, $namespaces = null, $root_ns = null) { // First call: create document and root node if (is_null($xml)) { $this->doc = new DOMDocument('1.0', 'utf8'); // Root namespace if ($root_ns) { $root = $this->doc->createElementNS($root_ns, $rootNodeName); } $xml =& $root; $this->doc->appendChild($root); // Namespaces foreach ($namespaces as $ns) { $root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . $ns['name'], $ns['url']); } } // loop though the array foreach ($data as $key => $value) { // normal list of nodes if (is_numeric($key)) { $key = $rootNodeName; } // Attributes support if ($key == $this->attr_arr_string) { // Add attributes to node foreach ($value as $attr_name => $attr_value) { $att = $this->doc->createAttribute($attr_name); $xml->appendChild($att); $att->appendChild($this->doc->createTextNode($attr_value)); } } else { // Add the value if there was a value together with the att if ($key == $this->value_string) { // Add value to node $xml->appendChild($this->doc->createTextNode($value)); } else { // delete any char not allowed in XML element names $key = preg_replace('/[^a-z0-9\\-\\_\\.\\:]/i', '', $key); // if there is another array found recrusively call this function if (is_array($value)) { // create a new node unless this is an array of elements if ($this->isAssoc($value)) { $node = $this->doc->createElement($key); $xml->appendChild($node); } else { $node = $xml; } // recrusive call - pass $key as the new rootNodeName $this->toXml($value, $key, $node); } else { // Add a single value $value = htmlentities($value); $t = $this->doc->createElement($key); $xml->appendChild($t); $v = $this->doc->createTextNode($value); $t->appendChild($v); } } } } $this->doc->formatOutput = true; echo Citruscart::dump($this->doc->saveXML()); return $this->doc->saveXML(); }
/** * Saves the properties for all attribute option values in list * * @return unknown_type */ function saveattributeoptionvalues() { JPluginHelper::importPlugin('citruscart'); $app = JFactory::getApplication(); $error = false; $this->messagetype = ''; $this->message = ''; $model = $this->getModel('productattributeoptionvalues'); $row = $model->getTable(); $id = $app->input->getInt('id', 0); $cids = $app->input->get('cid', array(0), 'request', 'array'); $field = $app->input->get('field', array(0), 'request', 'array'); $operator = $app->input->get('operator', array(0), 'request', 'array'); $value = $app->input->get('value', array(0), 'request', 'array'); foreach ($cids as $cid) { $row->load($cid); $row->productattributeoptionvalue_field = $field[$cid]; $row->productattributeoptionvalue_operator = $operator[$cid]; $row->productattributeoptionvalue_value = $value[$cid]; echo Citruscart::dump($row); if (!$row->check() || !$row->store()) { $this->message .= $row->getError(); $this->messagetype = 'notice'; $error = true; } } $row->reorder(); $productModel = $this->getModel('products'); $productModel->clearCache(); if ($error) { $this->message = JText::_('COM_CITRUSCART_ERROR') . " - " . $this->message; } else { $this->message = JText::_('COM_CITRUSCART_PRODUCT_OPTIONVALUES_SAVED_SUCCESSFULLY'); $this->messagetype = "Message"; } $redirect = "index.php?option=com_citruscart&view=products&task=setattributeoptionvalues&id={$id}&tmpl=component"; $redirect = JRoute::_($redirect, false); $app->redirect($redirect, $this->message, $this->messagetype); //$this->setRedirect( $redirect, $this->message, $this->messagetype ); }