In #1877902: Tile based argument I tried to do something similar: No arguments / no result.

This helps server load reduction / crashes :)

Opinions?

Comments

clemens.tolboom’s picture

clemens.tolboom’s picture

Status: Active » Needs review
StatusFileSize
new1.14 KB

The result from this patch is

{
  "type" : "FeatureCollection",
  "features" : []
}

which looks good to me.

dasjo’s picture

could we have this optional?

unfortunately the way that the bbox argument is implemented, we can't make use of the standard views argument options which normally allows you to specify the argument behavior in that regards.

clemens.tolboom’s picture

StatusFileSize
new2.15 KB

What about this. Added option to select empty result.

pol’s picture

Issue summary: View changes

Any status update on this please ?

basvredeling’s picture

Status: Needs review » Reviewed & tested by the community

I've tried out the patch in number 4 (adapted to work with: #2396781: Clean up the views_geojson module) It seems to do what it says. I don't know if I really like the implementation. But it looks good to commit and it's an improvement.

basvredeling’s picture

Status: Reviewed & tested by the community » Needs work

Okay, I've tried another approach. Please let me know what you think.
If you look at views_plugin_argument_default_bboxquery::get_argument() currently there still is a @todo in there to do some sanitization.
I've implemented some basic sanitization and set the views query to both built and executed so the query is not run and the empty result set is returned. The view is still rendered though and this returns a nice empty feature collection as in #2.

  /**
   * Return the default argument.
   */
  function get_argument() {
    $query = drupal_get_query_parameters();
    if (isset($query[$this->options['arg_id']])) {
      // Basic sanitization, checks if we only set 4 numerical coordinates.
      if (is_string($query[$this->options['arg_id']])) {
        $coordinates = explode(',', $query[$this->options['arg_id']]);
        if (count($coordinates > 4)) {
          unset($query[$this->options['arg_id']]);
          return FALSE;
        }
        foreach ($coordinates as $coordinate) {
          if (!is_numeric($coordinate)) {
            unset($query[$this->options['arg_id']]);
            return FALSE;
          }
        }
        return $query[$this->options['arg_id']];
      }
    }
    else {
      if ($this->argument->options['empty_result']) {
        // Return no values if arg not present and empty result option is set.
        $this->view->built = TRUE;
        $this->view->executed = TRUE;
        return FALSE;
      }
      else {
        // Return all values if arg not present.
        return TRUE;
      }
    }
  }

Let me know what you think and I'll create a patch.
We probably need to cleanup views_geojson_bbox_argument::query() too.

basvredeling’s picture

Status: Needs work » Needs review
StatusFileSize
new1.62 KB

I made the patch anyway. Easier to evaluate I guess.
I didn't include the views_geojson_bbox_argument::query() cleanup.

pol’s picture

Hello Bas,

The patch seems a good improvement for me I will commit it as soon as you tell me what you mean by query::cleanup() ?

Thx

basvredeling’s picture

StatusFileSize
new6.31 KB

This is the complete patch.
By cleanup views_geojson_bbox_argument::query() I mean the following:

  1. I removed this todo:

    // TODO: this argument should be set in
    // views_plugin_argument_default_bboxquery::get_argument
    // unfortunately that seems broken.
    // @see http://drupal.org/node/1884214

  2. I removed the references to the _no_result() method and the method itself. Because it contained an extra check for the "empty result" argument option.
  3. Moved all bbox coordinate processing to this class
  4. Added some comments to make clear why the code is where it is and what still needs to be done.

  • Pol committed 1c939df on 7.x-1.x authored by basvredeling
    Issue #1884214 by clemens.tolboom, basvredeling: BBOX argument handler...
basvredeling’s picture

Status: Needs review » Fixed

thanks

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.