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/sdo/sdoschoonmaak.nl/app/KommaApp/Kms/Core/Attributes/KmsFieldGroup.php
<?php

/**
 * Short description for the file.
 *
 * @copyright   (c) 2012-2015, Komma
 */

namespace App\KommaApp\Kms\Core\Attributes;

use App\KommaApp\Kms\Core\KmsFieldGroupRepository;
use App\KommaApp\Kms\Core\Sections\KmsFieldGroupSection;
use App\KommaApp\Kms\Core\Sections\SectionTabsCollection;

class KmsFieldGroup extends KmsAttribute
{

    public $label;
    public $viewName;
    public $viewComposer;
    public $data;
    public $fields;
    public $maxFieldGroups = null;
    public $sortable = false;

    public $itemKey = 0;

    function __construct($key, $value, array $options = [], array $errors = [], $siteId = null, $languageId = null, $section = null, $foreach = null)
    {
        parent::__construct($key, $value, $options, $errors, $siteId, $languageId, $section, $foreach);
        $this->label = $this->getOption('label', $key);
        $this->viewName = $this->getOption('viewName', $key);
        $this->viewComposer = $this->getOption('viewComposer', $key);
        $this->data = $this->getOption('data', $key);
        $this->fields = $this->getOption('fields', $key);
        $this->maxFieldGroups = $this->getOption('max_groups', $key);
        $this->sortable = $this->getOption('sortable', false);

        if ($this->viewComposer)
            \View::composer($this->viewName, $this->viewComposer);
    }

    public function render()
    {
        $kms = $this->section->getKms();

        $tabs = new SectionTabsCollection();
        $repo = new KmsFieldGroupRepository($kms);
        $section = new KmsFieldGroupSection($kms, $repo, $tabs);
        $section->setModelAttributesData($this->fields);
        $section->setKeyAsArray($this->key);

        if (!in_array(get_class($this->value), ['Illuminate\Database\Eloquent\Collection', 'Illuminate\Support\Collection'])) \App::abort(404, 'The FieldGroup value is not an collection');

        $rendered = '';
        foreach ($this->value as $item) {
            $section->setKeyArrayKey($this->itemKey);
            $section->setOrCreateModel($item);
            $rendered .= $this->renderFieldCollection($section);

            $this->itemKey++;
        }


        return \View::make('kms/attributes.fieldGroup', [
            'attribute' => $this,
            'data' => $this->data,
            'fieldGroup' => $rendered
        ])->render();


    }

    private function renderFieldCollection($section)
    {

        return \View::make('kms/attributes.fieldGroupCollection', [
            'attribute' => $this,
            'data' => $this->data,
            'fieldGroup' => $section
        ]);
    }

    public function renderEmptyFieldCollection()
    {
        $kms = $this->section->getKms();
        $tabs = new SectionTabsCollection();
        $repo = new KmsFieldGroupRepository($kms);
        $section = new KmsFieldGroupSection($kms, $repo, $tabs);

        $section->setModelAttributesData($this->fields);
        $section->setKeyAsArray($this->key);
        $section->setKeyArrayKey('itemKey');
        return $this->renderFieldCollection($section);

    }

}