00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Varien_Data_Tree_Node_Collection implements ArrayAccess, IteratorAggregate
00035 {
00036 private $_nodes;
00037 private $_container;
00038
00039 public function __construct($container)
00040 {
00041 $this->_nodes = array();
00042 $this->_container = $container;
00043 }
00044
00045 public function getNodes()
00046 {
00047 return $this->_nodes;
00048 }
00049
00050
00051
00052
00053 public function getIterator()
00054 {
00055 return new ArrayIterator($this->_nodes);
00056 }
00057
00058
00059
00060
00061 public function offsetSet($key, $value)
00062 {
00063 $this->_nodes[$key] = $value;
00064 }
00065
00066
00067
00068
00069 public function offsetGet($key)
00070 {
00071 return $this->_nodes[$key];
00072 }
00073
00074
00075
00076
00077 public function offsetUnset($key)
00078 {
00079 unset($this->_nodes[$key]);
00080 }
00081
00082
00083
00084
00085 public function offsetExists($key)
00086 {
00087 return isset($this->_nodes[$key]);
00088 }
00089
00090
00091
00092
00093 public function add(Varien_Data_Tree_Node $node)
00094 {
00095 $node->setParent($this->_container);
00096
00097
00098 if ($this->_container->getTree() instanceof Varien_Data_Tree) {
00099 $node->setTree($this->_container->getTree());
00100 }
00101
00102 $this->_nodes[$node->getId()] = $node;
00103
00104 return $node;
00105 }
00106
00107 public function delete($node)
00108 {
00109 if (isset($this->_nodes[$node->getId()])) {
00110 unset($this->_nodes[$node->getId()]);
00111 }
00112 return $this;
00113 }
00114
00115 public function count()
00116 {
00117 return count($this->_nodes);
00118 }
00119
00120 public function lastNode()
00121 {
00122 return !empty($this->_nodes) ? $this->_nodes[count($this->_nodes) - 1] : null;
00123 }
00124
00125 public function searchById($nodeId)
00126 {
00127 if (isset($this->_nodes[$nodeId])) {
00128 return $this->_nodes[$nodeId];
00129 }
00130 return null;
00131 }
00132 }