File: D:/HostingSpaces/SBogers10/wingssprayer.komma.pro/app/Pages/Kms/PageSection.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\Pages\Kms;
//The new object oriented attributes
use App\Attributes\Attribute;
use App\Attributes\ComponentArea;
use App\Base\SectionWithSiteLogic;
use App\Components\ComponentType\ComponentTypes;
use Komma\KMS\Core\Attributes\Documents;
use Komma\KMS\Core\ModelServiceInterface;
use Komma\KMS\Core\Sections\Tabs\Collections\CurrentSiteLanguagesTabs;
use App\Pages\Models\Page;
use Komma\KMS\Sites\SiteServiceInterface;;
use Komma\KMS\Core\Attributes\Models\ImageProperty;
use Komma\KMS\Core\Attributes\OnOff;
use Komma\KMS\Core\Attributes\Select;
use Komma\KMS\Core\Attributes\Seperator;
use Komma\KMS\Core\Attributes\TextArea;
use Komma\KMS\Core\Attributes\TextField;
use Komma\KMS\Core\Attributes\Title;
use Komma\KMS\Core\ValidationSet;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Komma\KMS\Users\Models\KmsUserRole;
final class PageSection extends SectionWithSiteLogic
{
protected $hasRoutes = true;
public $showSave = 'all';
public $showDelete = [1];
public $showCreate = [1];
/**
* PageSection constructor.
* @param $slug
*/
function __construct(string $slug)
{
$tabs = new CurrentSiteLanguagesTabs();
$this->siteService = app(SiteServiceInterface::class);
parent::__construct($tabs, $slug);
}
/**
* Generates the attributes for this section. They all must extend the App\Kms\Core\Attributes\Attribute class
* This is the place where you need to setup your sections appearance. Just make sure you build an array of attributes
* and put each attribute in a AbstractSectionTabItem with a SectionTabGroups constant to link them to a tab.
*
* @see PageRepository::saveModel()
* @param Model $currentModel
* @return Collection A collection of SectionTabItems
*/
protected function generateAttributes(Model $currentModel = null): Collection
{
$fixedAttributeTabItems = $this->generateFixedAttributes($currentModel);
$tabItems = $fixedAttributeTabItems;
$componentTypes = [
ComponentTypes::TEXT_IMAGE,
ComponentTypes::DOUBLE_TEXT,
ComponentTypes::VIDEO,
ComponentTypes::TEXT,
ComponentTypes::IMAGE,
ComponentTypes::DUPLEX,
];
if ($currentModel && $currentModel->code_name == 'about') {
$componentTypes = [
ComponentTypes::SLOGAN,
ComponentTypes::TEXT_IMAGE,
ComponentTypes::DUPLEX,
ComponentTypes::EMPLOYEES,
ComponentTypes::TROPHIES,
ComponentTypes::QUOTE,
];
}
if ($currentModel && in_array($currentModel->code_name, ['about', 'technique', 'installation', 'references', 'vacancies', 'suitable_machines'], true)) {
$componentTypes[] = ComponentTypes::INTRO;
}
if ($currentModel && in_array($currentModel->code_name, ['plan_demo', 'plan_meeting', 'contact', 'request_brochure', 'vacancies'], true)) {
$componentTypes[] = ComponentTypes::QUOTE;
}
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages([
(new ComponentArea())
->setComponentTypes($componentTypes)
->setSubFolder('dynamic_group_sections')
->mapValueFrom(Attribute::ValueFromComponentArea, 'dynamic_group_sections')
]);
return $tabItems->merge(collect($languageIndexedAttributes));
}
/**
* Generate fixed attributes
*
* @param Model|null $currentModel
* @return Collection
*/
private function generateFixedAttributes(Model $currentModel = null):Collection {
/** @var ModelServiceInterface $pageModelService */
$pageModelService = app(ModelServiceInterface::class);
$pageModelService->setModelClassName(Page::class);
//*****************************************************************************************\\
//*** Define attribute validation sets ***\\
//*****************************************************************************************\\
$codeNameValidationSet = (new ValidationSet())
->setRules('required')
->setMessages(['required' => __('validation.required')]);
$hasWildcardValidationSet = (new ValidationSet())
->setRules(['sometimes', 'required', 'integer'])
->setMessages([
'sometimes' => __('validation.required'),
'required' => __('validation.required'),
'min' => __('validation.min.numeric'),
]);
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
// //Build the general attributes and put them in the attributes array
$attributes[] = (new Title(__('kms/sites.type')))->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new OnOff())
->setLabelText(__('KMS::kms/global.uses_wildcard'))
->setExplanation(__('KMS::kms/pages.wildcard_explanation'))
->setMinimumUserRole(KmsUserRole::SuperAdmin)
->setValidationSet($hasWildcardValidationSet)
->mapValueFrom(Attribute::ValueFromModel, 'has_wildcard');
$attributes[] = (new Seperator())->setMinimumUserRole(KmsUserRole::SuperAdmin);
$attributes[] = (new Title(__('KMS::kms/pages.page')));
// $attributes[] = (new Video('Youtube'));
$attributes[] = (new TextField(__('KMS::kms/global.codeName')))
->setPlaceholderText(__('kms/global.enterCodeName'))
->setMinimumUserRole(KmsUserRole::SuperAdmin)
->setReadOnly(false)
->mapValueFrom(Attribute::ValueFromModel, 'code_name')
->setValidationSet($codeNameValidationSet);
$attributes[] = (new OnOff())
->setLabelText(__('kms/global.active'))
->switchOn()
->mapValueFrom(Attribute::ValueFromModel, 'active');
$pageOptionModels = $pageModelService->getOptionsForSelectAsTree();
$attributes[] = (new Select())
->setItems($pageOptionModels->toArray())
->setLabelText(__('KMS::kms/pages.parent_page'))
->setExcludeCurrentModelItem(true)
->mapValueFrom(Attribute::ValueFromItself, 'parent_id');
$attributes[] = (new Documents())
->setLabelText(__('kms/global.documents'))
// ->onlyAllowImages()
->setMaxDocuments(5)
->setSubFolder('pages')
->setImageProperties([
(new ImageProperty())->setName('thumb')->setCropMethod(ImageProperty::Fit)->setWidth(100),
(new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Resize)->setWidth(240),
(new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Resize)->setWidth(460),
(new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Resize)->setWidth(500),
])
->mapValueFrom(Attribute::ValueFromDocuments, 'pages');
$attributes[] = (new Seperator());
//Build an array with attributes for each current site language
$languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages([
(new Title(__('kms/global.information'))),
(new TextField(__('kms/global.title')))
->setPlaceholderText(__('kms/global.enterTitle'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'name'),
(new Seperator()),
(new TextField(__('kms/global.metaTitle')))
->setPlaceholderText(__('kms/global.enterTitle'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'meta_title'),
(new TextArea())
->setLabelText(__('kms/global.metaDescription'))
->setPlaceholderText(__('kms/global.enterMetaDescription'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'meta_description'),
]);
//Return all attributes as a collection
return collect(array_merge($attributes, $languageIndexedAttributes));
}
/**
* This method will stop the load entities of the kmsSiteSection
*
* @return array
*
*/
public function loadEntities(){
return [];
}
}