You are here:  » Sorting Filters


Sorting Filters

Submitted by gregor on Thu, 2012-11-15 17:57 in

I might be missing something here, but is there a way to resequence the filters within a list? Sometimes after I've already defined several filters, I realize that I need to insert a new filter up above the others to prepare some data. For example, I might need to insert a Search and Replace before some other filters that I've already defined. When this happens I define my new filter and then I have to redefine the old ones below it (sometimes 10 or more filters). It seems like I've also gone into the db at times to make some changes there for this. Is there a better way to do it? If not, I was thinking about adding a new field to the filters screen called Sort or Step. Then I could put a numeric value in the new field and when reading the filters I would Order By the Step value. I think I can figure out how to do this, but just wondering if there's already a way to insert a new filter above some other ones, or maybe some trick to doing this. ??

If I want to add the Step field, would you please give me a summary of the updates you would suggest? (which files, etc..)

Thanks,
Gregor

Submitted by support on Fri, 2012-11-16 18:43

Hi Gregor,

First add a sequence field to the filters table with the following dbmod.php script:

<?php
  
require("includes/common.php");
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."filters`
            ADD `sequence` INT(11) NOT NULL default '0'"
;
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

Next in admin/feeds_filters_configure.php look for the following code at line 111:

  print "<br /><br />";

...and REPLACE with:

  print "<br /><br />";
  print "Sequence:<br />";
  widget_textBox("sequence",$filter["sequence"]);
  print "<br /><br />";

Then look for the following code at line 65:

$sql = "UPDATE `".$config_databaseTablePrefix."filters` SET data = '".database_safe(serialize($filter["data"]))."' WHERE id='".database_safe($id)."'";

...and REPLACE with:

$sql = "UPDATE `".$config_databaseTablePrefix."filters` SET sequence='".database_safe($_POST["sequence"])."', data = '".database_safe(serialize($filter["data"]))."' WHERE id='".database_safe($id)."'";

For order on admin page, per feed filters, look for the following code at line 73 in feeds_filters.php:

$sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".Database_safe($filename)."' ORDER BY created";

...and REPLACE with;

$sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".Database_safe($filename)."' ORDER BY sequence,created";

Finally, to set the order in which filters are applied look for the following code at line 487 of includes/admin.php:

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".database_safe($admin_importFeed["filename"])."' OR filename='' ORDER BY filename,created";

...and REPLACE with;

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".database_safe($admin_importFeed["filename"])."' OR filename='' ORDER BY filename,sequence,created";

This makes `sequence` take priority over `created`, and you can always use negative numbers e.g. `-1` to prioritise a filter before `0` sequenced filters.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by gregor on Fri, 2012-11-16 19:10

Thanks David! That's a bit more than a summary :)

I'll try it this weekend.

Gregor

Submitted by gregor on Tue, 2012-11-20 16:20

This works beautifully! I also applied the changes to global filters. Thank you! This will be a great help.

Gregor

Submitted by Convergence on Fri, 2015-05-15 21:47

Heavily modded version 12/10B

Hi David,

We added this to our installs. Works great - thank you.

Noticing something different in our import_slow CRONs - looks like the import_slow process is not applying the filters in the assigned sorted order. Would we be correct in assuming our /scripts/import_slow.php file needs to be changed? If so, can you please help with that mod?

Thanks!

[edited to add] This could also be a 'conflict' with another mod you helped us with (post-mapping filters). That mod worked beautifully until we added the sort filter mod in this thread.

Thanks, again!

Submitted by support on Sat, 2015-05-16 09:25

Hi Convergence,

Yes - prior to 13/03B filters were loaded separately by scripts/import_slow.php so in that file look for the following code at line 121:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".database_safe($admin_importFeed["filename"])."' OR filename='' ORDER BY created";

...and REPLACE with:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".database_safe($admin_importFeed["filename"])."' OR filename='' ORDER BY sequence,created";

