File: D:/HostingSpaces/SBogers84/zuiderbos.nl/workbench/komma/kms/src/Komma/Kms/Faq/FaqController.php
<?php
namespace Komma\Kms\Faq;
/**
* Short description for the file.
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2015, Komma Mediadesign
*/
use Komma\Kms\Core\Kms;
use Komma\Kms\Core\SectionController;
use Komma\Kms\Core\Tree\TreeService;
use Komma\Kms\Faq\Models\Faq;
class FaqController extends SectionController
{
protected $slug = "Faq";
protected $treeService;
/**
* Constructor
* @param Kms $kms
* @param FaqSection $section
*/
public function __construct(Kms $kms, FaqSection $section, TreeService $treeService)
{
parent::__construct($kms, $section);
$this->treeService = $treeService;
$this->treeService->setRepository($this->section->getRepository());
$this->treeService->setModel(new Faq());
}
public function getStructureAsJson()
{
$tree = $this->treeService->getStructureAsJson();
return \Response::json($tree);
}
public function setStructureAsJson()
{
// Special way to get POST data send by ajax on IIS servers
$data = json_decode(\Request::instance()->getContent());
$tree = json_decode($data->tree);
$tree = $this->treeService->setStructureWithJson($tree);
return \Response::json($tree);
}
public function update()
{
// Get id from slug as snake case
// Directly to snake_case did'nt work
// First as camel did work
$camelSlug = camel_case($this->slug);
$snakeSlug = snake_case($camelSlug);
$id = \Route::current()->getParameter($snakeSlug);
// Get all input data
$data = \Input::all();
// Check if schools isset else make it an empty array
if(!isset($data['schools'])) $data['schools'] = [];
// Load entity in section
$this->section->loadEntity($id);
// Push data into attributes
$this->section->setAttributesData($data);
// Create a validator
$validator = $this->section->validateAttributes();
// Validate
if($validator->fails())
{
return \Redirect::action(get_class($this).'@show', [$this->slug => $id])
->withInput()
->withErrors($validator->messages());
}
// Save the entity
$this->section->update($id);
return \Redirect::action(get_class($this).'@show', [$this->slug => $id])
->with('success', 'Entity Saved'); // Pass the opened tab*/
}
}