<?php
/**
 * EvaEngine
 *
 * @link      https://github.com/AlloVince/eva-engine
 * @copyright Copyright (c) 2012 AlloVince (http://avnpc.com/)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 * @author    AlloVince
 */

namespace Group\Form;

/**
 * Eva Form will automatic combination form Elements & Validators & Filters
 * Also allow add sub forms and unit validate
 * 
 * @category   Eva
 * @package    Eva_Form
 */
class GroupForm extends \Eva\Form\Form
{
    /**
     * Form basic elements
     *
     * @var array
     */
    protected $mergeElements = array (
        'id' => array (
            'name' => 'id',
            'type' => 'hidden',
            'options' => array (
                'label' => 'Id',
            ),
            'attributes' => array (
                'value' => '',
            ),
        ),
        'groupKey' => array (
            'name' => 'groupKey',
            'type' => 'text',
            'options' => array (
                'label' => 'Group Key',
            ),
            'attributes' => array (
                'value' => '',
            ),
        ),
        'groupName' => array (
            'name' => 'groupName',
            'type' => 'text',
            'options' => array (
                'label' => 'Group Name',
            ),
            'attributes' => array (
                'value' => '',
            ),
        ),
        'status' => array (
            'name' => 'status',
            'type' => 'select',
            'options' => array (
                'label' => 'Status',
                'value_options' => array (
                    'active' => array (
                        'label' => 'Active',
                        'value' => 'active',
                    ),
                    'pending' => array (
                        'label' => 'Pending',
                        'value' => 'pending',
                    ),
                    'deleted' => array (
                        'label' => 'Deleted',
                        'value' => 'deleted',
                    ),
                ),
            ),
            'attributes' => array (
            ),
        ),
        'summary' => array (
            'name' => 'summary',
            'type' => 'text',
            'options' => array (
                'label' => 'Summary',
            ),
            'attributes' => array (
                'value' => '',
            ),
        ),
        'memberLimit' => array (
            'name' => 'memberLimit',
            'type' => 'text',
            'options' => array (
                'label' => 'Member Limit',
            ),
            'attributes' => array (
                'value' => '0',
            ),
        ),
        'memberEnable' => array (
            'name' => 'memberEnable',
            'type' => 'select',
            'options' => array (
                'label' => 'Allow Join',
                'value_options' => array (
                    '0' => array (
                        'label' => 'Disable',
                        'value' => 0,
                    ),
                    '1' => array (
                        'label' => 'Enable',
                        'value' => 1,
                    ),
                ),
            ),
            'attributes' => array (
                'value' => 1,
            ),
        ),

        'flag' => array (
            'name' => 'flag',
            'type' => 'text',
            'options' => array (
                'label' => 'Flag',
            ),
            'attributes' => array (
                'value' => '',
            ),
        ),
    );

    /**
     * Form basic Validators
     *
     * @var array
     */
    protected $mergeFilters = array (
        'id' => array (
            'name' => 'id',
            'required' => false,
            'filters' => array (
            ),
            'validators' => array (
                'notEmpty' => array (
                    'name' => 'NotEmpty',
                    'options' => array (
                    ),
                ),
            ),
        ),
        'groupKey' => array (
            'name' => 'groupKey',
            'required' => false,
            'filters' => array (
                'stripTags' => array (
                    'name' => 'StripTags',
                ),
                'stringTrim' => array (
                    'name' => 'StringTrim',
                ),
            ),
            'validators' => array (
                'notEmpty' => array (
                    'name' => 'NotEmpty',
                    'options' => array (
                    ),
                ),
                'stringLength' => array (
                    'name' => 'StringLength',
                    'options' => array (
                        'max' => '100',
                    ),
                ),
            ),
        ),
        'groupName' => array (
            'name' => 'groupName',
            'required' => false,
            'filters' => array (
                'stripTags' => array (
                    'name' => 'StripTags',
                ),
                'stringTrim' => array (
                    'name' => 'StringTrim',
                ),
            ),
            'validators' => array (
                'notEmpty' => array (
                    'name' => 'NotEmpty',
                    'options' => array (
                    ),
                ),
                'stringLength' => array (
                    'name' => 'StringLength',
                    'options' => array (
                        'max' => '100',
                    ),
                ),
            ),
        ),
        'status' => array (
            'name' => 'status',
            'required' => false,
            'filters' => array (
            ),
            'validators' => array (
                'notEmpty' => array (
                    'name' => 'NotEmpty',
                    'options' => array (
                    ),
                ),
                'inArray' => array (
                    'name' => 'InArray',
                    'options' => array (
                        'haystack' => array (
                            'active',
                            'pending',
                            'deleted',
                        ),
                    ),
                ),
            ),
        ),
        'summary' => array (
            'name' => 'summary',
            'required' => false,
            'filters' => array (
                'stripTags' => array (
                    'name' => 'StripTags',
                ),
                'stringTrim' => array (
                    'name' => 'StringTrim',
                ),
            ),
            'validators' => array (
                'notEmpty' => array (
                    'name' => 'NotEmpty',
                    'options' => array (
                    ),
                ),
                'stringLength' => array (
                    'name' => 'StringLength',
                    'options' => array (
                        'max' => '255',
                    ),
                ),
            ),
        ),
        'memberLimit' => array (
            'name' => 'memberLimit',
            'required' => false,
            'filters' => array (
            ),
            'validators' => array (
            ),
        ),
        'memberEnable' => array (
            'name' => 'memberEnable',
            'required' => false,
            'filters' => array (
            ),
            'validators' => array (
            ),
        ),
    );

    public function getLanguages($element)
    {
        $translator = \Eva\Api::_()->getServiceManager()->get('translator');
        $locale = $translator->getLocale();
        $languages = \Eva\Locale\Data::getList($locale, 'language');
        $element['options']['value_options'] = $languages;
        $element['attributes']['value'] = $locale;
        return $element;
    }
}
