Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Special Sort Order - Tricky?

Quote Reply
Special Sort Order - Tricky?
I'm trying to build a subcategory that Orders differently from all the other categories. Currently, I'm Ordering on a user_specific field called ImageIs where valid entries are Tall Wide and Square (It relates to an uploaded image, and depending on the value I can manually specify the image dimensions - which is necessary for quicker loading pages.)

So the ImageIs field does two things. It tells me the dimensions and it groups all my talls, square and wides together. For this one category however, I need to NOT Order according to the ImageIs, but rather by ID, (which is actually my second sort order for all the other categories) HOWEVER, I still need to use the ImageIs field to specify my dimensions. Leaving the ImageIs blank allows me to sort by ID, but then my pages load like a slug - It's a catch 22.

I looked in nph-build.cgi, and sub build_category_pages { }
the subroutine firsts grabs the links in the category AND sorts them by $LINKS{build_sort_order_category} at the same time. So because I'm grabbing ? categories, I can't say something like:

if CategoryID=somecategory) { $sortorder=(ID,IsNew,etc..);
} else { $sortorder=$LINKS{build_sort_order_category};
}

$get_links = $LINKDB->prepare (" SELECT * FROM $table WHERE CategoryID ? ORDER BY $sortorder LIMIT 1000 ");

Then I noticed sub build_sort_links, but that only appears to work if their are alt categories which there aren't.

So, where or how would I go about implementing this?

Thanks for any help.

Peace.

Kyle
Quote Reply
Re: Special Sort Order - Tricky? In reply to
You are going to have to "special case" it.

At the top of "sub build_category_pages" do another query like the "$get_links" query, to $get_catgory_nn_links using whatever sort order you want.

Then, when you are writing out the pages, you need to test for that ID, and when you find it, you need to again special case and override the segement of code:

Code:
# Get the links
$get_links->execute ($category_r->{'ID'});
$links_r = $get_links->fetchall_arrayref | | [];
$get_alt->execute ($category_r->{'ID'});
$alt_r = $get_alt->fetchall_arrayref | | [];
$links_r = &build_sort_links ($links_r, $alt_r) if (@{$alt_r});
$numlinks = $#{$links_r} + 1 | | 0;
$OUT{total} = $numlinks;
$total_links = $numlinks;

I wish I could be more specific, but you seem to have a grasp of perl coding. There may be other areas you have to tweak, but basically, you want to override the original "$get_links" query for that category, with the new one you did at the begining, then continue on with the rest of the links as if nothing had happened.

If you find a working solution let us know!

I know this isn't elegant, or pretty, but eventually I'm sure the ability to use different templates, sort orders, and other features on a category by category basis will be available.

IF you want to try a much grander solution -- you can add fields to the Categories table, that hold this extra information, then override the Links.pm defaults for each category if those fields test out non-null.

If you code carefully, you might be able to use the automatic scoping features to revert back to the 'default' values without having to explicitly save and restore them.


Quote Reply
Re: Special Sort Order - Tricky? In reply to
Thanks pugdog, You got my wheels spinning. And I came up with a work around, perhaps not that elegant, but I don't think it's that ugly either. It works at least on the surface of 20 builds and 50 or more different categories. I haven't had any problems except when I sort by ID in which case 8 comes after 20, but I can live with that.

This is what I did.

in nph-build.cgi
sub build_category_pages {}

RIGHT ABOVE:
$links_r = &build_sort_links ($links_r, $alt_r) if (@{$alt_r});

ADDED:
my $sort_special ='';
foreach my $key (keys %{$LINKS{sort_special_fields}}) {
if ($key eq $category_r->{'Name'}) {
$sort_special = ($LINKS{sort_special_fields}->{$key});
}
}


THEN CHANGED
$links_r = &build_sort_links ($links_r, $alt_r) if (@{$alt_r});

to:

$links_r = &build_sort_links ($links_r, $alt_r, $sort_special) if ((@{$alt_r}) | | ($sort_special));

IN sub build_sort_links {}

CHANGED:
my ($arr_a, $arr_b) = @_;

TO:
my $arr_a = shift;
my $arr_b = shift | | [];
my $sort = shift | | $LINKS{build_sort_order_category};

FINALLY, in Links.pm

ADDED:

$LINKS{sort_special_fields} = { "Category Name" => 'ID', "Category Name 2" => 'Title,ID'};

For example, I have a category called Ambiance Tour that I want sorted by ID. and a category called Decorative Stone/Panels that I want sorted by Title then by ID,

so I now have:
$LINKS{sort_special_fields} = { "Ambiance Tour" => 'ID', "Decorative Stone/Panels" => 'Title,ID'};

No problems as of this writing. I have no idea how this may or may not integrate with page.cgi, or with specially named categories, but with straight forward English category names with spaces and / I haven't had any problems. So if anyone else does, please post if this causes a problem with that.


Oh yeah, if you cut and paste remember to remove the space between the | |.

Peace.

Kyle



[This message has been edited by klangan (edited March 08, 2000).]
Quote Reply
Re: Special Sort Order - Tricky? In reply to
Cool!

Great to see so many people are actually having success with their mods!

LinkSQL is scary at first, but once you start, it's a HECK OF A LOT EASIER than working with the flat-file 2.0 version!

DBSQL.pm handles almost all the work of data access, and SQL/MySQL does all the file-handling.