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/shop.komma.nl/vendor/komma/kms/src/Core/Sections/Section.php
<?php

namespace Komma\KMS\Core\Sections;

use Komma\KMS\Core\Sections\Tabs\Collections\Tabs;
use Komma\KMS\Core\Sections\Tabs\SectionTab;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Lang;

/**
 * Class Section. Will replace KmsSection
 * @package App\Kms\Core\Sections
 */
abstract class Section
{
    protected Tabs $tabs;
    private string $submitButtonLabel;
    private string $sectionNewModel;
    private string $sectionTitle;
    private string $slug;

    function __construct(string $slug) {
        $this->slug = $slug;
        $this->tabs = new Tabs();
        $this->setSectionText();
    }

    /**
     * @return Tabs
     */
    public function getTabs(): Tabs
    {
        return $this->tabs;
    }

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

    public function getAttributes()
    {
        $attributes = [];
        foreach($this->tabs as $tab){
            /** @var SectionTab $tab */
            $attributes = array_merge($attributes, $tab->getItems()->toArray());
        }

        return collect($attributes);
    }

    /**
     * Set the section text
     */
    public function setSectionText()
    {
        $sectionTranslationFile = 'global';
        if($this->slug != '') $sectionTranslationFile = $this->slug;

        $newModelTranslationKey = $sectionTranslationFile.'.section.new';
        $sectionTitleTranslationKey = $sectionTranslationFile.'.section.title';

//        dd($this->packagePrefix.'kms/'.$sectionTitleTranslationKey);
        $this->setSectionNewModelTranslation(__('KMS::'.$newModelTranslationKey));
        $this->setSectionTitle(__('KMS::'.$sectionTitleTranslationKey));

        if( Lang::has('KMS::'.$sectionTranslationFile.'.section.submitButton')){
            $this->setSubmitButtonLabel(__('KMS::'.$sectionTranslationFile.'.section.submitButton'));
        }
        else {
            $this->setSubmitButtonLabel(__('KMS::global.save'));
        }
    }

    /**
     * @param string $sectionNewModel
     */
    public function setSectionNewModelTranslation(string $sectionNewModel)
    {
        $this->sectionNewModel = $sectionNewModel;
    }

    /**
     * @param string $sectionTitle
     */
    public function setSectionTitle(string $sectionTitle)
    {
        $this->sectionTitle = ucfirst($sectionTitle);
    }

    /**
     * @param string $submitButtonLabel
     */
    public function setSubmitButtonLabel(string $submitButtonLabel)
    {
        $this->submitButtonLabel = $submitButtonLabel;
    }

    /**
     * @return string
     */
    public function getSectionNewModel()
    {
        return $this->sectionNewModel;
    }

    /**
     * @return string
     */
    public function getSectionTitle()
    {
        return $this->sectionTitle;
    }

    /**
     * @return string
     */
    public function getSubmitButtonLabel()
    {
        return $this->submitButtonLabel;
    }
}