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/fire-tech/fire-tech.nl/app/KommaApp/Students/Kms/StudentSection.php
<?php
/**
 *
 *
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma
 */

namespace App\KommaApp\Students\Kms;

//The new object oriented attributes
use App\KommaApp\Courses\Kms\CourseService;
use App\KommaApp\Kms\Core\Attributes\AutocompleteInput;
use App\KommaApp\Kms\Core\Attributes\DatePicker;
use App\KommaApp\Kms\Core\Attributes\Models\SelectOption;
use App\KommaApp\Kms\Core\Attributes\OnOff;
use App\KommaApp\Kms\Core\Attributes\Select;
use App\KommaApp\Kms\Core\Attributes\View;
use App\KommaApp\Kms\Core\Sections\NoLanguageTabsDirector;
use App\KommaApp\Routes\RouteService;
use App\KommaApp\Kms\Core\Attributes\Attribute;
use App\KommaApp\Kms\Core\Attributes\TextField;

use App\KommaApp\Kms\Core\Attributes\Title;
use App\KommaApp\Kms\Core\Kms;
use App\KommaApp\Kms\Core\Sections\SectionTabGroups;
use App\KommaApp\Kms\Core\Sections\SectionTabItem;
use App\KommaApp\Kms\Core\Sections\SectionTabsBuilder;
use App\KommaApp\Kms\Core\Sections\SiteSection;
use App\KommaApp\Kms\Core\ValidationSet;
use App\KommaApp\Students\Models\Student;
use App\KommaApp\Subscriptions\Kms\SubscriptionService;
use App\KommaApp\Subscriptions\Models\Subscription;
use Illuminate\Database\Eloquent\Collection;

class StudentSection extends SiteSection
{
    protected $title = "Deelnemers";
    protected $subTitle = "Alle deelnemers";
    protected $slug = "students";
    protected $hasRoutes = false;

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

    /** @var CourseService $courseService */
    private $subscriptionService;

    /**
     * StudentSection constructor.
     * @param Kms $kms
     * @param StudentService $sectionService
     * @param RouteService $routeService
     */
//    function __construct(Kms $kms, StudentRepository $repository)
    function __construct(StudentService $sectionService, RouteService $routeService)
    {
        $this->subscriptionService = (new SubscriptionService());

        $sectionTabDirector = new NoLanguageTabsDirector(new SectionTabsBuilder()); //Can make tabs for us. also see KmsSection::__construct
        parent::__construct($sectionService, $routeService, $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 StudentRepository::saveModel()
     * @return Collection A collection of SectionTabItems
     */
    protected function generateAttributes(): Collection
    {
//        \Log::info("StudentSection::Generating attributes");

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

        $emailValidationSet = (new ValidationSet())
            ->setRules('required|email')
            ->setMessages([
                'required' => __('validation.required'),
                'email' => __('validation.email')
            ]);

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

        /** @var Student $student */
        $student = $this->getModel();
        $subscriptions = $student->subscriptions()->get();

        $viewData = [
            'subscriptions' => $subscriptions,
        ];

        //Build the general attributes and put them in the attributes array
        $attributes[] = (new Title(__('kms/students.student')));

        $attributes[] = (new TextField(__('site/form.company.label')))
            ->setPlaceholderText(__('kms/students.enterCompany'))
            ->mapValueFrom(Attribute::ValueFromModel, 'company');

        $attributes[] = (new TextField(__('site/form.student_name.label')))
            ->setPlaceholderText(__('kms/students.enterName'))
            ->mapValueFrom(Attribute::ValueFromModel, 'name');

        $attributes[] = (new TextField(__('kms/global.email')))
            ->setPlaceholderText(__('kms/global.enterEmail'))
            ->setValidationSet($emailValidationSet)
            ->mapValueFrom(Attribute::ValueFromModel, 'email');

        $attributes[] = (new DatePicker(__('kms/subscriptions.birthdate')))
            ->setTimeEnabled(false)
            ->mapValueFrom(Attribute::ValueFromModel, 'birthdate');

        $genders = [
            (new SelectOption())->setContent('onbekend')->setHtmlContent('onbekend')->setValue(null),
            (new SelectOption())->setContent('man')->setHtmlContent('man')->setValue('man'),
            (new SelectOption())->setContent('vrouw')->setHtmlContent('vrouw')->setValue('vrouw'),
        ];
        $attributes[] = (new Select())
            ->setItems($genders)
            ->setLabelText(__('kms/subscriptions.gender'))
            ->mapValueFrom(Attribute::ValueFromModel, 'gender');

        $vcaChoices = [
            (new SelectOption())->setContent('onbekend')->setHtmlContent('onbekend')->setValue(null),
            (new SelectOption())->setContent('VCA-Basis')->setHtmlContent('VCA-Basis')->setValue('VCA-Basis'),
            (new SelectOption())->setContent('VCA-Vol')->setHtmlContent('VCA-Vol')->setValue('VCA-Vol'),
        ];
        $attributes[] = (new Select())
            ->setItems($vcaChoices)
            ->setLabelText(__('kms/subscriptions.vca'))
            ->mapValueFrom(Attribute::ValueFromModel, 'vca');

        $attributes[] = (new Title('Inschrijvingen:'));
        $attributes[] = (new View('kms.partials.student_subscriptions'))
            ->setViewData($viewData);


        //Build an array with attributes for each current site language
        $languageIndexedAttributes = $this->createAttributesFromExistingAttributeForCurrentSiteLanguages([
//            (new Title(__('kms/global.information'))),
        ]);

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

    public function getModelTitle()
    {
        //If there is an title set use this
        if ($this->getModel() && $this->getModel()->exists && ($this->getModel()->title || $this->getModel()->title != "")) {
            return $this->getModel()->title;
        }

        return ucfirst(\Lang::get('kms'.DIRECTORY_SEPARATOR.'global.new_plural')) . ' ' . lcfirst(__('kms/students.student'));
    }
}