104 lines
2.7 KiB
PHP
Executable file
104 lines
2.7 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers\CMS;
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\SidebarWidget;
|
|
use Request;
|
|
|
|
|
|
class CMSSidebarController extends Controller
|
|
{
|
|
|
|
/*
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->middleware(['admin', '2fa']);
|
|
}
|
|
|
|
/**
|
|
* Show the application dashboard.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$data = [
|
|
'widgets' => SidebarWidget::all()->sortBy('pos'),//Feedback::where('lvl', 1)->get(),
|
|
];
|
|
return view('cms.sidebar.index', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function detail($id)
|
|
{
|
|
if($id == "new") {
|
|
$widget = new SidebarWidget();
|
|
$id = 'new';
|
|
$widget->active = 1;
|
|
|
|
}else{
|
|
$widget = SidebarWidget::findOrFail($id);
|
|
$id = $widget->id;
|
|
}
|
|
$data = [
|
|
'widget' => $widget,
|
|
'id' => $id,
|
|
];
|
|
return view('cms.sidebar.detail', $data);
|
|
}
|
|
|
|
|
|
public function store($id)
|
|
{
|
|
$data = Request::all();
|
|
if($id == "new") {
|
|
$widget = new SidebarWidget();
|
|
}else{
|
|
$widget = SidebarWidget::findOrFail($id);
|
|
}
|
|
|
|
$data['active'] = isset($data['active']) ? true : false;
|
|
$data['show_at'] = isset($data['show_at']) ? $data['show_at'] : null;
|
|
|
|
$component = isset($data['component']) ? $data['component'] : null;
|
|
|
|
if (in_array($component, [SidebarWidget::HOMEPAGE_PLANNABLE_TRIPS, SidebarWidget::HOMEPAGE_POPULAR_TRIPS])) {
|
|
$pageIds = isset($data['homepage_page_ids']) ? array_values(array_filter($data['homepage_page_ids'])) : [];
|
|
$newPageIds = isset($data['homepage_new_page_ids']) ? array_values(array_filter($data['homepage_new_page_ids'])) : [];
|
|
|
|
$data['html'] = json_encode([
|
|
'page_ids' => $pageIds,
|
|
'new_page_ids' => array_values(array_intersect($pageIds, $newPageIds)),
|
|
'new_badge_active' => false,
|
|
]);
|
|
} elseif ($component === SidebarWidget::NEWS_SIDEBAR_WIDGET && isset($data['homepage_news_limit'])) {
|
|
$data['html'] = json_encode([
|
|
'news_limit' => max(1, min(12, (int) $data['homepage_news_limit'])),
|
|
]);
|
|
}
|
|
|
|
$widget->fill($data)->save();
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('cms_sidebar_detail', [$widget->id]));
|
|
|
|
}
|
|
|
|
public function delete($id){
|
|
$widget = SidebarWidget::findOrFail($id);
|
|
$widget->delete();
|
|
\Session()->flash('alert-success', __('Sidebar Widget gelöscht'));
|
|
return redirect(route('cms_sidebar'));
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|