/**
* HtmlExt Helper class file.
*
* PHP versions 4 and 5
*
*
* Author: Tulio Faria (www.tuliofaria.net
*/
class HtmlExtHelper extends Helper{
function checkbox($fieldName, $value = NULL, $label=NULL, $i = NULL, $data = NULL){
$n = explode("/", $fieldName);
$fName = "data[".$n[0]."][".$n[1]."][]";
$fId = $n[0].$n[1].$i; // i contador
$checked = "";
// verificando se está marcado
if ($data!=NULL){
if (is_array($data)){
foreach($data as $d){
if (isset($d["id"])){
if ($d["id"]==$value){
$checked = ' checked="checked" ';
}
}
}
}else{
$checked = (in_array($value, $data)) ? 'checked="checked" ': '';
}
}
return "";
}
// uso:
// $fieldName : nome do campo
// $values : vetor com (valor => texto)
// $startTag : tag inicial do conjunto de inputs
// $endTag : tag final do conjunto de inputs
// $itemStartTag : tag inicial de cada input
// $itemEndTag : tag final de cada input
function checkboxes($fieldName, $values, $startTag, $endTag, $itemStartTag, $itemEndTag){
$r = $startTag;
$n = explode("/", $fieldName);
$int = (isset($this->data[$n[0]][$n[1]])) ? $this->data[$n[0]][$n[1]] : NULL;
$x = 0;
foreach($values as $ti=>$t){
$r .= $itemStartTag.$this->checkbox($fieldName, $ti, $t, $x++, $int).$itemEndTag;
}
$r.= $endTag;
return $r;
}
}
?>