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/kommabasic.nl/vendor/komma/kms/src/Core/Sections/Tabs/SectionTab.php
<?php namespace Komma\KMS\Core\Sections\Tabs;

use Illuminate\Support\Str;
use Komma\KMS\Core\Attributes\Attribute;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;

/**
 * Class SectionTab
 *
 * Represents one of the tabs off a section.
 *
 * @package App\Kms\Core\Sections
 */
class SectionTab implements SectionTabInterface
{
    private ?string $name;

    private Collection $items;

    private bool $isLanguageTabTemplate = false;

    /**
     * SectionTab constructor.
     * @param string $name
     */
    public function __construct(string $name = null)
    {
        $this->name = $name;
        $this->items = new Collection();
    }

    /**
     * @return string
     */
    public function getName(): string
    {
        return $this->name;
    }

    /**
     * @return string
     */
    public function getSlug(): string
    {
        return Str::slug($this->name);
    }

    /**
     * @return Collection of SectionTabItems
     */
    public function getItems(): Collection
    {
        return $this->items;
    }

    /**
     * @return SectionTabInterface
     */
    public function clearItems(): SectionTabInterface {
        $this->items = new Collection();
        return $this;
    }

    /**
     * @param $item
     * @return SectionTabInterface
     */
    public function addItem($item):SectionTabInterface
    {
        $this->items->push($item);
        return $this;
    }

//    /**
//     * @param Collection $items
//     * @return SectionTabInterface
//     */
//    public function addItems(Collection $items): SectionTabInterface
//    {
//        $this->items = $this->items->merge($items);
//        return $this;
//    }

    /**
     * @param array $items
     * @return SectionTabInterface
     */
    public function addItems(array $items): SectionTabInterface
    {
        $this->items = $this->items->merge($items);
        return $this;
    }

    /**
     * @param Collection $items
     * @return SectionTabInterface
     */
    public function setItems(Collection $items): SectionTabInterface
    {
        $this->items = $items;
        return $this;
    }

    /**
     * @return bool
     */
    public function isLanguageTabTemplate(): bool
    {
        return $this->isLanguageTabTemplate;
    }

    /**
     * @return SectionTab
     */
    public function markAsLanguageTabTemplate(): SectionTab
    {
        $this->isLanguageTabTemplate = true;
        return $this;
    }

    /**
     * For determining if the tab has an error or not.
     *
     * @param MessageBag $messageBag
     * @return bool
     */
    public function hasErrors(MessageBag $messageBag): bool
    {
        $hasErrors = false;
        $this->items->each(function($item) use(&$hasErrors, $messageBag) {
           if(is_a($item, Attribute::class)) {
               /** @var Attribute $item */
                if($messageBag->has((string) $item->getKey())) {
                    $hasErrors = true;
                }
           }
        });
        return $hasErrors;
    }
}