<?php
// +----------------------------------------------------------------------+
// | BxCMS                                                                |
// +----------------------------------------------------------------------+
// | Copyright (c) 2001-2006 Bitflux GmbH                                 |
// +----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or        |
// | modify it under the terms of the GNU General Public License (GPL)    |
// | as published by the Free Software Foundation; either version 2       |
// | of the License, or (at your option) any later version.               |
// | The GPL can be found at http://www.gnu.org/licenses/gpl.html         |
// +----------------------------------------------------------------------+
// | Author: Bitflux GmbH <flux@bitflux.ch>                               |
// +----------------------------------------------------------------------+
//
// $Id: db2xml.php 6159 2006-01-03 05:29:18Z chregu $

/**
 * Helper functions to be used when working with db2xml. Reduces the task
 * of getting XML from a database to one function call.
 *
 * @package
 * @category 
 * @author Bitflux GmbH <flux@bitflux.ch>
 */
class bx_helpers_db2xml {

    /**
     *  Returns a DOMDocument object which contains the data queried from the
     *  database by the passed query.
     *
     *  @param  string $query SQL query to be run.
     *  @param  boolean $fromMaster Whether to use the master DB or not in a master/slave setup.
     *  @access public
     *  @return object DOMObject containing the data returned from the query.
     */
    public static function getXMLByQuery($query, $fromMaster = false, $root = 'data') {
        if ($fromMaster) {
            $xml = new XML_db2xml($GLOBALS['POOL']->dbwrite, $root, 'Extended');
        } else {
            $xml = new XML_db2xml($GLOBALS['POOL']->db, $root, 'Extended');
        }
        $options = array(
            'formatOptions' => array ( 'xml_seperator' => '')
        );

        $xml->Format->SetOptions($options);
        $xml->add($query);
        $dom = $xml->getXMLObject();
        
        return $dom;
        
    }
}
?>
