Skip to content

Commit bd9db4e

Browse files
committed
tree are nodes are array: simplify
1 parent c2799f2 commit bd9db4e

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

library/Nestedset/Model.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -275,37 +275,37 @@ public function getAll($depth = null, $mode = 'include', $order = 'ASC')
275275
/**
276276
* Convert a tree array (with depth) into a hierarchical array.
277277
*
278-
* @param $tree|array Array with depth value.
278+
* @param $nodes|array Array with depth value.
279279
*
280280
* @return array
281281
*/
282-
public function toArray($tree = null)
282+
public function toArray(array $nodes = array())
283283
{
284-
return (new NestedSet_Model_Output)->toArray($this, $tree);
284+
return (new NestedSet_Model_Output)->toArray($this, $nodes);
285285
}
286286

287287
/**
288288
* Convert a tree array (with depth) into a hierarchical XML string.
289289
*
290-
* @param $tree|array Array with depth value.
290+
* @param $nodes|array Array with depth value.
291291
*
292292
* @return string
293293
*/
294-
public function toXml($tree = null)
294+
public function toXml(array $nodes = array())
295295
{
296-
return (new NestedSet_Model_Output)->toXml($this, $tree);
296+
return (new NestedSet_Model_Output)->toXml($this, $nodes);
297297
}
298298

299299
/**
300300
* Return nested set as JSON
301301
*
302-
* @params $tree|array Original 'flat' nested tree
302+
* @params $nodes|array Original 'flat' nested tree
303303
*
304304
* @return string
305305
*/
306-
public function toJson($tree = null)
306+
public function toJson(array $nodes = array())
307307
{
308-
return (new NestedSet_Model_Output)->toJson($this, $tree);
308+
return (new NestedSet_Model_Output)->toJson($this, $nodes);
309309
}
310310

311311
/**
@@ -316,9 +316,9 @@ public function toJson($tree = null)
316316
*
317317
* @return string
318318
*/
319-
public function toHtml($tree = null, $method = 'list')
319+
public function toHtml(array $nodes = array(), $method = 'list')
320320
{
321-
return (new NestedSet_Model_Output)->toHtml($this, $tree, $method);
321+
return (new NestedSet_Model_Output)->toHtml($this, $nodes, $method);
322322
}
323323

324324
/**

library/Nestedset/Model/Output.php

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@ class NestedSet_Model_Output
66
* Convert a tree array (with depth) into a hierarchical array.
77
*
88
* @param $model|NestedSet_Model Nested set model
9-
* @param $tree|array Array with depth value.
9+
* @param $nodes|array Array with depth value.
1010
*
1111
* @return array
1212
*/
13-
public function toArray(NestedSet_Model $nestedset, $tree = null)
13+
public function toArray(NestedSet_Model $nestedset, array $nodes = array())
1414
{
15-
if (empty($tree) || !is_array($tree)) {
15+
if (empty($nodes)) {
1616
$nodes = $nestedset->getAll();
1717
}
18-
else {
19-
$nodes = $tree;
20-
}
2118

2219
$result = array();
2320
$stackLevel = 0;
@@ -64,18 +61,15 @@ public function toArray(NestedSet_Model $nestedset, $tree = null)
6461
* Convert a tree array (with depth) into a hierarchical XML string.
6562
*
6663
* @param $model|NestedSet_Model Nested set model
67-
* @param $tree|array Array with depth value.
64+
* @param $nodes|array Array with depth value.
6865
*
6966
* @return string
7067
*/
71-
public function toXml(NestedSet_Model $nestedset, $tree = null)
68+
public function toXml(NestedSet_Model $nestedset, array $nodes = array())
7269
{
73-
if (empty($tree) || !is_array($tree)) {
70+
if (empty($nodes)) {
7471
$nodes = $nestedset->getAll();
7572
}
76-
else {
77-
$nodes = $tree;
78-
}
7973

8074
$xml = new DomDocument('1.0');
8175
$xml->preserveWhiteSpace = false;
@@ -119,13 +113,13 @@ public function toXml(NestedSet_Model $nestedset, $tree = null)
119113
/**
120114
* Return nested set as JSON
121115
*
122-
* @params $tree|array Original 'flat' nested tree
116+
* @params $nodes|array Original 'flat' nested tree
123117
*
124118
* @return string
125119
*/
126-
public function toJson(NestedSet_Model $nestedset, $tree = null)
120+
public function toJson(NestedSet_Model $nestedset, array $nodes = array())
127121
{
128-
$nestedArray = $this->toArray($nestedset, $tree);
122+
$nestedArray = $this->toArray($nestedset, $nodes);
129123
$result = json_encode($nestedArray);
130124

131125
return $result;
@@ -141,14 +135,11 @@ public function toJson(NestedSet_Model $nestedset, $tree = null)
141135
*
142136
* @return string
143137
*/
144-
public function toHtml(NestedSet_Model $nestedset, $tree = null, $method = 'list')
138+
public function toHtml(NestedSet_Model $nestedset, array $nodes = array(), $method = 'list')
145139
{
146-
if (empty($tree) || !is_array($tree)) {
140+
if (empty($nodes)) {
147141
$nodes = $nestedset->getAll();
148142
}
149-
else {
150-
$nodes = $tree;
151-
}
152143

153144
switch ($method) {
154145
case 'list':

0 commit comments

Comments
 (0)