Hi,

I’m trying to use view_savedsearches modules in order to notify users on new custom content posts.

The first issue was the impossibility to store saved search filters in the database. Hopefully, this was already fixed in another post by modifying the « views_savedsearches.js » file:

Function ahahDeleteBeforeSubmit
Line 37 : formData.push({ name: 'views_filters_form', value: $('form#views-filters')[0].formSerialize() });
Function ahahSaveBeforeSubmit

Line 53: formData.push({ name: 'views_filters_form', value: $('.view-'+ view_name+ ' .view-filters form')[0].formSerialize() });

With this only fix, the modules work very well BUT only for simple exposed content views filter (eg : search filter is price < 2000 € ).

In fact, I created a view of cars sales announce content type on which I want like to add search filter for the price and distance with integer operator is between min and max value.

In this case, search criteria of the exposed form in block store my saved search in database : (a:2:{s:23:"field_price";a:1:{s:3:"min";s:2:"10";s:3:"max";s:5:"30000";}s:16:"field_distance";a:2:{s:3:"min";s:0:"";s:3:"max";s:0:"";}}) but when I choose a saved search, it displays all the announces.

Apparently the problem is in the URL generation.

When in do a research the result’s page URL is :
…/recherche_auto?field_kilometrage_value[min]=&field_kilometrage_value[max]=1000&field_prix_value[min]=&field_prix_value[max]=

And when I load a saved search, result’s page URL is :
…/recherche_auto?field_kilometrage_value[]=&field_kilometrage_value[]=1000&field_prix_value[]=&field_prix_value[]= (min an max don't appear)

So the only problem is, I think, that the views_savedsearches_save_search_form function in views_savedsearches.module doesn’t generate correctly the result URL.

I’m totally newbie in Drupal so can anyone help me?

Comments

sLL4yeR’s picture

I noticed that the same problem happens when i'm searching with Hierarchical Select Taxonomy term.

No idea?

sLL4yeR’s picture

I seem that the is a problem in the '_views_savedsearches_filters_to_params' function.

I'm trying to work on it

sLL4yeR’s picture

Ok, here is my version of the _views_savedsearches_filters_to_params function :

function _views_savedsearches_filters_to_params($filters) {
    $query = '';

    if (is_array($filters)) {
        foreach ($filters as $filter_name => $filter_value) {
            if($filter_name == 'field_kilometrage_value') {
               
            }

            // Distinction between multiple-value filters and single-value filters.
            if (is_array($filter_value)) {
                foreach ($filter_value as $key => $value) {
                    if (strlen($query) > 0) {
                        $query .= '&';
                    }
                    if (!is_array($value)) {
                        if(($key == 'min')||($key == 'max')) {
                            $query .= drupal_urlencode($filter_name) . drupal_urlencode('[').$key.drupal_urlencode(']') .'='. drupal_urlencode($value);
                        }
                        else {
                            $query .= drupal_urlencode($filter_name) . drupal_urlencode('[]') .'='. drupal_urlencode($value);
                        }
                    }
                    else {
                        // Date-style parameter, like date_filter[value][date]=2009-05-11 in the URL encoded
                        $arr = drupal_urlencode('['. $key .']');
                        $open = drupal_urlencode('[');
                        $close = drupal_urlencode(']');
                        foreach ($value as $k => $v) {
                            if (strlen($query) > 0) {
                                $query .= '&';
                            }
                            if (is_array($v)) {
                                foreach ($v as $kk => $vv) {
                                    if (strlen($query) > 0) {
                                        $query .= '&';
                                    }
                                    $query .= $filter_name . $arr . $open . $k . $close;
                                    $query .= $open . $kk . $close . '=' . $vv;
                                }
                            }
                            else {
                                $query .= $filter_name . $arr . $open . $k . $close . '=' . $v;
                            }
                        }
                    }
                }
            }
            else {
                if (strlen($query) > 0) {
                    $query .= '&';
                }
                $query .= drupal_urlencode($filter_name) .'='. drupal_urlencode($filter_value);
            }
        }
    }
    return $query;
}

It may need some impovement but it works with my needs (Integer interval filter and Hierarchical Select Taxonomy)

remydenton’s picture

Title: Saved search Issue with 'In between' Integer filter » Saved search Issue with 'Is between' Integer filter

I ran into this same bug as well and ended up creating a very similar patch to fix it. I'm also using beta3, though from a quick glance it doesn't look like beta4 has addressed this either.