/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/widgets/data_source/MemoryDataSource.inc
ViewVC logotype

Diff of /nfo/php/libs/com.newsblob.phphtmllib/widgets/data_source/MemoryDataSource.inc

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

revision 1.1 by joko, Sat Mar 1 03:09:22 2003 UTC revision 1.2 by joko, Sat Mar 1 15:34:26 2003 UTC
# Line 5  Line 5 
5   *   *
6   * @author Sebastian Utz <seut@tunemedia.de>   * @author Sebastian Utz <seut@tunemedia.de>
7   * @author Andreas Motl <andreas.motl@ilo.de>   * @author Andreas Motl <andreas.motl@ilo.de>
8     * @copyright (c) 2003 - All Rights reserved.
9     * @license GNU LGPL (GNU Lesser General Public License)
10     *
11     * @author-url http://www.netfrag.org/~jonen/
12     * @author-url http://www.netfrag.org/~joko/
13     * @license-url http://www.gnu.org/licenses/lgpl.txt
14     *
15   * @package phpHtmlLib   * @package phpHtmlLib
16     * @module widgets::data_source::MemoryDataSource
17     *
18   */   */
19    
20  /**  /**
21   * $Id$   * $Id$
22   *   *
23   * $Log$   * $Log$
24     * Revision 1.2  2003/03/01 15:34:26  joko
25     * + introduced new 'label'-mechanism, purged old 'header'-mechanism
26     * + reworked internal data-structure and introduced new methods 'propagate_xyz'
27     * + added little debugging helper methods
28     *
29   * Revision 1.1  2003/03/01 03:09:22  joko   * Revision 1.1  2003/03/01 03:09:22  joko
30   * + moved here from data_list/MemoryDataListSource.inc   * + moved here from data_list/MemoryDataListSource.inc
31   *   *
# Line 59  class MemoryDataSource extends DataListS Line 73  class MemoryDataSource extends DataListS
73    
74    
75          /**          /**
76           * given data hash           * These hold data
77           *           *
78           */           */
79          var $_memory = array();          var $_memory = array();
   
80          var $_result = array();          var $_result = array();
81    
   
82          /**          /**
83           * this holds the headers read           * this holds the headers read
84           * array keys           * array keys
85           */           */
86          var $_data_keys = array();          var $_data_keys = array();
87    
88            /**
89             * This holds metadata
90             *
91             */
92            var $_schema = array();
93                    
94            /**
95             * This holds some information about the tracing level.
96             *
97             */
98            var $_debug = array(
99              notice => 0,
100              trace => 0,
101              payload => 0,
102            );
103    
104            /**
105             * This accumulates errors occouring while processing.
106             * $error = array($level, $message);
107             *
108             */
109          var $_errors = array();          var $_errors = array();
110    
111    
# Line 84  class MemoryDataSource extends DataListS Line 117  class MemoryDataSource extends DataListS
117           *           *
118           */           */
119          function MemoryDataSource( &$payload ) {          function MemoryDataSource( &$payload ) {
120        $this->_memory = &$payload;  
121        //print_r($object_list);        // tracing
122            $this->trace_payload('MemoryDataSource', $payload);
123    
124          // transfer data to "memory"
125            $this->_memory = &$payload;
126    
127          }          }
128    
129      function read_labels_from_result() {
130            $this->set_labels($this->_result[0]);
131      }
132    
133      function debug($method, $message) {
134        if ($this->_debug[notice]) {
135          if ($method) { $prefix = get_class($this) . "->" . $method . ": "; }
136          print $prefix . $message . "<br/>" . "\n";
137        }
138      }
139    
140      function trace($method, $var) {
141        if ($this->_debug[trace]) {
142          print get_class($this) . "->" . $method . ": " . Dumper($var) . "<br/>" . "\n";
143        }
144      }
145    
146      function trace_payload($method, $data) {
147        if ($this->_debug[payload]) {
148          $this->trace($method, $data);
149        }
150      }
151    
152          /**          /**
153           * The prequery.  We use this to read the file           * The prequery.  We use this to read the file
154           * into memory so we can do operations on the data           * into memory so we can do operations on the data
155           * (search, sort, etc.)           * (search, sort, etc.)
156           */           */
157          function do_prequery() {          function O_do_prequery() {
158                  $this->_get_header();                  $this->_read_schema();
159          }          }
160            function do_prequery() {
161      }
162      
163          /**          /**
164           * This function does the query           * This function does the query
165           * and search/sort           * and search/sort
# Line 109  class MemoryDataSource extends DataListS Line 171  class MemoryDataSource extends DataListS
171          }          }
172    
173          function handle_result() {          function handle_result() {
174              $this->debug("handle_result", "HANDLE RESULT!<br>");
175           $this->propagate_result();
176                    $this->set_total_rows( $count );
177                    $this->sort();
178        }
179    
180            function propagate_result() {
181              $this->debug('propagate_result', "PROPAGATE RESULT!");
182                  foreach ($this->_result as $value) {                  foreach ($this->_result as $value) {
183            if ($this->trace) { print Dumper($value); }            $this->trace_payload("propagate_result", $value);
184                          if ($this->add_data_row( $value)) {                          if ($this->add_data_row( $value)) {
185                                  $count++;                                  $count++;
186                          }                          }
187                  }                  }
   
                 $this->set_total_rows( $count );  
                 $this->sort();  
188      }      }
189    
190          /**          /**
# Line 154  class MemoryDataSource extends DataListS Line 221  class MemoryDataSource extends DataListS
221           * This file trys to get the Object Hash Keys.           * This file trys to get the Object Hash Keys.
222           *           *
223           */           */
224          function _get_header() {          function propagate_schema() {
225              $this->debug("propagate_schema", "PROPAGATE SCHEMA!<br>");
226                    /*                    /*
227                    // FIXME: patch to make php not croak if result is empty at this stage                    // FIXME: patch to make php not croak if result is empty at this stage
228                    if (!is_array($this->_memory[0])) {                    if (!is_array($this->_memory[0])) {
# Line 165  class MemoryDataSource extends DataListS Line 233  class MemoryDataSource extends DataListS
233                          return;                          return;
234                          }                          }
235  */  */
236                    foreach($this->_memory[0] as $key => $value) {                    foreach($this->_schema[labels] as $value) {
237                      //print "key: $key<br>";                        $this->debug("propagate_schema", "label: $value");
238                                  array_push($this->_data_keys, $key);                                  array_push($this->_data_keys, $value);
239                          }                                      }            
240          }          }
241    
242    
243    function get_header() {    function O_get_header() {
244      $this->_get_header();      $this->_read_schema();
245      return $this->_data_keys;      return $this->_data_keys;
246    }                }            
247    
248    function set_schema($columns) {    function get_labels() {
249      //print "columns: " . Dumper($columns);      return $this->_data_keys;
250      $this->_memory[0] = $columns;    }            
251    
252      function set_labels($labels_or_entry) {
253        if (is_hash($labels_or_entry)) {
254          if ($this->_debug[notice]) {
255            $this->debug('set_labels', 'hash was passed in (is_hash == true): just using keys');
256          }
257          $labels_or_entry = array_keys($labels_or_entry);
258        }
259        $this->trace('set_labels', $labels_or_entry);
260        $this->_schema[labels] = $labels_or_entry;
261        $this->propagate_schema();
262    }    }
263    
264    function get_data_source() {    function get_data_source() {

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

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