Search

I’m creating an extension to use a slider, but I stumble into some questions with filtering.

alt text

What I am trying to achieve here is that I can filter a datasource according to the range defined by the extension. So I have a from- and to- value, and anything that matches in between these values should pass.

For example: The entry has it’s slider-value set to 10-20. The page gets a $parameter with value ‘15’. This should match entries with value 10-20, 13-18, etc…, but not 8-11 and 20-24 offcourse.

Now I was trying to do this myself, but I’m not sure on how an extension can ‘hook’ into the filter of the datasource.

The extension can be looked at on github at https://github.com/kanduvisla/slider. Any help would be greatly appreciated.

Attachments:
SS-2010-11-29_17.12.41.png

I’ve not delved into this, but is it possible to do a filter twice on a field in the datasource editor?

I mean, select the slider and do a ‘less than’ value, then select the slider again and do a ‘more than’ value?

If that’s possible, it would be good as you could select ‘less than’ and more than’ also, as well as ‘between’

I don’t know if it’s possible though…

You can do it, I’ve done it. Let me double-check my code…

OK, basically, I had to set two URL variables and then filter that filed with this:

mysql: value >= {$url-min:1} AND value <= {$url-max:1000000}

Then, of couse, the URL variables over-ride the default and I get my filter. The only trick is you have to set a max and min at the beginning that is as much as the max and min you’ll otherwise get. If you don’t nothing shows up until you specify something in a search.

By the way, the slider is the jQuery UI one. If you need more information about the code just ask and I’ll post what I can (seeing as it’s client work).

EDIT: I was beaten to it by Doug…

Ok, just tried and no you can’t filter twice.

And I’ve just re-read your question. There is a function called buildDSRetrivalSQL in fields that you would use to build your query. The reflection field uses it if you need a reference?

It has the following values passed in to it, although without docs and experience, I wouldn’t know what these values contain:

buildDSRetrivalSQL($data, &$joins, &$where, $andOperation = false)

You could create the function for testing, and do the following to find out

buildDSRetrivalSQL($data, &$joins, &$where, $andOperation = false){
    var_dump($data);
    var_dump($joins);
    var_dump($where);
    var_dump($andOperation);
}

Someone else will have much better knowledge of all this though ;)

So, I have the following returning correctly in your extension. I must say this is crap, as I haven’t taken any other cases than 1 single value into account, i.e. no regex, no filters at all really, but it is a working example:

    // Filter functions:

    public function canFilter()
    {
        return true;
    }

    public function buildDSRetrivalSQL($data, &$joins, &$where, $andOperation = false) {

        $field_id = $this->get('id');

        if (!is_array($data)) $data = array($data);

        foreach ($data as &$value) {
            $value = $this->cleanValue($value);
        }

        $this->_key++;

        $joins .= "
            LEFT JOIN
                `sym_entries_data_{$field_id}` AS t{$field_id}_{$this->_key}
                ON (e.id = t{$field_id}_{$this->_key}.entry_id)
        ";
        $where .= "
            AND
            ('{$value}' >= t{$field_id}_{$this->_key}.value_from
            AND '{$value}' <= t{$field_id}_{$this->_key}.value_to)
        ";
        /*
        var_dump($value);
        var_dump($data);
        var_dump($joins);
        var_dump($where);
        */

        return true;
    }

I hope it is helpful…

You’ve got me thinking about this, nearly done it for you and will send a pull request for you to look at when I’m done ;)

EDIT: Pull request sent ;)

@designermonkey: Thank you very much! This is how open source is meant to work! ;-)

I finished the extension, and I am going to add it to this website now.

Hello to everyone!

I need to do this kind of range filtering for a site, but i'm kinda new to Symphony and don't really get Doug's solution. First of all, what is the

mysql:

part? Is there a mysql filter of some kind? Then the 'value' needs to be the name of the field i'm filtering? I'm a bit confused, any help is appreciated.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details