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