<?php

class Goweb_Chart_Styles_Definition {
    
    // ------------------------------------------------ //
    // PROPERTIES -------------------------- PROPERTIES //
    // ------------------------------------------------ //
    
    private $_styles = array();
    private $_options = array();
    private $_stylesElement = array();
    
    // ------------------------------------------------ //
    // METHODS -------------------------------- METHODS //
    // ------------------------------------------------ //
    public function __construct() {
        $this->_options = array('name', 'type', 'param', 'start', 'duration', 'alpha');
    }
    
    public function add() {
        $styleInput = '<style ';
        foreach ($this->_styles as $key => $value) {
            $styleInput .= $key . "='" . $value . "' ";
        }
        $styleInput .= ' />';
        $this->_stylesElement[] = $styleInput;
        
        $this->_clearOptions();
    }
    
    public function render() {
        if (count($this->_stylesElement) > 0) {
            $styleInputs = '';
            $styleInputs .= '<definition>';
            foreach ($this->_stylesElement as $styleElement) {
                $styleInputs .= $styleElement;
            }
            $styleInputs .= '</definition>';
            return $styleInputs;
        } else {
            return '';
        }
    }
    
    public function __set($key, $value) {
        if (in_array($key, $this->_options)) {
            $this->_styles[$key] = $value;
        }
    }
    
    private function _clearOptions() {
        $this->_styles = array();
    }
    
}

?>
