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/medvalue.komma.pro/app/KommaApp/Kms/Core/Sections/KmsSectionSubTab.php
<?php namespace App\KommaApp\Kms\Core\Sections;

use Illuminate\Support\MessageBag;


class KmsSectionSubTab implements KmsSectionSubTabInterface
{

    protected $name;
    protected $slug;

    protected $items;
    protected $subTabs = [];

    public function __construct($name, $slug)
    {
        $this->items = [];
        $this->name = $name;
        $this->slug = $slug;
    }

    public function getName()
    {
        return $this->name;
    }

    public function getSlug()
    {
        return $this->slug;
    }

    public function addItem(&$item)
    {
        $this->items[] = $item;
    }

    public function getItems()
    {
        $items = [];
        foreach ($this->items as $item) {
            if ($item->checkIfUserIsEligible(\Auth::user()))
                $items[] = $item;
        }
        return $items;
    }

    public function hasErrors(MessageBag $errors)
    {
        foreach ($this->items as $item) {
            if ($errors->get($item->getKey())) return true;
        }
        return false;
    }

    public function getOrCreateSubTab($name)
    {
        if (!$tab = $this->getSubTabBySlug($name)) {
            return $this->subTabs[] = new KmsSectionSubTab($name, $name);
        }

        return $tab;
    }

    protected function getSubTabBySlug($slug)
    {
        foreach ($this->subTabs as $tab) {
            if ($tab->getSlug() == $slug) return $tab;
        }
        return null;
    }

    public function hasTabs()
    {
        return (count($this->subTabs) > 0);
    }

    public function getTabs()
    {
        return $this->subTabs;
    }

}