<?php 
class VstFieldSet{
	
	protected $_elementos= array();
	protected $_id = '';	
	protected $_role = '';
	protected $_class = '';
	protected $_legend = '';
	protected $_soloLectura = false;
	
	
	public function __construct($legend='', $id="",  $class = '', $role = ''){
		$this->_id = $id;
		$this->_role = $role;
		$this->_class = $class;
		$this->_legend = $legend;
		
	}
	
	public function setRole($value){
		$this->_role = $value;
	}
	
	public function setSoloLectura($valor){
		$this->_soloLectura = true;
	}
	
	public function render(){
		$salida = '';
		

		
		$salida .= '<fieldset  id="'.$this->_id.'" role="'.$this->_role.'" class="'.$this->_class.'" ';
		if ($this->_soloLectura)
			$salida .= ' disabled ';
		$salida .= '>';
		if ($this->_legend){
			$salida .= '<legend>'.$this->_legend.'</legend>';
		}
		
		ob_flush();
		foreach ($this->_elementos as $elemento){
			
			if(strlen($elemento['clase'])>0)
				$salida .= '<div class="'.$elemento['clase'].'">';
			
			if(strlen($elemento['titulo'])>0)
				$salida .= '<h3>'.$elemento['titulo'].'</h3>' ;
			if(is_object($elemento['elemento'])){
				$salida .= $elemento['elemento']->render();
			}else{
				$salida .= $elemento['elemento'];
			}
			
			if(strlen($elemento['clase'])>0)
				$salida .= '</div>';
			
			
		}
		$salida .= '</fieldset>';
		
		
		return $salida;
	}
	public function __toString(){
		return $this->render();
	}
	
	public function addElement(&$elemento, $titulo = '' , $clase = ''){
		$this->_elementos[] = array( 'elemento' => $elemento, 'titulo' => $titulo, 'clase'=>$clase);
	}
	
}