@@ -19,7 +19,7 @@ public static function clearCache()
1919 public static function all ()
2020 {
2121 return Cache::rememberForever ('BlogCategories ' , function () {
22- $ records = ModelUtil::all ('blog_category ' , [], ['* ' ], ['sort ' , 'desc ' ]);
22+ $ records = ModelUtil::all ('blog_category ' , [], ['* ' ], ['sort ' , 'asc ' ]);
2323 AssetsUtil::recordsFixFullOrDefault ($ records , 'cover ' , 'asset/image/none.png ' );
2424 foreach ($ records as $ k => $ v ) {
2525 $ records [$ k ]['_url ' ] = UrlUtil::category ($ v );
@@ -34,6 +34,12 @@ public static function categoryTree()
3434 return TreeUtil::nodesToTree ($ nodes );
3535 }
3636
37+ public static function categoryChainWithItems ($ categoryId )
38+ {
39+ $ records = self ::all ();
40+ return TreeUtil::nodesChainWithItems ($ records , $ categoryId );
41+ }
42+
3743 public static function get ($ id )
3844 {
3945 foreach (self ::all () as $ one ) {
@@ -44,6 +50,15 @@ public static function get($id)
4450 return null ;
4551 }
4652
53+ public static function listChildCategories ($ categoryId )
54+ {
55+ $ records = self ::all ();
56+ $ records = array_filter ($ records , function ($ item ) use ($ categoryId ) {
57+ return $ item ['pid ' ] == $ categoryId ;
58+ });
59+ return array_values ($ records );
60+ }
61+
4762 public static function childrenIds ($ categoryId )
4863 {
4964 if ($ categoryId <= 0 ) {
0 commit comments