File: D:/HostingSpaces/SBogers10/ehbo.today/app/KommaApp/Events/Kms/EventSection.php
<?php
namespace App\KommaApp\Events\Kms;
//The new object oriented attributes
use App\KommaApp\Events\Models\Event;
use App\KommaApp\Kms\Core\Attributes\AutocompleteInput;
use App\KommaApp\Kms\Core\Attributes\DatePicker;
use App\KommaApp\Kms\Core\Attributes\OnOff;
use App\KommaApp\Kms\Core\Attributes\Seperator;
use App\KommaApp\Kms\Core\Attributes\TextArea;
use App\KommaApp\Kms\Core\Attributes\TextField;
use App\KommaApp\Kms\Core\Attributes\View;
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\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\Kms\Core\ValidationSet;
use App\KommaApp\Users\Kms\UserService;
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 EventSection extends Section
{
protected $title = "Events";
protected $subTitle = "Events for everyone";
protected $slug = "events";
public $showSave = 'all';
public $showDelete = [Roles::SuperAdmin,Roles::Admin];
public $showCreate = [Roles::SuperAdmin,Roles::Admin];
/** @var UserService $userService */
private $userService;
/**
* EventSection constructor.
* @param EventService $sectionService
* @param RouteService $routeService
* @param SiteServiceInterface $siteService
*/
function __construct(EventService $sectionService, RouteService $routeService, SiteServiceInterface $siteService)
{
$sectionTabDirector = new NoLanguageTabsDirector(new SectionTabsBuilder()); //Can make tabs for us. also see KmsSection::__construct
$this->title = __('kms/Events.title');
$this->subTitle = __('kms/Events.sub_title');
$this->userService = \App::make(UserService::class);
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 EventRepository::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) ***\\
//*****************************************************************************************\\
$nameValidationSet = (new ValidationSet())
// ->setRules('required|unique:Events,Eventname')
->setRules([
'required',
Rule::unique('Events', 'name')->ignore($model->id)
])
->setMessages([
'required' => __('validation.required'),
'unique' => __('kms/Events.already_exists')
]);
$numericValidationSet = (new ValidationSet())
->setRules(['present', 'integer'])
->setMessages([
'required' => __('validation.required'),
'unique' => __('validation.integer')
]);
//*****************************************************************************************\\
//*** Generate the attributes ***\\
//*****************************************************************************************\\
$attributes = [];
$subscribedTab = [];
$attributes[] = (new Seperator());
//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('Events')
// ->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 DatePicker(__('kms/events.date')))
->setTimeEnabled(false)
->setTimeOnly(false)
->mapValueFrom(Attribute::ValueFromModel, 'date');
$attributes[] = (new DatePicker('Starttijd'))
->setTimeEnabled(true)
->setTimeOnly(true)
->mapValueFrom(Attribute::ValueFromModel, 'starttime');
$attributes[] = (new DatePicker('Eindtijd'))
->setTimeEnabled(true)
->setTimeOnly(true)
->mapValueFrom(Attribute::ValueFromModel, 'endtime');
$attributes[] = (new DatePicker(__('kms/events.max_subscription_date')))
->setTimeEnabled(false)
->setTimeOnly(false)
->mapValueFrom(Attribute::ValueFromModel, 'max_subscription_date');
$subscribedTab[] = $eventUsersPartial = (new View('kms.partials.eventSubscribers'));
if ($model->exists) {
$eventUsersPartial->setViewData([
'subscribed_users' => $model->users()->get(),
'event' => $model
]);
}
//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($languageIndexedAttributes as $attribute) $tabItems->push(new SectionTabItem($attribute, SectionTabGroups::General));
foreach($attributes as $attribute) $tabItems->push(new SectionTabItem($attribute, SectionTabGroups::General));
$this->sectionTabDirector->addTab('Ingeschreven leden');
foreach($subscribedTab as $subscribedTabItem) $tabItems->push(new SectionTabItem($subscribedTabItem, 'Ingeschreven leden'));
return $tabItems;
}
}