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

namespace App\KommaApp\Questions\Kms;

//The new object oriented attributes
use App\KommaApp\Kms\Core\Sections\Section;
use App\KommaApp\Questions\Models\QuestionTranslation;
use App\KommaApp\Routes\RouteService;
use App\KommaApp\Sites\SiteServiceInterface;
use App\KommaApp\Kms\Core\Attributes\Attribute;
use App\KommaApp\Kms\Core\Attributes\OnOff;
use App\KommaApp\Kms\Core\Attributes\TextField;
use App\KommaApp\Kms\Core\Sections\CurrentSiteLanguagesTabsDirector;
use App\KommaApp\Kms\Core\Sections\SectionTabGroups;
use App\KommaApp\Kms\Core\Sections\SectionTabItem;
use App\KommaApp\Kms\Core\Sections\SectionTabsBuilder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;


class QuestionSection extends Section
{
    protected $slug = "questions";

    public $showSave = 'all';
    public $showDelete = 'all';
    public $showCreate = 'all';

    /**
     * QuestionSection constructor.
     * @param QuestionService $sectionService
     * @param RouteService $routeService
     * @param SiteServiceInterface $siteService
     */
    function __construct(QuestionService $sectionService, RouteService $routeService, SiteServiceInterface $siteService)
    {
        $sectionTabDirector = new CurrentSiteLanguagesTabsDirector(new SectionTabsBuilder());
        parent::__construct($sectionService, $routeService, $siteService, $sectionTabDirector);
    }

    /**
     * Generates the attributes for this section. They all must extend the App\KommaApp\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 QuestionRepository::saveModel()
     * @return Collection A collection of SectionTabItems
     */
    protected function generateAttributes(): Collection
    {
        /** @var Model $model */
        $model = $this->loadModel($this->getModel());

        //*****************************************************************************************\\
        //*** Define attribute validation sets                                                  ***\\
        //*****************************************************************************************\\


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

        //Build the general attributes and put them in the attributes array

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

        //Build an array with attributes for each current site language
        $languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages([
            (new TextField('Vraag'))
                ->setLabelText('Vraag')
                ->mapValueFrom(Attribute::ValueFromTranslationModel, 'name'),

            (new TextField('Antwoord'))
                ->setLabelText('Antwoord')
                ->mapValueFrom(Attribute::ValueFromTranslationModel, 'description'),
        ]);



        //****************************************************************************************************************************************\\
        //*** 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;
    }
}