You are here

function _votingapi_process_action_set in Voting API 5

1 call to _votingapi_process_action_set()
_votingapi_process_actions in ./votingapi_actions.module

File

./votingapi_actions.module, line 115

Code

function _votingapi_process_action_set($content = NULL, $votes = array(), $results = array(), $action_set = NULL, &$actions) {

  // a little safety code to catch malformed sets.
  if (!isset($action_set['conditions'])) {
    $action_set['conditions'] = array();
  }
  if (!isset($action_set['actions'])) {
    $action_set['actions'] = array();
  }
  if (!isset($action_set['subsets'])) {
    $action_set['subsets'] = array();
  }

  // Here, we iterate through every rule. The value starts as true,
  // and a single false will trip it to failure state.
  foreach ($action_set['conditions'] as $condition) {
    $function = $condition['handler'];
    if (function_exists($function)) {

      // this calls a handler with several ops. 'process' and 'input' are the two i've thought of.
      $conditions_result = $function('process', $content, $votes, $results, $condition);
    }
    else {
      $conditions_result = FALSE;
    }
    if ($action_set['condition_mask'] == 'AND') {
      if ($conditions_result === FALSE) {

        // bail out to avoid unecessary processing.
        return FALSE;
      }
      else {

        // AND the set result and rule result together.
        if (isset($set_result)) {
          $set_result = $set_result && $conditions_result;
        }
        else {
          $set_result = $conditions_result;
        }
      }
    }
    else {
      if ($action_set['condition_mask'] == 'OR') {

        // OR the set result and rule result together.
        $set_result = $set_result || $conditions_result;
      }
    }
  }
  if ($set_result == TRUE) {

    // Now check sub-actions.
    foreach ($action_set['subsets'] as $subset) {

      // check the required flag of the subset. if it is, evaluate it.
      if ($subset['required'] == TRUE) {
        $set_result = $set_result && _votingapi_process_action_set($content, $votes, $results, $subset, $actions);
        if ($set_result == FALSE) {
          return FALSE;
        }
      }
    }
    if ($set_result == TRUE) {

      // It's still true after executing required subsets. Add the actions, then process optional subsets.
      foreach ($action_set['actions'] as $action) {
        $actions[] = $action;
      }
      foreach ($action_set['subsets'] as $subset) {

        // now handle the non-required subsets
        if ($subset['required'] == FALSE) {
          _votingapi_process_action_set($content, $votes, $results, $subset, $actions);
        }
      }
    }
  }
  return $set_result;
}