propel-om
[ class tree: propel-om ] [ index: propel-om ] [ all elements ]

Source for file NestedSetRecursiveIterator.php

Documentation is available at NestedSetRecursiveIterator.php

  1. <?php
  2.  
  3. /*
  4.  *  $Id: NestedSetRecursiveIterator.php 542 2007-01-15 23:36:37Z heltem $
  5.  *
  6.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  7.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  8.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  9.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  10.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  12.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  13.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  14.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  16.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17.  *
  18.  * This software consists of voluntary contributions made by many individuals
  19.  * and is licensed under the LGPL. For more information please see
  20.  * <http://propel.phpdb.org>.
  21.  */
  22.  
  23. /**
  24.  * Pre-order node iterator for Node objects.
  25.  *
  26.  * @author     Heltem <heltem@o2php.com>
  27.  * @version    $Revision: 542 $
  28.  * @package    propel.om
  29.  */
  30. class NestedSetRecursiveIterator implements RecursiveIterator
  31. {
  32.     protected $topNode = null;
  33.  
  34.     protected $curNode = null;
  35.  
  36.     public function __construct($node{
  37.         $this->topNode = $node;
  38.         $this->curNode = $node;
  39.     }
  40.  
  41.     public function rewind({
  42.         $this->curNode = $this->topNode;
  43.     }
  44.  
  45.     public function valid({
  46.         return ($this->curNode !== null);
  47.     }
  48.  
  49.     public function current({
  50.         return $this->curNode;
  51.     }
  52.  
  53.     public function key({
  54.         $key array();
  55.         foreach ($this->curNode->getPath(as $node{
  56.             $key[$node->getPrimaryKey();
  57.         }
  58.         return implode('.'$key);
  59.     }
  60.  
  61.     public function next({
  62.         $nextNode null;
  63.  
  64.         if ($this->valid()) {
  65.             while (null === $nextNode{
  66.                 if (null === $this->curNode{
  67.                     break;
  68.                 }
  69.  
  70.                 if ($this->curNode->hasNextSibling()) {
  71.                     $nextNode $this->curNode->retrieveNextSibling();
  72.                 else {
  73.                     break;
  74.                 }
  75.             }
  76.             $this->curNode = $nextNode;
  77.         }
  78.         return $this->curNode;
  79.     }
  80.  
  81.     public function hasChildren({
  82.         return $this->curNode->hasChildren();
  83.     }
  84.  
  85.     public function getChildren({
  86.         return new NestedSetRecursiveIterator($this->curNode->retrieveFirstChild());
  87.     }
  88. }

Documentation generated on Thu, 22 Nov 2007 03:33:45 +0000 by phpDocumentor 1.4.0