You are here

function _views_send_get_from_views_result in Views Send 6

Find the value for a given "field" in a Views result (row).

If the "field" is a proper field, we check the raw array. First we look for "value" and then for a specific key if given. Then we check if there is just one key.

3 calls to _views_send_get_from_views_result()
views_send_form_alter in ./views_send.module
Implementation of hook_form_alter().
views_send_mail_action in ./views_send.module
Main action callback.
views_send_mail_action_validate in ./views_send.module
Validation callback for views_send_mail action configuration form.

File

./views_send.module, line 968
The Views Send module.

Code

function _views_send_get_from_views_result($views_result, $key, $extra_key = FALSE) {
  $value = FALSE;
  if (substr($key, 0, 6) == 'field_') {

    // We don't know the table alias, just that it starts with
    // or contains 'node_data_' and ends with the field key.
    foreach ($views_result as $resultkey => $data) {
      if (preg_match("/^(.*)node_data_(.*){$key}\$/", $resultkey)) {
        $views_value = $data;
        break;
      }
    }

    // If the field is a plain string, just return it.
    if (!is_array($views_value)) {
      return $views_value;
    }

    // Abort immediately if the field is an empty array.
    if (count($views_value) == 0) {
      return FALSE;
    }

    // AFAICT the code below is never executed because Views 2 (on Drupal 6)
    // doesn't have fields as arrays with 'raw' key.
    if (isset($views_value[0]['raw']['value'])) {
      $value = $views_value[0]['raw']['value'];
    }
    else {
      if ($extra_key && isset($views_value[0]['raw'][$extra_key])) {
        $value = $views_value[0]['raw'][$extra_key];
      }
      if (!$value && count($views_value[0]['raw']) == 1) {
        $value = array_pop($views_value[0]['raw']);
      }
    }
  }
  else {
    $value = $views_result->{$key};
  }
  return $value;
}