|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace crocodicstudio\crudbooster\Modules\ModuleGenerator; |
|
4
|
|
|
|
|
5
|
|
|
use crocodicstudio\crudbooster\controllers\CBController; |
|
6
|
|
|
use crocodicstudio\crudbooster\controllers\FormValidator; |
|
7
|
|
|
use crocodicstudio\crudbooster\helpers\CRUDBooster; |
|
8
|
|
|
use crocodicstudio\crudbooster\Modules\PrivilegeModule\PrivilegeRepo; |
|
9
|
|
|
use Illuminate\Support\Facades\DB; |
|
10
|
|
|
|
|
11
|
|
|
class AdminModulesController extends CBController |
|
12
|
|
|
{ |
|
13
|
|
|
public function cbInit() |
|
14
|
|
|
{ |
|
15
|
|
|
$this->table = 'cms_modules'; |
|
16
|
|
|
$this->primaryKey = 'id'; |
|
17
|
|
|
$this->titleField = 'name'; |
|
18
|
|
|
$this->limit = 100; |
|
19
|
|
|
$this->buttonAdd = false; |
|
20
|
|
|
$this->buttonExport = false; |
|
21
|
|
|
$this->buttonImport = false; |
|
22
|
|
|
$this->buttonFilter = false; |
|
23
|
|
|
$this->buttonDetail = false; |
|
24
|
|
|
$this->buttonBulkAction = false; |
|
25
|
|
|
$this->buttonActionStyle = 'button_icon'; |
|
26
|
|
|
$this->orderby = ['is_protected' => 'asc', 'name' => 'asc']; |
|
27
|
|
|
|
|
28
|
|
|
$this->makeColumns(); |
|
29
|
|
|
|
|
30
|
|
|
$this->form = Form::makeForm($this->table); |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
$this->scriptJs = " |
|
33
|
|
|
$(function() { |
|
34
|
|
|
$('#table_name').change(function() { |
|
35
|
|
|
var v = $(this).val(); |
|
36
|
|
|
$('#path').val(v); |
|
37
|
|
|
}) |
|
38
|
|
|
}) "; |
|
39
|
|
|
|
|
40
|
|
|
$this->addAction[] = [ |
|
41
|
|
|
'label' => 'Module Wizard', |
|
42
|
|
|
'icon' => 'fa fa-wrench', |
|
43
|
|
|
'url' => CRUDBooster::mainpath('step1').'/[id]', |
|
44
|
|
|
"showIf" => "[is_protected] == 0", |
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
|
|
//$this->indexButton[] = ['label' => 'Generate New Module', 'icon' => 'fa fa-plus', 'url' => CRUDBooster::mainpath('step1'), 'color' => 'success']; |
|
48
|
|
|
} |
|
49
|
|
|
// public function getIndex() { |
|
50
|
|
|
// $data['page_title'] = 'Module Generator'; |
|
51
|
|
|
// $data['result'] = DB::table('cms_modules')->where('is_protected',0)->orderby('name','asc')->get(); |
|
52
|
|
|
// $this->cbView('CbModulesGen::index',$data); |
|
53
|
|
|
// } |
|
54
|
|
|
|
|
55
|
|
|
private function makeColumns() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->col = [ |
|
58
|
|
|
['label' => 'name', 'name' => 'name'], |
|
59
|
|
|
['label' => "Table", 'name' => "table_name"], |
|
60
|
|
|
['label' => "Path", 'name' => "path"], |
|
61
|
|
|
['label' => "Controller", 'name' => "controller"], |
|
62
|
|
|
['label' => "Protected", 'name' => "is_protected", "visible" => false], |
|
63
|
|
|
]; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
function hookBeforeDelete($ids) |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
|
|
foreach ($ids as $id) { |
|
69
|
|
|
$controller = ModulesRepo::getControllerName($id); |
|
70
|
|
|
DB::table('cms_menus')->where('path', 'like', '%'.$controller.'%')->delete(); |
|
71
|
|
|
@unlink(controller_path($controller)); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $ids; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getTableColumns($table) |
|
78
|
|
|
{ |
|
79
|
|
|
$columns = \Schema::getColumnListing($table); |
|
80
|
|
|
|
|
81
|
|
|
return response()->json($columns); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getCheckSlug($slug) |
|
85
|
|
|
{ |
|
86
|
|
|
$check = ModulesRepo::countByPath($slug); |
|
87
|
|
|
$lastId = DB::table('cms_modules')->max('id') + 1; |
|
88
|
|
|
|
|
89
|
|
|
return response()->json(['total' => $check, 'lastid' => $lastId]); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function getAdd() |
|
93
|
|
|
{ |
|
94
|
|
|
$this->cbLoader(); |
|
95
|
|
|
|
|
96
|
|
|
return redirect()->route("ModulesControllerGetStep1"); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function getStep1(Step1Handler $handler) |
|
100
|
|
|
{ |
|
101
|
|
|
$this->cbLoader(); |
|
102
|
|
|
|
|
103
|
|
|
return $handler->showForm(); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function getStep2($id, Step2Handler $handler) |
|
107
|
|
|
{ |
|
108
|
|
|
$this->cbLoader(); |
|
109
|
|
|
|
|
110
|
|
|
return $handler->showForm($id); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function postStep1(Step1Handler $handler) |
|
114
|
|
|
{ |
|
115
|
|
|
$this->cbLoader(); |
|
116
|
|
|
|
|
117
|
|
|
return $handler->handleFormSubmit(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function postStep2(Step2Handler $handler) |
|
121
|
|
|
{ |
|
122
|
|
|
$this->cbLoader(); |
|
123
|
|
|
|
|
124
|
|
|
return $handler->handleFormSubmit(); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function getStep3($id, Step3Handler $step3) |
|
128
|
|
|
{ |
|
129
|
|
|
$this->cbLoader(); |
|
130
|
|
|
|
|
131
|
|
|
return $step3->showForm($id); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function getTypeInfo($type = 'text') |
|
135
|
|
|
{ |
|
136
|
|
|
header("Content-Type: application/json"); |
|
137
|
|
|
echo file_get_contents(CbComponentsPath($type).'/info.json'); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function postStep3(Step3Handler $handler) |
|
141
|
|
|
{ |
|
142
|
|
|
$this->cbLoader(); |
|
143
|
|
|
|
|
144
|
|
|
return $handler->handleFormSubmit(); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function getStep4($id, Step4Handler $handler) |
|
148
|
|
|
{ |
|
149
|
|
|
$this->cbLoader(); |
|
150
|
|
|
|
|
151
|
|
|
return $handler->showForm($id); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
public function postStepFinish(Step4Handler $handler) |
|
155
|
|
|
{ |
|
156
|
|
|
$this->cbLoader(); |
|
157
|
|
|
|
|
158
|
|
|
return $handler->handleFormSubmit(); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
public function postAddSave() |
|
162
|
|
|
{ |
|
163
|
|
|
$this->cbLoader(); |
|
164
|
|
|
app(FormValidator::class)->validate(null, $this->form, $this); |
|
165
|
|
|
$this->inputAssignment(); |
|
166
|
|
|
|
|
167
|
|
|
//Generate Controller |
|
168
|
|
|
if ($this->arr['controller'] == '') { |
|
169
|
|
|
$this->arr['controller'] = ControllerGenerator::generateController(request('table_name'), basename(request('path'))); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
$this->arr['created_at'] = YmdHis(); |
|
173
|
|
|
$this->table()->insert($this->arr); |
|
174
|
|
|
|
|
175
|
|
|
//Insert Menu |
|
176
|
|
|
if ($this->arr['controller']) { |
|
177
|
|
|
(new CreateMenuForNewModule())->execute($this->arr['controller'], $this->arr['name'], $this->arr['icon']); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
$moduleId = $this->arr['id']; |
|
181
|
|
|
|
|
182
|
|
|
(new PrivilegeRepo())->grantAllPermissions($moduleId); |
|
183
|
|
|
|
|
184
|
|
|
//Refresh Session Roles |
|
185
|
|
|
CRUDBooster::refreshSessionRoles(); |
|
186
|
|
|
|
|
187
|
|
|
//$ref_parameter = Request::input('ref_parameter'); |
|
188
|
|
|
if (request('return_url')) { |
|
189
|
|
|
CRUDBooster::redirect(request('return_url'), cbTrans("alert_add_data_success"), 'success'); |
|
190
|
|
|
} |
|
191
|
|
|
if (request('submit') == cbTrans('button_save_more')) { |
|
192
|
|
|
CRUDBooster::redirect(CRUDBooster::mainpath('add'), cbTrans('alert_add_data_success'), 'success'); |
|
193
|
|
|
} |
|
194
|
|
|
CRUDBooster::redirect(CRUDBooster::mainpath(), cbTrans('alert_add_data_success'), 'success'); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
public function postEditSave($id) |
|
198
|
|
|
{ |
|
199
|
|
|
$this->cbLoader(); |
|
200
|
|
|
|
|
201
|
|
|
//$row = $this->table()->where($this->primaryKey, $id)->first(); |
|
202
|
|
|
|
|
203
|
|
|
app(FormValidator::class)->validate($id, $this->form, $this); |
|
204
|
|
|
|
|
205
|
|
|
$this->inputAssignment(); |
|
206
|
|
|
|
|
207
|
|
|
//Generate Controller |
|
208
|
|
|
$route_basename = basename(request('path')); |
|
209
|
|
|
if ($this->arr['controller'] == '') { |
|
210
|
|
|
$this->arr['controller'] = ControllerGenerator::generateController(request('table_name'), $route_basename); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
$this->findRow($id)->update($this->arr); |
|
214
|
|
|
|
|
215
|
|
|
//Refresh Session Roles |
|
216
|
|
|
CRUDBooster::refreshSessionRoles(); |
|
217
|
|
|
|
|
218
|
|
|
backWithMsg(cbTrans('alert_update_data_success')); |
|
219
|
|
|
} |
|
220
|
|
|
} |
|
221
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.