1: <?php
2: /**
3: * Copyright 2013-2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2013-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Iterator for the IMP_Ftree object.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2013-2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: class IMP_Ftree_Iterator implements RecursiveIterator
24: {
25: /**
26: * Sorted list of elements.
27: *
28: * @var array
29: */
30: protected $_elts = array();
31:
32: /**
33: * Constructor.
34: *
35: * @param mixed $elt Either the parent element of the level
36: * (IMP_Ftree_Element object), or a flat list of
37: * Ftree elements to use as the base level.
38: */
39: public function __construct($elt)
40: {
41: $this->_elts = ($elt instanceof IMP_Ftree_Element)
42: ? $elt->child_list
43: : $elt;
44: }
45:
46: /* RecursiveIterator methods. */
47:
48: /**
49: */
50: public function getChildren()
51: {
52: return new self($this->current());
53: }
54:
55: /**
56: */
57: public function hasChildren()
58: {
59: return $this->current()->children;
60: }
61:
62: /**
63: */
64: public function current()
65: {
66: return current($this->_elts);
67: }
68:
69: /**
70: */
71: public function key()
72: {
73: return key($this->_elts);
74: }
75:
76: /**
77: */
78: public function next()
79: {
80: next($this->_elts);
81: }
82:
83: /**
84: */
85: public function rewind()
86: {
87: reset($this->_elts);
88: }
89:
90: /**
91: */
92: public function valid()
93: {
94: return !is_null($this->key());
95: }
96:
97: }
98: