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/wingssprayer.komma.pro/app/MachineTypes/Kms/MachinetypeSection.php
<?php
/**
 *
 *
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma
 */

namespace App\Machinetypes\Kms;

//The new object oriented attributes
use App\Attributes\Attribute;
use App\Attributes\ComponentArea;
use App\Base\SectionWithSiteLogic;
use App\Components\ComponentType\ComponentTypes;
use App\Partners\Models\Partner;
use Illuminate\Validation\Rule;
use Komma\KMS\Core\Attributes\Documents;
use Komma\KMS\Core\Attributes\Models\SelectOption;
use Komma\KMS\Core\ModelServiceInterface;
use Komma\KMS\Core\Sections\Tabs\Collections\CurrentSiteLanguagesTabs;
use App\Machinetypes\Models\Machinetype;
use Komma\KMS\Core\Sections\Tabs\Collections\NoLanguageTabs;
use Komma\KMS\Sites\SiteServiceInterface;
use Komma\KMS\Core\Attributes\Models\ImageProperty;
use Komma\KMS\Core\Attributes\OnOff;
use Komma\KMS\Core\Attributes\Select;
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 Komma\KMS\Core\ValidationSet;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Komma\KMS\Users\Models\KmsUserRole;

final class MachinetypeSection extends SectionWithSiteLogic
{
    /**
     * MachinetypeSection constructor.
     * @param $slug
     */
    function __construct(string $slug)
    {
        $tabs = new NoLanguageTabs();
        parent::__construct($tabs, $slug);
    }

    /**
     * Generates the attributes for this section. They all must extend the App\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 MachinetypeRepository::saveModel()
     * @param Model $currentModel
     * @return Collection A collection of SectionTabItems
     */
    protected function generateAttributes(Model $currentModel = null): Collection
    {
        return $this->generateFixedAttributes($currentModel);
    }

    /**
     * Generate fixed attributes
     *
     * @param Model|null $currentModel
     * @return Collection
     */
    private function generateFixedAttributes(Model $currentModel = null):Collection {
        $imageValidationSet = (new ValidationSet())
            ->setRules([
                'required',
                Rule::notIn(['[]']),
            ])
            ->setMessages([
                'required' => __('validation.required'),
                'not_in' => __('validation.required'),
            ]);

        /** @var ModelServiceInterface $partnerModelService */
        $partnerModelService = app(ModelServiceInterface::class);
        $partnerModelService->setModelClassName(Partner::class);

        //*****************************************************************************************\\
        //*** Generate the attributes                                                           ***\\
        //*****************************************************************************************\\
        $attributes = [];

        $attributes[] = (new OnOff())
            ->setLabelText(__('kms/global.active'))
            ->switchOn()
            ->mapValueFrom(Attribute::ValueFromModel, 'active');


        $partnerOptionModels = $partnerModelService->getOptionsForSelectAsTree()->filter(fn(SelectOption $selectOption) => $selectOption->getContent() != '/');

        $attributes[] = (new Select())
            ->setItems($partnerOptionModels->toArray())
            ->setLabelText('Merk')
            ->mapValueFrom(Attribute::ValueFromModel, 'partner_id');


        $attributes[] = (new TextField('Type'))
            ->mapValueFrom(Attribute::ValueFromModel, 'type');


        $attributes[] = (new TextField('Werkbreedte'))
            ->mapValueFrom(Attribute::ValueFromModel, 'working_width');


        $attributes[] = (new TextField('parent_id'))
            ->setValue('1')
            ->setStyleClass('hidden')
            ->mapValueFrom(Attribute::ValueFromItself, 'parent_id');

        $attributes[] = (new Documents())
            ->setLabelText('Afbeelding')
            ->setAccept('image/*')
            ->setMaxDocuments(1)
            ->setSubFolder('machinetypes')
            ->setSmallDragAndDropArea()
            ->setImageProperties([
                (new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Fit)->setHeight(160)->setWidth(160),
                (new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Resize)->setWidth(1024),
            ])
            ->mapValueFrom(Attribute::ValueFromDocuments, 'machinetypes');


        //Return all attributes as a collection
        return collect(array_merge($attributes));
    }


    /**
     * This method will stop the load entities of the kmsSiteSection
     *
     * @return array
     *
     */
    public function loadEntities(){
        return [];
    }
}