HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers84/zuiderbos.nl/workbench/komma/kms/src/Komma/Kms/Jobs/JobController.php
<?php namespace Komma\Kms\Jobs;

/**
 * @author      Pascal Lemmen <pascal@komma.pro>
 * @copyright   (c) 2012-2016, Komma Mediadesign
 */

use Komma\Kms\Core\Kms;
use Komma\Kms\Core\SectionController;
use Komma\Kms\Core\Tree\TreeService;
use Komma\Kms\Jobs\Models\Job;


class JobController extends SectionController
{
    protected $slug = "jobs";

    protected $treeService;

    /**
     * Constructor
     * @param Kms $kms
     * @param JobSection $section
     */
    public function __construct(Kms $kms, JobSection $section, TreeService $treeService)
    {
        parent::__construct($kms, $section);

        $this->treeService = $treeService;
        $this->treeService->setRepository($this->section->getRepository());
        $this->treeService->setModel(new Job());
    }

    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);
    }

    /**
     * Save an existing item
     *
     * @return mixed
     */
    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')
            ->withInput(compact(\Input::get('tab-slug'))); // Pass the opened tab*/
    }

}