Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Node.php
Go to the documentation of this file.
1 <?php
7 
10 
19 {
25  protected $_parent;
26 
32  protected $_tree;
33 
39  protected $_childNodes;
40 
46  protected $_idField;
47 
56  public function __construct($data, $idField, $tree, $parent = null)
57  {
58  $this->setTree($tree);
59  $this->setParent($parent);
60  $this->setIdField($idField);
61  $this->setData($data);
62  $this->_childNodes = new Collection($this);
63  }
64 
70  public function getId()
71  {
72  return $this->getData($this->getIdField());
73  }
74 
81  public function setIdField($idField)
82  {
83  $this->_idField = $idField;
84  return $this;
85  }
86 
92  public function getIdField()
93  {
94  return $this->_idField;
95  }
96 
103  public function setTree(Tree $tree)
104  {
105  $this->_tree = $tree;
106  return $this;
107  }
108 
114  public function getTree()
115  {
116  return $this->_tree;
117  }
118 
125  public function setParent($parent)
126  {
127  $this->_parent = $parent;
128  return $this;
129  }
130 
136  public function getParent()
137  {
138  return $this->_parent;
139  }
140 
146  public function hasChildren()
147  {
148  return $this->_childNodes->count() > 0;
149  }
150 
155  public function setLevel($level)
156  {
157  $this->setData('level', $level);
158  return $this;
159  }
160 
165  public function setPathId($path)
166  {
167  $this->setData('path_id', $path);
168  return $this;
169  }
170 
176  public function isChildOf($node)
177  {
178  }
179 
186  public function loadChildren($recursionLevel = 0)
187  {
188  $this->_tree->load($this, $recursionLevel);
189  return $this;
190  }
191 
197  public function getChildren()
198  {
199  return $this->_childNodes;
200  }
201 
206  public function getAllChildNodes(&$nodes = [])
207  {
208  foreach ($this->_childNodes as $node) {
209  $nodes[$node->getId()] = $node;
210  $node->getAllChildNodes($nodes);
211  }
212  return $nodes;
213  }
214 
218  public function getLastChild()
219  {
220  return $this->_childNodes->lastNode();
221  }
222 
229  public function addChild($node)
230  {
231  $this->_childNodes->add($node);
232  return $this;
233  }
234 
239  public function appendChild($prevNode = null)
240  {
241  $this->_tree->appendChild($this, $prevNode);
242  return $this;
243  }
244 
250  public function moveTo($parentNode, $prevNode = null)
251  {
252  $this->_tree->moveNodeTo($this, $parentNode, $prevNode);
253  return $this;
254  }
255 
261  public function copyTo($parentNode, $prevNode = null)
262  {
263  $this->_tree->copyNodeTo($this, $parentNode, $prevNode);
264  return $this;
265  }
266 
271  public function removeChild($childNode)
272  {
273  $this->_childNodes->delete($childNode);
274  return $this;
275  }
276 
281  public function getPath(&$prevNodes = [])
282  {
283  if ($this->_parent) {
284  $prevNodes[] = $this;
285  $this->_parent->getPath($prevNodes);
286  }
287  return $prevNodes;
288  }
289 
293  public function getIsActive()
294  {
295  return $this->_getData('is_active');
296  }
297 
301  public function getName()
302  {
303  return $this->_getData('name');
304  }
305 }
__construct($data, $idField, $tree, $parent=null)
Definition: Node.php:56
getData($key='', $index=null)
Definition: DataObject.php:119
loadChildren($recursionLevel=0)
Definition: Node.php:186
moveTo($parentNode, $prevNode=null)
Definition: Node.php:250
appendChild($prevNode=null)
Definition: Node.php:239
setData($key, $value=null)
Definition: DataObject.php:72
copyTo($parentNode, $prevNode=null)
Definition: Node.php:261
getPath(&$prevNodes=[])
Definition: Node.php:281