@@ -15,30 +15,24 @@ class ItemsController extends LfmController
1515 *
1616 * @return mixed
1717 */
18- public function getItems (Request $ request )
18+ public function getItems ()
1919 {
2020 $ currentPage = self ::getCurrentPageFromRequest ();
2121
2222 $ perPage = $ this ->helper ->getPaginationPerPage ();
2323 $ items = array_merge ($ this ->lfm ->folders (), $ this ->lfm ->files ());
2424
25- $ items = array_map (function ($ item ) {
26- return $ item ->fill ()->attributes ;
27- }, $ items );
28-
29- $ keyword = $ request ->keyword ;
25+ $ keyword = request ()->get ('keyword ' , "" );
3026 if (!empty ($ keyword )) {
31- $ items = array_values (array_filter ($ items , function ($ item ) use ($ keyword ) {
32- if ($ this ->like_match ("% " .$ keyword ."% " , $ item ['name ' ])) {
33- return true ;
34- } else {
35- return false ;
36- }
37- }));
27+ $ items = array_filter ($ items , function ($ item ) use ($ keyword ) {
28+ return str_contains ($ item ->name , $ keyword );
29+ });
3830 }
3931
4032 return [
41- 'items ' => array_slice ($ items , ($ currentPage - 1 ) * $ perPage , $ perPage ),
33+ 'items ' => array_map (function ($ item ) {
34+ return $ item ->fill ()->attributes ;
35+ }, array_slice ($ items , ($ currentPage - 1 ) * $ perPage , $ perPage )),
4236 'paginator ' => [
4337 'current_page ' => $ currentPage ,
4438 'total ' => count ($ items ),
@@ -49,12 +43,6 @@ public function getItems(Request $request)
4943 ];
5044 }
5145
52- public function like_match ($ pattern , $ subject )
53- {
54- $ pattern = str_replace ('% ' , '.* ' , preg_quote ($ pattern , '/ ' ));
55- return (bool ) preg_match ("/^ {$ pattern }$/i " , $ subject );
56- }
57-
5846 public function move ()
5947 {
6048 $ items = request ('items ' );
@@ -122,10 +110,4 @@ private static function getCurrentPageFromRequest()
122110
123111 return $ currentPage ;
124112 }
125-
126- private static function getKeywordFromRequest ()
127- {
128- $ keyword = request ()->get ('keyword ' , "" );
129- return $ keyword ;
130- }
131113}
0 commit comments