dbscript
[ class tree: dbscript ] [ index: dbscript ] [ all elements ]

Source for file resultiterator.php

Documentation is available at resultiterator.php

  1. <?php
  2.  
  3.   /** 
  4.    * dbscript for PHP 4 & 5 - restful crud framework
  5.    * @version 0.1.2 -- 19-Feb-2007
  6.    * @author Brian Hendrickson <brian@dbscript.net>
  7.    * @link http://dbscript.net/
  8.    * @copyright Copyright 2007 Brian Hendrickson
  9.    * @package dbscript
  10.    * @license http://www.opensource.org/licenses/mit-license.php MIT License
  11.    */
  12.  
  13.   /**
  14.    * Result Iterator
  15.    * 
  16.    * Attached to a RecordSet to lazy-load its result resource.
  17.    * 
  18.    * More info...
  19.    * {@link http://dbscript.net/resultiterator}
  20.    * 
  21.    * @package dbscript
  22.    * @author Brian Hendrickson <brian@dbscript.net>
  23.    * @access public
  24.    * @version 0.1.2
  25.    */
  26.    
  27. class ResultIterator extends GenericIterator {
  28.  
  29.   var $rs;
  30.   var $result;
  31.   var $rowcount;
  32.   var $table_name;
  33.   var $tablemapper;
  34.   var $pkvals;
  35.  
  36.   function ResultIterator&$rs$table {
  37.  
  38.     $this->rs =$rs;
  39.     $this->result =$rs->result;
  40.     $this->table_name = $table;
  41.     $this->_currentRow = 0;
  42.     $this->EOF = false;
  43.     $this->tablemapper = array();
  44.     $this->pkvals = array();
  45.     $this->rowcount = 0;
  46.     foreach $rs->rowmap as $table => $pkvals {
  47.       if ($table == $this->table_name{
  48.         foreach $pkvals as $pk => $result_row {
  49.           if ($pk != 0{
  50.             $this->tablemapper[$result_row;
  51.             $this->pkvals[$pk;
  52.             $this->rowcount++;
  53.           }
  54.         }
  55.       }
  56.     }
  57.   }
  58.  
  59.   function seek$row {
  60.     $return false;
  61.     if !$this->rowcount > )) {
  62.       $this->EOF = true;
  63.     }
  64.     if !$row $this->rowcount )) {
  65.       $this->EOF = true;
  66.     }
  67.     if ($this->valid()) {
  68.       $this->_currentRow = $row;
  69.       $return true;
  70.     }
  71.     return $return;
  72.   }
  73.   
  74.   function MoveFirst({
  75.     $this->EOF = false;
  76.     $this->_currentRow = 0;
  77.     if ($this->seek)) return $this->Load();
  78.     return false;
  79.   }
  80.   
  81.   function MoveNext({
  82.     $db =db_object();
  83.     if ($this->seek$this->_currentRow )) {
  84.       $rec $this->Load();
  85.       $this->_currentRow++;
  86.       foreach ($db->models[$this->table_name]->relations as $table=>$vals{
  87.         if (!(isset($rec->$table))) 
  88.           $rec->$table $rec->FirstChild$table );
  89.       }
  90.       return $rec;
  91.     }
  92.     return false;
  93.   }
  94.   
  95.   function FirstChild$parent_pkval {
  96.     $this->_currentRow = array_search$this->rs->relations[$parent_pkval][$this->table_name][0]$this->pkvalsfalse );
  97.     if $this->seek$this->_currentRow && in_array$this->pkvals[$this->_currentRow]$this->rs->relations[$parent_pkval][$this->table_name) ) {
  98.       return $this->Load();
  99.     }
  100.     return false;
  101.   }
  102.   
  103.   function NextChild$parent_pkval {
  104.     if $this->seek$this->_currentRow && in_array$this->pkvals[$this->_currentRow]$this->rs->relations[$parent_pkval][$this->table_name) ) {
  105.       $rec $this->Load();
  106.       $this->_currentRow++;
  107.       return $rec;
  108.     }
  109.     return false;
  110.   }
  111.   
  112.   function Load({
  113.     if !$this->valid() ) ) return NULL;
  114.     return $this->rs->Load$this->table_name$this->tablemapper[$this->_currentRow);
  115.   }
  116.  
  117. }
  118.  
  119. ?>

Documentation generated on Mon, 19 Feb 2007 10:25:03 -0800 by phpDocumentor 1.3.1