File: D:/HostingSpaces/SBogers10/ehbo.today/app/KommaApp/Competences/Kms/CompetenceSection.php
<?php
namespace App\KommaApp\Competences\Kms;
//The new object oriented attributes
use App\KommaApp\Kms\Core\Attributes\DatePicker;
use App\KommaApp\Kms\Core\Attributes\Documents;
use App\KommaApp\Kms\Core\Attributes\OnOff;
use App\KommaApp\Kms\Core\Attributes\Select;
use App\KommaApp\Kms\Core\Attributes\TextArea;
use App\KommaApp\Kms\Core\Attributes\TextField;
use App\KommaApp\Kms\Core\Sections\CurrentSiteLanguagesTabsDirector;
use App\KommaApp\Kms\Core\Sections\NoLanguageTabsDirector;
use App\KommaApp\Routes\RouteService;
use App\KommaApp\Kms\Core\Attributes\Attribute;
use App\KommaApp\Kms\Core\Attributes\Images;
use App\KommaApp\Kms\Core\Attributes\Models\ImageProperty;
use App\KommaApp\Kms\Core\Attributes\Seperator;
use App\KommaApp\Kms\Core\Attributes\Title;
use App\KommaApp\Kms\Core\Sections\Section;
use App\KommaApp\Kms\Core\Sections\SectionTabGroups;
use App\KommaApp\Kms\Core\Sections\SectionTabItem;
use App\KommaApp\Kms\Core\Sections\SectionTabsBuilder;
use App\KommaApp\Sites\SiteServiceInterface;
use App\KommaApp\Users\Roles;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Validation\Rule;
use Illuminate\Database\Eloquent\Collection;
class CompetenceSection extends Section
{
protected $title = "Competences";
protected $subTitle = "What you can";
protected $slug = "competences";
public $showSave = 'all';
public $showDelete = [Roles::SuperAdmin,Roles::Admin];
public $showCreate = [Roles::SuperAdmin,Roles::Admin];
/**
* CompetenceSection constructor.
* @param CompetenceService $sectionService
* @param RouteService $routeService
* @param SiteServiceInterface $siteService
*/
function __construct(CompetenceService $sectionService, RouteService $routeService, SiteServiceInterface $siteService)
{
$sectionTabDirector = new NoLanguageTabsDirector(new SectionTabsBuilder()); //Can make tabs for us. also see KmsSection::__construct
$this->title = __('kms/competences.title');
$this->subTitle = __('kms/competences.sub_title');
parent::__construct($sectionService, $routeService, $siteService, $sectionTabDirector);
}
/**
* Generates the attributes for this section. They all must extend the App\KommaApp\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 CompetenceRepository::saveModel()
* @return Collection A collection of SectionTabItems
*/
protected function generateAttributes(): Collection
{
/** @var Model $model */
$model = $this->loadModel($this->getModel());
//*****************************************************************************************\\
//*** Define attribute validation sets (Laravel validation rules and message sets) ***\\
//*****************************************************************************************\\
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
//Build the general attributes and put them in the attributes array
$attributes[] = (new Title(__('kms/global.general')));
// $attributes[] = (new Documents())
// ->setLabelText(__('kms/global.images'))
// ->setSubFolder('Competences')
// ->setMaxDocuments(1) //TODO. Seems not implemented yet
// ->setAccept('image/*')
// ->mapValueFrom(Attribute::ValueFromDocuments, 'documents');
$attributes[] = (new OnOff())
->setLabelText(__('kms/global.active'))
->mapValueFrom(Attribute::ValueFromModel, 'active');
$attributes[] = (new Select())
->setLabelText(__('kms/competences.renew_every'))
->setItems($this->sectionService->getCompetenceRenewIntervalOptions()->toArray())
->mapValueFrom(Attribute::ValueFromModel, 'renew_interval');
$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 TextArea())
->setLabelText(__('kms/global.description'))
->setPlaceholderText(__('kms/global.description'))
->mapValueFrom(Attribute::ValueFromTranslationModel, 'description'),
// (new TextArea())
// ->setLabelText(__('kms/global.metaDescription'))
// ->mapValueFrom(Attribute::ValueFromTranslationModel, 'meta_description'),
]);
//****************************************************************************************************************************************\\
//*** Put the all attributes in a SectionTabItem so we can track for which tab they are. And then put SectionTabItems in a Collection ***\\
//****************************************************************************************************************************************\\
$tabItems = new Collection();
foreach($attributes as $attribute) $tabItems->push(new SectionTabItem($attribute, SectionTabGroups::General));
foreach($languageIndexedAttributes as $attribute) $tabItems->push(new SectionTabItem($attribute, SectionTabGroups::General));
return $tabItems;
}
}