27 private $_persistenceFacade = null;
28 private $_session = null;
49 $aggregationKinds=array()) {
50 $this->_persistenceFacade = $persistenceFacade;
51 $this->_session = $session;
54 $this->_oidList = array();
55 $this->_processedOidList = array();
56 $this->_currentOid = $oid;
57 $this->_startOid = $oid;
58 $this->_currentDepth = 0;
59 $this->_aggregationKinds = $aggregationKinds;
67 $uid = md5(uniqid(
""));
68 $state = array(
'end' => $this->_end,
'oidList' => $this->_oidList,
'processedOidList' => $this->_processedOidList,
69 'currentOID' => $this->_currentOid,
'currentDepth' => $this->_currentDepth,
'aggregationKinds' => $this->_aggregationKinds);
70 $this->_session->set(
'PersistentIterator.'.$uid, $state);
81 public static function load($persistenceFacade, $session, $uid) {
83 $state = $session->
get(
'PersistentIterator.'.$uid);
89 $state[
'currentOID']);
90 $instance->_end = $state[
'end'];
91 $instance->_oidList = $state[
'oidList'];
92 $instance->_processedOidList = $state[
'processedOidList'];
93 $instance->_currentDepth = $state[
'currentDepth'];
94 $instance->_aggregationKinds = $state[
'aggregationKinds'];
119 $this->_processedOidList[] = $this->_currentOid->__toString();
121 $node = $this->_persistenceFacade->load($this->_currentOid);
124 $childOIDs = array();
125 $mapper = $node->getMapper();
126 $relations = $mapper->getRelations(
'child');
128 foreach ($relations as $relation) {
129 $aggregationKind = $relation->getOtherAggregationKind();
130 if ($relation->getOtherNavigability() && ($followAll || in_array($aggregationKind, $this->_aggregationKinds))) {
131 $childValue = $node->getValue($relation->getOtherRole());
132 if ($childValue != null) {
133 $children = $relation->isMultiValued() ? $childValue : array($childValue);
134 foreach ($children as $child) {
135 $childOIDs[] = $child->getOID();
140 $this->
addToQueue($childOIDs, ++$this->_currentDepth);
143 if (
sizeof($this->_oidList) != 0) {
144 list($oid, $depth) = array_pop($this->_oidList);
147 while (
sizeof($this->_oidList) > 0 && in_array($oidStr, $this->_processedOidList)) {
148 list($oid, $depth) = array_pop($this->_oidList);
152 if (
sizeof($this->_oidList) == 0 && in_array($oidStr, $this->_processedOidList)) {
155 $this->_currentOid = $oid;
156 $this->_currentDepth = $depth;
169 $this->_oidList= array();
170 $this->_processedOidList = array();
172 $this->_currentDepth = 0;
188 for ($i=sizeOf($oidList)-1; $i>=0; $i--) {
189 $this->_oidList[] = array($oidList[$i], $depth);
Node related interfaces and classes.
static load($persistenceFacade, $session, $uid)
Load an iterator state from the session.
current()
Return the current element.
ObjectId is the unique identifier of an object.
valid()
Checks if current position is valid.
addToQueue($oidList, $depth)
Add oids to the processing queue.
Session is the interface for session implementations and defines access to session variables...
rewind()
Rewind the Iterator to the first element.
__toString()
Get a string representation of the object id.
__construct(PersistenceFacade $persistenceFacade, Session $session, ObjectId $oid, $aggregationKinds=array())
Constructor.
next()
Move forward to next element.
PersistenceFacade defines the interface for PersistenceFacade implementations.
PersistentIterator is used to iterate over a tree/list built of oids using a Depth-First-Algorithm.
key()
Return the key of the current element.
save()
Save the iterator state to the session.
get($key)
Returns the value of an session variable.