source: Dev/branches/rest-dojo-ui/Demo/rdfapi/dataset/IteratorFindQuadsDb.php @ 312

Last change on this file since 312 was 312, checked in by jkraaijeveld, 13 years ago
File size: 3.0 KB
Line 
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$
18* @author Daniel Westphal (http://www.d-westphal.de)
19*
20*
21* @package      dataset
22* @access       public
23**/
24class IteratorFindQuadsDb
25{
26        /**
27        * Holds a reference to the associated DB resultSet.
28        *
29        * @var          $dbResultSets ADODB result
30        * @access       private
31        */
32        var $dbResultSet;
33       
34        /**
35        * Holds a reference to the associated datasetDb.
36        *
37        * @var          $datasetDb datasetDb
38        * @access       private
39        */
40        var $datasetDb;
41
42        /**
43        * boolean value, if the results should be returned as triples.
44        *
45        * @var          boolean
46        * @access       private
47        */
48        var $returnAsTriples;
49       
50        /**
51    * Constructor.
52    *
53    * @param dataset
54        * @access       public
55    */
56        function IteratorFindQuadsDb(&$dbResultSet,&$datasetDb,$returnAsTriples=false)
57        {
58                $this->dbResultSet=& $dbResultSet;
59                $this->datasetDb=& $datasetDb;
60                $this->returnAsTriples=$returnAsTriples;
61        }
62       
63        /**
64    * Resets iterator list to start.
65    *
66        * @access public
67    */
68        function rewind()
69        {
70                //not supported
71        }
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               
84                return true;
85        }
86       
87        /**
88    * Moves Iterator to the next item in the list.
89    *
90        * @access       public
91    */
92        function next()
93        {
94                if ($this->dbResultSet!==false)
95                        $this->dbResultSet->moveNext();
96        }
97       
98        /**
99    * Returns the current item.
100    *
101    * @return   mixed
102        * @access       public
103    */
104        function &current()
105        {
106                if ($this->dbResultSet===false)
107                        return null;
108                // subject
109                if ($this->dbResultSet->fields[5] == 'r')
110                $sub = new Resource($this->dbResultSet->fields[0]);
111                else
112                $sub = new BlankNode($this->dbResultSet->fields[0]);
113
114                // predicate
115                $pred = new Resource($this->dbResultSet->fields[1]);
116
117                // object
118                if ($this->dbResultSet->fields[6] == 'r')
119                $obj = new Resource($this->dbResultSet->fields[2]);
120                elseif ($this->dbResultSet->fields[6] == 'b')
121                $obj = new BlankNode($this->dbResultSet->fields[2]);
122                else {
123                        $obj = new Literal($this->dbResultSet->fields[2], $this->dbResultSet->fields[3]);
124                        if ($this->dbResultSet->fields[4])
125                        $obj->setDatatype($this->dbResultSet->fields[4]);
126                }
127
128                if($this->returnAsTriples)
129                        return (new Statement($sub, $pred, $obj));
130
131                return (new Quad(new Resource($this->dbResultSet->fields[7]),$sub,$pred,$obj));
132        }
133       
134        /**
135    * Returns the key of the current item.
136    *
137    * @return   integer
138        * @access       public
139    */
140        function key()
141        {
142                return $this->dbResultSet->_currentRow;
143        }
144}
145?>
Note: See TracBrowser for help on using the repository browser.