File: D:/HostingSpaces/SBogers33/bbec.nl/workbench/komma/kms/src/Komma/Kms/Core/ShopSectionController.php
<?php
/**
* Short description for the file.
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2015, Komma Mediadesign
*/
namespace Komma\Kms\Core;
use Komma\Kms\Core\Sections\KmsSection;
class ShopSectionController extends KmsController
{
protected $section;
protected $slug = null;
function __construct(Kms $kms, KmsSection $section)
{
parent::__construct($kms);
$this->section = $section;
}
public function index()
{
$this->section->showEntity = false;
return $this->section->render();
}
public function show()
{
return $this->edit();
}
public function create()
{
$this->section->setErrors(\Session::get('errors'));
return $this->section->render();
}
public function store()
{
// Get input
$data = \Input::all();
$this->section->setAttributesData($data);
$validator = $this->section->validateAttributes();
if($validator->fails())
{
return \Redirect::action(get_class($this).'@create',[
'shop' => $this->kms->getCurrentShopSlug(),
])->withInput()->withErrors($validator->messages());
}
$page = $this->section->save();
return \Redirect::action(get_class($this).'@show',[
'shop' => $this->kms->getCurrentShopSlug(),
$this->slug => $page->id
])
->with('success', 'Entity Saved');
}
public function edit()
{
// Get input
$id = \Route::current()->getParameter(str_replace('-','_',$this->slug));
$this->section->loadEntity($id);
$this->section->setErrors(\Session::get('errors'));
return $this->section->render();
}
public function update()
{
// Get input
$id = \Route::current()->getParameter(str_replace('-','_',$this->slug));
$data = \Input::all();
$this->section->loadEntity($id);
$this->section->setAttributesData($data);
$validator = $this->section->validateAttributes();
if($validator->fails())
{
return \Redirect::action(get_class($this).'@show',[
'shop' => $this->kms->getCurrentShopSlug(),
$this->slug => $id
])->withInput()->withErrors($validator->messages());
}
$this->section->update($id);
return \Redirect::action(get_class($this).'@show',[
'shop' => $this->kms->getCurrentShopSlug(),
$this->slug => $id
])
->with('success', 'Entity Saved')
->withInput(compact(\Input::get('tab-slug'))); // Pass the opened tab
}
public function destroy()
{
// Get input
$id = \Route::current()->getParameter(str_replace('-','_',$this->slug));
// Action
$this->section->destroy($id);
// Create output
return \Redirect::action(get_class($this).'@index',[
'shop' => $this->kms->getCurrentShopSlug()
]);
}
}