Source for file IteratorFindQuadsDb.php

Documentation is available at IteratorFindQuadsDb.php

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

Documentation generated on Fri, 13 Jan 2006 07:48:27 +0100 by phpDocumentor 1.3.0RC4