<?php
class Goweb_Chart_Categories {
    
    // ------------------------------------------------ //
    // PROPERTIES -------------------------- PROPERTIES //
    // ------------------------------------------------ //
    
    private $_categories = array();
    private $_options = array();
    private $_categoriesElement = array();
    
    // ------------------------------------------------ //
    // METHODS -------------------------------- METHODS //
    // ------------------------------------------------ //
    public function __construct() {
        $this->_options = array('showLabel', 'label', 'toolText');
    }
    
    public function add() {
        $catInput = '<category ';
        foreach ($this->_categories as $key => $value) {
            $catInput .= $key . "='" . $value . "' ";
        }
        $catInput .= ' />';
        $this->_categoriesElement[] = $catInput;
        
        $this->_clearOptions();
    }
    
    public function render() {
        if (count($this->_categoriesElement) > 0) {
            $catInputs = '';
            $catInputs .= '<categories>';
            foreach ($this->_categoriesElement as $catElement) {
                $catInputs .= $catElement . "";
            }
            $catInputs .= '</categories>';
            return $catInputs;
        } else {
            return "";
        }
    }
    
    public function __set($key, $value) {
        if (in_array($key, $this->_options)) {
            $this->_categories[$key] = $value;
        }
    }
    
    private function _clearOptions() {
        $this->_categories = array();
    }
    
}
?>
