<?php
 class vB_Xml_Export_PageTemplate extends vB_Xml_Export { public function getXml(?vB_XML_Builder &$xml = NULL) { if (empty($xml)) { $xml = new vB_XML_Builder(); $returnString = TRUE; } else { $returnString = FALSE; } $xml->add_group('pagetemplates'); $pageTemplateTable = $this->db->fetchTableStructure('pagetemplate'); $pageTemplateTableColumns = array_diff($pageTemplateTable['structure'], array('guid', $pageTemplateTable['key'])); $widgetInstanceTable = $this->db->fetchTableStructure('widgetinstance'); $widgetInstanceTableColumns = array_diff($widgetInstanceTable['structure'], array('guid', 'widgetid', 'pagetemplateid', $widgetInstanceTable['key'])); $pageTemplates = $this->db->assertQuery('pagetemplate', array( vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::CONDITIONS_KEY => array('product' => $this->productid) )); $screenLayouts = $this->db->getRows('screenlayout', array(), false, 'screenlayoutid'); if (!empty($pageTemplates)) { foreach ($pageTemplates AS $pageTemplate) { $info[$pageTemplate[$pageTemplateTable['key']]] = $pageTemplate; } if (!empty($info)) { $widgetsInfo = array(); $widgetInstances = $this->db->getRows('widgetinstance', array('pagetemplateid' => array_keys($info))); foreach($widgetInstances AS $widgetInstance) { $info[$widgetInstance['pagetemplateid']]['widgets'][$widgetInstance['widgetinstanceid']] = $widgetInstance; $widgetsInfo[$widgetInstance['widgetid']] = ''; } if (!empty($widgetsInfo)) { $widgets = $this->db->getRows('widget', array('widgetid' => array_keys($widgetsInfo))); foreach($widgets AS $widget) { $widgetsInfo[$widget['widgetid']] = $widget['guid']; } } foreach ($info AS $pageTemplate) { $xml->add_group('pagetemplate', array('guid' => $pageTemplate['guid'])); foreach ($pageTemplateTableColumns AS $column) { if ($pageTemplate[$column] != NULL) { if ($column == 'screenlayoutid') { $screenLayoutId = $pageTemplate[$column]; if (!empty($screenLayouts[$screenLayoutId]) AND !empty($screenLayouts[$screenLayoutId]['guid'])) { $xml->add_tag('screenlayoutguid', $screenLayouts[$screenLayoutId]['guid']); } else { $xml->add_tag($column, $pageTemplate[$column]); } } else { $xml->add_tag($column, $pageTemplate[$column]); } } } if (isset($pageTemplate['widgets']) AND !empty($pageTemplate['widgets'])) { $xml->add_group('widgets'); foreach ($pageTemplate['widgets'] AS $widgetInstance) { $xml->add_group('widgetinstance'); foreach($widgetInstanceTableColumns AS $column) { $xml->add_tag($column, $widgetInstance[$column]); } $xml->add_tag('widgetguid', $widgetsInfo[$widgetInstance['widgetid']]); $xml->close_group(); } $xml->close_group(); } $xml->close_group(); } } } $xml->close_group(); if ($returnString) { return $xml->fetch_xml(); } } } 