csv_vistable

The Inline Google Spreadsheet Viewer csv vistable class.

Defined (1)

The class is defined in the following location(s).

/lib/vistable.php  
  1. class csv_vistable extends vistable { 
  2. private $table; 
  3.  
  4. public function __construct($tqx, $tq, $tqrt, $tz, $locale, $extra=NULL) { 
  5. parent::__construct($tqx, $tq, $tqrt, $tz, $locale, $extra); 
  6.  
  7. public function setup_table($data) 
  8. $this->fields = array(); 
  9. $row = $this->next_row($data); 
  10. if ($row === NULL) return; 
  11. foreach ($row as &$id) { 
  12. $type = 'string'; 
  13. if (preg_match('/^(.*) as (date|datetime|boolean|timeofday|number)$/', $id, $matches)) { 
  14. $id = $matches[1]; 
  15. $type = $matches[2]; 
  16. $this->fields[$id] = array(TYPE=>SIMPLE, VALUE=>$id, 'type' => $type); 
  17. $cols = $row; 
  18. $this->table = array(); 
  19. while (($row = $this->next_row($data)) !== FALSE) { 
  20. if (count($row) > count($cols)) continue; 
  21. $this->table[] = array_combine(array_slice($cols, 0, count($row)), $row); 
  22.  
  23. protected function fetch_table($query) 
  24. $rows = $this->table; 
  25.  
  26. if (!$rows) { 
  27. $this->error("internal_error", "no data", ""); 
  28. return FALSE; 
  29.  
  30. $cols = $this->query_filter($rows, $query); 
  31.  
  32. return array('cols' => $cols, 'rows' => $rows); 
  33.  
  34. private function next_row(&$data) 
  35. if (preg_match('/^(([^\"\n]*(\"[^\"]*\"))*[^\"\n]*)\n(.*)$/s', $data, $matches)) { 
  36. $data=$matches[4]; 
  37. $ret = $matches[1]; 
  38. } else if ($data !== "") { 
  39. $ret = $data; 
  40. $data = ""; 
  41. } else { 
  42. return FALSE; 
  43.  
  44. $ret .= ", "; 
  45. $row = array(); 
  46. while ($ret !== "") { 
  47. if (preg_match('/^\s*\"(([^\"]*\"\")*[^\"]*)\"\s*, (.*)$/', $ret, $matches)) { 
  48. $ret = $matches[3]; 
  49. $row[] = $matches[1]; 
  50. } else if (preg_match('/^([^, ]*), (.*)$/', $ret, $matches)) { 
  51. $ret = $matches[2]; 
  52. $row[] = $matches[1]; 
  53. } else { 
  54. return FALSE; 
  55.  
  56. return $row; 
  57. };