[PHPVortex-Commit] phpvortex TB_Base.class.php,1.6,1.7
Brought to you by:
nop144666
From: Thiago R. <nop...@us...> - 2004-10-04 18:12:21
|
Update of /cvsroot/phpvortex/phpvortex In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25088 Modified Files: TB_Base.class.php Log Message: TB_Base now using the FT_* Where() member function, ShowList() accepts a new parameter to search for data and added the member function NumPages() Index: TB_Base.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/TB_Base.class.php,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TB_Base.class.php 4 Oct 2004 16:35:32 -0000 1.6 --- TB_Base.class.php 4 Oct 2004 18:11:17 -0000 1.7 *************** *** 143,149 **** /** ! * Set the internal to a record to show/edit, or a blank one. * ! * @param array $data Array containing the primary key(s) to the table as 'field' => 'value'. * @param bool $pkonly Use only the pkey's in the search? * @return bool Returns TRUE on success, FALSE on error. --- 143,149 ---- /** ! * Set the internal buffer to a record to show/edit, or a blank one. * ! * @param array $data Array containing the data to seek as 'field' => 'value'. * @param bool $pkonly Use only the pkey's in the search? * @return bool Returns TRUE on success, FALSE on error. *************** *** 157,161 **** $where = ''; foreach ($this->fields as $field) if (!$pkonly || $field->pkey) { ! if (isset($data[$field->name_form]) && ($key = $field->Consist($data)) !== FALSE) $where .= (strlen($where)?' AND ':'')."{$field->name_db} = $key"; } if (!strlen($where)) { --- 157,161 ---- $where = ''; foreach ($this->fields as $field) if (!$pkonly || $field->pkey) { ! if (isset($data[$field->name_form])) $where .= (strlen($where)?' AND ':'').$field->Where($data[$field->name_form]); } if (!strlen($where)) { *************** *** 200,204 **** } if ($field->pkey) { ! $where .= (strlen($where)?' AND ':'')."{$field->name_db} = $value"; } else { isset($data[$field->name_form]) and $values[$field->name_db] = $value; --- 200,204 ---- } if ($field->pkey) { ! $where .= (strlen($where)?' AND ':'').$field->Where($value); } else { isset($data[$field->name_form]) and $values[$field->name_db] = $value; *************** *** 257,261 **** $where = ''; foreach ($this->fields as $field) if ($field->pkey) { ! if (isset($this->data[$field->name_db])) $where .= (strlen($where)?' AND ':'')."{$field->name_db} = ".$field->ConsistFormat($this->data[$field->name_db]); } if (!strlen($where)) { --- 257,261 ---- $where = ''; foreach ($this->fields as $field) if ($field->pkey) { ! if (isset($this->data[$field->name_db])) $where .= (strlen($where)?' AND ':'').$field->Where($this->data[$field->name_db]); } if (!strlen($where)) { *************** *** 275,281 **** * @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 = ''; --- 275,282 ---- * @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. + * @param array $data Array containing the data to seek as 'field' => 'value'. * @return bool Returns TRUE on success, FALSE on error. */ ! function ShowList($url = '', $page = -1, $data = NULL) { $fields = ''; *************** *** 287,292 **** } $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; --- 288,301 ---- } $sql = "SELECT $fields FROM {$this->name_db}"; + if (!empty($data)) { + $where = ''; + foreach ($this->fields as $field) { + if (isset($data[$field->name_form])) $where .= (strlen($where)?' AND ':'').$field->Where($data[$field->name_form]); + } + if (strlen($where)) $sql .= " WHERE $where"; + } if (!empty($this->list_order)) $sql .= " ORDER BY {$this->list_order}"; ! if ($page >= 0) $sql .= ' LIMIT '.($this->list_recspage * $page).", {$this->list_recspage}"; ! dv(3, "ShowList SELECT", $sql); if (!($rs = $this->db->Query($sql))) { $this->error = TB_ERR_DB; *************** *** 320,323 **** --- 329,361 ---- echo "</tbody>\n</table></div>\n"; } + + /** + * Gets the number of pages of a list. + * + * @param array $data Array containing the data to seek as 'field' => 'value'. + * @return int Returns the number of pages in a list. + */ + function NumPages($data = NULL) + { + $sql = "SELECT COUNT(*) as cnt FROM {$this->name_db}"; + if (!empty($data)) { + $where = ''; + foreach ($this->fields as $field) { + if (isset($data[$field->name_form])) $where .= (strlen($where)?' AND ':'').$field->Where($data[$field->name_form]); + } + if (strlen($where)) $sql .= " WHERE $where"; + } + dv(3, "NumPages SELECT", $sql); + if (!($rs = $this->db->Query($sql))) { + $this->error = TB_ERR_DB; + return FALSE; + } + if (($row = $rs->Row()) === FALSE) { + $this->error = TB_ERR_DB; + return FALSE; + } + $rs->Close(); + return (int)ceil($row['cnt'] / $this->list_recspage); + } } |