I am working on a site where I want to pass a room capacity value in to a numeric contextual filter and list all rooms with a capacity less than or equal to that capacity. I found a patch for dates which added operations to that argument handler, so I adapted it for the numeric argument. I thought I would put in a feature request with my patch in case anyone feels like this would be a nice feature in views going forward. Cheers.

Comments

joel_osc’s picture

Here is a patch which may be worth looking at - it is based on the patch in this thread #1417886: 'Less than' operator for contextual arguments

joel_osc’s picture

Issue summary: View changes

Clarifiations.

robertwb’s picture

@joel_osc - This is good stuff, and I think that it really, really is useful to expand Drupals capabilities in the area of numerical data content management and analysis. I am going to put up a modified patch here in case you want to look at it. It does a couple of things differently, some stylistic, and others I think very important to have this adopted into the main branch:

  • Maintains the existing "not" functionality - it appears to me (I could be wrong) from reading your code that sites with "not" filter already in place this would break them - the attached patch maintains the NOT behavior and allows it to combine with the added comparators.
  • Adds a message telling the user that the comparator does not work when multiple values are submitted (but NOT does work since it is still supported).
  • List Text - It goes *against* the way Filters present comparison operators, that is, instead of a verbal description of the operator "greater than or qual to" it uses the mathematical symbol ">=". I also did this to store the comparator as a text abbrev "lt", "gt", because I feared escape sequences would jumble it up (perhaps this was an unfounded fear).
  • Creates a function "_comparator_options()" on the object to return the list of operator keys/descriptors. (because they are used in two places in my function, 1 for selection and the 2nd for actual rendering)
  • My patch is written against the 7.x-3.x-dev branch - I think that writing the patch against the current dev branch is needed if one desires it to be adopted?

Either way, it's nice to know someone else is interested in this type of functionality. If you want to consider all or some of my approaches

robertwb’s picture

Status: Active » Needs review

Marking as "Needs Review" - thus far implemented original by OP, modified and tested by @robertwb on 4 installs - 2 MySQL and 2 PostgreSQL.

The last submitted patch, 1: views-numeric_filter_operations-1829506-2.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 2: views-numeric_filter_operations-1829506-3.x-dev-3.patch, failed testing.

robertwb’s picture

Version: 7.x-3.5 » 7.x-3.x-dev

Status: Needs work » Needs review
joel_osc’s picture

Great additions to the original, thanks!

robertwb’s picture

setting status to needs review for retesting

robertwb’s picture

StatusFileSize
new2.56 KB

Resubmitting patch for testing

robertwb’s picture

robertwb’s picture

Priority: Minor » Normal
Status: Needs review » Needs work
robertwb’s picture

Status: Needs work » Needs review
robertwb’s picture

Updated patch to include exportable settings.

robertwb’s picture

Export support added in #14 will only work if related issue patch is applied because of existing views bug where generic export_plugin support is broken for all settings beyond 'default_argument_type'.

chris matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The 3 year old patch in #14 to views_handler_argument_numeric.inc does not apply to the latest views 7.x-3.x-dev and if still relevant needs to be rerolled.

views-numeric-argument-comparators-14.patch:24: trailing whitespace.
    
views-numeric-argument-comparators-14.patch:34: trailing whitespace.
  
Checking patch handlers/views_handler_argument_numeric.inc...
error: while searching for:

    $options['break_phrase'] = array('default' => FALSE, 'bool' => TRUE);
    $options['not'] = array('default' => FALSE, 'bool' => TRUE);

    return $options;
  }

  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);

    // allow + for or, , for and
    $form['break_phrase'] = array(
      '#type' => 'checkbox',

error: patch failed: handlers/views_handler_argument_numeric.inc:29
error: handlers/views_handler_argument_numeric.inc: patch does not apply
andrew answer’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new2.35 KB

Patch rerolled.