I've reviewed the changes I helped you with regarding post mapping filters, which is based on the filter name e.g. "Text After (Post Mapping)" so shouldn't be affected by this mod... It works by looking for "PM" in the namespace of the filter - any containing "PM" are applied post-mapping but if it looks like that has stopped working for some reason let me know and I'll check it out further with you of course ( if you wanted to double check that the code is in place, I reviewed it from our email of 13th April - check includes/admin.php around line 353 for the comment /* apply user filters (post mapping) */ )

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Tue, 2015-05-19 18:44

Hi David,

Thanks for the assistance.

We're stilling seeing something 'different' from before we installed the above mod.

Can we follow-up via email?

Thanks!

Submitted by support on Tue, 2015-05-19 18:57

Sure!

email me as attachments any modified files relevant to this mod and I'll check them out for you in context...

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Sat, 2016-05-21 15:40

v12/10B - Heavily Modded

Hi David,

We would like to apply this to the Global Filers.

Can you help, please?

Thanks!

Submitted by support on Sun, 2016-05-22 10:26

Hi Convergence,

The above should be applying to global filters (where filename field is empty), I just had a look back at the code where filters are loaded in the latest copies of includes/admin.php and admin/import_slow.php and I noticed that there is a slightly different ORDER BY clause in effect.

admin/import_slow.php is using at line 604:

$sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".database_safe($admin_importFeed["filename"])."' OR filename='' ORDER BY filename,sequence,created";

and includes/admin.php at line 93:

$sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".database_safe($admin_importFeed["filename"])."' OR filename='' ORDER BY sequence,created";

...so to bring them in line, REPLACE with:

$sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".database_safe($admin_importFeed["filename"])."' OR filename='' ORDER BY filename,sequence,created";

That may be all it is, apologies if misunderstood let me know if you're still not sure of course...

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Mon, 2016-05-30 07:51

Hi David,

Am a little behind getting back to you, sorry.

Just a reminder, this is for our heavily modded version 12/10B.

/import_slow.php is not in /admin/ but in /scripts/

We currently have the following on line 144:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".database_safe($admin_importFeed["filename"])."' OR filename='' ORDER BY sequence,created";

in includes/admin.php we have the following on line 601:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".database_safe($admin_importFeed["filename"])."' OR filename='' ORDER BY filename,sequence,created";

and on line 711:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".database_safe($sourceFilename)."' ORDER BY created";

However, while I could be wrong, I do not believe changing scripts/import_slow.php on line 144 to:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".database_safe($admin_importFeed["filename"])."' OR filename='' ORDER BY filename,sequence,created";

will totally "fix" what we need.

Thinking in order for us to visually see the filters and sequence order we need to change something in admin/global_filters.php and/or admin/global_filters_configure.php; similar to what was done to admin/feeds_filters_configure.php above.

Right now, in Global Filters, we are unable to enter in a sequence order.

And for a kicker, somewhere, sometime in the past, in a galaxy far far away, we put in a mod (think it was originally requested by Gregor) to display the contents of the filter in a column called "Criteria" within admin/feeds_filters.php. However, we never applied this to the Global Filters - it would be nice to have that as well.

Clear as mud?

Thanks again, David - No rush - we've survived for something like six years without it... :)

Submitted by support on Mon, 2016-05-30 13:30

Hi,

Ah yes the sequence mods would be required for global filters. If you could email me;

admin/feeds_filters.php
admin/feeds_filters_configure.php
admin/global_filters.php
admin/global_filters_configure.php

...I'll copy the sequencing and criteria code across for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by smartprice24 on Tue, 2017-10-24 07:30

Hi David.

In PT 16/10A, not work.

Missing argument in includes/widget.php

in this line:
function widget_textBox($label,$name,$required,$default,$placeholder="",$columns=6,$atts="")

Is possible fix?

Many thanks.
G.

Submitted by support on Tue, 2017-10-24 09:26

Hi,

Filter re-sequencing is already included in 16/10A - you should see the up / down buttons alongside the Configure button (enabled when more than one filter has been added) so no changes necessary for 16/10A (and since 14/06A), let me know if you're still not sure of course and I'll check it out further with you...

Cheers,
David.
--
PriceTapestry.com