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/stafa/stafa.nl/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\Buttons\Kms\ButtonService;
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\Attributes\MultiSelect;
use App\Komma\Kms\Core\Sections\Section;
use App\Komma\Routes\RouteService;
use App\Komma\Servicepoints\Kms\ServicepointService;
use App\Komma\Servicepoints\Models\Servicepoint;
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\Sections\CurrentSiteLanguagesTabsDirector;
use App\Komma\Kms\Core\Sections\SectionTabGroups;
use App\Komma\Kms\Core\Sections\SectionTabItem;
use App\Komma\Kms\Core\Sections\SectionTabsBuilder;
use App\Komma\Kms\Core\ValidationSet;
use Illuminate\Database\Eloquent\Collection;

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

    public $showSave = 'all';
    public $showDelete = [1];
    public $showCreate = [1];

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

    /**
     * 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.
     *
     * @return Collection A collection of SectionTabItems
     * @throws \Exception
     * @see PageRepository::saveModel()
     */
    protected function generateAttributes(): Collection
    {
        $fixedAttributeTabItems = $this->generateFixedAttributes();
        $tabItems = $fixedAttributeTabItems;

        $languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages([
            (new ComponentArea())
                ->setComponentTypes([
                    ComponentTypes::TEXT,
                    ComponentTypes::DOUBLE_TEXT,
                    ComponentTypes::VIDEO,
                    ComponentTypes::IMAGE,
                    ComponentTypes::TEXT_IMAGE,
                    ComponentTypes::TEXT_HEX_IMAGE,
                    ComponentTypes::TESTIMONIAL,
//                    ComponentTypes::IMAGE_SLIDER,
                    ComponentTypes::DOUBLE_DOWNLOADS,
                ])
                ->setSubFolder('dynamic_group_sections')
                ->mapValueFrom(Attribute::ValueFromComponentArea, 'dynamic_group_sections'),
        ]);

        foreach ($languageIndexedAttributes as $attribute) {
            $tabItems->push(new SectionTabItem($attribute, SectionTabGroups::Languages));
        }

        return $tabItems;
    }

    /**
     * Generate fixed attributes
     *
     * @return Collection
     */
    private function generateFixedAttributes(): Collection
    {

        /** @var Page $model */
        $model = $this->getModel();

        /** @var PageService $pageService */
        $pageService = $this->getSectionService();

        //*****************************************************************************************\\
        //*** 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 Title(__('kms/sites.type')));
        $attributes[] = (new TextField(__('kms/sites.type')))
            ->setReadOnly(true)
            ->mapValueFrom(Attribute::ValueFromItself, 'site_name');

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

        $attributes[] = (new Title(__('kms/pages.page')));

//        $attributes[] = (new Video('Youtube'));

        $attributes[] = (new TextField(__('kms/global.codeName')))
            ->setPlaceholderText(__('kms/global.enterCodeName'))
            ->setMinimumUserRole(KmsUserRole::SuperAdmin)
            ->setReadOnly(false)
            ->mapValueFrom(Attribute::ValueFromModel, 'code_name')
            ->setValidationSet($codeNameValidationSet);

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

        $pageOptionModels = $pageService->getOptionsForSelect();
        $attributes[] = (new Select())
            ->setItems($pageOptionModels->toArray())
            ->setLabelText(__('kms/pages.parent_page'))
            ->setExcludeCurrentModelItem(true)
            ->mapValueFrom(Attribute::ValueFromModel, 'parent_id');

        // Image used in hero
        // !! Make sure sizes are the same as in HTML srcset 'w' descriptor !!!
        $attributes[] = (new Documents())
            ->setLabelText(__('kms/global.images'))
//            ->onlyAllowImages()
            ->setMaxDocuments(5)
            ->setSmallDragAndDropArea()
            ->setSubFolder('pages')
            ->setImageProperties([
                (new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Fit)->setWidth(360)->setHeight(416),
                (new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Fit)->setWidth(468)->setHeight(541),
                (new ImageProperty())->setName('large')->setCropMethod(ImageProperty::Fit)->setWidth(576)->setHeight(666),
            ])
            ->mapValueFrom(Attribute::ValueFromDocuments, 'pages');


        // Intro text section only visible on homepage
        if (in_array($model->code_name, ['about','jobs'])) {
            $attributes[] = (new Seperator());
            $attributes[] = (new Title(__('kms/global.imageslider')));
            // Image used in imageslider
            // !! Make sure sizes are the same as in HTML srcset 'w' descriptor !!!
            $attributes[] = (new Documents())
                ->onlyAllowImages()
                ->setSmallDragAndDropArea()
                ->setMaxDocuments(15)
                ->setSubFolder('imageslider')
                ->setImageProperties([
                    (new ImageProperty())->setName('small')->setCropMethod(ImageProperty::Resize)->setHeight(275),
                    (new ImageProperty())->setName('medium')->setCropMethod(ImageProperty::Resize)->setHeight(400),
                ])
                ->mapValueFrom(Attribute::ValueFromDocuments, 'imageslider');
        }


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

        $buttonsService = \App::make(ButtonService::class);
        $buttonModels = $buttonsService->getOptionsForSelect();

        $languageAttributes = [
            (new Title(__('kms/global.information'))),

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

            (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'),

            (new Seperator()),

            (new Title(__('kms/global.hero'))),

            (new TextField(__('kms/global.heroTitle')))
                ->mapValueFrom(Attribute::ValueFromTranslationModel, 'hero_title'),

            (new TextArea())
                ->setLabelText(__('kms/global.heroDescription'))
                ->mapValueFrom(Attribute::ValueFromTranslationModel, 'hero_description'),

            (new MultiSelect())
                ->setItems($buttonModels->toArray())
                ->setLabelText(__('kms/global.button'))
                ->setMaxItemsToSelect(1)
                ->mapValueFrom(Attribute::ValueFromTranslationModel, 'hero_button_id'),
        ];


        // Intro text section only visible on homepage
        if ($model->code_name == 'home') {
            $languageAttributes[] = (new Seperator());

            $languageAttributes[] = (new Title(__('kms/global.information')));

            $languageAttributes[] = (new TextField(__('kms/global.title')))
                ->mapValueFrom(Attribute::ValueFromTranslationModel, 'intro_title');

            $languageAttributes[] = (new TextArea())
                ->setLabelText(__('kms/global.introText'))
                ->mapValueFrom(Attribute::ValueFromTranslationModel, 'intro_text');

            $languageAttributes[] = (new MultiSelect())
                ->setItems($buttonModels->toArray())
                ->setLabelText(__('kms/global.introButton'))
                ->setMaxItemsToSelect(1)
                ->mapValueFrom(Attribute::ValueFromTranslationModel, 'intro_button_id');
        }

        // Servicepoint only on some pages
        if (in_array($model->code_name, ['home', 'services', 'projects', 'webshop'])) {
            $languageAttributes[] = (new Seperator());

            $languageAttributes[] = (new Title(__('kms/global.CtaServicepoints')));

            // Pick a servicepoint per language on the homepage
            // servicepoint_id gets re-used for this, but is shown in the CTA row
            $languageAttributes[] = (new MultiSelect())
                ->setItems($servicepointOptions->toArray())
                ->setLabelText(__('kms/global.CtaServicepoints'))
                ->setMaxItemsToSelect(1)
                ->canBeLinkedWith(Servicepoint::class)
                ->mapValueFrom(Attribute::ValueFromTranslationModel, 'servicepoint_id');

        }


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

        //****************************************************************************************************************************************\\
        //*** 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 ($attributes as $attribute) {
            $tabItems->push(new SectionTabItem($attribute, SectionTabGroups::General));
        }
        foreach ($languageIndexedAttributes as $attribute) {
            $tabItems->push(new SectionTabItem($attribute, SectionTabGroups::Languages));
        }

        return $tabItems;
    }


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