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/SBogers33/bbec.nl/workbench/komma/kms/src/Komma/Kms/Blocks/BlockController.php
<?php namespace Komma\Kms\Blocks;

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

use Komma\Kms\Core\Kms;
use Komma\Kms\Core\SectionController;


class BlockController extends SectionController
{
    protected $slug = "blocks";
    protected $type = '';
    protected $typeSlug = '';
    /**
     * Constructor
     * @param Kms $kms
     * @param BlockSection $section
     */
    public function __construct(Kms $kms, BlockSection $section)
    {
        parent::__construct($kms, $section);

        $slug = \Request::segment(3);

        if($slug == null) $slug = 'all';


        // Set subtitle and define special slug for sidebar active state
        $this->section->setSubTitle( "Pagina" );
        \Session::put('specialSlug', $slug);
        \View::share('specialSlug', $slug);


        $this->section->type = $slug;

        $this->type = $slug;

        $this->section->loadEntities();
    }

    /**
     * Show edit form
     *
     * @return mixed
     */
    public function edit()
    {
        // Get id from route
        $id = \Route::current()->getParameter('id');

        // Load entity in the section
        $this->section->loadEntity($id);

        // Parse data into attributes
        $this->section->populateAttributes();

        // Append dynamic lock parameter from Database to last items (so don't change the position)
        $myAttributes = $this->section->getAttributes();
        //$myAttributes[ sizeof($myAttributes) - 1]->dynamicLock = $this->section->getEntity()->dynamic_lock;
        $this->section->setAttributesData($myAttributes);

        $this->section->setErrors(\Session::get('errors'));

        return $this->section->render();
    }

    /**
     * Save a new item
     *
     * @return mixed
     */
    public function store()
    {
        $data = \Input::all();
        $data['type'] = $this->type;

        // Load entity in the section
        $this->section->loadEntity();

        // Populate attributes
        $this->section->setAttributesData($data);

        // Create a validator object
        $validator = $this->section->validateAttributes();

        // Validate data
        if($validator->fails())
        {
            return \Redirect::back()
                ->withInput()
                ->withErrors($validator->messages());
        }

        // Save entity
        $entity = $this->section->save();

        return \Redirect::to('/kms/'.$this->slug.'/'.$this->type.'/'.$entity->id)
            ->with('success', 'Entity Saved');
    }

    /**
     * Save an existing item
     *
     * @return mixed
     */
    public function update()
    {
        // Get id from route
        $id = \Route::current()->getParameter('id');

        // Get all input data
        $data = \Input::all();

        // 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::back()
                ->withInput()
                ->withErrors($validator->messages());
        }

        // Save the entity
        $this->section->update($id);

        return \Redirect::to('/kms/'.$this->slug.'/'.$this->type.'/'.$id)
            ->with('success', 'Entity Saved')
            ->withInput(compact(\Input::get('tab-slug'))); // Pass the opened tab*/
    }


    /**
     * Delete an existing item
     *
     * @return mixed
     */
    public function destroy()
    {
        // Get id from route
        $id = \Route::current()->getParameter('id');

        // Action
        $this->section->destroy($id);

        // Create output
        return \Redirect::to('/kms/'.$this->slug.'/'.$this->type)
            ->with('message', 'Entity Removed');
    }
}