You are here

function heartbeat_variables_compare in Heartbeat 6.3

Same name and namespace in other branches
  1. 6.4 modules/heartbeat_rules/hrules.module \heartbeat_variables_compare()

compares variables that need to be included with variables that are already there and check their values to fit as default value in a textarea

Parameters

array $settings:

array $form_settings:

string $variables:

Return value

string fit for textarea

2 calls to heartbeat_variables_compare()
heartbeat_rules_default_action_form in ./heartbeat.rules.inc
Action drupal message configuration form.
heartbeat_rules_users_action_form in ./heartbeat.rules.inc
User action drupal message configuration form.

File

./heartbeat.common.inc, line 57
Commonly functions used in heartbeat

Code

function heartbeat_variables_compare($settings, $form_variables = null, $variables = array(), $flipped = true) {
  $default_values = '';

  // form_state first, while editing the form (changing message id for instance)
  if (isset($form_variables)) {
    $vars = heartbeat_decode_message_variables($form_variables, false);
  }
  else {
    if (isset($settings['variables_param'])) {
      $vars = heartbeat_decode_message_variables($settings['variables_param'], false);
    }
    else {
      $vars = heartbeat_decode_message_variables($message->variables, false);
    }
  }
  if ($flipped) {
    $variables = array_flip($variables);
  }

  // See if there is already a token assignment on a variable
  foreach ($variables as $variable_word => $key) {

    // Standardize possible variable formats
    $variable_normal = !eregi("@", $variable_word) ? "@" . $variable_word : $variable_word;
    $variable_part = !eregi("#", $variable_word) ? "#" . $variable_word : $variable_word;
    if (!empty($vars[$variable_normal])) {
      $default_values .= $variable_normal . "=" . $vars[$variable_normal] . "\r\n";
    }
    elseif (!empty($vars[$variable_part])) {
      $default_values .= $variable_part . "=" . $vars[$variable_part] . "\r\n";
    }
    elseif (!empty($vars[$variable_word])) {
      $default_values .= $variable_normal . "=" . $vars[$variable_word] . "\r\n";
    }
    else {
      $default_values .= $variable_normal . "=\r\n";
    }
  }
  return $default_values;
}