<?php
Goweb::loadClass("Goweb_Chart_Set");

class Goweb_Chart_Dataset {
    
    // ------------------------------------------------ //
    // PROPERTIES -------------------------- PROPERTIES //
    // ------------------------------------------------ //
    private $_dataset = array();
    private $_options = array();
    private $_datasetElement = array();
    
    private $_myDataSets = array();
    
    public $set = null;
    
    // ------------------------------------------------ //
    // METHODS -------------------------------- METHODS //
    // ------------------------------------------------ //
    public function __construct() {
        // renderAs  ->  COLUMN, AREA or LINE
        
        $this->_options = array('renderAs', 'parentYAxis', 'showPlotBorder',
                                'plotBorderColor', 'plotBorderThickness',
                                'plotBorderAlpha', 'plotBorderAlpha',
                                'seriesName', 'color', 'alpha', 'showValues',
                                'dashed', 'includeInLegend', 'drawAnchors',
                                'anchorSides', 'anchorRadius', 'anchorBorderColor',
                                'anchorBorderThickness', 'anchorBgColor',
                                'anchorAlpha', 'lineThickness', 'lineDashLen',
                                'lineDashGap');
        
        $this->set = new Goweb_Chart_Set();
    }
    
    public function put() {
        if (count($this->_dataset) > 0) {
            $datasetElement = "";
            $datasetElement .= "<dataset ";
            foreach ($this->_dataset as $key => $value) {
                $datasetElement .= $key . "='" . $value . "' ";
            }
            $datasetElement .= ">";
            $datasetElement .= $this->set->render();
            $datasetElement .= "</dataset>";
            $this->_myDataSets[] = $datasetElement;
            $this->_clearOptions();
        }
    }
    
    public function render() {
        if (count($this->_myDataSets) > 0) {
            $dataSets = '';
            foreach ($this->_myDataSets as $dataset) {
                $dataSets .= $dataset;
            }
            return $dataSets;
        }
        return '';
    }
    
    public function __set($key, $value) {
        if (in_array($key, $this->_options)) {
            $this->_dataset[$key] = $value;
        }
    }
    
    private function _clearOptions() {
        $this->_dataset = array();
    }
    
}
?>
