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/mountadvies.komma.pro/app/Components/ComponentType/Types/Downloads.php
<?php


namespace App\Components\ComponentType\Types;

use App\Buttons\Kms\ButtonService;
use App\Buttons\Models\Button;
use App\Components\Component\ViewComponent;
use Komma\KMS\Core\Attributes\MultiSelect;
use App\Components\ComponentType\ComponentTypes;
use Komma\KMS\Core\Attributes\Attribute;
use Komma\KMS\Core\Attributes\Documents;
use Komma\KMS\Core\Attributes\Models\ImageProperty;
use Komma\KMS\Core\Attributes\OnOff;
use Komma\KMS\Core\Attributes\Seperator;
use Komma\KMS\Core\Attributes\TextArea;
use Komma\KMS\Core\Attributes\TextField;
use Komma\KMS\Core\Attributes\Title;
use App\Servicepoints\Kms\ServicepointService;
use App\Servicepoints\Models\Servicepoint;

class Downloads extends AbstractComponentType
{
    public function __construct()
    {
        //Set an id that corresponds to the ComponentTypes enum
        $this->id = ComponentTypes::DOWNLOADS;

        //Set icon and name
        $this->name = 'downloads';

        parent::__construct();

        $servicePointService = \App::make(ServicepointService::class);
        $selectServicePointOptions = $servicePointService->getOptionsForSelect(false, true);

        $buttonsService = \App::make(ButtonService::class);
        $selectButtonOptions = $buttonsService->getOptionsForSelect(false, true);

        $this->attributes->push((new TextField(__('kms/attributes/components.title')))
            ->mapValueFrom(Attribute::ValueFromComponent, 'download_title')
        );

        $this->attributes->push(new Title('Downloads'));

        $this->attributes->push((new Documents())
            ->setSubFolder('component_downloads')
            ->setMaxDocuments(12)
            ->mapValueFrom(Attribute::ValueFromComponent, 'downloads') //Needed to sustain Attribute integrity.
        );

        $this->attributes->push(new Seperator());
        $this->attributes->push(new Title(__('kms/attributes/components.contact_person')));

        $this->attributes->push((new TextField('Titel'))
            ->mapValueFrom(Attribute::ValueFromComponent, 'personal_header')
        );

        $this->attributes->push((new MultiSelect())
            ->setLabelText(__('kms/attributes/components.contact_person'))
            ->setItems($selectServicePointOptions->toArray())
            ->setMaxItemsToSelect(1)
            ->canBeLinkedWith(Servicepoint::class)
            ->mapValueFrom(Attribute::ValueFromComponent, 'servicepoints')
        );

        $this->attributes->push((new MultiSelect())
            ->setLabelText(__('KMS::kms/global.button'))
            ->setItems($selectButtonOptions->toArray())
            ->setMaxItemsToSelect(1)
            ->canBeLinkedWith(Button::class)
            ->mapValueFrom(Attribute::ValueFromComponent, 'servicePointButton')
        );

        $this->attributes->push(new Seperator());
        $this->attributes->push(new Title(__('kms/attributes/components.options')));

        $this->attributes->push((new OnOff())
            ->setLabelText(__('kms/attributes/components.swap_download_contactperson'))
            ->mapValueFrom(Attribute::ValueFromComponent, 'reversed')
        );
    }

    public function prepare(ViewComponent $viewComponent)
    {
        $viewComponent->downloads = $viewComponent->downloads->sortBy('sort_order');
        return $viewComponent;
    }
}