You are here

function rules_evaluate_elements in Rules 6

Evaluates the elements in a recursive way The elements are a tree of rules, conditions, actions and logical operations (AND, OR,..)

Each element is executed by using rules_execute_element().

Elements can use '#execute' to set their execution handler, which can be used to to customize the evaluation of the children. E.g. the element 'OR' does this and evaluates to TRUE if at least one of its children evaluate to TRUE.

Parameters

$elements An array of elements to evaluate:

$state The current evaluation state:

4 calls to rules_evaluate_elements()
rules_evaluate_rule_set in rules/rules.module
Evaluates the configured rules for the given rule set and evaluation state. This is used, when rule sets are invoked by action. So the action can set up a new state, working with the same variables. So the original execution state can take over…
rules_execute_and in rules/rules.module
Execution handler for the AND element Evaluates to TRUE if all children evaluate to TRUE..
rules_execute_or in rules/rules.module
Execution handler for the OR element Evaluates to TRUE if at least one children evaluate to TRUE..
rules_execute_rule in rules/rules.module
Execution handler for rules

File

rules/rules.module, line 324
Rules engine module

Code

function rules_evaluate_elements($elements, &$state) {
  $result = FALSE;

  //Execute the current element if not yet executed
  if (!isset($elements['#_executed'])) {
    $elements['#_executed'] = TRUE;
    _rules_element_defaults($elements);
    $result = rules_execute_element($elements, $state);
  }

  // we default to evaluate like an AND, which means we stop as soon as one element evaluates to FALSE
  // so if the element hasn't evaluated the children, start now
  if (!isset($elements['#_evaluated']) || $elements['#_evaluated'] == FALSE) {
    $elements['#_evaluated'] = TRUE;
    $result = rules_execute_and($elements, $state);
  }
  return $result;
}