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 extends Varien_Object
00035 {
00036
00037
00038
00039
00040
00041 protected $_parent;
00042
00043
00044
00045
00046
00047
00048 protected $_tree;
00049
00050
00051
00052
00053
00054
00055 protected $_childNodes;
00056
00057
00058
00059
00060
00061
00062 protected $_idField;
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 public function __construct($data, $idFeild, $tree, $parent = null)
00073 {
00074 $this->setTree($tree);
00075 $this->setParent($parent);
00076 $this->setIdField($idFeild);
00077 $this->setData($data);
00078 $this->_childNodes = new Varien_Data_Tree_Node_Collection($this);
00079 }
00080
00081
00082
00083
00084
00085
00086 public function getId()
00087 {
00088 return $this->getData($this->getIdField());
00089 }
00090
00091
00092
00093
00094
00095
00096
00097 public function setIdField($idField)
00098 {
00099 $this->_idField = $idField;
00100 return $this;
00101 }
00102
00103
00104
00105
00106
00107
00108 public function getIdField()
00109 {
00110 return $this->_idField;
00111 }
00112
00113
00114
00115
00116
00117
00118
00119 public function setTree(Varien_Data_Tree $tree)
00120 {
00121 $this->_tree = $tree;
00122 return $this;
00123 }
00124
00125
00126
00127
00128
00129
00130 public function getTree()
00131 {
00132 return $this->_tree;
00133 }
00134
00135
00136
00137
00138
00139
00140
00141 public function setParent($parent)
00142 {
00143 $this->_parent = $parent;
00144 return $this;
00145 }
00146
00147
00148
00149
00150
00151
00152 public function getParent()
00153 {
00154 return $this->_parent;
00155 }
00156
00157
00158
00159
00160
00161
00162 public function hasChildren()
00163 {
00164 return $this->_childNodes->count() > 0;
00165 }
00166
00167 public function setLevel($level)
00168 {
00169 $this->setData('level', $level);
00170 return $this;
00171 }
00172
00173 public function setPathId($path)
00174 {
00175 $this->setData('path_id', $path);
00176 return $this;
00177 }
00178
00179 public function isChildOf($node)
00180 {
00181
00182 }
00183
00184
00185
00186
00187
00188
00189
00190 public function loadChildren($recursionLevel=0)
00191 {
00192 $this->_tree->load($this, $recursionLevel);
00193 return $this;
00194 }
00195
00196
00197
00198
00199
00200
00201 public function getChildren()
00202 {
00203 return $this->_childNodes;
00204 }
00205
00206 public function getAllChildNodes(&$nodes = array())
00207 {
00208 foreach ($this->_childNodes as $node) {
00209 $nodes[$node->getId()] = $node;
00210 $node->getAllChildNodes($nodes);
00211 }
00212 return $nodes;
00213 }
00214
00215 public function getLastChild()
00216 {
00217 return $this->_childNodes->lastNode();
00218 }
00219
00220
00221
00222
00223
00224
00225
00226 public function addChild($node)
00227 {
00228 $this->_childNodes->add($node);
00229 return $this;
00230 }
00231
00232 public function appendChild($prevNode=null)
00233 {
00234 $this->_tree->appendChild($this, $prevNode);
00235 return $this;
00236 }
00237
00238 public function moveTo($parentNode, $prevNode=null)
00239 {
00240 $this->_tree->moveNodeTo($this, $parentNode, $prevNode);
00241 return $this;
00242 }
00243
00244 public function copyTo($parentNode, $prevNode=null)
00245 {
00246 $this->_tree->copyNodeTo($this, $parentNode, $prevNode);
00247 return $this;
00248 }
00249
00250 public function removeChild($childNode)
00251 {
00252 $this->_childNodes->delete($childNode);
00253 return $this;
00254 }
00255
00256 public function getPath(&$prevNodes = array())
00257 {
00258 if ($this->_parent) {
00259 array_push($prevNodes, $this);
00260 $this->_parent->getPath($prevNodes);
00261 }
00262 return $prevNodes;
00263 }
00264
00265 public function getIsActive()
00266 {
00267 return $this->_getData('is_active');
00268 }
00269
00270 public function getName()
00271 {
00272 return $this->_getData('name');
00273 }
00274
00275 }