File tree Expand file tree Collapse file tree 1 file changed +20
-13
lines changed
Expand file tree Collapse file tree 1 file changed +20
-13
lines changed Original file line number Diff line number Diff line change 44
55class GetFiles {
66
7- private $ files ;
7+ private $ path ;
8+ private $ order ;
9+ private $ exclude ;
810
9- public function __construct ( $ path = '' ) {
10- $ this ->files = [];
11- foreach (array_diff (scandir ($ path ), ['. ' , '.. ' ]) as $ file ) {
12- $ this ->files [$ file ] = filemtime ($ path . '/ ' . $ file );
13- }
11+ public function __construct ( $ path = '' , $ order = '' , $ exclude = '' ) {
12+ $ this ->path = $ path ;
13+ $ this ->order = $ order ;
14+ $ this ->exclude = $ exclude ;
1415 }
1516
16- public function sortDate ( $ direction = '' ) {
17- if ($ direction == 'DESC ' ) {
18- arsort ($ this ->files ); // newest first
19- } elseif ($ direction == 'ASC ' ) {
20- asort ($ this ->files ); // oldest first
17+ public function sortDate () {
18+ $ files = [];
19+ foreach (array_diff (scandir ($ this ->path ), $ this ->exclude ) as $ file ) {
20+ $ files [$ file ] = filemtime ($ this ->path . '/ ' . $ file );
21+ }
22+
23+ if ($ this ->order == 'DESC ' ) {
24+ arsort ($ files ); // newest first
25+ } elseif ($ this ->order == 'ASC ' ) {
26+ asort ($ files ); // oldest first
2127 } else {
2228 // alphabetical/default
2329 }
24- $ this ->files = array_keys ($ this ->files );
25- print_r ( ($ this ->files ) ? $ this ->files : false );
30+ $ files = array_keys ($ files );
31+
32+ return json_encode ($ files );
2633 }
2734
2835}
You can’t perform that action at this time.
0 commit comments