Tree.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Data;
  7. use Magento\Framework\Data\Tree\Node;
  8. use Magento\Framework\Data\Tree\Node\Collection as NodeCollection;
  9. /**
  10. * Data tree
  11. *
  12. * @api
  13. * @author Magento Core Team <core@magentocommerce.com>
  14. * @since 100.0.2
  15. */
  16. class Tree
  17. {
  18. /**
  19. * Nodes collection
  20. *
  21. * @var NodeCollection
  22. */
  23. protected $_nodes;
  24. /**
  25. * Enter description here...
  26. *
  27. */
  28. public function __construct()
  29. {
  30. $this->_nodes = new NodeCollection($this);
  31. }
  32. /**
  33. * Enter description here...
  34. *
  35. * @return \Magento\Framework\Data\Tree
  36. */
  37. public function getTree()
  38. {
  39. return $this;
  40. }
  41. /**
  42. * Enter description here...
  43. *
  44. * @param Node $parentNode
  45. * @return void
  46. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  47. */
  48. public function load($parentNode = null)
  49. {
  50. }
  51. /**
  52. * Enter description here...
  53. *
  54. * @param int|string $nodeId
  55. * @return void
  56. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  57. */
  58. public function loadNode($nodeId)
  59. {
  60. }
  61. /**
  62. * Append child
  63. *
  64. * @param array|Node $data
  65. * @param Node $parentNode
  66. * @param Node $prevNode
  67. * @return Node
  68. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  69. */
  70. public function appendChild($data, $parentNode, $prevNode = null)
  71. {
  72. if (is_array($data)) {
  73. $node = $this->addNode(new Node($data, $parentNode->getIdField(), $this), $parentNode);
  74. } elseif ($data instanceof Node) {
  75. $node = $this->addNode($data, $parentNode);
  76. }
  77. return $node;
  78. }
  79. /**
  80. * Add node
  81. *
  82. * @param Node $node
  83. * @param Node $parent
  84. * @return Node
  85. */
  86. public function addNode($node, $parent = null)
  87. {
  88. $this->_nodes->add($node);
  89. $node->setParent($parent);
  90. if ($parent !== null && $parent instanceof Node) {
  91. $parent->addChild($node);
  92. }
  93. return $node;
  94. }
  95. /**
  96. * Move node
  97. *
  98. * @param Node $node
  99. * @param Node $parentNode
  100. * @param Node $prevNode
  101. * @return void
  102. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  103. */
  104. public function moveNodeTo($node, $parentNode, $prevNode = null)
  105. {
  106. }
  107. /**
  108. * Copy node
  109. *
  110. * @param Node $node
  111. * @param Node $parentNode
  112. * @param Node $prevNode
  113. * @return void
  114. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  115. */
  116. public function copyNodeTo($node, $parentNode, $prevNode = null)
  117. {
  118. }
  119. /**
  120. * Remove node
  121. *
  122. * @param Node $node
  123. * @return $this
  124. */
  125. public function removeNode($node)
  126. {
  127. $this->_nodes->delete($node);
  128. if ($node->getParent()) {
  129. $node->getParent()->removeChild($node);
  130. }
  131. unset($node);
  132. return $this;
  133. }
  134. /**
  135. * Create node
  136. *
  137. * @param Node $parentNode
  138. * @param Node $prevNode
  139. * @return void
  140. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  141. */
  142. public function createNode($parentNode, $prevNode = null)
  143. {
  144. }
  145. /**
  146. * Get child
  147. *
  148. * @param Node $node
  149. * @return void
  150. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  151. */
  152. public function getChild($node)
  153. {
  154. }
  155. /**
  156. * Get children
  157. *
  158. * @param Node $node
  159. * @return void
  160. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  161. */
  162. public function getChildren($node)
  163. {
  164. }
  165. /**
  166. * Enter description here...
  167. *
  168. * @return NodeCollection
  169. */
  170. public function getNodes()
  171. {
  172. return $this->_nodes;
  173. }
  174. /**
  175. * Enter description here...
  176. *
  177. * @param Node $nodeId
  178. * @return Node
  179. */
  180. public function getNodeById($nodeId)
  181. {
  182. return $this->_nodes->searchById($nodeId);
  183. }
  184. /**
  185. * Get path
  186. *
  187. * @param Node $node
  188. * @return array
  189. */
  190. public function getPath($node)
  191. {
  192. if ($node instanceof Node) {
  193. } elseif (is_numeric($node)) {
  194. if ($_node = $this->getNodeById($node)) {
  195. return $_node->getPath();
  196. }
  197. }
  198. return [];
  199. }
  200. }