File: D:/HostingSpaces/SBogers10/lc-hydraulics.komma.nl/app/KommaApp/Segments/Kms/SegmentController.php
<?php
namespace App\KommaApp\Segments\Kms;
/**
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
use App\KommaApp\Kms\Core\SiteSectionController;
use App\KommaApp\Kms\Core\Tree\TreeService;
use App\KommaApp\Segments\Models\Segment;
class SegmentController extends SiteSectionController
{
protected $slug = "segments";
protected $forModelName = Segment::class;
protected $treeService;
/**
* Constructor
* @param SegmentSection $section
* @param TreeService $treeService
*/
public function __construct(SegmentSection $section, TreeService $treeService)
{
parent::__construct($section);
$this->treeService = $treeService;
$this->treeService->setSectionService($this->section->getSectionService());
$this->treeService->setModel(new Segment());
}
public function getSegmentStructureAsJson($siteSlug)
{
$this->kms->setSite($siteSlug);
$tree = $this->treeService->getStructure();
return \Response::json($tree);
}
public function setSegmentStructureAsJson($siteSlug)
{
$this->kms->setSite($siteSlug);
// 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);
}
}