File: D:/HostingSpaces/SBogers10/lmbm.komma.pro/app/KommaApp/Kms/Core/Attributes/Dynamic.php
<?php
namespace App\KommaApp\Kms\Core\Attributes;
use App\KommaApp\Kms\Core\Attributes\Models\AbstractBlockSettings;
use App\KommaApp\Kms\Core\Attributes\Traits\LabelTrait;
use App\KommaApp\Kms\Core\Sections\KmsSiteSection;
use App\KommaApp\Kms\Core\Sections\Section;
use Illuminate\Database\Eloquent\Model;
/**
* Class Dynamic
* @package App\KommaApp\Kms\Core\Attributes
*/
class Dynamic extends Attribute
{
use LabelTrait;
/** @var string $subFolder This is the subfolder of the path public/uploads/images where the images for this attribute wil be placed in*/
private $subFolder;
/** @var AbstractBlockSettings[] $blockSettings */
private $blockSettings;
private $dynamicLocked = false;
/**
* Dynamic constructor.
*/
public function __construct()
{
parent::__construct();
}
/**
* Returns a view that visually represents this attribute
*
* @return \Illuminate\View\View
*/
public function render()
{
//retrieve model and model id.
$model = null;
$request = request();
$route = $request->route();
if(method_exists($route->controller, 'getSection') == false) throw new \RuntimeException("The controller: '".get_class($route->controller)."' did not have a public 'getSection' method while it should have one.");
/** @var Section $section */
$section = $route->controller->getSection();
$model = $section->getSectionService()->getModel();
// dd($model);
return \View::make('kms/attributes.dynamic', [
'attribute' => $this,
'forModel' => $model
]);
}
/**
* @return string
*/
public function getSubFolder(): string
{
return $this->subFolder;
}
/**
* @param string $subFolder
* @return Dynamic
*/
public function setSubFolder(string $subFolder): Dynamic
{
$this->subFolder = $subFolder;
return $this;
}
/**
* @param bool $asJson
* @return AbstractBlockSettings[]|string
*/
public function getBlockSettings($asJson = true)
{
if($asJson == false) return $this->blockSettings;
$toEncode = [];
foreach($this->blockSettings as $blockSetting) {
$toEncode[$blockSetting->getBlockType()] = $blockSetting->jsonSerialize();
}
$blockSettings = json_encode($toEncode);
return $blockSettings;
}
/**
* @param AbstractBlockSettings[] $blockSettings
* @return Dynamic
*/
public function setBlockSettings(array $blockSettings): Dynamic
{
$this->blockSettings = $blockSettings;
return $this;
}
/**
* @return bool
*/
public function isDynamicLocked(): bool
{
return $this->dynamicLocked;
}
/**
* @param bool $dynamicLock
* @return Dynamic
*/
public function setDynamicLocked(): Dynamic
{
$this->dynamicLocked = true;
return $this;
}
}