HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/ehbo.today/app/KommaApp/ArchivedEvents/Kms/ArchivedEventSection.php
<?php

namespace App\KommaApp\ArchivedEvents\Kms;

//The new object oriented attributes
use App\KommaApp\ArchivedEvents\Models\ArchivedEvent;
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 ArchivedEventSection extends Section
{
    protected $title = "ArchivedEvents";
    protected $subTitle = "ArchivedEvents for everyone";
    protected $slug = "archivedevents";

    public $showSave = 'none';
    public $showDelete = [];
    public $showCreate = [];

    /** @var UserService $userService  */
    private $userService;

    /**
     * ArchivedEventSection constructor.
     * @param ArchivedEventService $sectionService
     * @param RouteService $routeService
     * @param SiteServiceInterface $siteService
     */
    function __construct(ArchivedEventService $sectionService, RouteService $routeService, SiteServiceInterface $siteService)
    {
        $sectionTabDirector = new NoLanguageTabsDirector(new SectionTabsBuilder()); //Can make tabs for us. also see KmsSection::__construct

        $this->title = __('kms/ArchivedEvents.title');
        $this->subTitle = __('kms/ArchivedEvents.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 ArchivedEventRepository::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:ArchivedEvents,ArchivedEventname')
            ->setRules([
                'required',
                Rule::unique('ArchivedEvents', 'name')->ignore($model->id)
            ])
            ->setMessages([
                'required' => __('validation.required'),
                'unique' => __('kms/ArchivedEvents.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('ArchivedEvents')
//            ->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/archivedEvents.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/archivedEvents.max_subscription_date')))
            ->setTimeEnabled(false)
            ->setTimeOnly(false)
            ->mapValueFrom(Attribute::ValueFromModel, 'max_subscription_date');

        $subscribedTab[] = $archivedEventUsersPartial = (new View('kms.partials.archivedEventSubscribers'));
        if ($model->exists) {
            $archivedEventUsersPartial->setViewData([
                'subscribed_users' => $model->users()->get(),
                'archivedEvent' => $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;
    }
}