You are here

function _ip_geoloc_plugin_style_set_marker_color in IP Geolocation Views & Maps 7

Same name and namespace in other branches
  1. 8 src/Plugin/views/style/ip_geoloc_plugin_style.inc \_ip_geoloc_plugin_style_set_marker_color()

Set the marker color based on the differentiator, if any.

1 call to _ip_geoloc_plugin_style_set_marker_color()
ip_geoloc_plugin_style_extract_locations in views/ip_geoloc_plugin_style.inc
Extract an array of locations from the supplied views_plugin_style.

File

views/ip_geoloc_plugin_style.inc, line 1035
ip_geoloc_plugin_style.inc

Code

function _ip_geoloc_plugin_style_set_marker_color(&$location, $row, $differentiator, $is_tax_term, $view_args, $diff_color_ass) {
  if (!empty($differentiator)) {
    $differentiator_value = _ip_geoloc_plugin_style_get_differentiator_value($row, $differentiator, $view_args);
    if (!empty($differentiator_value) || $differentiator_value === 0) {
      foreach ($diff_color_ass as $key => $association) {
        if ($is_tax_term) {
          $association = _ip_geoloc_plugin_style_match_on_taxonomy_term_or_parent($differentiator_value, $diff_color_ass);
          $is_match = !empty($association);
        }
        elseif (is_array($differentiator_value)) {

          // Eg AddressField, has multiple subvalues. All must match the
          // corresponding differentiator subvalues.
          $is_match = TRUE;
          foreach ($association['differentiator_value'] as $name => $subvalue) {
            if (!isset($differentiator_value[$name]) || !ip_geoloc_is_in_range($differentiator_value[$name], $subvalue, $view_args)) {
              $is_match = FALSE;
              break;
            }
          }
        }
        else {

          // Single value, either as a simple value or an array of length 1.
          $range = $association['differentiator_value'];
          $is_match = ip_geoloc_is_in_range($differentiator_value, $range, $view_args);
        }
        if ($is_match) {
          break;
        }
      }
      if ($is_match) {
        $location->marker_color = $association['color'];
        if (!empty($association['special char'])) {
          $location->marker_special_char = $association['special char'];
        }
        if (!empty($association['special char class'])) {
          $location->marker_special_char_class = $association['special char class'];
        }
      }
    }
  }
  if (isset($location->marker_color) && is_array($location->marker_color)) {
    $location->marker_color = reset($location->marker_color);
  }
}