<?php
/**
 * core.framework
 *
 * @category   Core
 * @package    Core_Form
 * @copyright  Copyright (c) 2011. Burza d.o.o. (http://web.burza.hr/en/)
 * @license    proprietary
 */

/**
 * @category  Core
 * @package   Core_Form
 * @copyright Copyright (c) 2011. Burza d.o.o. (http://web.burza.hr/en/)
 * @license   proprietary
 */
class Core_Form_Element_Multicheckbox extends Core_Form_Element_MultiValue_Collection
{
    /**
     * @var array
     */
    protected $_defaultAttribs = array(
        Core_Form::CONTEXT_DEFAULT => array(),
        Core_Form::CONTEXT_ANGULAR => array('cf-form-element' => 'cf-form-element'),
    );

    protected $_prototypeType = 'checkbox';

    /**
     * @var string
     */
    protected $_template = 'Core/Form/Element/MultiValue/Checkbox.tpl';

    /**
     * @var string
     */
    protected $_macro    = 'element';

    public function populateRaw(array $data)
    {
        $rawValues = array();
        foreach ($data as $item) {
            $rawValues[$item] = $this->getPrototypeInstance()->getCheckedValue();
        }
        parent::populateRaw($rawValues);
    }

    public function getRawValues()
    {
        $rawValues = array();
        $elements  = $this->getElements();
        foreach($elements as $element) {
            if ($element->isChecked()) {
                $rawValues[] = $element->getName();
            }
        }
        return $rawValues;
    }
}
