*/ WBClass::load('WBPAT_Forms_Rule'); /** * patForms Rule Fraction * * Given value must be * * @version 0.1.0 * @package Wombat * @subpackage patForms */ class patForms_Rule_Fraction extends WBPAT_Forms_Rule { /** * default config values * - factor * - add * * @var array */ protected $config = array( 'factor' => '4', 'add' => '0' ); /** * Initialize validation codes using gettext * * @access protected * @return bool $success Always returns true. * @see $attributeDefaults */ public function loadValidatiorErrorCodes() { $this->validatorErrorCodes = array( 1 => patI18n::dgettext('wombat', 'The value is an invalid fraction.'), ); return true; } /** * method called by patForms or any patForms_Element to validate the * element or the form. * * @param patForms_Element $form object * @return bool true on sucess */ public function applyRule(&$element, $type = PATFORMS_RULE_AFTER_VALIDATION) { if (empty($this->config['factor'])) { WBClass::load('WBException_Config'); throw new WBException_Config('Config value "factor" required!', 1, __CLASS__); } $x = floatval($element->getValue()); if (empty($x)) { return true; } $m = floatval($this->config['factor']); $c = floatval($this->config['add']); $y = $x * $m + $c; if (floor($y) == $y) { return true; } $this->addValidationError(1); return false; } } ?>