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/reiskick.komma.nl/app/Hotels/Kms/HotelSection.php
<?php

namespace App\Hotels\Kms;

use App\Components\ComponentTypes;
use App\Countries\Kms\CountryModelService;
use App\Hotels\Models\Hotel;
use App\MustDos\Models\MustDo;
use Illuminate\Database\Eloquent\Model;
use Komma\KMS\Core\Attributes\Attribute;
use Komma\KMS\Core\Attributes\ComponentArea;
use Komma\KMS\Core\Attributes\DatePicker;
use Komma\KMS\Core\Attributes\Documents;
use Komma\KMS\Core\Attributes\Models\SelectOption;
use Komma\KMS\Core\Attributes\OnOff;
use Komma\KMS\Core\Attributes\Select;
use Komma\KMS\Core\Attributes\TextArea;
use Komma\KMS\Core\Attributes\TextField;
use Komma\KMS\Core\ModelServiceInterface;
use Komma\KMS\Core\Sections\Section;
use Komma\KMS\Users\Models\KmsUserRole;

final class HotelSection extends Section
{

    /**
     * Define the attributes and tabs for this section.
     *
     * @param Model $currentModel
     */
    public function defineAttributesAndTabs(Model $currentModel = null): void
    {

        /** @var ModelServiceInterface $pageModelService */
        $modelService = app()->make(ModelServiceInterface::class);
        $modelService->setModelClassName(Hotel::class);
        $optionModels = $modelService->getOptionsForSelectAsTree();

        $ratingOptions = [
            (new SelectOption())
                ->setValue(-1)
                ->setContent('Geen rating')
                ->setHtmlContent('Geen rating'),
        ];

        for($r = 0; $r <= 5; $r++) {
            $label = $r .' sterren';
            if($r == 1) $label = $r . ' ster';

            $ratingOptions[] = (new SelectOption())
                ->setValue($r)
                ->setContent($label)
                ->setHtmlContent($label);
        }

        /** @var CountryModelService $countryService */
        $countryService = app()->make(CountryModelService::class);

        $this->tabs->makeTab()->addItems([

            (new OnOff())
                ->setReference('active')
                ->setLabelText(__('KMS::global.active'))
                ->switchOn(),

            (new Documents())
                ->setReference('hotels')
                ->setLabelText(__('KMS::global.image'))
                ->onlyAllowImages()
                ->setSmallDragAndDropArea()
                ->setMaxDocuments(1)
                ->setSubFolder('hotels'),

            (new Select())
                ->setItems($ratingOptions)
                ->setLabelText('Sterren')
                ->setReference('rating'),

            (new Select())
                ->setItems($countryService->getOptionsForSelect()->toArray())
                ->setLabelText('Land')
                ->setReference('country_id'),

            (new Select())
                ->setItems($optionModels->toArray())
                ->setLabelText(__('KMS::pages.parent_page'))
                ->enableExcludeCurrentModelItem()
                ->setMinimumUserRole(KmsUserRole::SuperAdmin)
                ->mapValueFrom(Attribute::ValueFromItself, 'parent_id'),
        ]);

        $this->tabs->makeLanguageTabTemplate()->addItems([
            (new TextField())
                ->setReference('name')
                ->setLabelText(__('KMS::global.title')),

            (new TextArea())
                ->setReference('description')
                ->setLabelText(__('KMS::global.description')),

            (new TextField())
                ->setReference('link')
                ->setLabelText(__('KMS::global.link')),


        ]);
    }
}