P.D: Me gustaria saber que piensan de los "constructores dinamicos" que estoy utilizando
Código PHP:
<?
abstract class HTML{
protected $id;
protected $clase;
protected $style;
protected $title;
protected $lang;
protected $dire;
protected $onclick;
protected $ondblclick;
protected $onmousedown;
protected $onmouseup;
protected $onmouseover;
protected $onmousemove;
protected $onmouseout;
protected $onkeypress;
protected $onkeydown;
protected $onkeyup;
function __construct($atributos_html){
foreach ($atributos_html as $variable => $contenido){
$this->$variable = $contenido;
}
}
}
class Select extends HTML {
private $name;
private $multiple;
private $size;
private $disabled;
private $tabindex;
private $onfocus;
private $onblur;
private $onchange;
private $opcion;
private $i;
private $sw;
function __construct($atributos_html,$atributos_select,$opciones,$seleted)
{
parent::__construct($atributos_html);
foreach ($atributos_select as $variable => $contenido){
$this->$variable = $contenido;
}
$this->opciones = $opciones;
$this->seleted = $seleted;
}
function __toString(){
$cadena = "<select id = '$this->id' class = '$this->class' style = '$this->style' title = '$this->title' lang = '$this->lang' dir = '$this->dir' onclick = '$this->onclick' ondblclick = '$this->ondblclick' onmousedown = '$this->onmousedown' onmouseup = '$this->onmouseup' onmouseover = '$this->onmouseover' onmousemove = '$this->onmousemove' onmouseout = '$this->onmouseout' onkeypress = '$this->onkeypress' onkeydown = '$this->onkeydown' onkeyup = '$this->onkeyup' name = '$this->name' $this->multiple size = '$this->size' $this->disabled tabindex = '$this->tabindex' onfocus = '$this->onfocus' onblur = '$this->onblur' onchange = '$this->onchange'>";
foreach ($this->opciones as $clave => $valor){
if (is_array($this->seleted)){
$sw=0;
for ($i=0;$i<=count($this->seleted);$i++){
if ($clave==$this->seleted[$i]){
$cadena .= "<OPTION VALUE='$clave' selected='selected'>".$valor."</OPTION>";
$sw=1;
}
elseif($sw==0 and $i==count($this->seleted)) {
$cadena .= "<OPTION VALUE='$clave'>".$valor."</OPTION>";
}
}
}
elseif ($clave==$this->seleted)
$cadena .= "<OPTION VALUE='$clave' selected='selected'>".$valor."</OPTION>";
else
$cadena .= "<OPTION VALUE='$clave'>".$valor."</OPTION>";
}
$cadena .="</select>";
return $cadena;
}
}
$atributos_html = array('id'=>'id01','onclick'=>'funcion','class'=>'clase01');
$atributos_select = array('name'=>'primer_select','size'=>'3','multiple'=>'multiple');
$opciones = array('01'=>'op01','02'=>'op02','03'=>'op03');
$seleccion = array (01,03);
$select = new Select ($atributos_html,$atributos_select,$opciones,$seleccion);
$select2 = new Select ($atributos_html,$atributos_select,$opciones,array(01,02));
$select3 = new Select ($atributos_html,$atributos_select,$opciones,'-');
echo $select;
echo "</br>";
echo $select2;
echo "</br>";
echo $select3;
?>