|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Webfactor\Laravel\Backpack\Documents\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
|
6
|
|
|
|
|
7
|
|
|
use Webfactor\Laravel\Backpack\Documents\Requests\DocumentRequest as StoreRequest; |
|
8
|
|
|
use Webfactor\Laravel\Backpack\Documents\Requests\DocumentRequest as UpdateRequest; |
|
9
|
|
|
|
|
10
|
|
|
class DocumentCrudController extends CrudController |
|
11
|
|
|
{ |
|
12
|
|
|
public function setup() |
|
13
|
|
|
{ |
|
14
|
|
|
/* |
|
15
|
|
|
|-------------------------------------------------------------------------- |
|
16
|
|
|
| BASIC CRUD INFORMATION |
|
17
|
|
|
|-------------------------------------------------------------------------- |
|
18
|
|
|
*/ |
|
19
|
|
|
$this->crud->setModel(config('webfactor.documents.model_class')); |
|
20
|
|
|
$this->crud->setRoute(config('webfactor.documents.backend.route_prefix').'/'.config('webfactor.documents.backend.route')); |
|
|
|
|
|
|
21
|
|
|
$this->crud->setEntityNameStrings(trans('webfactor::documents.entity_name_singular'), |
|
22
|
|
|
trans('webfactor::documents.entity_name_plural')); |
|
23
|
|
|
|
|
24
|
|
|
/* |
|
25
|
|
|
|-------------------------------------------------------------------------- |
|
26
|
|
|
| BASIC CRUD INFORMATION |
|
27
|
|
|
|-------------------------------------------------------------------------- |
|
28
|
|
|
*/ |
|
29
|
|
|
|
|
30
|
|
|
// ------ CRUD FIELDS |
|
31
|
|
|
|
|
32
|
|
|
$this->crud->addField([ |
|
33
|
|
|
'name' => 'type', |
|
34
|
|
|
'label' => 'Dokumentenart', |
|
35
|
|
|
'type' => 'select_from_array', |
|
36
|
|
|
'options' => $this->getTypeOptions(), |
|
37
|
|
|
'allows_null' => false, |
|
38
|
|
|
'allows_multiple' => false |
|
39
|
|
|
]); |
|
40
|
|
|
|
|
41
|
|
|
$this->crud->addField([ |
|
42
|
|
|
'name' => 'title', |
|
43
|
|
|
'label' => trans('webfactor::documents.title') |
|
44
|
|
|
]); |
|
45
|
|
|
|
|
46
|
|
|
$this->crud->addField([ |
|
47
|
|
|
'name' => 'body', |
|
48
|
|
|
'label' => trans('webfactor::documents.body'), |
|
49
|
|
|
'type' => $this->bodyFieldType() |
|
50
|
|
|
]); |
|
51
|
|
|
|
|
52
|
|
|
// ------ CRUD COLUMNS |
|
53
|
|
|
|
|
54
|
|
|
$this->crud->addColumns([ |
|
55
|
|
|
[ |
|
56
|
|
|
'name' => 'type', |
|
57
|
|
|
'label' => trans('webfactor::documents.type') |
|
58
|
|
|
], |
|
59
|
|
|
[ |
|
60
|
|
|
'name' => 'title', |
|
61
|
|
|
'label' => trans('webfactor::documents.title') |
|
62
|
|
|
], |
|
63
|
|
|
[ |
|
64
|
|
|
'name' => 'body', |
|
65
|
|
|
'label' => trans('webfactor::documents.body') |
|
66
|
|
|
] |
|
67
|
|
|
]); |
|
68
|
|
|
|
|
69
|
|
|
// ------ CRUD BUTTONS |
|
70
|
|
|
|
|
71
|
|
|
// ------ CRUD ACCESS |
|
72
|
|
|
|
|
73
|
|
|
// ------ CRUD REORDER |
|
74
|
|
|
|
|
75
|
|
|
// ------ CRUD DETAILS ROW |
|
76
|
|
|
|
|
77
|
|
|
// ------ REVISIONS |
|
78
|
|
|
|
|
79
|
|
|
// ------ AJAX TABLE VIEW |
|
80
|
|
|
|
|
81
|
|
|
// ------ DATATABLE EXPORT BUTTONS |
|
82
|
|
|
|
|
83
|
|
|
// ------ ADVANCED QUERIES |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function getTypeOptions() |
|
87
|
|
|
{ |
|
88
|
|
|
$types = collect(config('webfactor.documents.types')); |
|
89
|
|
|
|
|
90
|
|
|
return $types->mapWithKeys(function ($type) { |
|
91
|
|
|
return [$type => trans('webfactor::documents.types.'.$type)]; |
|
92
|
|
|
}); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function bodyFieldType() |
|
96
|
|
|
{ |
|
97
|
|
|
$types = [ |
|
98
|
|
|
'plaintext' => 'textarea', |
|
99
|
|
|
'html' => 'summernote', |
|
100
|
|
|
'md' => 'simplemde' |
|
101
|
|
|
]; |
|
102
|
|
|
|
|
103
|
|
|
return $types[config('webfactor.documents.body_type', 'plaintext')]; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function store(StoreRequest $request) |
|
107
|
|
|
{ |
|
108
|
|
|
// your additional operations before save here |
|
109
|
|
|
$redirect_location = parent::storeCrud($request); |
|
|
|
|
|
|
110
|
|
|
// your additional operations after save here |
|
111
|
|
|
// use $this->data['entry'] or $this->crud->entry |
|
|
|
|
|
|
112
|
|
|
return $redirect_location; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function update(UpdateRequest $request) |
|
116
|
|
|
{ |
|
117
|
|
|
// your additional operations before save here |
|
118
|
|
|
$redirect_location = parent::updateCrud($request); |
|
|
|
|
|
|
119
|
|
|
// your additional operations after save here |
|
120
|
|
|
// use $this->data['entry'] or $this->crud->entry |
|
|
|
|
|
|
121
|
|
|
return $redirect_location; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.