File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 11### 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 44
55class Collection extends BaseCollection {
66
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+
724 /**
825 * Build tree from node list. Each item will have set children relation.
926 *
@@ -27,20 +44,22 @@ public function toTree($rootNodeId = null)
2744
2845 $ rootNodeId = $ this ->getRootNodeId ($ rootNodeId );
2946
30- if (!isset ( $ dictionary[ $ rootNodeId] ))
47+ if (!$ dictionary-> has ( $ rootNodeId ))
3148 {
3249 return $ result ;
3350 }
3451
35- $ result ->items = $ dictionary[ $ rootNodeId] ;
52+ $ result ->items = $ dictionary-> get ( $ rootNodeId) ;
3653
3754 foreach ($ this ->items as $ item )
3855 {
3956 $ key = $ item ->getKey ();
4057
41- $ children = new BaseCollection (isset ($ dictionary [$ key ]) ? $ dictionary [$ key ] : array ());
58+ $ children = $ dictionary ->has ($ key )
59+ ? $ dictionary ->get ($ key )
60+ : array ();
4261
43- $ item ->setRelation ('children ' , $ children );
62+ $ item ->setRelation ('children ' , new BaseCollection ( $ children) );
4463 }
4564
4665 return $ result ;
You can’t perform that action at this time.
0 commit comments