1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace UniSharp\LaravelFilemanager\Controllers; |
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
|
|
|
|
10
|
|
|
class ItemsController extends LfmController |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Get the images to load for a selected folder. |
14
|
|
|
* |
15
|
|
|
* @return mixed |
16
|
|
|
*/ |
17
|
|
|
public function getItems() |
18
|
|
|
{ |
19
|
|
|
$currentPage = self::getCurrentPageFromRequest(); |
20
|
|
|
|
21
|
|
|
$perPage = $this->helper->getPaginationPerPage(); |
|
|
|
|
22
|
|
|
$items = array_merge($this->lfm->folders(), $this->lfm->files()); |
|
|
|
|
23
|
|
|
|
24
|
|
|
return [ |
25
|
|
|
'items' => array_map(function ($item) { |
26
|
|
|
return $item->fill()->attributes; |
27
|
|
|
}, array_slice($items, ($currentPage - 1) * $perPage, $perPage)), |
28
|
|
|
'paginator' => [ |
29
|
|
|
'current_page' => $currentPage, |
30
|
|
|
'total' => count($items), |
31
|
|
|
'per_page' => $perPage, |
32
|
|
|
], |
33
|
|
|
'display' => $this->helper->getDisplayMode(), |
34
|
|
|
'working_dir' => $this->lfm->path('working_dir'), |
35
|
|
|
]; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function move() |
39
|
|
|
{ |
40
|
|
|
$items = request('items'); |
|
|
|
|
41
|
|
|
$folder_types = array_filter(['user', 'share'], function ($type) { |
42
|
|
|
return $this->helper->allowFolderType($type); |
|
|
|
|
43
|
|
|
}); |
44
|
|
|
return view('laravel-filemanager::move') |
|
|
|
|
45
|
|
|
->with([ |
46
|
|
|
'root_folders' => array_map(function ($type) use ($folder_types) { |
47
|
|
|
$path = $this->lfm->dir($this->helper->getRootFolder($type)); |
|
|
|
|
48
|
|
|
|
49
|
|
|
return (object) [ |
50
|
|
|
'name' => trans('laravel-filemanager::lfm.title-' . $type), |
|
|
|
|
51
|
|
|
'url' => $path->path('working_dir'), |
52
|
|
|
'children' => $path->folders(), |
53
|
|
|
'has_next' => ! ($type == end($folder_types)), |
54
|
|
|
]; |
55
|
|
|
}, $folder_types), |
56
|
|
|
]) |
57
|
|
|
->with('items', $items); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function domove() |
61
|
|
|
{ |
62
|
|
|
$target = $this->helper->input('goToFolder'); |
|
|
|
|
63
|
|
|
$items = $this->helper->input('items'); |
64
|
|
|
|
65
|
|
|
foreach ($items as $item) { |
66
|
|
|
$old_file = $this->lfm->pretty($item); |
|
|
|
|
67
|
|
|
$is_directory = $old_file->isDirectory(); |
68
|
|
|
|
69
|
|
|
if ($old_file->hasThumb()) { |
70
|
|
|
$new_file = $this->lfm->setName($item)->thumb()->dir($target); |
71
|
|
|
if ($is_directory) { |
72
|
|
|
event(new FolderIsMoving($old_file->path(), $new_file->path())); |
|
|
|
|
73
|
|
|
} else { |
74
|
|
|
event(new FileIsMoving($old_file->path(), $new_file->path())); |
75
|
|
|
} |
76
|
|
|
$this->lfm->setName($item)->thumb()->move($new_file); |
77
|
|
|
} |
78
|
|
|
$new_file = $this->lfm->setName($item)->dir($target); |
79
|
|
|
$this->lfm->setName($item)->move($new_file); |
80
|
|
|
if ($is_directory) { |
81
|
|
|
event(new FolderWasMoving($old_file->path(), $new_file->path())); |
82
|
|
|
} else { |
83
|
|
|
event(new FileWasMoving($old_file->path(), $new_file->path())); |
84
|
|
|
} |
85
|
|
|
}; |
86
|
|
|
|
87
|
|
|
return parent::$success_response; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
private static function getCurrentPageFromRequest() |
91
|
|
|
{ |
92
|
|
|
$currentPage = (int) request()->get('page', 1); |
|
|
|
|
93
|
|
|
$currentPage = $currentPage < 1 ? 1 : $currentPage; |
94
|
|
|
|
95
|
|
|
return $currentPage; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.