identifier_content = config('fewo.identifier_content'); $this->identifier_fewo = config('fewo.identifier_fewo'); } /* * ALL */ public function all($step = false) { $data = [ 'contents' => CMSContent::where('identifier', '=', $this->identifier_content)->get()->sortBy('pos'), 'identifier_content' => $this->identifier_content, 'step' => $step ]; return view('cms.fewo.all.index', $data); } public function storeAll($step = false) { $data = Request::all(); /*if($data['action'] === 'saveAll') { //saveAll on each change }*/ $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->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(); } } //last if($data['action'] === 'addItem'){ $create = [ 'name' => 'Abschnitt', 'field' => 'full_text', 'decimal' => 1, 'identifier' => $this->identifier_content, 'pos' => $i, ]; CMSContent::create($create); //store in cms old Datebase \App\Models\Sym\CmsContent::create($create); } \Session()->flash('alert-save', '1'); return redirect(route('cms_fewo_all', [$step])); } public function deleteAll($id){ $content = CMSContent::findOrFail($id); $content->delete(); $m = \App\Models\Sym\CmsContent::find($id); $m->delete(); \Session()->flash('alert-success', __('Content gelöscht')); return back(); //redirect(route('cms_content_all')); } /* * CONTENT */ public function content() { $data = [ 'fewo_lodgings' => FewoLodging::all() ]; return view('cms.fewo.content.index', $data); } public function detail($id, $step = false) { $fewo = FewoLodging::findOrFail($id); $identifier_fewo = $this->identifier_fewo.Util::sanitize($fewo->pdf_name); // //this->identifier_fewo = 'fewo-pdf-'; $data = [ 'contents' => CMSContent::where('identifier', '=', $this->identifier_content)->get()->sortBy('pos'), 'fewo' => $fewo, 'identifier_content' => $this->identifier_content, 'identifier_fewo' => $identifier_fewo, 'step' => $step ]; return view('cms.fewo.content.detail', $data); } public function store($id, $step = false) { $data = Request::all(); $fewo = FewoLodging::findOrFail($id); $identifier_fewo = $this->identifier_fewo.Util::sanitize($fewo->pdf_name); $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'] === $this->identifier_content) { $last_content_id = $content->id; } if ($item['identifier'] === $identifier_fewo) { $content->setObjectBy('page-break', (isset($item['page-break']) ? 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(); } } } if($data['action'] === 'previewPDF'){ $pdf_content = BookingFewo::getFeWoCMSContentForPDF($this->identifier_content, $identifier_fewo); $pdf_file = new CreatePDF('pdf.fewo_instructions'); return $pdf_file->create([ 'contents' => $pdf_content, 'fewo' => $fewo ] ); } if($data['action'] === 'addItem' && isset($data['content_pos_id'])) { $create = [ 'name' => 'Abschnitt', 'field' => 'full_text', 'decimal' => 1, 'integer' => $data['content_pos_id'], 'identifier' => $identifier_fewo, '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_fewo_content_detail', [$id, $step])); } }