X-Git-Url: https://git.llucax.com/mecon/meconlib.git/blobdiff_plain/12c3b7e967b107891284467e01c4e941223b29fe..491e3ed8d9646fc86ccbf3ed9ed1593faedbe167:/lib/MECON/HTML/QuickForm/mdate.php diff --git a/lib/MECON/HTML/QuickForm/mdate.php b/lib/MECON/HTML/QuickForm/mdate.php index 2697234..3c28d14 100644 --- a/lib/MECON/HTML/QuickForm/mdate.php +++ b/lib/MECON/HTML/QuickForm/mdate.php @@ -1,31 +1,28 @@ - +------------------------------------------------------------------------------- +$Id$ +-----------------------------------------------------------------------------*/ require_once 'HTML/QuickForm/date.php'; require_once 'Date.php'; @@ -36,8 +33,7 @@ require_once 'Validate.php'; * Modificado para que cumpla con los requisitos de mecon * */ -class HTML_QuickForm_mdate extends HTML_QuickForm_date -{ +class MECON_HTML_QuickForm_mdate extends HTML_QuickForm_date { // {{{ constructor /** @@ -50,45 +46,38 @@ class HTML_QuickForm_mdate extends HTML_QuickForm_date * @access public * @return void */ - function HTML_QuickForm_mdate($elementName=null, $elementLabel=null, $options=array(), $attributes=null) - { - $this->_options = array ('es' => array ( - 'weekdays_short'=> array ('--' => '--', 'Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'), - 'weekdays_long' => array ('--' => '--', 'Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'), - 'months_short' => array ('--' => '--', 'Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'), - 'months_long' => array ('--' => '--', 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septimbre', 'Octubre', 'Noviembre', 'Diciembre') - ) - ); - - parent::HTML_QuickForm_date($elementName, $elementLabel, $options, $attributes); + function MECON_HTML_QuickForm_mdate($elementName=null, $elementLabel=null, $options=array(), $attributes=null) { + $this->_locale = array ('es' => array ( + 'weekdays_short'=> array ('' => '--', 'Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'), + 'weekdays_long' => array ('' => '--', 'Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'), + 'months_short' => array ('' => '--', 'Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'), + 'months_long' => array ('' => '--', + 'Enero', 'Febrero', 'Marzo', + 'Abril', 'Mayo', 'Junio', + 'Julio', 'Agosto', 'Septiembre', + 'Octubre', 'Noviembre', 'Diciembre') + ) + ); + parent::HTML_QuickForm_date($elementName, $elementLabel, + array_merge(array('language'=>'es','format'=>'d F Y'), $options), + $attributes); } //end constructor - // }}} - // {{{ _createNumericOptionList() - - /** - * Creates a numeric option list based on a start number and end number - * - * @param int $start The start number - * @param int $end The end number - * - * @access public - * @return array An array of numeric options. - */ - function _createNumericOptionList($start, $end) - { - $options = array(); - //TODO - //Verificar que esto este funcionando bien. - $options['--'] = '--'; - //Hasta aca - for ($i = $start; $i <= $end; $i++) { + /** + * Creates an option list containing the numbers from the start number to the end, inclusive + * + * @param int The start number + * @param int The end number + * @param int Increment by this value + * @access private + * @return array An array of numeric options. + */ + function _createOptionList($start, $end, $step = 1) { + for ($i = $start, $options = array('' => '--'); $start > $end? $i >= $end: $i <= $end; $i += $step) { $options[$i] = sprintf('%02d', $i); } - return $options; - - } // end func _createNumericOptionList + } // end func _createOptionList /** * Devuelve un objeto date @@ -97,12 +86,16 @@ class HTML_QuickForm_mdate extends HTML_QuickForm_date * @access public * @return object Date. */ - function &getValue() - { - if ($this->_selectedDate['Y'] != 00) { - return new Date (sprintf("%04d-%02d-%02d 00:00:00",$this->_selectedDate['Y'],$this->_selectedDate['F'],$this->_selectedDate['d'])); - } - else { + function &getValue() { + + $date = parent::getValue(); + + if ($date['Y'][0]) { + return new Date (@sprintf("%04d-%02d-%02d %02d:%02d:00", + $date['Y'][0], $date['F'][0], + $date['d'][0], $date['H'][0], + $date['i'][0])); + } else { return null; } } // end func getValue @@ -116,14 +109,21 @@ class HTML_QuickForm_mdate extends HTML_QuickForm_date * @access public * @return bool */ - function validate($valor, $nombre, $formato = '') - { - $str = sprintf ("%4d-%02d-%02d",$valor['Y'],$valor['F'],$valor['d']); - - if ($valor['Y'] != '--' && $valor['d'] != '--' && $valor['F'] != '--') { + function validate($valor, $nombre, $formato = '') { + // Si viene completamente lleno, se valida con el paquete Validate + if ($valor['Y'] and $valor['d'] and $valor['F']) { + $str = sprintf('%4d-%02d-%02d', $valor['Y'], $valor['F'], $valor['d']); return Validate::date($str, array('format' => '%Y-%m-%d')); + // Si viene completamente vacio, es valido. + } + elseif (!$valor['Y'] and !$valor['d'] and !$valor['F']) { + return true; + // Si viene a medio completar, es invalido. + } + else { + return false; } - return true; } // end func validate } + ?>