class RulesDateInputEvaluator

A class implementing a rules input evaluator processing date input.

This is needed to treat relative date inputs for strtotime() correctly. Consider for example "now".

Hierarchy

Expanded class hierarchy of RulesDateInputEvaluator

Related topics

1 string reference to 'RulesDateInputEvaluator'
rules_rules_core_evaluator_info in modules/rules_core.rules.inc
Implements hook_rules_evaluator_info() on behalf of the pseudo rules_core module.

File

modules/rules_core.eval.inc, line 68

View source
class RulesDateInputEvaluator extends RulesDataInputEvaluator {
    const DATE_REGEX_LOOSE = '/^(\\d{4})-?(\\d{2})-?(\\d{2})([T\\s]?(\\d{2}):?(\\d{2}):?(\\d{2})?)?$/';
    
    /**
     * Overrides RulesDataInputEvaluator::prepare().
     */
    public function prepare($text, $var_info) {
        if (is_numeric($text)) {
            // Let rules skip this input evaluators in case it's already a timestamp.
            $this->setting = NULL;
        }
    }
    
    /**
     * Overrides RulesDataInputEvaluator::evaluate().
     */
    public function evaluate($text, $options, RulesState $state) {
        return self::gmstrtotime($text);
    }
    
    /**
     * Convert a time string to a GMT (UTC) unix timestamp.
     */
    public static function gmstrtotime($date) {
        // Pass the current timestamp in UTC to ensure the retrieved time is UTC.
        return strtotime($date, time());
    }
    
    /**
     * Determine whether the given date string specifies a fixed date.
     */
    public static function isFixedDateString($date) {
        return is_string($date) && preg_match(self::DATE_REGEX_LOOSE, $date);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
RulesDataInputEvaluator::attachForm public static function Overrides RulesDataProcessor::attachForm(). Overrides RulesDataProcessor::attachForm
RulesDataInputEvaluator::evaluators public static function Returns all input evaluators that can be applied to the parameters type.
RulesDataInputEvaluator::getEvaluatorOptions protected function Generates the evaluator $options.
RulesDataInputEvaluator::getPreparedValue protected function Return $this or skip this processor by returning the next processor. Overrides RulesDataProcessor::getPreparedValue
RulesDataInputEvaluator::help public static function Provide some usage help for the evaluator. 3
RulesDataInputEvaluator::prepareSetting public static function Overridden to prepare input evaluator processors. Overrides RulesDataProcessor::prepareSetting
RulesDataInputEvaluator::process public function Overridden to generate evaluator $options and invoke evaluate(). Overrides RulesDataProcessor::process 1
RulesDataInputEvaluator::processors public static function Overrides RulesDataProcessor::processors(). Overrides RulesDataProcessor::processors
RulesDataInputEvaluator::__construct protected function Overridden to invoke prepare(). Overrides RulesDataProcessor::__construct
RulesDataProcessor::$processor protected property Allows chaining processors. If set, the next processor to invoke.
RulesDataProcessor::$setting protected property The processors' setting value.
RulesDataProcessor::access public static function Return whether the current user has permission to use the processor. 1
RulesDataProcessor::dependencies public function Returns an array of modules which we depend on.
RulesDataProcessor::editAccess public function Determines whether the current user has permission to edit this chain of
data processors.
2
RulesDataProcessor::form protected static function Defines the processor form element. 3
RulesDataProcessor::getChainSettings public function Gets the settings array for this and all contained chained processors.
RulesDataProcessor::getSetting public function Gets the settings of this processor.
RulesDataProcessor::unchain protected function
RulesDataProcessor::_item_sort public static function
RulesDateInputEvaluator::DATE_REGEX_LOOSE constant
RulesDateInputEvaluator::evaluate public function Overrides RulesDataInputEvaluator::evaluate(). Overrides RulesDataInputEvaluator::evaluate
RulesDateInputEvaluator::gmstrtotime public static function Convert a time string to a GMT (UTC) unix timestamp.
RulesDateInputEvaluator::isFixedDateString public static function Determine whether the given date string specifies a fixed date.
RulesDateInputEvaluator::prepare public function Overrides RulesDataInputEvaluator::prepare(). Overrides RulesDataInputEvaluator::prepare