Location: PHPKode > scripts > Piragibe > piragibe/PGBPropertyBag/PGBValidationDefs.php
<?php
require_once 'Piragibe/PGBPropertyBag.php';
/**
* A set of definitions to validate PGBFields
*
* A specialised property bag, containing directives for validation. The directives can comprise
* the following:
*
* - Type        -> can be "number", "date", "cpf", "cnpj"
* - Required    -> true or false
* - LowerBound  -> the lowest possible value for a field
* - UpperBound  -> the highest possible value for a field
* - InSet       -> array containing all possible values
* 		'possible value' -> anything (the value should be the key)
* - InQuery     -> array containing query definition to verify against
*       'conn'->    PGBConnection to use when executing statement
*       'sql' ->    SQL statement, using ? as a placeholder for fields's value, that must
*                   return a non-empty set
* @package Piragibe
* @author Francisco Piragibe
* @version 1.00
* @subpackage PGBPropertyBag
 * @copyright Copyright &copy; 2006, Francisco Piragibe
 * This file is part of The PIRAGIBE Framework.
 *
 * The PIRAGIBE Framework 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.
 * 
 * The PIRAGIBE Framework 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 The PIRAGIBE Framework; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*
*/ 
class PGBValidationDefs extends PGBPropertyBag {
    
    /**
     * Getter for the field type.
     * @return string the fields's type
     */
    function getType() {
        return strtolower($this->get( 'Type' ));
    }
    
    /**
     * Getter for the required attribute.
     * @return boolean true if the property is set to any value; false otherwise
     */
    function isRequired() {
        if ( $this->get('Required') ) {
            return true;
        }
        else {
            return false;
        }
    }
    
    /**
     * Getter for the lowest admissible value.
     * @return mixed the lowest value the field can have (the true meaning of "lowest" depends on the field's type
     */
    function getLowerBound() {
        return $this->get( 'LowerBound' );
    }
    
    /**
     * Getter for the highest admissible value.
     * @return mixed the highest value the field can have (the true meaning of "highest" depends on the field's type
     */
    function getUpperBound() {
        return $this->get( 'UpperBound' );
    }
    
    /**
     * Getter for a discrete set the field value must be in.
     * 
     * This is useful for fields having discrete domains, like sex, for instance.
     * @return array an array, indexed by the possible values
     */
    function getBaseSet() {
        return $this->get( 'InSet' );
    }
    
    /**
     * Getter for a query definition that will get the possible values.
     * 
     * The query is defined by a SQL statement that should be executed by a PGBConnection object.
     * Before attempting to execute it, the framework will replace every question mark by the value
     * to be validated.
     * @return array an array containing the PGBConnection and the SQL statement to be executed
     */
    function getBaseQuery() {
        return $this->get( 'InQuery' );
    }
    
} 
?>
Return current item: Piragibe