/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/widgets/data_list/CSVFILEDataListSource.inc
ViewVC logotype

Diff of /nfo/php/libs/com.newsblob.phphtmllib/widgets/data_list/CSVFILEDataListSource.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by jonen, Thu May 6 12:59:55 2004 UTC revision 1.4 by jonen, Thu May 6 16:27:46 2004 UTC
# Line 10  Line 10 
10   * @package phpHtmlLib   * @package phpHtmlLib
11   */   */
12    
13    require_once($phphtmllib."/widgets/data_list/ArrayDataListSource.inc");
14    
15    
16    
17  /**  /**
# Line 28  Line 30 
30   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@buildabetterweb.com>
31   * @package phpHtmlLib   * @package phpHtmlLib
32   */   */
33  class CSVFILEDataListSource extends DataListSource {  class CSVFILEDataListSource extends ArrayDataListSource {
34    
35    
36          /**          /**
# Line 96  class CSVFILEDataListSource extends Data Line 98  class CSVFILEDataListSource extends Data
98           * and search/sort           * and search/sort
99           */           */
100          function do_query() {          function do_query() {
         $count = 0;  
                 while ($line = fgets($this->_fp, $this->_maxlinelength)) {  
                         if ($this->add_data_row( $this->_construct_row(trim($line)))) {  
                                 $count++;  
                         }  
                 }  
101    
102                  //close the file          //we always want to filter.
103                  fclose($this->_fp);          //because we read the entry,
104            //then filter it.  
105            $this->_prequery_filter();
106    
107            $count = count($this->_data);
108    
109          if ($count > 0) {          if ($count > 0) {
110              $this->set_total_rows( $count );              $this->set_total_rows( $count );
111              $this->sort();              $this->sort();
# Line 114  class CSVFILEDataListSource extends Data Line 115  class CSVFILEDataListSource extends Data
115          }          }
116          }          }
117    
118          /**      /**
119           * This function returns the next row of       * Lets walk the file and read the entry, and
120           * valid data.         * filter what we don't want.
121           *       *
122           */       */
123          function get_next_data_row() {      function _prequery_filter() {
124                  $index = $this->get_data_index();          $count=0;
125                  $limit = $this->get_limit();          while ($line = fgets($this->_fp, $this->_maxlinelength)) {
126                  $offset = $this->get_offset();                          if ($this->add_data_row( $this->_construct_row(trim($line)))) {
127                                    $count++;
                 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;  
128                          }                          }
129                  }                  }
130          }  
131            //close the file
132            fclose($this->_fp);
133        }
134    
135    
136          /**          /**
# Line 171  class CSVFILEDataListSource extends Data Line 162  class CSVFILEDataListSource extends Data
162                  if (strncmp('#', $line, 1) != 0 &&                  if (strncmp('#', $line, 1) != 0 &&
163                          strncmp('//', $line, 2) != 0 && !empty($line)) {                          strncmp('//', $line, 2) != 0 && !empty($line)) {
164                          $tmp = explode(",", $line);                          $tmp = explode(",", $line);
165                          //xmp_var_dump( $row );                          
166                          $row = array();                          $row = array();
167                          foreach( $this->_csv_headers as $index => $name ) {                          foreach( $this->_csv_headers as $index => $name ) {
168                                  $row[$name] = $tmp[$index];                                  $row[$name] = $tmp[$index];
169                          }                          }
170                  }                  }
   
                 //xmp_var_dump( $row );  
171                  return $row;                  return $row;
172          }          }
173                    
# Line 207  class CSVFILEDataListSource extends Data Line 196  class CSVFILEDataListSource extends Data
196                          return FALSE;                          return FALSE;
197                  }                  }
198          }          }
   
         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;  
                 }  
         }  
           
199  }  }
200  ?>  ?>

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed