File tree 2 files changed +24
-5
lines changed
2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 1
1
### 1.0.1
2
- * Removed ` Collection::toDictionary ` . Use ` Collection::groupBy ` .
2
+ * ` Collection::toDictionary ` is now obsolete . Use ` Collection::groupBy ` .
Original file line number Diff line number Diff line change 4
4
5
5
class Collection extends BaseCollection {
6
6
7
+ /**
8
+ * Convert list of nodes to dictionary with specified key.
9
+ *
10
+ * If no key is specified then "parent_id" is used.
11
+ *
12
+ * @param string $key
13
+ *
14
+ * @return array
15
+ * @deprecated since 1.1
16
+ */
17
+ public function toDictionary ($ key = null )
18
+ {
19
+ if ($ key === null ) $ key = $ this ->first ()->getParentIdName ();
20
+
21
+ return $ this ->groupBy ($ key )->all ();
22
+ }
23
+
7
24
/**
8
25
* Build tree from node list. Each item will have set children relation.
9
26
*
@@ -27,20 +44,22 @@ public function toTree($rootNodeId = null)
27
44
28
45
$ rootNodeId = $ this ->getRootNodeId ($ rootNodeId );
29
46
30
- if (!isset ( $ dictionary[ $ rootNodeId] ))
47
+ if (!$ dictionary-> has ( $ rootNodeId ))
31
48
{
32
49
return $ result ;
33
50
}
34
51
35
- $ result ->items = $ dictionary[ $ rootNodeId] ;
52
+ $ result ->items = $ dictionary-> get ( $ rootNodeId) ;
36
53
37
54
foreach ($ this ->items as $ item )
38
55
{
39
56
$ key = $ item ->getKey ();
40
57
41
- $ children = new BaseCollection (isset ($ dictionary [$ key ]) ? $ dictionary [$ key ] : array ());
58
+ $ children = $ dictionary ->has ($ key )
59
+ ? $ dictionary ->get ($ key )
60
+ : array ();
42
61
43
- $ item ->setRelation ('children ' , $ children );
62
+ $ item ->setRelation ('children ' , new BaseCollection ( $ children) );
44
63
}
45
64
46
65
return $ result ;
You can’t perform that action at this time.
0 commit comments