[PHPVortex-Commit] phpvortex TB_Base.class.php,1.4,1.5
Brought to you by:
nop144666
From: Thiago R. <nop...@us...> - 2004-10-01 20:53:48
|
Update of /cvsroot/phpvortex/phpvortex In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29189 Modified Files: TB_Base.class.php Log Message: Added the member function ShowList to TB_Base. Needs more work, but it's already working, see the test code Index: TB_Base.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/TB_Base.class.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TB_Base.class.php 30 Sep 2004 19:34:38 -0000 1.4 --- TB_Base.class.php 1 Oct 2004 20:52:29 -0000 1.5 *************** *** 90,93 **** --- 90,117 ---- /** + * Array containing references to the fields to use in lists. + * @var array + */ + var $fields_list = array(); + + /** + * Order by parameter used in lists. + * @var string + */ + var $list_order = ''; + + /** + * Number of records per page to display in lists. + * @var int + */ + var $list_recspage = 25; + + /** + * Array containing references to the fields to use in forms. + * @var FT_Base + */ + var $fields_form = array(); + + /** * Array the current row of the table, for output, edit or search. * @var array *************** *** 178,182 **** $where .= (strlen($where)?' AND ':'')."{$field->name_db} = $value"; } else { ! $values[$field->name_db] = $value; } } --- 202,206 ---- $where .= (strlen($where)?' AND ':'')."{$field->name_db} = $value"; } else { ! isset($data[$field->name_form]) and $values[$field->name_db] = $value; } } *************** *** 230,233 **** --- 254,258 ---- { if (!empty($data)) if (!$this->Seek($data)) return FALSE; + if (empty($this->data)) return FALSE; $where = ''; foreach ($this->fields as $field) if ($field->pkey) { *************** *** 244,247 **** --- 269,315 ---- return TRUE; } + + /** + * Outputs a list for viewing/editing records. + * + * @todo Use the $url parameter, and add the pkeys to the select + * + * @param string $url URL to link the records to. The function replaces the string "PKEY" with the pkeys and values for the record. Leave blank for no links. + * @param int $page Current page to show the records. Leave -1 to show all records. + * @return bool Returns TRUE on success, FALSE on error. + */ + function ShowList($url = '', $page = -1) + { + $fields = ''; + foreach ($this->fields_list as $field) { + $fields .= (strlen($fields)?', ':'').$field->name_db; + } + $sql = "SELECT $fields FROM {$this->name_db}"; + if (!empty($this->list_order)) $sql .= " ORDER BY {$this->list_order}"; + if ($page >= 0) $sql .= ' LIMIT '.($this->list_recspage * $page).' TO '.(($this->list_recspage * $page) + ($this->list_recspage - 1)); + if (!($rs = $this->db->Query($sql))) { + $this->error = TB_ERR_DB; + return FALSE; + } + if (!($rows = $rs->All())) { + $this->error = TB_ERR_EMPTY; + return FALSE; + } + echo "<div class='div_list'><table class='tb_{$this->name}'>\n<thead><tr>\n"; + foreach ($this->fields_list as $field) { + echo "<th>{$field->label}</th>\n"; + } + echo "</tr></thead>\n<tbody>\n"; + foreach ($rows as $row) { + echo "<tr>\n"; + foreach ($this->fields_list as $field) { + echo "<td>"; + $field->ShowPlain($row[$field->name_db]); + echo "</td>\n"; + } + echo "</tr>\n"; + } + echo "</tbody>\n</table></div>\n"; + } } |