You are here

function _ca_convert_conditions in Ubercart 6.2

Helper function for converting Ubercart's Workflow-ng conditions.

1 call to _ca_convert_conditions()
_ca_convert_configurations in ca/ca.admin.inc
Batch API callback for Workflow-ng configuration conversion.

File

ca/ca.admin.inc, line 1210
Conditional actions overview UI.

Code

function _ca_convert_conditions($condition_tree) {
  static $condition_data;
  $ca_condition = array();
  if (!isset($condition_data)) {
    $condition_data = module_invoke_all('ca_condition');
  }

  // Handle multiple conditions recursively.
  if ($condition_tree['#type'] == 'AND' || $condition_tree['#type'] == 'OR') {
    $ca_condition['#operator'] = $condition_tree['#type'];
    $ca_condition['#conditions'] = array();
    for ($i = 0; isset($condition_tree[$i]); $i++) {
      $condition = _ca_convert_conditions($condition_tree[$i]);
      if ($condition) {
        $ca_condition['#conditions'][] = $condition;
      }
    }
  }
  elseif ($condition_tree['#type'] == 'condition') {

    // Some conditions were renamed but check the same things.
    switch ($condition_tree['#name']) {
      case 'uc_order_condition_order_total':
        $ca_condition['#name'] = 'uc_order_condition_total';
        break;
      case 'uc_payment_condition_balance':
        $ca_condition['#name'] = 'uc_payment_condition_order_balance';
        break;
      case 'workflow_ng_condition_custom_php':
        $ca_condition['#name'] = 'ca_condition_custom_php';
        break;
      case 'workflow_ng_condition_user_hasrole':
        $ca_condition['#name'] = 'ca_condition_user_roles';
        $condition_tree['#settings']['operator'] = $condition_tree['#settings']['operation'];
        unset($condition_tree['#settings']['operation']);
        break;
      default:
        $ca_condition['#name'] = $condition_tree['#name'];
        break;
    }
    if (isset($condition_tree['#label'])) {
      $ca_condition['#title'] = $condition_tree['#label'];
    }
    else {
      $ca_condition['#title'] = $condition_data[$ca_condition['#name']]['#title'];
    }
    $ca_condition['#argument_map'] = $condition_tree['#argument map'];
    foreach ($ca_condition['#argument_map'] as $key => $value) {
      if ($key == 'user') {
        $key = 'account';
      }
      if ($value == 'user') {
        $value = 'account';
      }
      $ca_condition['#argument_map'][$key] = $value;
    }
    $ca_condition['#settings'] = $condition_tree['#settings'];
    if (isset($condition_tree['#negate'])) {
      $ca_condition['#settings']['negate'] = $condition_tree['#negate'];
    }
  }
  return $ca_condition;
}