You are here

function ip_geoloc_get_view_result in IP Geolocation Views & Maps 7

Returns as an array the raw value(s) of a field in the results set.

Parameters

object $views_plugin_style: The Views plugin.

mixed, field array or field name (string): The field or name of the field in the View.

int index: The row index into the Views result set.

Return value

array The raw value(s) of the field in the specified row of the results set.

2 calls to ip_geoloc_get_view_result()
ip_geoloc_plugin_style_extract_locations in views/ip_geoloc_plugin_style.inc
Extract an array of locations from the supplied views_plugin_style.
ip_geoloc_plugin_style_leaflet::fill_out_location_regions in views/ip_geoloc_plugin_style_leaflet.inc

File

views/ip_geoloc_plugin_style.inc, line 1312
ip_geoloc_plugin_style.inc

Code

function ip_geoloc_get_view_result($views_plugin_style, $field, $index) {
  $field_name = is_array($field) ? $field['field_name'] : $field;
  if (!isset($views_plugin_style->view->result[$index])) {
    drupal_set_message(t("Field %name: no value found amongst view results.", array(
      '%name' => $field_name,
    )), 'warning', FALSE);
    return NULL;
  }
  $row = $views_plugin_style->view->result[$index];
  if (isset($row->{"field_{$field_name}"}) && $row->{"field_{$field_name}"} != array()) {
    $values = $row->{"field_{$field_name}"};
  }
  elseif (isset($row->{"views_{$field_name}"})) {
    $values = $row->{"views_{$field_name}"};
  }
  elseif (isset($row->{$field_name})) {
    $values = $row->{$field_name};
  }
  elseif (isset($views_plugin_style->view->field[$field_name])) {
    $values = $views_plugin_style
      ->get_field_value($index, $field_name);
  }
  elseif (!empty($row->_entity_properties)) {

    // Search API emergency fallback
    $values = _ip_geoloc_plugin_style_get_search_api_value($row, $field_name);
  }
  else {
    return array(
      '',
    );
  }
  if (!is_array($values)) {
    return array(
      $values,
    );
  }
  $single_values = array();
  foreach ($values as $value) {
    if (isset($value['raw'])) {
      $value = $value['raw'];
    }
    if (isset($field['type'])) {
      if ($field['type'] == 'addressfield') {
        return $value;
      }
      if (is_array($value)) {
        $value = $field['type'] == 'taxonomy_term_reference' ? $value['tid'] : reset($value);
      }
    }
    elseif (is_array($value)) {
      $value = reset($value);
    }
    $single_values[] = $value;
  }
  return $single_values;
}