|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Backend; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\Theme; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use App\Http\Controllers\Controller; |
|
8
|
|
|
use Lloople\Notificator\Notificator; |
|
9
|
|
|
use App\Http\Resources\ThemeResource; |
|
10
|
|
|
use App\Http\Requests\ThemeFormRequest; |
|
11
|
|
|
use App\ViewModels\ThemeDetailViewModel; |
|
12
|
|
|
|
|
13
|
|
|
class ThemesController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
private $pagination = 50; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Display a listing of the resource. |
|
19
|
|
|
* |
|
20
|
|
|
* @param \Illuminate\Http\Request $request |
|
21
|
|
|
* |
|
22
|
|
|
* @return \Illuminate\Http\Response |
|
23
|
|
|
*/ |
|
24
|
|
|
public function index(Request $request) |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
return view('backend.themes.index'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Show the form for creating a new resource. |
|
31
|
|
|
* |
|
32
|
|
|
* @return \Illuminate\Http\Response |
|
33
|
|
|
*/ |
|
34
|
|
|
public function create() |
|
35
|
|
|
{ |
|
36
|
|
|
return view('backend.themes.edit', ['view' => new ThemeDetailViewModel(new Theme())]); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Store a newly created resource in storage. |
|
41
|
|
|
* |
|
42
|
|
|
* @param ThemeFormRequest $request |
|
43
|
|
|
* |
|
44
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
45
|
|
|
*/ |
|
46
|
|
View Code Duplication |
public function store(ThemeFormRequest $request) |
|
|
|
|
|
|
47
|
|
|
{ |
|
48
|
|
|
$theme = new Theme(); |
|
49
|
|
|
|
|
50
|
|
|
$theme->name = $request->name; |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
$theme->selected = $request->has('selected'); |
|
53
|
|
|
|
|
54
|
|
|
$theme->updateColors($request->all()); |
|
55
|
|
|
|
|
56
|
|
|
$theme->save(); |
|
57
|
|
|
|
|
58
|
|
|
if ($theme->selected) { |
|
59
|
|
|
$theme->disableOtherThemes(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
Notificator::success('Theme created successfully'); |
|
63
|
|
|
|
|
64
|
|
|
return redirect()->route('backend.themes.edit', $theme); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Show the form for editing the specified resource. |
|
69
|
|
|
* |
|
70
|
|
|
* @param \App\Models\Theme $theme |
|
71
|
|
|
* |
|
72
|
|
|
* @return void |
|
73
|
|
|
*/ |
|
74
|
|
|
public function edit(Theme $theme) |
|
75
|
|
|
{ |
|
76
|
|
|
return view('backend.themes.edit', ['view' => new ThemeDetailViewModel($theme)]); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Update the specified resource in storage. |
|
81
|
|
|
* |
|
82
|
|
|
* @param \App\Http\Requests\ThemeFormRequest $request |
|
83
|
|
|
* @param \App\Models\Theme $theme |
|
84
|
|
|
* |
|
85
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
86
|
|
|
*/ |
|
87
|
|
View Code Duplication |
public function update(ThemeFormRequest $request, Theme $theme) |
|
|
|
|
|
|
88
|
|
|
{ |
|
89
|
|
|
$theme->name = $request->name; |
|
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
$theme->selected = $request->has('selected'); |
|
92
|
|
|
|
|
93
|
|
|
$theme->updatecolors($request->all()); |
|
94
|
|
|
|
|
95
|
|
|
$theme->save(); |
|
96
|
|
|
|
|
97
|
|
|
if ($theme->selected) { |
|
98
|
|
|
$theme->disableOtherThemes(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
Notificator::success('Theme edited successfully'); |
|
102
|
|
|
|
|
103
|
|
|
return redirect()->route('backend.themes.edit', $theme); |
|
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Remove the specified resource from storage. |
|
108
|
|
|
* |
|
109
|
|
|
* @param \Illuminate\Http\Request $request |
|
110
|
|
|
* @param \App\Models\Theme $theme |
|
111
|
|
|
* |
|
112
|
|
|
* @return array |
|
113
|
|
|
* @throws \Exception |
|
114
|
|
|
*/ |
|
115
|
|
|
public function destroy(Request $request, Theme $theme) |
|
116
|
|
|
{ |
|
117
|
|
|
if ($theme->selected) { |
|
118
|
|
|
if ($request->ajax()) { |
|
119
|
|
|
return [ |
|
120
|
|
|
'result' => false, |
|
121
|
|
|
'message' => 'Default theme cannot be deleted.', |
|
122
|
|
|
]; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
Notificator::error('Default theme cannot be deleted.'); |
|
126
|
|
|
|
|
127
|
|
|
return back(); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
$theme->delete(); |
|
131
|
|
|
|
|
132
|
|
|
if ($request->ajax()) { |
|
133
|
|
|
return [ |
|
134
|
|
|
'result' => true, |
|
135
|
|
|
'message' => 'Theme deleted successfully.', |
|
136
|
|
|
]; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
Notificator::success('Theme deleted successfully.'); |
|
140
|
|
|
|
|
141
|
|
|
return redirect()->route('backend.themes.index'); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
View Code Duplication |
public function resource(Request $request) |
|
|
|
|
|
|
145
|
|
|
{ |
|
146
|
|
|
$themes = Theme::select('*'); |
|
147
|
|
|
|
|
148
|
|
|
if ($request->has('q')) { |
|
149
|
|
|
$themes->where('name', 'like', "%{$request->q}%"); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
return ThemeResource::collection($themes->orderBy('selected', 'DESC')->orderBy('name')->paginate($this->pagination)); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.