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

Source for file StatementIterator.php

Documentation is available at StatementIterator.php

  1. <?php
  2. // ----------------------------------------------------------------------------------
  3. // Class: RDF_StatementIterator
  4. // ----------------------------------------------------------------------------------
  5. /**
  6.  * Iterator for traversing models.
  7.  * This class can be used for iterating forward and backward trough Model_Memorys.
  8.  * It should be instanced using the getIterator() method of a Model_Memory.
  9.  *
  10.  * @version V0.7
  11.  * @author Chris Bizer <chris@bizer.de>
  12.  * @package util
  13.  * @access public
  14.  */
  15. {
  16.     /**
  17.      * Reference to the Model_Memory
  18.      *
  19.      * @var object Model_Memory 
  20.      * @access protected
  21.      */
  22.     var $model;
  23.  
  24.     /**
  25.      * Current position
  26.      * StatementIterator does not use the build in PHP array iterator,
  27.      * so you can use serveral iterators on a single Model_Memory.
  28.      *
  29.      * @var integer 
  30.      * @access protected
  31.      */
  32.     var $position;
  33.  
  34.     /**
  35.      * @param object Model_Memory 
  36.      * @access public
  37.      */
  38.     function RDF_StatementIterator(&$model)
  39.     {
  40.         $this->model = $model;
  41.         $this->position = -1;
  42.     }
  43.  
  44.     /**
  45.      * Returns TRUE if there are more statements.
  46.      *
  47.      * @return boolean 
  48.      * @access public
  49.      */
  50.     function hasNext()
  51.     {
  52.         if ($this->position < count($this->model->triples- 1{
  53.             return true;
  54.         else {
  55.             return false;
  56.         }
  57.     }
  58.  
  59.     /**
  60.      * Returns TRUE if the first statement has not been reached.
  61.      *
  62.      * @return boolean 
  63.      * @access public
  64.      */
  65.     function hasPrevious()
  66.     {
  67.         if ($this->position > 0{
  68.             return true;
  69.         else {
  70.             return false;
  71.         }
  72.     }
  73.  
  74.     /**
  75.      * Returns the next statement.
  76.      *
  77.      * @return statement or null if there is no next statement.
  78.      * @access public
  79.      */
  80.     function next()
  81.     {
  82.         if ($this->position < count($this->model->triples- 1{
  83.             $this->position++;
  84.             return $this->model->triples[$this->position];
  85.         else {
  86.             return null;
  87.         }
  88.     }
  89.  
  90.     /**
  91.      * Returns the previous statement.
  92.      *
  93.      * @return statement or null if there is no previous statement.
  94.      * @access public
  95.      */
  96.     function previous()
  97.     {
  98.         if ($this->position > 0{
  99.             $this->position--;
  100.             return $this->model->triples[$this->position];
  101.         else {
  102.             return null;
  103.         }
  104.     }
  105.  
  106.     /**
  107.      * Returns the current statement.
  108.      *
  109.      * @return statement or null if there is no current statement.
  110.      * @access public
  111.      */
  112.     function current()
  113.     {
  114.         if (($this->position >= 0&& ($this->position < count($this->model->triples))) {
  115.             return $this->model->triples[$this->position];
  116.         else {
  117.             return null;
  118.         }
  119.     }
  120.  
  121.     /**
  122.      * Moves the pointer to the first statement.
  123.      *
  124.      * @return void 
  125.      * @access public
  126.      */
  127.     function moveFirst()
  128.     {
  129.         $this->position = 0;
  130.     }
  131.  
  132.     /**
  133.      * Moves the pointer to the last statement.
  134.      *
  135.      * @return void 
  136.      * @access public
  137.      */
  138.     function moveLast()
  139.     {
  140.         $this->position = count($this->model->triples- 1;
  141.     }
  142.  
  143.     /**
  144.      * Moves the pointer to a specific statement.
  145.      * If you set an off-bounds value, next(), previous() and current() will return null
  146.      *
  147.      * @return void 
  148.      * @access public
  149.      */
  150.     function moveTo($position)
  151.     {
  152.         $this->position = $position;
  153.     }
  154.  
  155.     /**
  156.      * Returns the current position of the iterator.
  157.      *
  158.      * @return integer 
  159.      * @access public
  160.      */
  161.     function getCurrentPosition()
  162.     {
  163.         return $this->position;
  164.     }
  165. }
  166.  
  167. ?>

Documentation generated on Mon, 11 Mar 2019 15:39:30 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.