SVN Alba r5031 - in prosistem/alba/trunk/alba/apps/principal: lib modules/cuenta/validate
Author: josx Date: 2007-08-29 15:11:11 -0300 (Wed, 29 Aug 2007) New Revision: 5031 Added: prosistem/alba/trunk/alba/apps/principal/lib/albaCuentaValidador.class.php Modified: prosistem/alba/trunk/alba/apps/principal/modules/cuenta/validate/edit.yml Log: Se agrego un validador para que no existan dos cuentas con el mismo nombre Added: prosistem/alba/trunk/alba/apps/principal/lib/albaCuentaValidador.class.php =================================================================== --- prosistem/alba/trunk/alba/apps/principal/lib/albaCuentaValidador.class.php 2007-08-29 17:13:01 UTC (rev 5030) +++ prosistem/alba/trunk/alba/apps/principal/lib/albaCuentaValidador.class.php 2007-08-29 18:11:11 UTC (rev 5031) @@ -0,0 +1,86 @@ +<?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 + */ + + + +/** + * albaCuentaValidador valida el cuenta. + * + * @package alba + * @author José Luis Di Biase <[email protected]> + * @author Héctor Sanchez <[email protected]> + * @author Fernando Toledo <[email protected]> + * @version SVN: $Id: albaCuentaValidador.class.php 4242 2007-02-16 20:00:22Z ftoledo $ + * @filesource + * @license GPL + */ + +class albaCuentaValidador extends sfValidator { + + + function initialize($context, $parameters = null) + { + // initialize parent + parent::initialize($context); + + // set defaults + $this->getParameterHolder()->set('cuenta_error', 'Invalid input'); + $this->getParameterHolder()->add($parameters); + return true; + } + + /** + * Ejecuta la validación del cuenta. + * + * @param value A file or parameter value/array. + * @param error An error message reference. + * + * @return bool verdadero, si ha pasado con éxtio la validación, de lo contrario falso. + */ + + public function execute(&$value, &$error) + { + + $campo_param1 = $this->getParameterHolder()->get('campo'); + $cuenta = $this->getContext()->getRequest()->getParameter('cuenta'); + + $campo_param = $this->getParameterHolder()->get('campo_id'); + $id = $this->getContext()->getRequest()->getParameter($campo_param); + + $c = new Criteria(); + $c->add(CuentaPeer::NOMBRE, $cuenta["$campo_param1"], Criteria::EQUAL); + $cuentas = CuentaPeer::doSelectOne($c); + + // existe o no el mismo usuario en la DB + if($cuentas) { + if(($cuentas->getNombre() == $cuenta["$campo_param1"]) AND ($id == $cuentas->getId())) { + return true; + } else { + $error = $this->getParameterHolder()->get('cuenta_error'); + return false; + } + } else { + return true; + } + } + +} + +?> \ No newline at end of file Property changes on: prosistem/alba/trunk/alba/apps/principal/lib/albaCuentaValidador.class.php ___________________________________________________________________ Name: svn:keywords + "Id Author URL Date Rev" Modified: prosistem/alba/trunk/alba/apps/principal/modules/cuenta/validate/edit.yml =================================================================== --- prosistem/alba/trunk/alba/apps/principal/modules/cuenta/validate/edit.yml 2007-08-29 17:13:01 UTC (rev 5030) +++ prosistem/alba/trunk/alba/apps/principal/modules/cuenta/validate/edit.yml 2007-08-29 18:11:11 UTC (rev 5031) @@ -16,7 +16,7 @@ cuenta{nombre}: required: Yes required_msg: El campo nombre es obligatorio - validators: caracteresMaximos128 + validators: caracteresMaximos128, cuentaValidador cuenta{razon_social}: required: Yes @@ -79,4 +79,11 @@ param: cuit_error: El CUIT ingresado es invalido - \ No newline at end of file + +cuentaValidador: + class: albaCuentaValidador + param: + campo: nombre + campo_id: id + cuenta_error: La cuenta ya exite +
participants (1)
-
commits@pressenter.com.ar