sidebar in cms

This commit is contained in:
Kevin Adametz 2019-02-14 13:49:53 +01:00
parent ed80b25b85
commit 30d5ca3b44
10 changed files with 969 additions and 378 deletions

View file

@ -1,9 +1,9 @@
<?php
namespace App\Http\Controllers;
namespace App\Http\Controllers\CMS;
use App\Http\Controllers\Controller;
use App\Models\Feedback;
use Carbon\Carbon;
use Input;

View file

@ -0,0 +1,88 @@
<?php
namespace App\Http\Controllers\CMS;
use App\Http\Controllers\Controller;
use App\Models\SidebarWidget;
use Input;
class CMSSidebarController extends Controller
{
/*
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
}
/**
* 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 = Input::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;
$widget->fill($data)->save();
$widget->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'));
}
}

View file

@ -0,0 +1,100 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class SidebarWidget extends Model
{
protected static $shows = [
'home' => 'Startseite',
'search' => 'Suche',
'default' => 'Standartseiten',
'overview' => 'Übersicht',
'program' => 'Programme',
'booking' => 'Buchungen',
'bookingconfirm' => 'Buchungsbestätigung',
];
protected static $components = [
'aboutSternToursWidget' => 'Wir: STERN TOURS',
'searchSidebarWidget' => 'Kulturreisen suchen',
'navSidebarWidget' => 'Reiseprogramme',
'topVotingWidget' => 'TOP bewertet',
'feedbacksSidebarWidget' => 'Kundenfeedback',
'travelGuideSidebarWidget' => 'Reiseführer',
'travelMagazineSidebarWidget' => 'Reisemagazin',
'offersSidebarWidget' => 'Angebote',
];
protected $connection = 'mysql_stern';
protected $table = 'sidebar_widgets';
protected $casts = ['show_at' => 'array'];
protected $fillable = [
'name', 'component', 'html', 'show_at', 'pos', 'active'
];
public static function getComponentsOptions($setKey = false){
$options = self::$components;
$ret = '<option value="">Keine Komponente laden (nur HTML)</option>\n';
foreach ($options as $key => $option){
$attr = ($key == $setKey) ? 'selected="selected"' : '';
$ret .= '<option value="'.$key.'" '.$attr.'>'.$option.'</option>\n';
}
return $ret;
}
public static function getShowsOptions($setKey){
if(!is_array($setKey))
$setKey = [];
$options = self::$shows;
$ret = "";
foreach ($options as $key => $option){
$attr = in_array($key, $setKey) ? 'selected="selected"' : '';
$ret .= '<option value="'.$key.'" '.$attr.'>'.$option.'</option>\n';
}
return $ret;
}
public function getShowsAtString(){
$ret = "";
if($this->show_at){
foreach($this->show_at as $show_at){
if(isset(self::$shows[$show_at])){
$ret .= self::$shows[$show_at].", ";
}
}
}
return rtrim($ret, ", ");
}
/*
* public function getVotesDetailAttribute($details)
{
return json_decode($details, true);
}
then when you will call $store->votes_detail you will get the expected result.
After that you can use mutators to convert an array back to JSON when it is saved back in the DB. Define the method setVotesDetailAttribute($value) as follows:
public function setVotesDetailsAttribute($value)
{
$this->attributes['votes_detail'] = json_encode($value);
}
*/
}