<?php
goweb::loadClass('Zend_Form_Element_Select');
/**
 * Goweb Sitemanager 5 Framework
 *
 * @version    5.1.3
 * @category   Goweb
 * @package    Goweb_View
 * @subpackage Helper
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2010 (c) Goweb (http://www.goweb.pt)
 */

/**
 *
 * @version    5.1.3
 * @category   Goweb
 * @package    Goweb_View
 * @subpackage Helper
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2010 (c) Goweb (http://www.goweb.pt)
 */
class Goweb_Form_Element_Select extends Zend_Form_Element_Select{
    /**
     * Este metodo adiciona directamente uma opcao es opcoes do select.
     *
     * @param   string  $key     O valor da chave
     * @param   array   $label   O label a ser mostrado
     * @throws  Goweb_Exception  Se o a chave je existir nas opcoes do elemento
     */
    public function addOption($option, $value = '') {
        if (strpos($value, '&') !== false){
            $value = html_entity_decode($value, NULL, CHARSET);
        }
        $this->addMultiOption($option, $value);
    }

    /**
     * Constructor
     *
     */
     public function __construct($spec, $options = null){
         $this->_config['multiple'] = false;
        parent::__construct($spec, $options);
        if (is_array($spec)) {
            if (isset($this->_config['multiple']) && $this->_config['multiple']){
                $this->_isArray = true;
                $this->multiple = 'multiple';
            }
        }
    }

    /**
     * Overloading: set object property
     *
     * @param  string $key
     * @param  mixed $value
     * @return void
     */
    public function __set($key, $value){
        if ($key == 'multiple'){
            $this->_config['multiple'] = $value;
            if (isset($this->_config['multiple']) && $this->_config['multiple']){
                $this->_isArray = true;
                $this->multiple = 'multiple';
            }
        } else {
            return parent::__set($key, $value);
        }
    }
}