Source for file ResIterator.php
Documentation is available at ResIterator.php
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* Implementation of a resource iterator.
* This Iterator should be used in a for-loop like:
* $it = $ontClass->listInstances();
* for ($it->rewind(); $it->valid(); $it->next())
* $currentResource=$it->current();
* @version $Id: fsource_resModel__resModelResIterator.php.html 443 2007-06-01 16:25:38Z cax $
* @author Daniel Westphal <mail at d-westphal dot de>
* Holds a reference to the assoiated ResModel / OntModel
* If the current resource is valid
* @var obejct ResResource
* The subject to search for.
* @var object ResResource
* The predicate to search for.
* @var object ResResource
* The object to search for.
* @var object ResResource
* If the resource, we're intrested in is the subject (s), predicate(p),
* or object (o) of the found statements
* Defines the type of resource, we'd like to receive.
* If set, each resource will first be checked, if it's
var $findLiteralWithLang;
* $subject, $predicate, and $object are used like inf find().
* $getSPO supports the strings 's', 'p', and 'o' to return
* either the subject, predicate, or object of the result statements.
* $returnType supports the strings 'ResProperty', 'ResLiteral',
* 'OntProperty', 'OntClass', and 'Individual' and returns the resources
* @param object ResResource $subject
* @param object ResResource $predicate
* @param object ResResource $object
* @param object ResModel $associatedModel
* @param string $returnType
function ResIterator($subject,$predicate,$object,$getSPO,& $associatedModel,$returnType =
false)
$this->searchSubject =
& $subject;
$this->searchPredicate =
& $predicate;
$this->searchObject =
& $object;
$this->returnType =
$returnType;
$this->associatedModel =
& $associatedModel;
$this->findLiteralWithLang =
false;
* Resets iterator list to start
* Says if there are additional items left in the list
* Moves Iterator to the next item in the list
$this->valid=
($this->_getNextResource());
* Returns the current item
return $this->currentResource;
* Returns the next Resource (subject, predicate,
* or object of the next matching statement).
* @return object resResource
function _getNextResource()
if ($this->findLiteralWithLang)
$nextStatement =
$this->associatedModel->findFirstMatchingStatement($this->searchSubject,$this->searchPredicate,$this->searchObject,$this->key);
if ($nextStatement ===
null)
$object =
$nextStatement->getObject();
if ($object->getLanguage() !=
$this->findLiteralWithLang)
$hasCorrectLanguage=
false;
$hasCorrectLanguage=
true;
} while (!$hasCorrectLanguage);
$nextStatement =
$this->associatedModel->findFirstMatchingStatement($this->searchSubject,$this->searchPredicate,$this->searchObject,$this->key);
if ($nextStatement ===
null)
$this->currentResource =
$this->_getResourceAs($nextStatement->getSubject());
$this->currentResource =
$this->_getResourceAs($nextStatement->getPredicate());
$this->currentResource =
$this->_getResourceAs($nextStatement->getObject());
* Returns the key of the current item
* Sets that only Literals with the matching
* language should be returned
$this->findLiteralWithLang =
$language;
* Returns the $resource as an instance of the type
* specified in $this->returnType.
* @param object ResResource
* @return object ResResource
function _getResourceAs($resource)
if ($this->findLiteralWithLang &&
$resource->getLanguage() !=
$this->findLiteralWithLang)
$this->_getNextResource();
switch ($this->returnType) {
return $this->associatedModel->createProperty($resource->getLabel());
$newLiteral =
$this->associatedModel->createLiteral($resource->getLabel(),$resource->getLanguage());
$newLiteral->setDatatype($resource->getDatatype());
return $this->associatedModel->createOntProperty($resource->getLabel());
return $this->associatedModel->createOntClass($resource->getLabel());
return $this->associatedModel->createIndividual($resource->getLabel());
Documentation generated on Fri, 1 Jun 2007 16:51:25 +0200 by phpDocumentor 1.3.2