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?
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] } } );
}
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] } } );
}