3

So, I'm working on a custom views handler that will allow users to filter based on field comparisons.

I've overridden the operator to use my own function defined elsewhere in the module that implements hook_options() that is also used in rules. I'm trying to guess at an appropriate way of building the query.

The example provided in the default compare_fields class that I'm extending does this:

  $snippet = $left_table_alias . '.' . $left_handler->real_field . ' ' . $this->options['operator'] . ' ' . $right_table_alias . '.' . $right_handler->real_field;

  $this->query->add_where_expression($this->options['group'], $snippet);

But I'd prefer to use a function I've already defined elsewhere that, instead of using a WHERE clause, will compare two fields with an operator to determine whether a TRUE value is returned from a geophp GEOS method. The function is as simple as this:

function geofield_rules_compare_geofields($left_geometry, $op, $right_geometry) {
$geophp = geophp_load();
$source_wkt = geoPHP::load($left_geometry['geom']);
  if (!$geophp) {
    drupal_set_message(t("Unable to load geoPHP library. Not all values will be calculated correctly"), 'error');
    return;
  }
  if (geoPHP::geosInstalled()) {
      switch ($op) {
      default:
      case 'contains()':
        if ($source_wkt->contains($right_geometry)){
          return true;
        }
      case 'within()':
        if ($source_wkt->within($right_geometry)) {
          return true;
        }
    }
  } else {
    dpm('shit, no GEOS');
  }

  // TODO: More methods
}

The operators used in the case statements are provided by the function I already mentioned.

How would you go about implementing the views handler filter query in this case?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.