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