--- nfo/php/libs/com.newsblob.phphtmllib/widgets/data_list/CSVFILEDataListSource.inc 2004/05/06 12:59:55 1.3 +++ nfo/php/libs/com.newsblob.phphtmllib/widgets/data_list/CSVFILEDataListSource.inc 2004/05/06 16:27:46 1.4 @@ -4,12 +4,14 @@ * that gets the data from a CSV formatted file. * * - * $Id: CSVFILEDataListSource.inc,v 1.3 2004/05/06 12:59:55 jonen Exp $ + * $Id: CSVFILEDataListSource.inc,v 1.4 2004/05/06 16:27:46 jonen Exp $ * * @author Walter A. Boring IV * @package phpHtmlLib */ +require_once($phphtmllib."/widgets/data_list/ArrayDataListSource.inc"); + /** @@ -28,7 +30,7 @@ * @author Walter A. Boring IV * @package phpHtmlLib */ -class CSVFILEDataListSource extends DataListSource { +class CSVFILEDataListSource extends ArrayDataListSource { /** @@ -96,15 +98,14 @@ * and search/sort */ function do_query() { - $count = 0; - while ($line = fgets($this->_fp, $this->_maxlinelength)) { - if ($this->add_data_row( $this->_construct_row(trim($line)))) { - $count++; - } - } - //close the file - fclose($this->_fp); + //we always want to filter. + //because we read the entry, + //then filter it. + $this->_prequery_filter(); + + $count = count($this->_data); + if ($count > 0) { $this->set_total_rows( $count ); $this->sort(); @@ -114,32 +115,22 @@ } } - /** - * This function returns the next row of - * valid data. - * - */ - function get_next_data_row() { - $index = $this->get_data_index(); - $limit = $this->get_limit(); - $offset = $this->get_offset(); - - if ($limit == -1) { - //don't limit the data - if ($index > $this->get_total_rows()) { - return NULL; - } else { - return $this->_data[$index]; - } - } else { - $left_to_show = $limit - ($index - $offset); - if ($left_to_show > 0) { - return $this->_data[$index]; - } else { - return NULL; + /** + * Lets walk the file and read the entry, and + * filter what we don't want. + * + */ + function _prequery_filter() { + $count=0; + while ($line = fgets($this->_fp, $this->_maxlinelength)) { + if ($this->add_data_row( $this->_construct_row(trim($line)))) { + $count++; } } - } + + //close the file + fclose($this->_fp); + } /** @@ -171,14 +162,12 @@ if (strncmp('#', $line, 1) != 0 && strncmp('//', $line, 2) != 0 && !empty($line)) { $tmp = explode(",", $line); - //xmp_var_dump( $row ); + $row = array(); foreach( $this->_csv_headers as $index => $name ) { $row[$name] = $tmp[$index]; } } - - //xmp_var_dump( $row ); return $row; } @@ -207,73 +196,5 @@ return FALSE; } } - - function sort() { - $sortby = $this->get_orderby(); - //ok we need to sort the data by the - //column in the table - if ($this->_is_column_sortable($sortby)) { - //looks like we can sort this column - usort($this->_data, array($this, "cmp")); - } - } - - function cmp($data1, $data2) { - $sortby = $this->get_orderby(); - $ret = strnatcmp( $data1[$sortby], $data2[$sortby]); - if ($this->get_reverseorder() == "true") { - $ret *= -1; - } - return $ret; - } - - function _find_data( $row_data ) { - //look for the 'needle' in the 'haystack' - - $needle = $this->get_searchby_value(); - $haystack = $row_data[$this->get_searchby()]; - - switch ($this->get_simplesearch_modifier()) { - case "BEGINS": - if (strncasecmp($needle, $haystack, strlen($needle)) == 0) { - return TRUE; - } else { - return FALSE; - } - break; - - case "CONTAINS": - if (stristr($haystack, $needle)) { - return TRUE; - } else { - return FALSE; - } - break; - case "EXACT": - if (strcasecmp($needle, $haystack) == 0) { - return TRUE; - } else { - return FALSE; - } - break; - case "ENDS": - $needle_len = strlen( $needle ); - $haystack_len = strlen( $haystack ); - if ($needle_len > $haystack_len) { - return FALSE; - } else if ($needle_len == $haystack_len) { - $tmp = $haystack; - } else { - $tmp = substr($haystack, $haystack_len - $needle_len); - } - if (strncasecmp($needle, $tmp, $needle_len) == 0) { - return TRUE; - } else { - return FALSE; - } - break; - } - } - } ?>