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

Question only for experts.

Quote Reply
Question only for experts.
The following is a global i've been working on today, what it does is display a pulldown menu of all categories that contain links with a certain criteria, usefull if you plan to have multiple types of records in your links SQL instalation. But.. I've a small problem... at the end of the code you'll see a sort routine

I took almost all of this from Links SQL code, but I don't understand how to sort the pulldown by name and indent the subcategories like this:

MAIN CATEGORY1
.....Subcategory
.....Subcategory

MAIN CATEGORY2
.....Subcategory
.....Subcategory

As you can see with the code I had to place the ident field on the right. There's NO WAY a Can ident the fields and sort it by name properly. can somebody give me a hand?


Code:

sub {

#################################################################

# SHOW ONLY CATEGORIES THAT CONTAIN LINKS OF TYPE $LinkType #

#################################################################

my $onlyroot = 0; # set to 1 for displaying root categories only

my $mult = 1; # Number of columns

my $margin = " >>>> ";

###############################################################

my ($rec) = @_;

my $LinkType = $rec->{LinkType} || 'Regular';

my ($name,$id,$category,$ident);

my $db = $DB->table('Category');

my $self = $DB->html($db, $IN);

my $sth = $db->select ( ['ID', 'Full_Name', 'FatherID'] );

my $cat_link = $DB->table('CatLinks', 'Links', 'Category');

my %res = ();

my %sortby = ();

while (my ($id, $name, $tags) = $sth->fetchrow_array) {

my $child_total = $cat_link->count(GT::SQL::Condition->new(['Full_Name', 'LIKE', "$name/%"], ['isValidated', '=', 'Yes'], ['LinkType', '=', "$LinkType"]));

my $root_total = $cat_link->count({ LinkType => $LinkType, isValidated => 'Yes', 'Links.ID' => $id });

my $total_acum = ($child_total + $root_total);

$ident = "";

if ($tags == 0) {$ident = "$margin"}

if ($onlyroot == 1) {

if (($total_acum > 0) && ($tags == 0)) {

$res{$id} = "$name $ident";

$sortby{$id} = "$name";

}

}

else {

if ($total_acum > 0) {

$res{$id} = "$name $ident";

$sortby{$id} = "$name";

}

}

}

return $self->select ( { name => $name, values => \%res, value => $id, multiple => $mult , sort => sub { lc $_[0] cmp lc $_[1] } } );

}

Last edited by:

jaltuve: Mar 28, 2003, 4:41 PM
Subject Author Views Date
Thread Question only for experts. jaltuve 3206 Mar 28, 2003, 4:40 PM
Thread Re: [jaltuve] Question only for experts.
webmaster33 3115 Mar 29, 2003, 8:44 AM
Thread Re: [webmaster33] Question only for experts.
Paul 3078 Mar 29, 2003, 8:58 AM
Thread Re: [Paul] Question only for experts.
webmaster33 3091 Mar 29, 2003, 9:16 AM
Thread Re: [webmaster33] Question only for experts.
Paul 3083 Mar 29, 2003, 9:29 AM
Thread Re: [Paul] Question only for experts.
webmaster33 3087 Mar 29, 2003, 9:36 AM
Thread Re: [webmaster33] Question only for experts.
jaltuve 3057 Mar 29, 2003, 3:44 PM
Post Re: [jaltuve] Question only for experts.
webmaster33 3050 Mar 29, 2003, 5:32 PM