<?php
// Copyright (c) MetaClass Groningen, 2014-2015

namespace VisualM\ManagementBundle\Form;


class Fieldset {

    public $name, $label, $formNames, $template;
    /** @var string translation_domain */
    public $translationDomain;

    /**
     * Fieldset constructor.
     * @param string $name
     * @param string|null $label defaults to $name
     * @param array $formNames with names of the form elements to be included int the fieldset
     * @param string|null $template
     * @param string|null $translationDomain
     */
    public function __construct($name, $label=null, $formNames=array(), $template=null, $translationDomain=null)
    {
        $this->name = $name;
        $this->label = $label;
        $this->formNames = $formNames;
        $this->template = $template;
        $this->translationDomain = $translationDomain;
    }

    public function addFormName($value, $key=null)
    {
        if ($key === null) {
            $this->formNames[] = $value;
        } else {
            $this->formNames[$key] = $value;
        }
        return $this;
    }

    public function hasFormName($name)
    {
        return in_array($name, $this->formNames);
    }

    /**
     * @param string|null $default
     * @return string $this->translationDomain or $default
     */
    public function getTranslationDomain($default=null)
    {
        return null === $this->translationDomain
            ? $default
            : $this->translationDomain;
    }
} 