File: D:/HostingSpaces/SBogers10/blije-gasten.komma.pro/app/Komma/Kms/ActionLog/ActionLogSection.php
<?php
namespace App\Komma\Kms\ActionLog;
//The new object oriented attributes
use App\Komma\Kms\Core\Attributes\Attribute;
use App\Komma\Kms\Core\Attributes\DatePicker;
use App\Komma\Kms\Core\Attributes\Models\SelectOption;
use App\Komma\Kms\Core\Attributes\Select;
use App\Komma\Kms\Core\Sections\Section;
use App\Komma\Kms\Core\Attributes\Title;
use App\Komma\Kms\Core\Sections\Tabs\Collections\NoLanguageTabs;
use App\Komma\Users\Kms\KmsUserService;
use App\Komma\Users\Models\KmsUserRole;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
final class ActionLogSection extends Section
{
protected $title = "Action log";
protected $subtitle = "Who did what";
protected $slug = "actionlog";
protected $hasRoutes = false;
/**
* @var ActionLogModelService $sectionService
*/
protected $sectionService;
/** @var KmsUserService $userService */
private $userService;
/**
* PageSection constructor.
* @param string $slug
*/
// function __construct(Kms $kms, PageRepository $repository)
function __construct(string $slug)
{
$this->title = ucfirst(__('kms/actionlog.section.title'));
$this->submitButtonLabel = __('kms/actionlog.retrieve');
$this->userService = app(KmsUserService::class);
$sectionTabDirector = new NoLanguageTabs();
parent::__construct($sectionTabDirector, $slug);
}
/**
* Generates the attributes for this section. They all must extend the App\Komma\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
{
// \Log::info("PageSection::Generating attributes");
//*****************************************************************************************\\
//*** Define attribute validation sets ***\\
//*****************************************************************************************\\
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
//Build the general attributes and put them in the attributes array
$attributes[] = (new Title(__('kms/actionlog.section.title')))
->setMinimumUserRole(KmsUserRole::Admin);
$attributes[] = (new DatePicker(__('kms/actionlog.from')))
->setMinimumUserRole(KmsUserRole::Admin)
->mapValueFrom(Attribute::ValueFromItself, 'from');
$attributes[] = (new DatePicker(__('kms/actionlog.trough')))
->setMinimumUserRole(KmsUserRole::Admin)
->mapValueFrom(Attribute::ValueFromItself, 'trough');
$userSelectOptionModels = $this->userService->getOptionsForSelect();
$userSelectOptionModels->prepend(
(new SelectOption())
->setContent(__('kms/actionlog.all_users'))
->setHtmlContent(__('kms/actionlog.all_users'))
->setValue(0)
);
$attributes[] = (new Select())
->setItems($userSelectOptionModels->toArray())
->setLabelText(__('kms/actionlog.user_filter'))
->setMinimumUserRole(KmsUserRole::Admin)
->mapValueFrom(Attribute::ValueFromItself, 'user_filter');
//Return all attributes as a collection
return collect(array_merge($attributes));
}
}