@@ -236,7 +236,7 @@ public function enabledShareFolder()
236236 *** File System ***
237237 ****************************/
238238
239- public function getDirectories ($ path, $ sort_type = ' alpha ' )
239+ public function getDirectories ($ path )
240240 {
241241 $ thumb_folder_name = config ('lfm.thumb_folder_name ' );
242242 $ all_directories = File::directories ($ path );
@@ -260,16 +260,10 @@ public function getDirectories($path, $sort_type = 'alpha')
260260 }
261261 }
262262
263- if ($ sort_type == 'alpha ' ) {
264- uasort ($ arr_dir , array ($ this , 'compareDirAlpha ' ));
265- } elseif ($ sort_type == 'time ' ) {
266- uasort ($ arr_dir , array ($ this , 'compareDirTime ' ));
267- }
268-
269263 return $ arr_dir ;
270264 }
271265
272- public function getFilesWithInfo ($ path, $ sort_type = ' alpha ' )
266+ public function getFilesWithInfo ($ path )
273267 {
274268 $ arr_files = [];
275269
@@ -306,12 +300,6 @@ public function getFilesWithInfo($path, $sort_type = 'alpha')
306300 ];
307301 }
308302
309- if ($ sort_type == 'alpha ' ) {
310- uasort ($ arr_files , array ($ this , 'compareFileAlpha ' ));
311- } elseif ($ sort_type == 'time ' ) {
312- uasort ($ arr_files , array ($ this , 'compareFileTime ' ));
313- }
314-
315303 return $ arr_files ;
316304 }
317305
@@ -338,44 +326,27 @@ public function fileIsImage($file)
338326 return starts_with ($ mime_type , 'image ' );
339327 }
340328
341- private static function compareDirAlpha ($ a , $ b )
342- {
343- $ cmp = strcmp ($ a ->name , $ b ->name );
344-
345- if ($ cmp == 0 ) {
346- return 0 ;
347- }
348-
349- return ($ cmp > 0 ) ? 1 : -1 ;
350- }
351-
352- private static function compareDirTime ($ a , $ b )
329+ public function sortFilesAndDirectories ($ arr_items , $ sort_type )
353330 {
354- if ($ a ->updated == $ b ->updated ) {
355- return 0 ;
331+ if ($ sort_type == 'time ' ) {
332+ $ key_to_sort = 'updated ' ;
333+ } elseif ($ sort_type == 'alpha ' ) {
334+ $ key_to_sort = 'name ' ;
335+ } else {
336+ $ key_to_sort = 'updated ' ;
356337 }
357338
358- return ($ a ->updated > $ b ->updated ) ? 1 : -1 ;
359- }
360-
361- private static function compareFileAlpha ($ a , $ b )
362- {
363- $ cmp = strcmp ($ a ['name ' ], $ b ['name ' ]);
364-
365- if ($ cmp == 0 ) {
366- return 0 ;
367- }
339+ uasort ($ arr_items , function ($ a , $ b ) use ($ key_to_sort ) {
340+ $ cmp = strcmp ($ a ->{$ key_to_sort }, $ b ->{$ key_to_sort });
368341
369- return ($ cmp > 0 ) ? 1 : -1 ;
370- }
342+ if ($ cmp == 0 ) {
343+ return 0 ;
344+ }
371345
372- private static function compareFileTime ($ a , $ b )
373- {
374- if ($ a ['updated ' ] == $ b ['updated ' ]) {
375- return 0 ;
376- }
346+ return ($ cmp > 0 ) ? 1 : -1 ;
347+ });
377348
378- return ( $ a [ ' updated ' ] > $ b [ ' updated ' ]) ? 1 : - 1 ;
349+ return $ arr_items ;
379350 }
380351
381352
0 commit comments