class cweb_grid {
var $column_obj; // 欄位
var $item_arr; // 項目列
var $param; // 參數列
function cweb_grid()
{
$this->column_obj = new empty_object;
$this->item_arr = array();
$this->param = array();
}
function _pre_html()
{
$param_str = "";
foreach($this->param as $key => $value )
{
$param_str .= " {$key}=\"{$value}\" ";
}
$result = "<table " . $param_str . " >";
return $result;
}
function _after_html()
{
return "</table>";
}
function _arr2obj($row)
{
return $row;
}
function _proc_row($row)
{
$result = "";
foreach($this->column_obj as $key => $value)
{
if( !isset($row->$key) )
$result .= "<td ></td>";
else
$result .= "<td >{$row->$key}</td>";
}
$result = "<tr> {$result} </tr>";
return $result;
}
function _proc_column()
{
return $this->_proc_row($this->column_obj);
}
function _proc_item()
{
$result = "";
foreach($this->item_arr as $item)
{
$result .= $this->_proc_row($item);
}
return $result;
}
function insert_column($key, $text)
{
$this->column_obj->$key = $text;
}
function insert_item($row)
{
$obj = $this->_arr2obj($row);
$this->item_arr[] = $obj;
}
function add_param($key, $value)
{
$this->param[$key] = $value;
}
function outHtml()
{
$result = "";
$result .= $this->_pre_html();
$result .= $this->_proc_column();
$result .= $this->_proc_item();
$result .= $this->_after_html();
return $result;
}
}
2011年5月19日 星期四
cweb_grid
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言