SVN Alba r4347 - in prosistem/alba/trunk/alba/apps/principal: lib modules/horarioescolar/templates modules/horarioescolar/validate modules/turnos/validate
Author: josx Date: 2007-02-28 18:19:57 -0300 (Wed, 28 Feb 2007) New Revision: 4347 Added: prosistem/alba/trunk/alba/apps/principal/lib/albaHorasValidator.class.php Modified: prosistem/alba/trunk/alba/apps/principal/lib/albaCUITValidator.class.php prosistem/alba/trunk/alba/apps/principal/modules/horarioescolar/templates/_turnos_select.php prosistem/alba/trunk/alba/apps/principal/modules/horarioescolar/validate/edit.yml prosistem/alba/trunk/alba/apps/principal/modules/turnos/validate/edit.yml Log: Agregue validacion para fk_turnos_id en horarioescolar, validadcion para horas en turnos y horarioescolar Modified: prosistem/alba/trunk/alba/apps/principal/lib/albaCUITValidator.class.php =================================================================== --- prosistem/alba/trunk/alba/apps/principal/lib/albaCUITValidator.class.php 2007-02-28 20:20:23 UTC (rev 4346) +++ prosistem/alba/trunk/alba/apps/principal/lib/albaCUITValidator.class.php 2007-02-28 21:19:57 UTC (rev 4347) @@ -22,8 +22,8 @@ * albaCUITValidator Valida el CUIT * * @package alba - * @author H�ctor Sanchez <[email protected]> - * @author Jos� Luis Di Biase <[email protected]> + * @author Héctor Sanchez <[email protected]> + * @author José Luis Di Biase <[email protected]> * @author Fernando Toledo <[email protected]> * @version SVN: $Id$ * @filesource Added: prosistem/alba/trunk/alba/apps/principal/lib/albaHorasValidator.class.php =================================================================== --- prosistem/alba/trunk/alba/apps/principal/lib/albaHorasValidator.class.php 2007-02-28 20:20:23 UTC (rev 4346) +++ prosistem/alba/trunk/alba/apps/principal/lib/albaHorasValidator.class.php 2007-02-28 21:19:57 UTC (rev 4347) @@ -0,0 +1,144 @@ +<?php + +/** + * This file is part of Alba. + * + * Alba is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Alba is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Alba; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +/** + * Validador de Horas + * + * @package alba + * @author José Luis Di Biase <[email protected]> + * @author Héctor Sanchez <[email protected]> + * @author Fernando Toledo <[email protected]> + * @version SVN: $Id$ + * @filesource + * @license GPL + */ + +class albaHorasValidator extends sfValidator +{ + /** + * Execute this validator. + * + * @param mixed A file or parameter value/array. + * @param error An error message reference. + * + * @return bool true, if this validator executes successfully, otherwise false. + */ + public function execute (&$value, &$error) + { + + $value1 = $this->getValidHour($value); + if (!$value1) + { + $error = $this->getParameter('hora_error'); + return false; + } + + // Is there a compare to do? + $compareHourParam = $this->getParameter('compare'); + $compareHour = $this->getContext()->getRequest()->getParameter($compareHourParam); + + // If the compare date is given + if ($compareHour) + { + $operator = trim($this->getParameter('operator', '=='), '\'" '); + $value2 = $this->getValidHour($compareHour); + + +// print_R($value); +// echo "<br>"; +// print_R($value1); +// echo "<br>";echo "<br>"; +// print_R($compareHour); +// echo "<br>"; +// print_R($value2); +// echo "<br>";echo "<br>"; +// die; + + + + // If the check date is valid, compare it. Otherwise ignore the comparison + if ($value2) + { + $valid = false; + switch ($operator) + { + case '>': + $valid = $value1 > $value2; + break; + case '>=': + $valid = $value1 >= $value2; + break; + case '==': + $valid = $value1 == $value2; + break; + case '<=': + $valid = $value1 <= $value2; + break; + case '<': + $valid = $value1 < $value2; + break; + + default: + throw new sfValidatorException(sprintf('Invalid hora comparison operator "%s"', $operator)); + } + + if (!$valid) + { + $error = $this->getParameter('compare_error'); + return false; + } + } + } + + return true; + } + + /** + * Converts the given time into a Unix timestamp. + * + * Returns null if the time is invalid. + * + * @param $value Date to convert. + * @param $culture Language culture to use. + */ + private function getValidHour($value) + { + if(strlen($value['minute'])==1) $value['minute'] = "0".$value['minute']; + $hora = $value['hour'].":".$value['minute']." ".$value['ampm']; + return strtotime($hora); + } + + /** + * Initializes the validator. + */ + public function initialize($context, $parameters = null) + { + // Initialize parent + parent::initialize($context, $parameters); + + // Set defaults + $this->getParameterHolder()->set('hora_error', 'Hora Inválida'); + $this->getParameterHolder()->set('compare_error', 'Falló la comparacion'); + $this->getParameterHolder()->add($parameters); + + return true; + } +} Property changes on: prosistem/alba/trunk/alba/apps/principal/lib/albaHorasValidator.class.php ___________________________________________________________________ Name: svn:keywords + Id Date Author Rev URL Modified: prosistem/alba/trunk/alba/apps/principal/modules/horarioescolar/templates/_turnos_select.php =================================================================== --- prosistem/alba/trunk/alba/apps/principal/modules/horarioescolar/templates/_turnos_select.php 2007-02-28 20:20:23 UTC (rev 4346) +++ prosistem/alba/trunk/alba/apps/principal/modules/horarioescolar/templates/_turnos_select.php 2007-02-28 21:19:57 UTC (rev 4347) @@ -1,3 +1,8 @@ +<div class="content<?php if ($sf_request->hasError('horarioescolar{fk_turnos_id}')): ?> form-error<?php endif; ?>"> +<?php if ($sf_request->hasError('horarioescolar{fk_turnos_id}')): ?> + <?php echo form_error('horarioescolar{fk_turnos_id}', array('class' => 'form-error-msg')) ?> +<?php endif; ?> +</div> <? $aTurnos = array(); $c = new Criteria(); Modified: prosistem/alba/trunk/alba/apps/principal/modules/horarioescolar/validate/edit.yml =================================================================== --- prosistem/alba/trunk/alba/apps/principal/modules/horarioescolar/validate/edit.yml 2007-02-28 20:20:23 UTC (rev 4346) +++ prosistem/alba/trunk/alba/apps/principal/modules/horarioescolar/validate/edit.yml 2007-02-28 21:19:57 UTC (rev 4347) @@ -2,9 +2,11 @@ post: - "horarioescolar{hora_inicio}" - "horarioescolar{hora_fin}" - - "horarioescolar{dia}" - - "horarioescolar{nombre}" - - "horarioescolar{descripcion}" + - "horarioescolar{dia}" + - "horarioescolar{nombre}" + - "horarioescolar{descripcion}" + - "horarioescolar{fk_turnos_id}" + - "horarioescolar{fk_horarioescolartipo_id}" fillin: enabled: on @@ -13,10 +15,12 @@ horarioescolar{hora_inicio}: required: Yes required_msg: El campo hora inicio es obligatorio + validators: horaInicio horarioescolar{hora_fin}: required: Yes required_msg: El campo hora fin es obligatorio + validators: horaFin horarioescolar{dia}: required: Yes @@ -32,6 +36,14 @@ required_msg: El campo nombre es obligatorio validators: caracteresMaximos128 + horarioescolar{fk_turnos_id}: + required: Yes + required_msg: El campo turnos es obligatorio + + horarioescolar{fk_horarioescolartipo_id}: + required: Yes + required_msg: El campo tipo de horario escolar es obligatorio + caracteresMaximos255: class: sfStringValidator @@ -53,4 +65,18 @@ min: 0 min_error: El número debe ser positivo - \ No newline at end of file +horaInicio: + class: albaHorasValidator + param: + hora_error: El campo debe ser una hora + compare: horarioescolar[hora_fin] + operator: < + compare_error: La hora de inicio debe ser anterior a la hora de fin + +horaFin: + class: albaHorasValidator + param: + hora_error: EL campo debe ser una hora + compare: horarioescolar[hora_inicio] + operator: > + compare_error: La hora de fin debe ser posterior a la hora de inicio Modified: prosistem/alba/trunk/alba/apps/principal/modules/turnos/validate/edit.yml =================================================================== --- prosistem/alba/trunk/alba/apps/principal/modules/turnos/validate/edit.yml 2007-02-28 20:20:23 UTC (rev 4346) +++ prosistem/alba/trunk/alba/apps/principal/modules/turnos/validate/edit.yml 2007-02-28 21:19:57 UTC (rev 4347) @@ -12,10 +12,12 @@ turnos{hora_inicio}: required: Yes required_msg: El campo hora inicio es obligatorio + validators: horaInicio turnos{hora_fin}: required: Yes required_msg: El campo hora fin es obligatorio + validators: horaFin turnos{descripcion}: required: Yes @@ -27,3 +29,19 @@ param: max: 255 max_error: La maxima cantidad de caracteres permitida es de 255 + +horaInicio: + class: albaHorasValidator + param: + hora_error: El campo debe ser una hora + compare: turnos[hora_fin] + operator: < + compare_error: La hora de inicio debe ser anterior a la hora de fin + +horaFin: + class: albaHorasValidator + param: + hora_error: EL campo debe ser una hora + compare: turnos[hora_inicio] + operator: > + compare_error: La hora de fin debe ser posterior a la hora de inicio
participants (1)
-
commits@pressenter.com.ar