Source for file IteratorFindQuadsDb.php

Documentation is available at IteratorFindQuadsDb.php

  1. <?php 
  2. //----------------------------------------------------------------------------------
  3. // Class: IteratorFindQuadsDb
  4. // ----------------------------------------------------------------------------------
  5.  
  6.  
  7. /**
  8. * Implementation of a quad iterator.
  9. *
  10. * This Iterator should be used like:
  11. * for($iterator = $dataset->findInNamedGraphs(null,null,null,null); $iterator->valid(); $iterator->next())
  12. * {
  13. *    $currentQuad=$iterator->current();
  14. * };
  15. *
  16. *
  17. @version  $Id: fsource_dataset__datasetIteratorFindQuadsDb.php.html 442 2007-06-01 16:19:26Z cax $
  18. @author Daniel Westphal (http://www.d-westphal.de)
  19. *
  20. *
  21. @package     dataset
  22. @access    public
  23. ***/
  24. {
  25.     /**
  26.     * Holds a reference to the associated DB resultSet.
  27.     *
  28.     * @var        $dbResultSets ADODB result
  29.     * @access    private
  30.     */
  31.     var $dbResultSet;
  32.     
  33.     /**
  34.     * Holds a reference to the associated datasetDb.
  35.     *
  36.     * @var        $datasetDb datasetDb
  37.     * @access    private
  38.     */
  39.     var $datasetDb;
  40.  
  41.     /**
  42.     * boolean value, if the results should be returned as triples.
  43.     *
  44.     * @var        boolean 
  45.     * @access    private
  46.     */
  47.     var $returnAsTriples;
  48.     
  49.     /**
  50.     * Constructor.
  51.     *
  52.     * @param dataset 
  53.     * @access    public
  54.     */
  55.     function IteratorFindQuadsDb(&$dbResultSet,&$datasetDb,$returnAsTriples=false)
  56.     {
  57.         $this->dbResultSet=$dbResultSet;
  58.         $this->datasetDb=$datasetDb;
  59.         $this->returnAsTriples=$returnAsTriples;
  60.     }
  61.     
  62.     /**
  63.     * Resets iterator list to start.
  64.     *
  65.     * @access public
  66.     */
  67.     function rewind()
  68.     {
  69.         //not supported
  70.     }
  71.     
  72.     /**
  73.     * Says if there are additional items left in the list.
  74.     *
  75.     * @return    boolean 
  76.     * @access    public
  77.     */
  78.     function valid()
  79.     {
  80.         if (($this->dbResultSet ===falseOR ($this->dbResultSet->EOF) )
  81.             return false;
  82.         
  83.         return true;
  84.     }
  85.     
  86.     /**
  87.     * Moves Iterator to the next item in the list.
  88.     *
  89.     * @access    public
  90.     */
  91.     function next()
  92.     {
  93.         if ($this->dbResultSet!==false)
  94.             $this->dbResultSet->moveNext();
  95.     }
  96.     
  97.     /**
  98.     * Returns the current item.
  99.     *
  100.     * @return    mixed 
  101.     * @access    public
  102.     */
  103.     function &current()
  104.     {
  105.         if ($this->dbResultSet===false)
  106.             return null;
  107.         // subject
  108.         if ($this->dbResultSet->fields[5== 'r')
  109.         $sub new Resource($this->dbResultSet->fields[0]);
  110.         else
  111.         $sub new BlankNode($this->dbResultSet->fields[0]);
  112.  
  113.         // predicate
  114.         $pred new Resource($this->dbResultSet->fields[1]);
  115.  
  116.         // object
  117.         if ($this->dbResultSet->fields[6== 'r')
  118.         $obj new Resource($this->dbResultSet->fields[2]);
  119.         elseif ($this->dbResultSet->fields[6== 'b')
  120.         $obj new BlankNode($this->dbResultSet->fields[2]);
  121.         else {
  122.             $obj new Literal($this->dbResultSet->fields[2]$this->dbResultSet->fields[3]);
  123.             if ($this->dbResultSet->fields[4])
  124.             $obj->setDatatype($this->dbResultSet->fields[4]);
  125.         }
  126.  
  127.         if($this->returnAsTriples)
  128.             return (new Statement($sub$pred$obj));
  129.  
  130.         return (new Quad(new Resource($this->dbResultSet->fields[7]),$sub,$pred,$obj));
  131.     }
  132.     
  133.     /**
  134.     * Returns the key of the current item.
  135.     *
  136.     * @return    integer 
  137.     * @access    public
  138.     */
  139.     function key()
  140.     {
  141.         return $this->dbResultSet->_currentRow;
  142.     }
  143. }
  144. ?>

Documentation generated on Fri, 1 Jun 2007 16:49:35 +0200 by phpDocumentor 1.3.2