2
2
3
3
namespace UniSharp \LaravelFilemanager \Controllers ;
4
4
5
+ use UniSharp \LaravelFilemanager \Events \FileIsMoving ;
6
+ use UniSharp \LaravelFilemanager \Events \FileWasMoving ;
7
+ use UniSharp \LaravelFilemanager \Events \FolderIsMoving ;
8
+ use UniSharp \LaravelFilemanager \Events \FolderWasMoving ;
9
+
5
10
class ItemsController extends LfmController
6
11
{
7
12
/**
@@ -19,4 +24,56 @@ public function getItems()
19
24
'working_dir ' => $ this ->lfm ->path ('working_dir ' ),
20
25
];
21
26
}
27
+
28
+ public function move ()
29
+ {
30
+ $ items = request ('items ' );
31
+ $ folder_types = array_filter (['user ' , 'share ' ], function ($ type ) {
32
+ return $ this ->helper ->allowFolderType ($ type );
33
+ });
34
+ return view ('laravel-filemanager::move ' )
35
+ ->with ([
36
+ 'root_folders ' => array_map (function ($ type ) use ($ folder_types ) {
37
+ $ path = $ this ->lfm ->dir ($ this ->helper ->getRootFolder ($ type ));
38
+
39
+ return (object ) [
40
+ 'name ' => trans ('laravel-filemanager::lfm.title- ' . $ type ),
41
+ 'url ' => $ path ->path ('working_dir ' ),
42
+ 'children ' => $ path ->folders (),
43
+ 'has_next ' => ! ($ type == end ($ folder_types )),
44
+ ];
45
+ }, $ folder_types ),
46
+ ])
47
+ ->with ('items ' , $ items );
48
+ }
49
+
50
+ public function domove ()
51
+ {
52
+ $ target = $ this ->helper ->input ('goToFolder ' );
53
+ $ items = $ this ->helper ->input ('items ' );
54
+
55
+ foreach ($ items as $ item ) {
56
+ $ old_file = $ this ->lfm ->pretty ($ item );
57
+ $ is_directory = $ old_file ->isDirectory ();
58
+
59
+ if ($ old_file ->hasThumb ()) {
60
+ $ new_file = $ this ->lfm ->setName ($ item )->thumb ()->dir ($ target );
61
+ if ($ is_directory ) {
62
+ event (new FolderIsMoving ($ old_file ->path (), $ new_file ->path ()));
63
+ } else {
64
+ event (new FileIsMoving ($ old_file ->path (), $ new_file ->path ()));
65
+ }
66
+ $ this ->lfm ->setName ($ item )->thumb ()->move ($ new_file );
67
+ }
68
+ $ new_file = $ this ->lfm ->setName ($ item )->dir ($ target );
69
+ $ this ->lfm ->setName ($ item )->move ($ new_file );
70
+ if ($ is_directory ) {
71
+ event (new FolderWasMoving ($ old_file ->path (), $ new_file ->path ()));
72
+ } else {
73
+ event (new FileWasMoving ($ old_file ->path (), $ new_file ->path ()));
74
+ }
75
+ };
76
+
77
+ return parent ::$ success_response ;
78
+ }
22
79
}
0 commit comments