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

/**
 * Generic elements for date separated by day, month and year.
 *
 * @version    5.1.3
 * @category   Goweb
 * @package    Goweb_Form
 * @subpackage Element
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2010 (c) Goweb (http://www.goweb.pt)
 */
class Goweb_Form_Element_DateSeparated extends Zend_Form_Element_Xhtml {
    /**
     * Mudar o view helper
     * @var string
     */
    public $helper = 'formDateSeparated';

    /**
     * Processes the element, returns the date
     *
     * @return null|string
     */
    public function getValue() {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        $returnValue = '';
        foreach (array($this->getName().'[ano]', $this->getName().'[mes]', $this->getName().'[dia]') as $elementName){
            $returnValue .= isset($post[$elementName]) ? $post[$elementName] . '-' : null; 
        }
        if (strlen($returnValue) > 1 && substr($returnValue, -1) == '-'){
            $returnValue = substr($returnValue, 0, -1);
        }
        return $returnValue;
        
    }
}