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

namespace App\Komma\Pages\Kms;

//The new object oriented attributes
use App\Komma\Components\ComponentType\ComponentTypes;
use App\Komma\Kms\Core\Attributes\Documents;
use App\Komma\Kms\Core\Attributes\ComponentArea;
use App\Komma\Kms\Core\ModelServiceInterface;
use App\Komma\Kms\Core\Sections\Section;
use App\Komma\Kms\Core\Sections\Tabs\Collections\CurrentSiteLanguagesTabs;
use App\Komma\Kms\Core\Sections\Tabs\Collections\NoLanguageTabs;
use App\Komma\Kms\Core\Sections\Tabs\SectionTab;
use App\Komma\Pages\Models\Page;
use App\Komma\Sites\SiteServiceInterface;
use App\Komma\Users\Models\KmsUserRole;
use App\Komma\Kms\Core\Attributes\Attribute;
use App\Komma\Kms\Core\Attributes\Models\ImageProperty;
use App\Komma\Kms\Core\Attributes\OnOff;
use App\Komma\Kms\Core\Attributes\Select;
use App\Komma\Kms\Core\Attributes\Seperator;
use App\Komma\Kms\Core\Attributes\TextArea;
use App\Komma\Kms\Core\Attributes\TextField;
use App\Komma\Kms\Core\Attributes\Title;
use App\Komma\Kms\Core\ValidationSet;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;

final class PageSection extends Section
{
    protected $hasRoutes = true;

    /**
     * PageSection constructor.
     * @param $slug
     */
    function __construct(string $slug)
    {
        $tabs = new NoLanguageTabs();
        $this->siteService = app(SiteServiceInterface::class);
        parent::__construct($tabs, $slug);
    }

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

        $componentTypes = [
            ComponentTypes::TEXT_IMAGE,
            ComponentTypes::DOUBLE_TEXT,
            ComponentTypes::VIDEO,
            ComponentTypes::TEXT,
            ComponentTypes::IMAGE,
            ComponentTypes::SEPARATOR,
            ComponentTypes::NAMED_AREA
        ];

        if(isset($currentModel)) {

            switch ($currentModel->code_name) {
                case 'references';
                    $componentTypes = [
                        ComponentTypes::NAMED_AREA,
                        ComponentTypes::REFERENCE
                    ];
                    break;

                case 'about';
                    $componentTypes[] = ComponentTypes::COLLEAGUES;
                    break;

                case 'caterers';
                    $componentTypes[] = ComponentTypes::STEPS;
                    $componentTypes[] = ComponentTypes::LOGO_SLIDER;
                    break;

                case 'workflow';
                    $componentTypes = [
                        ComponentTypes::NAMED_AREA,
                        ComponentTypes::TEXT_IMAGE,
                        ComponentTypes::TEXT_DOWNLOADS,
                    ];
                    break;
            }
        }


        $languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages([
            (new ComponentArea())
                ->setComponentTypes($componentTypes)
                ->setSubFolder('dynamic_group_sections')
                ->mapValueFrom(Attribute::ValueFromComponentArea, 'dynamic_group_sections'),
        ]);

        return $tabItems->merge(collect($languageIndexedAttributes));
    }

    /**
     * Generate fixed attributes
     *
     * @return Collection
     */
    private function generateFixedAttributes(): Collection
    {
        /** @var ModelServiceInterface $pageModelService */
        $pageModelService = app(ModelServiceInterface::class);
        $pageModelService->setModelClassName(Page::class);

        //*****************************************************************************************\\
        //*** Define attribute validation sets                                                  ***\\
        //*****************************************************************************************\\
        $codeNameValidationSet = (new ValidationSet())
            ->setRules('required')
            ->setMessages(['required' => __('validation.required')]);

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

        //Build the general attributes and put them in the attributes array
        $attributes[] = (new TextField(__('kms/sites.type')))
            ->setValue($this->siteService->getCurrentSite()->name)
            ->setReadOnly(true)
            ->setStyleClass('hidden')
            ->setMinimumUserRole(KmsUserRole::SuperAdmin)
            ->mapValueFrom(Attribute::ValueFromItself, 'site_name');

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

        $pageOptionModels = $pageModelService->getOptionsForSelectAsTree();
        $attributes[] = (new Select())
            ->setItems($pageOptionModels->toArray())
            ->setLabelText(__('kms/pages.parent_page'))
            ->setExcludeCurrentModelItem(true)
            ->setMinimumUserRole(KmsUserRole::SuperAdmin)
            ->mapValueFrom(Attribute::ValueFromItself, 'parent_id');


        //Build an array with attributes for each current site language
        $languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages([

            (new TextField(__('kms/global.title')))
                ->setPlaceholderText(__('kms/global.enterTitle'))
                ->mapValueFrom(Attribute::ValueFromTranslationModel, 'name'),

            (new TextField('Slug'))
                ->setPlaceholderText(__('kms/global.enterUrl'))
                ->setMinimumUserRole(KmsUserRole::SuperAdmin)
                ->mapValueFrom(Attribute::ValueFromTranslationModel, 'slug'),

        ]);

        $attributes = array_merge($attributes, $languageIndexedAttributes);

        $attributes[] = (new Documents())
            ->setLabelText(__('kms/global.header_image'))
            ->onlyAllowImages()
            ->setMaxDocuments(1)
            ->setSubFolder('pages')
            ->setSmallDragAndDropArea()
            ->setImageProperties([
                (new ImageProperty())->setName('thumb')->setCropMethod(ImageProperty::Fit)->setWidth(100),
                (new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Resize)->setWidth(450),
                (new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Resize)->setWidth(1200),
                (new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Resize)->setWidth(2000),
            ])
            ->mapValueFrom(Attribute::ValueFromDocuments, 'pages');

        $attributes[] = (new Seperator());

        //Build an array with attributes for each current site language
        $languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages([

            (new Title('SEO')),

            (new TextField(__('kms/global.metaTitle')))
                ->setPlaceholderText(__('kms/global.enterTitle'))
                ->mapValueFrom(Attribute::ValueFromTranslationModel, 'meta_title'),

            (new TextArea())
                ->setLabelText(__('kms/global.metaDescription'))
                ->setPlaceholderText(__('kms/global.enterMetaDescription'))
                ->mapValueFrom(Attribute::ValueFromTranslationModel, 'meta_description'),
        ]);

        $attributes = array_merge($attributes, $languageIndexedAttributes);

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


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