Backend\Modules\Extensions\Engine\Model::createTemplateXmlForExport PHP Méthode

createTemplateXmlForExport() public static méthode

Create template XML for export
public static createTemplateXmlForExport ( string $theme ) : string
$theme string
Résultat string
    public static function createTemplateXmlForExport($theme)
    {
        $charset = BackendModel::getContainer()->getParameter('kernel.charset');
        // build xml
        $xml = new \DOMDocument('1.0', $charset);
        $xml->preserveWhiteSpace = false;
        $xml->formatOutput = true;
        $root = $xml->createElement('templates');
        $xml->appendChild($root);
        $db = BackendModel::getContainer()->get('database');
        $records = $db->getRecords(self::QRY_BROWSE_TEMPLATES, array($theme));
        foreach ($records as $row) {
            $template = self::getTemplate($row['id']);
            $data = unserialize($template['data']);
            $templateElement = $xml->createElement('template');
            $templateElement->setAttribute('label', $template['label']);
            $templateElement->setAttribute('path', $template['path']);
            $root->appendChild($templateElement);
            $positionsElement = $xml->createElement('positions');
            $templateElement->appendChild($positionsElement);
            foreach ($data['names'] as $name) {
                $positionElement = $xml->createElement('position');
                $positionElement->setAttribute('name', $name);
                $positionsElement->appendChild($positionElement);
            }
            $formatElement = $xml->createElement('format');
            $templateElement->appendChild($formatElement);
            $formatElement->nodeValue = $data['format'];
        }
        return $xml->saveXML();
    }

Usage Example

 /**
  * Export the templates as XML.
  */
 protected function parse()
 {
     $xml = Model::createTemplateXmlForExport($this->selectedTheme);
     $filename = 'templates_' . BackendModel::getUTCDate('d-m-Y') . '.xml';
     header('Content-type: text/xml');
     header('Content-disposition: attachment; filename="' . $filename . '"');
     echo $xml;
     exit;
 }
All Usage Examples Of Backend\Modules\Extensions\Engine\Model::createTemplateXmlForExport