*$x=new myArrayObject(); *$x->a=1; *$x->b=2; *$x['c']=3; *$x['valori']='5'; *foreach ($x as $i=>$j) echo $i.'=>'.$j.'
'; *echo $x->valori; * * @link http://it2.php.net/manual/en/class.arrayobject.php Vedi manuale online della classe madre */ class myArrayObject extends ArrayObject { /** @ignore */ function __toString() {return var_export($this->getArrayCopy(),true);} /** @ignore */ function __set($par,$val) { $this[$par]=$val;} /** @ignore */ function __get($par) {return $this[$par];} /** @ignore */ function __isset($par) {return isset($this[$par]);} /** @ignore */ function __unset($par) {unset($this[$par]);} } /** * Permette di raggruppare i campi in gruppi in modo da personalizzarne il layout * attraverso la riscrittura del metodo get_html */ class myGroupFields extends myArrayObject{ /** @ignore */ protected static $campi; protected $label,$form; public $Prevede_label=false; /** * @param array $campi elenco dei nomi dei campi (riferiti alla form) * @param string $label del gruppo */ function __construct($campi,$label='') { $this->label=$label; foreach ($campi as &$v) {$this[$v]=$v; self::$campi[strtoupper($v)]=$this; } } /** @ignore */ function in_form(&$form){ $this->form=&$form; foreach ($this as $k=>&$field) {$this[$k]=$form->campo($field); $form->salta_get_html($k); if (method_exists($this,'get_xml')) $form->salta_get_xml($k); } } /** * Restituisce la label del gruppo di campi * * @return unknown */ function get_label(){ return $this->label; } /** @ignore */ function __get($par) {return $this[strtoupper($par)];} /** @ignore */ function __set($par,$val) { $this[strtoupper($par)]=strtoupper($val);} /** * Restituisce l'html per la label del campo $k, * se il campo non è nella form restituisce null * * @param string $k * @return string */ function html_label($k) { if(!$this->form->campo($k)) return null; return $this->form->htmlLabelCampo($k,false,true); } /** * Restituisce l'html del campo $k, * se il campo non è nella form restituisce null * * @param string $k * @return string */ function &html_campo($k) { if(!$this->form->campo($k)) return null; return $this->form->Get_html_campo($k); } /** * Restituisce il valore del campo $k, * se il campo non è nella form restituisce null * * @param string $k * @return mixed */ function &value_campo($k) { if(!$this->form->campo($k)) return null; return $this->form->campo($k)->get_value(); } /** * Restituisce il valore del della label campo $k, * se il campo non è nella form restituisce null * * @param string $k * @return string */ function &value_label($k) { if(!$this->form->campo($k)) return null; return $this->form->get_label($k); } /** * Restituisce true se il campo $k è nascosto o è stato rimosso, * se il campo non è nella form restituisce null * * @param string $k * @return boolean */ function is_hidden($k){ if(!$this->form->campo($k)) return null; return $this->form->campo($k)->estende('myHidden',true) || $this->form->campo($k)->is_hidden(); } /** * Restituisce l'xml della form * * @param string $campo nome del campo di cui si vuole l'xml * @param char $case se omesso si rispetta il case originale dei campi (o del DB) , U= maiuscolo L=minuscolo * @return string */ function &xml_campo($campo,$case='') { return $this->form->get_xml('',$case,false,$campo,null,true); } function &get_html() { if($this->label) $out="{$this->label}"; foreach ($this as $k=>&$v) $out.="{$this->html_label($k)}{$this->html_campo($k)}"; return $out; } /** @ignore */ function __call($func,$pars){ switch ($func) { case 'get_id': case 'get_name': return md5(serialize($this)); break; } } /** @ignore */ function __toString(){ return $this->get_html(); } } ?>