Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

BUG?: Sub-cat sort order for Related links

Quote Reply
BUG?: Sub-cat sort order for Related links
There appears to be a bug in the sort order of related sub-cats.

They are sorted by the {Name} of their destination category, rather than the specific relational name they have been given.

Example:

http://www.qango.com/dir2006/Arts/index.html

Note how "Shopping and Services@" comes in between A and B (becasue it's real destination is 'Arts and Crafts') - when it should be alphabetically sorted under S.

I wondered if anyone can advise how to correct it / re-sort it?

Many thanks,
Shaun
Quote Reply
Re: [qango] BUG?: Sub-cat sort order for Related links In reply to
It's a bug, the related categories with a RelationName have to be manually resorted in the code. It should be fixed in the next release.

Adrian
Quote Reply
Re: [brewt] BUG?: Sub-cat sort order for Related links In reply to
brewt,

Thanks - is it a fairly simple fix?

If so, could I be a pain and ask for the mod code in advance of the next release?


Thanks,
Shaun
Quote Reply
Re: [qango] BUG?: Sub-cat sort order for Related links In reply to
Here's a diff:
Code:
--- Build.pm 26 Jul 2006 01:20:04 -0000 1.129
+++ Build.pm 1 Aug 2006 01:11:10 -0000
@@ -731,12 +731,30 @@
if (@subcat_ids or keys %related_ids) {
$cat_db->select_options("ORDER BY $opts->{cat_sb} $opts->{cat_so}") if $opts->{cat_sb};
my $sth = $cat_db->select({ ID => [@subcat_ids, keys %related_ids] });
+ my @rel_loop;
while (my $cat = $sth->fetchrow_hashref) {
+ $cat->{URL} = "$CFG->{build_root_url}/" . $cat_db->as_url($cat->{Full_Name}) . "/" . ($CFG->{build_index_include} ? $CFG->{build_index} : '');
if (exists $related_ids{$cat->{ID}}) {
$cat->{Related} = 1;
$cat->{RelationName} = $related_ids{$cat->{ID}};
+# Relations with a custom name need to be re-sorted
+ if ($cat->{RelationName}) {
+ push @rel_loop, $cat;
+ next;
+ }
+ }
+ push @cat_loop, $cat;
+ }
+# Re-sort related categories using their RelationName rather than the related
+# category's name
+ RELATION: while (my $cat = pop @rel_loop) {
+ for (my $i = 0; $i < @cat_loop; $i++) {
+ my $name = (exists $cat_loop[$i]->{RelationName} and $cat_loop[$i]->{RelationName}) ? $cat_loop[$i]->{RelationName} : $cat_loop[$i]->{Name};
+ if (lc $cat->{RelationName} lt lc $name) {
+ splice @cat_loop, $i, 0, $cat;
+ next RELATION;
+ }
}
- $cat->{URL} = "$CFG->{build_root_url}/" . $cat_db->as_url($cat->{Full_Name}) . "/" . ($CFG->{build_index_include} ? $CFG->{build_index} : '');
push @cat_loop, $cat;
}
my $print_cat;

Adrian
Quote Reply
Re: [brewt] BUG?: Sub-cat sort order for Related links In reply to
brewt,

Many thanks - works a treat Smile

Shaun