284 lines
11 KiB
PHP
284 lines
11 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\CMS;
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\CMSContent;
|
|
use App\Services\Util;
|
|
use Request;
|
|
|
|
|
|
class CMSBookingController extends Controller
|
|
{
|
|
|
|
protected $identifier_general_name;
|
|
protected $identifier_content_name;
|
|
|
|
protected $identifier_content;
|
|
protected $identifier_general;
|
|
|
|
|
|
public function __construct()
|
|
{
|
|
$this->middleware(['admin', '2fa']);
|
|
|
|
$this->identifier_general_name = config('booking.identifier_general_name');
|
|
$this->identifier_content_name = config('booking.identifier_content_name');
|
|
$this->identifier_general = config('booking.identifier_general');
|
|
$this->identifier_content = config('booking.identifier_content');
|
|
}
|
|
/*
|
|
* ALL
|
|
*/
|
|
public function all()
|
|
{
|
|
$data = [
|
|
'values' => CMSContent::where('identifier', '=', $this->identifier_general_name)->get()->sortBy('pos'),
|
|
];
|
|
return view('cms.booking.all.index', $data);
|
|
}
|
|
|
|
public function detailAll($id)
|
|
{
|
|
$general_name = CMSContent::findOrFail($id);
|
|
$identifier_general = $this->identifier_general.$general_name->id;
|
|
$data = [
|
|
'contents' => CMSContent::where('identifier', '=', $identifier_general)->get()->sortBy('pos'),
|
|
'general_name' => $general_name,
|
|
'identifier_general' => $identifier_general,
|
|
];
|
|
return view('cms.booking.all.detail', $data);
|
|
}
|
|
|
|
public function storeAll($id = null)
|
|
{
|
|
$data = Request::all();
|
|
|
|
if($data['action'] === 'newOrSaveName'){
|
|
if($data['id'] === 'new'){
|
|
$create = [
|
|
'name' => $data['name'],
|
|
'field' => 'text',
|
|
'decimal' => 1,
|
|
'identifier' => $this->identifier_general_name,
|
|
'pos' => CMSContent::where('identifier', '=', $this->identifier_general_name)->count() + 1,
|
|
];
|
|
$content = CMSContent::create($create);
|
|
//store in cms old Datebase
|
|
\App\Models\Sym\CmsContent::create($create);
|
|
return redirect(route('cms_booking_all_detail', [$content->id]));
|
|
}else{
|
|
$content = CMSContent::findOrFail($data['id']);
|
|
$content->name = $data['name'];
|
|
$content->slug = null;
|
|
$content->save();
|
|
return redirect(route('cms_booking_all'));
|
|
}
|
|
}
|
|
|
|
if($data['action'] === 'addItem'){
|
|
$general_name = CMSContent::findOrFail($id);
|
|
$identifier_general = $this->identifier_general.$general_name->id;
|
|
$create = [
|
|
'name' => '#empty#',
|
|
'field' => 'full_text',
|
|
'decimal' => 1,
|
|
'identifier' => $identifier_general,
|
|
'pos' => CMSContent::where('identifier', '=', $identifier_general)->count() + 1,
|
|
];
|
|
CMSContent::create($create);
|
|
//store in cms old Datebase
|
|
\App\Models\Sym\CmsContent::create($create);
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('cms_booking_all_detail', [$id]));
|
|
|
|
}
|
|
if($data['action'] === 'saveAll'){
|
|
$i = 1;
|
|
if(isset($data['contents'] )) {
|
|
foreach ($data['contents'] as $content_id => $item) {
|
|
$content = CMSContent::findOrFail($content_id);
|
|
$content->setObjectBy('page-break', (isset($item['page-break']) ? true : false));
|
|
$content->setObjectBy('repeat-country', (isset($item['repeat-country']) ? true : false));
|
|
$content->setObjectBy('repeat-airline', (isset($item['repeat-airline']) ? true : false));
|
|
$content->name = $item['name'];
|
|
$content->slug = null;
|
|
$content->decimal = isset($item['in_pdf']) ? 1 : 0;
|
|
$content->full_text = $item['full_text'];
|
|
$content->pos = $i++;
|
|
$content->save();
|
|
}
|
|
}
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('cms_booking_all_detail', [$id]));
|
|
}
|
|
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('cms_booking_all'));
|
|
}
|
|
|
|
public function deleteAll($id, $do){
|
|
if($do === 'name'){
|
|
$general_name = CMSContent::findOrFail($id);
|
|
$find = CMSContent::findObjectsBy('general_id', $general_name->id);
|
|
if(count($find)){
|
|
\Session()->flash('alert-error', __('Vorlage kann nicht gelöscht werden, ist bei den Inhalten noch in Verwendung.'));
|
|
return back();
|
|
}
|
|
$identifier_general = $this->identifier_general.$general_name->id;
|
|
//check is use
|
|
$contents = CMSContent::where('identifier', '=', $identifier_general)->get();
|
|
foreach($contents as $con){
|
|
$con->delete();
|
|
}
|
|
$contents = \App\Models\Sym\CmsContent::where('identifier', '=', $identifier_general)->get();
|
|
foreach($contents as $con){
|
|
$con->delete();
|
|
}
|
|
\Session()->flash('alert-success', __('Vorlage gelöscht'));
|
|
}
|
|
|
|
if($do === 'item'){
|
|
\Session()->flash('alert-success', __('Abschnitt gelöscht'));
|
|
}
|
|
$content = CMSContent::findOrFail($id);
|
|
$content->delete();
|
|
$m = \App\Models\Sym\CmsContent::find($id);
|
|
$m->delete();
|
|
return back();
|
|
}
|
|
/*
|
|
* CONTENT
|
|
*/
|
|
public function content()
|
|
{
|
|
$data = [
|
|
'values' => CMSContent::where('identifier', '=', $this->identifier_content_name)->get()->sortBy('pos'),
|
|
'identifier_general_name' => $this->identifier_general_name,
|
|
];
|
|
return view('cms.booking.content.index', $data);
|
|
}
|
|
|
|
public function detailContent($id)
|
|
{
|
|
$content_name = CMSContent::findOrFail($id);
|
|
$identifier_content = $this->identifier_content.$content_name->id;
|
|
$gerneral_id = $content_name->getObjectBy('general_id');
|
|
$identifier_general = $this->identifier_general.$gerneral_id;
|
|
|
|
$data = [
|
|
'contents' => CMSContent::where('identifier', '=', $identifier_general)->get()->sortBy('pos'),
|
|
'content_name' => $content_name,
|
|
'identifier_content' => $identifier_content,
|
|
'identifier_general' => $identifier_general,
|
|
];
|
|
return view('cms.booking.content.detail', $data);
|
|
}
|
|
|
|
public function storeContent($id = null)
|
|
{
|
|
$data = Request::all();
|
|
|
|
if($data['action'] === 'newOrSaveName'){
|
|
if($data['id'] === 'new'){
|
|
$create = [
|
|
'name' => $data['name'],
|
|
'field' => 'text',
|
|
'decimal' => 1,
|
|
'identifier' => $this->identifier_content_name,
|
|
'pos' => CMSContent::where('identifier', '=', $this->identifier_content_name)->count() + 1,
|
|
];
|
|
$content = CMSContent::create($create);
|
|
$content->setObjectBy('general_id', (isset($data['general_id']) ? $data['general_id'] : 0));
|
|
$content->save();
|
|
//store in cms old Datebase
|
|
\App\Models\Sym\CmsContent::create($create);
|
|
return redirect(route('cms_booking_content_detail', [$content->id]));
|
|
}else{
|
|
$content = CMSContent::findOrFail($data['id']);
|
|
$content->setObjectBy('general_id', (isset($data['general_id']) ? $data['general_id'] : 0));
|
|
$content->name = $data['name'];
|
|
$content->slug = null;
|
|
$content->save();
|
|
return redirect(route('cms_booking_content'));
|
|
}
|
|
}
|
|
|
|
$content_name = CMSContent::findOrFail($id);
|
|
$identifier_content = $this->identifier_content.$content_name->id;
|
|
$gerneral_id = $content_name->getObjectBy('general_id');
|
|
$identifier_general = $this->identifier_general.$gerneral_id;
|
|
|
|
if($data['action'] === 'addItem' && isset($data['content_pos_id'])) {
|
|
$create = [
|
|
'name' => '#empty#',
|
|
'field' => 'full_text',
|
|
'decimal' => 1,
|
|
'integer' => $data['content_pos_id'],
|
|
'identifier' => $identifier_content,
|
|
'pos' => 0,
|
|
];
|
|
CMSContent::create($create);
|
|
//store in cms old Datebase
|
|
\App\Models\Sym\CmsContent::create($create);
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('cms_booking_content_detail', [$id]));
|
|
}
|
|
|
|
if($data['action'] === 'saveAll'){
|
|
$i = 1;
|
|
$last_content_id = null;
|
|
if(isset($data['contents'] )) {
|
|
foreach ($data['contents'] as $content_id => $item) {
|
|
$content = CMSContent::findOrFail($content_id);
|
|
if ($item['identifier'] === $identifier_general) {
|
|
$last_content_id = $content->id;
|
|
}
|
|
if ($item['identifier'] === $identifier_content) {
|
|
$content->setObjectBy('page-break', (isset($item['page-break']) ? true : false));
|
|
$content->setObjectBy('repeat-country', (isset($item['repeat-country']) ? true : false));
|
|
$content->setObjectBy('repeat-airline', (isset($item['repeat-airline']) ? true : false));
|
|
$content->name = $item['name'];
|
|
$content->slug = null;
|
|
$content->decimal = isset($item['in_pdf']) ? 1 : 0;
|
|
$content->full_text = $item['full_text'];
|
|
$content->integer = $last_content_id != null ? $last_content_id : $content->integer; //is the main obj
|
|
$content->pos = $i++;
|
|
$content->save();
|
|
}
|
|
}
|
|
}
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('cms_booking_content_detail', [$id]));
|
|
}
|
|
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('cms_booking_content'));
|
|
}
|
|
|
|
public function deleteContent($id, $do){
|
|
if($do === 'name'){
|
|
$content_name = CMSContent::findOrFail($id);
|
|
$identifier_content = $this->identifier_content.$content_name->id;
|
|
$contents = CMSContent::where('identifier', '=', $identifier_content)->get();
|
|
foreach($contents as $con){
|
|
$con->delete();
|
|
}
|
|
$contents = \App\Models\Sym\CmsContent::where('identifier', '=', $identifier_content)->get();
|
|
foreach($contents as $con){
|
|
$con->delete();
|
|
}
|
|
\Session()->flash('alert-success', __('Vorlage gelöscht'));
|
|
}
|
|
|
|
if($do === 'item'){
|
|
\Session()->flash('alert-success', __('Abschnitt gelöscht'));
|
|
}
|
|
$content = CMSContent::findOrFail($id);
|
|
$content->delete();
|
|
$m = \App\Models\Sym\CmsContent::find($id);
|
|
$m->delete();
|
|
return back();
|
|
}
|
|
}
|