Gossamer Forum
Quote Reply
Category list issue
This is really a basic question about PageBuilder and printing category lists ...

I want to create a new OPML-file, which is an XML-file looking like this:

Code:
...
<outline text="Services">
<outline text="Google API">
<outline text="Implementations">
</outline>
<outline text="Applications">
</outline>
</outline>
<outline text="xmlStorageSystem">
<outline text="Implementations">
</outline>
</outline>
</outline>
...



Here, "Services" would be a toplevel category, with "Google API" and "xmlStorageSystem" would be sub-categories (and "Implementations" the name of two sub-sub-categories, etc.).
But with some somewhat complex nesting within tags...

Can anyone help me here?

I can make the "flat" lists, like these...

Get and print main categories:

Code:
sub {
my $tags = shift;
my $cat_db = $DB->table('Category');
my @root_cats = $cat_db->select (['Full_Name'], { FatherID => 0 })->fetchall_list;
my $output;
foreach my $root_cat (@root_cats) {
my $url = $cat_db->as_url($root_cat);
my $id = $cat_db->as_id($root_cat);
$output .= qq~<outline text="$root_cat" type="link" url="$CFG->{build_root_url}/$url" />\n~;
}
return $output;
}


Get and print all categories:

Code:
sub {
my $tags = shift;
my $cat_db = $DB->table('Category');
$cat_db->select_options("ORDER BY Full_Name");
my @root_cats = $cat_db->select (['Full_Name'])->fetchall_list;
my $output;
foreach my $root_cat (@root_cats) {
my $url = $cat_db->as_url($root_cat);
$output .= qq~<outline text="$root_cat" type="link" url="$CFG->{build_root_url}/$url" />\n~;
}
return $output;
}


But how to make the nested lists??

Last edited by:

gotze: Apr 16, 2003, 12:18 PM
Quote Reply
Re: [gotze] Category list issue In reply to
Hi,

You don't happen to have a global that list all links in one Main category and all sub categorories of that mai n category do you?

Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Category list issue In reply to
Something like this?

sub {
my ($all_ids,@list);

my $tags = shift
my $cat_id = $tags->{ID};
$all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids, $cat_id;
my $link_db = $DB->table('Links','CatLinks','Category');
my $condition = GT::SQL::Condition->new( 'isValidated','=','Yes','CategoryID', 'IN', \@$all_ids);
my $sth = $link_db->select($condition);
while (my $link = $sth->fetchrow_hashref) {
push @list, $link;
}

my $output;
foreach my $link (@list) {
$output .= qq~<li><a href="$CFG->{db_cgi_url}/jump.cgi?ID=$link->{ID}">$link->{'Title'}</a>~;
}

return $output;

}
Quote Reply
Re: [afinlr] Category list issue In reply to
Cheers :-)

Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Category list issue In reply to
OK, back to my question now, please Angelic Anyone?
Quote Reply
Re: [gotze] Category list issue In reply to
If you start with your root cats sub, so that you select the root cats using

my $sth0 = $cat_db->select ( ['ID','Full_Name'],{ FatherID => 0 });

then use a while loop to loop through the root categories instead of your foreach loop:

while (my ($cat_id,$name) = $sth2->fetchrow_array){ ... }

Now, within the while loop you could add another select for all the sub categories of that root category using

my $sth1 = $cat_db->select ( ['ID','Full_Name'],{ FatherID => $cat_id });

and keep going for the depth that you want.

Hope that makes sense.

Laura.
Quote Reply
Re: [afinlr] Category list issue In reply to
Thanks Laura,

Now, don't laugh at me ... here is what I'm trying. Of course, it's wrong, because I basically don't know what I'm doing ...

Code:


sub {
my $tags = shift;
my $cat_db = $DB->table('Category');
my $sth0 = $cat_db->select ( ['ID','Full_Name'],{ FatherID => 0 });

$output .= qq~</outline>\n~;
my $output;
while (my ($cat_id,$name) = $sth2->fetchrow_array){
my $sth1 = $cat_db->select ( ['ID','Full_Name'],{ FatherID => $cat_id });
$output .= qq~<outline text="$sth1" type="link" />\n~;
}
return $output;
}


Well, it must be something like this, just coded right Crazy Please help ...

John
Quote Reply
Re: [gotze] Category list issue In reply to
You're on the right lines but I think it is a little more involved than that. Something like this?

sub {
my $tags = shift;
my $cat_db = $DB->table('Category');
my $sth0 = $cat_db->select ( ['ID','Full_Name'],{ FatherID => 0 });

my ($output,$url,$url1,$url2);
while (my ($cat_id,$name) = $sth0->fetchrow_array){
$url = $cat_db->as_url($name);
$output .= qq~<outline text="$name" type="link" url="$CFG->{build_root_url}/$url">\n~;
my $sth1 = $cat_db->select ( ['ID','Full_Name'],{ FatherID => $cat_id });
while (my ($cat1_id,$name1) = $sth1->fetchrow_array){
$url1 = $cat_db->as_url($name1);
$output .= qq~<outline text="$name1" type="link" url="$CFG->{build_root_url}/$url1">\n~;
my $sth2 = $cat_db->select ( ['ID','Full_Name'],{ FatherID => $cat1_id });
while (my ($cat2_id,$name2) = $sth2->fetchrow_array){
$url2 = $cat_db->as_url($name2);
$output .= qq~<outline text="$name2" type="link" url="$CFG->{build_root_url}/$url2">\n~;
# If you need more depth you'll need to add more while loops in here.
$output .= "</outline>";
}
$output .= "</outline>";
}
$output .= "</outline>";
}
return $output;
}
Quote Reply
Re: [afinlr] Category list issue In reply to
Yes!! That did it. I'm thrilled! Thanks Laura Smile

FWIW, I use the global to produce an OPML-file, see

http://slashdemocracy.org/links/all.opml

This allows me to do cool stuff, such as this:

http://slashdemocracy.org/...ser.php?fil=all.opml
(which might not look like much, but really is way cool ... see my blog more more)

Once again, LSQL proves to be such a wonderful tool. Everything is possible with it, it seems ... especially with a little help from wonderful people like Laura.

John
PS: If anyone is using this code, just add $cat_db->select_options("ORDER BY Full_Name"); to order the list alphabetically.
PPS: Anyone interested in OPML? Let me know. (OK, I have said that several times before ... I know)
Quote Reply
Re: [gotze] Category list issue In reply to
How about WML? It more interesting Smile

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Category list issue In reply to
WML? Maybe. I don't think it's useful in my case, but there may be places where it's useful.

John
Quote Reply
Re: [gotze] Category list issue In reply to
Was just joking... I'm going to dig a bit into WML nowadays.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...