*/ WBClass::load('WBPAT_Forms_Rule'); /** * patForms Rule ConfigExists * * Check whether config exists. Use loader to load config and check whether loading fails * * @version 0.1.0 * @package Wombat * @subpackage patForms */ class patForms_Rule_TimeDomain extends WBPAT_Forms_Rule { /** * name of the element that will be validated * @access private * @var string */ private $_validelement = ''; /** * name of the element that will be used as base for validation * @access private * @var string */ private $_baseelement = ''; /** * if the element to be validated is this specific date, the rule is always valid * * @access private * @var string */ private $_ignoredate = ''; /** * offset * * Before and after offset to the base time. * Values can be everything accepted by strtotime(). * * @access private * @public array */ private $_offset = array( 'before' => '', 'after' => '' ); /** * XML confic to local config * * * @param array $config */ public function setConfig($config = array()) { if (isset($config['ignoredate'])){ $this->_ignoredate = $config['ignoredate']; } $this->_validelement = $config['validelement']; $this->_baseelement = $config['baseelement']; $this->_offset['before'] = $config['offset']['before']; $this->_offset['after'] = $config['offset']['after']; //respect time direction from user if ($this->_offset['before'][0] != '-' && $this->_offset['before'][0] != '+'){ $this->_offset['before'] = '- '.$this->_offset['before']; } if ($this->_offset['after'][0] != '-' && $this->_offset['after'][0] != '+'){ $this->_offset['after'] = '+ '.$this->_offset['after']; } } /** * method called by patForms or any patForms_Element to validate the * element or the form. * * @access public * @param object patForms form objecty */ function applyRule( &$form, $type = PATFORMS_RULE_AFTER_VALIDATION ) { $validtime = strtotime($form->getElement( $this->_validelement )->getValue(false)); if ($this->_ignoredate != ''){ if (strtotime($this->_ignoredate) == $validtime){ return true; } } $basetime = strtotime($form->getElement( $this->_baseelement )->getValue(false)); $offset_after = strtotime($this->_offset['after'], $basetime); $offset_before = strtotime($this->_offset['before'], $basetime); /* debug: $d_str = "d m Y h:i:s"; echo '
base: '.gmdate($d_str, $basetime); printf('
before ("%s"): %s', $this->_offset['before'], gmdate($d_str, $offset_before)); printf('
after ("%s"): %s', $this->_offset['after'], gmdate($d_str, $offset_after)); */ if ($offset_before < $validtime && $offset_after > $validtime){ return true; } $this->addValidationError(1); return false; } /** * Initialize validation codes using gettext * * Overwrite this function to add element's error codes * * @access protected * @return bool $success Always returns true. * @see $attributeDefaults */ function loadValidatiorErrorCodes() { $this->validatorErrorCodes = array( 1 => patI18n::dgettext( 'patForms', 'Bezahldatum muss in der Nähe des Erstellungsdatums liegen' ), ); return true; } }