1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\app\Http\Controllers\Operations; |
4
|
|
|
|
5
|
|
|
trait Reorder |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Reorder the items in the database using the Nested Set pattern. |
9
|
|
|
* |
10
|
|
|
* Database columns needed: id, parent_id, lft, rgt, depth, name/title |
11
|
|
|
* |
12
|
|
|
* @return Response |
|
|
|
|
13
|
|
|
*/ |
14
|
|
|
public function reorder() |
15
|
|
|
{ |
16
|
|
|
$this->crud->hasAccessOrFail('reorder'); |
|
|
|
|
17
|
|
|
|
18
|
|
|
if (! $this->crud->isReorderEnabled()) { |
19
|
|
|
abort(403, 'Reorder is disabled.'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
// get all results for that entity |
23
|
|
|
$this->data['entries'] = $this->crud->getEntries(); |
|
|
|
|
24
|
|
|
$this->data['crud'] = $this->crud; |
25
|
|
|
$this->data['title'] = trans('backpack::crud.reorder').' '.$this->crud->entity_name; |
26
|
|
|
|
27
|
|
|
// load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
28
|
|
|
return view($this->crud->getReorderView(), $this->data); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Save the new order, using the Nested Set pattern. |
33
|
|
|
* |
34
|
|
|
* Database columns needed: id, parent_id, lft, rgt, depth, name/title |
35
|
|
|
* |
36
|
|
|
* @return |
37
|
|
|
*/ |
38
|
|
|
public function saveReorder() |
39
|
|
|
{ |
40
|
|
|
$this->crud->hasAccessOrFail('reorder'); |
41
|
|
|
|
42
|
|
|
$all_entries = \Request::input('tree'); |
43
|
|
|
|
44
|
|
|
if (count($all_entries)) { |
45
|
|
|
$count = $this->crud->updateTreeOrder($all_entries); |
46
|
|
|
} else { |
47
|
|
|
return false; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return 'success for '.$count.' items'; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.