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

namespace App\QuestionCategories\Kms;

//The new object oriented attributes
use App\Base\SectionWithSiteLogic;
use App\QuestionCategories\Models\QuestionCategory;
use App\Questions\Kms\QuestionService;
use App\SteLanguages\Models\SteLanguage;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Komma\KMS\Core\Attributes\Attribute;
use Komma\KMS\Core\Attributes\MultiSelect;
use Komma\KMS\Core\Attributes\OnOff;
use Komma\KMS\Core\Attributes\Select;
use Komma\KMS\Core\Attributes\TextField;
use Komma\KMS\Core\ModelServiceInterface;
use Komma\KMS\Core\Sections\Tabs\Collections\AllUsedLanguagesTabs;
use Komma\KMS\Users\Models\KmsUserRole;

final class QuestionCategorySection extends SectionWithSiteLogic
{

    /**
     * PageSection constructor.
     * @param $slug
     */
//    function __construct(Kms $kms, PageRepository $repository)
    function __construct($slug)
    {
        $tabs = new AllUsedLanguagesTabs();
        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 PageRepository::saveModel()
     * @param Model $currentModel
     * @return Collection A collection of SectionTabItems
     */
    protected function generateAttributes(Model $currentModel = null): Collection
    {
//        \Log::info("PageSection::Generating attributes");

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

        /** @var ModelServiceInterface $steLanguageModelService */
        $steLanguageModelService = app(ModelServiceInterface::class);
        $steLanguageModelService->setModelClassName(QuestionCategory::class);
        $attributes[] = (new Select())
            ->setItems($steLanguageModelService->getOptionsForSelectAsTree()->toArray())
            ->setLabelText(__('kms/pages.parent_page'))
            ->setExcludeCurrentModelItem(true)
            ->setStyleClass('hidden')
            ->mapValueFrom(\App\Attributes\Attribute::ValueFromItself, 'parent_id');

        //Build the general attributes and put them in the attributes array
        $attributes[] = (new OnOff())
            ->setLabelText(__('kms/global.active'))
            ->switchOn()
            ->mapValueFrom(Attribute::ValueFromModel, 'active');

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

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

        /** @var ModelServiceInterface $questionService */
        $questionService = app(QuestionService::class);

        $attributes[] = (new MultiSelect())
            ->setItems($questionService->getOptionsForSelect()->toArray())
            ->setLabelText(__('kms/question_categories.questions'))
            ->enableSortable()
            ->mapValueFrom(Attribute::ValueFromModelHasManyRelation, 'questions|id');

        $languageIndexedAttributes = $this->createAttributesFromExistingAttributeForAllUsedLanguagesBySites([
            (new TextField(__('kms/global.title')))
                ->setPlaceholderText(__('kms/global.enterTitle'))
                ->mapValueFrom(Attribute::ValueFromTranslationModel, 'name'),
        ]);

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

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

}