|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace crocodicstudio\crudbooster\Modules\MenuModule; |
|
4
|
|
|
|
|
5
|
|
|
use crocodicstudio\crudbooster\controllers\CBController; |
|
6
|
|
|
use Illuminate\Support\Facades\Request; |
|
7
|
|
|
use Illuminate\Support\Facades\DB; |
|
8
|
|
|
use Illuminate\Support\Facades\Cache; |
|
9
|
|
|
use Illuminate\Support\Facades\PDF; |
|
|
|
|
|
|
10
|
|
|
use Illuminate\Support\Facades\Excel; |
|
|
|
|
|
|
11
|
|
|
use CRUDBooster; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class AdminMenusController extends CBController |
|
14
|
|
|
{ |
|
15
|
|
|
public function cbInit() |
|
16
|
|
|
{ |
|
17
|
|
|
$this->table = "cms_menus"; |
|
18
|
|
|
$this->primaryKey = "id"; |
|
19
|
|
|
$this->title_field = "name"; |
|
20
|
|
|
$this->limit = 20; |
|
21
|
|
|
$this->orderby = ["id" => "desc"]; |
|
22
|
|
|
|
|
23
|
|
|
$this->setButtons(); |
|
24
|
|
|
|
|
25
|
|
|
$id = CRUDBooster::getCurrentId(); |
|
26
|
|
|
$row = CRUDBooster::first($this->table, $id); |
|
27
|
|
|
$row = (Request::segment(3) == 'edit') ? $row : null; |
|
28
|
|
|
|
|
29
|
|
|
$this->script_js = view('CbMenu::js', ['id' => $id, 'type' => $row->type])->render(); |
|
30
|
|
|
|
|
31
|
|
|
$this->setCols(); |
|
32
|
|
|
|
|
33
|
|
|
list($statisticId, $moduleId) = $this->getMenuId($row); |
|
34
|
|
|
$this->form = MenusForm::makeForm($statisticId, $moduleId, $row); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getIndex() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->cbLoader(); |
|
40
|
|
|
|
|
41
|
|
|
$return_url = Request::fullUrl(); |
|
42
|
|
|
|
|
43
|
|
|
$page_title = 'Menu Management'; |
|
44
|
|
|
|
|
45
|
|
|
return view('CbMenu::menus_management', compact('return_url', 'page_title')); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function hookBeforeAdd(&$postData) |
|
49
|
|
|
{ |
|
50
|
|
|
$postData['parent_id'] = 0; |
|
51
|
|
|
|
|
52
|
|
|
$postData['path'] = $this->getMenuPath($postData); |
|
53
|
|
|
|
|
54
|
|
|
unset($postData['module_slug']); |
|
55
|
|
|
unset($postData['statistic_slug']); |
|
56
|
|
|
|
|
57
|
|
|
if ($postData['is_dashboard'] == 1) { |
|
58
|
|
|
//If set dashboard, so unset for first all dashboard |
|
59
|
|
|
$this->table()->where('is_dashboard', 1)->update(['is_dashboard' => 0]); |
|
60
|
|
|
Cache::forget('sidebarDashboard'.CRUDBooster::myPrivilegeId()); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function hookBeforeEdit(&$postData, $id) |
|
65
|
|
|
{ |
|
66
|
|
|
if ($postData['is_dashboard'] == 1) { |
|
67
|
|
|
//If set dashboard, so unset for first all dashboard |
|
68
|
|
|
$this->table()->where('is_dashboard', 1)->update(['is_dashboard' => 0]); |
|
69
|
|
|
Cache::forget('sidebarDashboard'.CRUDBooster::myPrivilegeId()); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$postData['path'] = $this->getMenuPath($postData); |
|
73
|
|
|
|
|
74
|
|
|
unset($postData['module_slug']); |
|
75
|
|
|
unset($postData['statistic_slug']); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function hookAfterDelete($id) |
|
79
|
|
|
{ |
|
80
|
|
|
$this->table()->where('parent_id', $id)->delete(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function postSaveMenu() |
|
84
|
|
|
{ |
|
85
|
|
|
$this->cbInit(); |
|
86
|
|
|
$isActive = request('isActive'); |
|
87
|
|
|
$post = json_decode(request('menus'), true); |
|
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
foreach ($post[0] as $i => $menu) { |
|
90
|
|
|
$pid = $menu['id']; |
|
91
|
|
|
$children = $menu['children'][0] ?: []; |
|
92
|
|
|
|
|
93
|
|
|
foreach ($children as $index => $child) { |
|
94
|
|
|
$this->findRow($child['id'])->update(['sorting' => $index + 1, 'parent_id' => $pid, 'is_active' => $isActive]); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$this->findRow($pid)->update(['sorting' => $i + 1, 'parent_id' => 0, 'is_active' => $isActive]); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return response()->json(['success' => true]); |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param $postdata |
|
105
|
|
|
* @return string |
|
106
|
|
|
*/ |
|
107
|
|
|
private function getMenuPath($postdata) |
|
108
|
|
|
{ |
|
109
|
|
|
if ($postdata['type'] == 'Statistic') { |
|
110
|
|
|
$stat = CRUDBooster::first('cms_statistics', ['id' => $postdata['statistic_slug']])->slug; |
|
111
|
|
|
return 'statistic-builder/show/'.$stat; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
if ($postdata['type'] == 'Module') { |
|
115
|
|
|
return CRUDBooster::first('cms_moduls', ['id' => $postdata['module_slug']])->path; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
private function setButtons() |
|
120
|
|
|
{ |
|
121
|
|
|
$this->buttonTableAction = true; |
|
122
|
|
|
$this->button_action_style = "FALSE"; |
|
123
|
|
|
$this->button_add = false; |
|
|
|
|
|
|
124
|
|
|
$this->deleteBtn = true; |
|
125
|
|
|
$this->button_edit = true; |
|
126
|
|
|
$this->buttonDetail = true; |
|
127
|
|
|
$this->button_show = false; |
|
|
|
|
|
|
128
|
|
|
$this->button_filter = true; |
|
|
|
|
|
|
129
|
|
|
$this->buttonExport = false; |
|
130
|
|
|
$this->button_import = false; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @param $row |
|
135
|
|
|
* @return array |
|
136
|
|
|
*/ |
|
137
|
|
|
private function getMenuId($row) |
|
138
|
|
|
{ |
|
139
|
|
|
$idModule = $idStatistic = 0; |
|
140
|
|
|
|
|
141
|
|
|
if ($row->type == 'Module') { |
|
142
|
|
|
$idModule = DB::table('cms_moduls')->where('path', $row->path)->first()->id; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
if ($row->type == 'Statistic') { |
|
146
|
|
|
$row->path = str_replace('statistic-builder/show/', '', $row->path); |
|
147
|
|
|
$idStatistic = DB::table('cms_statistics')->where('slug', $row->path)->first()->id; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
return [$idStatistic, $idModule]; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
private function setCols() |
|
154
|
|
|
{ |
|
155
|
|
|
$this->col = []; |
|
156
|
|
|
$this->col[] = ["label" => "Name", "name" => "name"]; |
|
157
|
|
|
$this->col[] = ["label" => "Is Active", "name" => "is_active"]; |
|
158
|
|
|
} |
|
159
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths