Gossamer Forum
Quote Reply
Alpha-bar global
Hi,

I'm currently upgrading to Glinks 3.1 from LinksSQL 2.1

I have hard-coded a mod into 2.1 to display an alphabetical sub-category list across the top of the sub-cats section using a custom field IsAlpha (Yes,[No]) - sorted alphabetically, of course Smile

This is handy for things like Actors or Bands, where you list sites under a specific single letter.

Any idea on how to begin converting this to a global?

Many thanks,
Shaun

Last edited by:

qango: Jul 25, 2006, 4:56 AM
Quote Reply
Re: [qango] Alpha-bar global In reply to
Can you paste your mod so I can have a go at converting it? Easier that starting from scratch...
Quote Reply
Re: [qango] Alpha-bar global In reply to
A few ideas from playing with the templates.

Did you do a search on this? I know 2-3 years ago this came up several times. I started an alpha bar, that actually became more of a start/end of word search/select.

The trick with globals, is to remember that since they are working within the template, you need to call them from the template with the right additional (or helpful) parameters. You have access to all the template tags, if you use the new calling conventions, and you can return new values either as :

{key1 => val1, ke2 => val2}, an anon hash that is added to the existing template tags (or overwrites them)

{ 'found_fields_like' => \@found_hashkeys } as the array of hash_refs that you can loop through (push @array hashref) (look in the search pm for some examples)

Or, you can return a hash of hashs, like: { 'return_hash' => {%$rec} } which gives you the hash.field access to variables, so you don't overwrite them or crush them.

There are examples of all this scattered through the code. This gives you a HUGE amount of power to put all the display code and HTML into the templates, and return only arrays or HoH of values to the calling template.

With the new advances in the GL3 code, especially the category tree, you can do things like:

my $letter = shift;
my $id = shift;
$letter .= '%' # that should be start of word is letter, followed by anything
my $cond = GT::SQL::Condition->new('isAlpha' => 'Like' => $letter );
my $children = $tree->children(id = $id, condition => $cond);

Then, you would deal with the display and such of the $children

That should return the list of array of hashrefs (only one ID passed in).

So, your alpha bar would only need to pass in the Category_ID and the starting letter. You could generate your category bar, or even hard-code it into your template with HTML code, and the <%ID%> field for the c ategory.

Paging is pretty automatic, if you add in the mh and nh parameters, just look at some of the code.

The next hurdle is how you want the display pages to be shown. You can have small script, you can pass it back through page.cgi to display the alpha templates, or you could use the standard templates, by adding in a flag to call the global above to return the isAlpha values if a flag field was passed in, or the regular values if not.

Just a few thoughts.... Maybe some are not so clear.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Alpha-bar global In reply to
Okay, here's the code.

It actually creates three separate category groups:- AlphaBar, Top Level, and then the usual regular (level 2) categories.

There are two custom fields in the Category table to achieve this (AlphaBar [Yes,No]) and (Cat_Level [1,2])

Ideally I'd like this same functionality using globals in Glinks, without having to manually edit Build.pm

On the category page itself, I would like the have <%AlphaBar%> if needed (check all subcats for AlphaBar eq 'Yes'), then the level 1 subcats <%SubCats1%>, then the remaining level 2 afterwards <%SubCats2%>.

Any help or advice greatly appreciated Smile

Quote:


# Get the subcategories and related categories as either Yahoo style (integrated) or
# separated into two outputs..
my $subcat_ids = []; my $relate_ids = [];
$display{category_loop} = [$category];
$display{category_loop_top} = [$category];
$display{category_alpha_loop} = [$category];
$display{category_sorted_loop} = [$category];
if ($CFG->{build_category_yahoo}) {
$sth = $cat_db->select ( { FatherID => $category->{ID} }, ['ID'] );
$sth->rows() and ($subcat_ids = $sth->fetchall_arrayref);
$sth = $related_db->select ( { CategoryID => $category->{ID} }, ['RelatedID','RelationName'] ) or die $GT::SQL::error;
$sth->rows() and ($relate_ids = $sth->fetchall_arrayref);
if (@$subcat_ids || @$relate_ids) {
my %rel = map { $_->[0] => $_->[1] } @$relate_ids;
my $ids = '(' . join (",", map { $_->[0] } @$subcat_ids, @$relate_ids) . ')';
$cat_db->select_options ("ORDER BY $CFG->{build_category_sort}") if ($CFG->{build_category_sort});
$sth = $cat_db->select ( GT::SQL::Condition->new ('ID', 'IN', \$ids) );
while (my $cat = $sth->fetchrow_hashref) {
if (exists $rel{$cat->{ID}}) {
$cat->{Related} = 1;
$cat->{Name} = $rel{$cat->{ID}};
}
if ($cat->{Cat_Level} eq "1") {
push @{$display{category_loop_top}}, $cat;
}
else {
if ($cat->{AlphaBar} eq "Yes") {
push @{$display{category_alpha_loop}}, $cat;
}
else {
push @{$display{category_loop}}, $cat;
push @{$display{sort_data}}, $cat;
}
}
}
# Take the current category_loop array of hashes and reorder by the value of the 'Name' field
if (exists $display{sort_data}) {
foreach my $hashref ( sort {lc($a->{Name}) cmp lc($b->{Name})} @{$display{sort_data}}) {
push @{$display{category_sorted_loop}}, $hashref;
}
}
# Print out the sub-category tables
$display{categoryalpha} = Links::SiteHTML::display ('print_cat_alpha', $display{category_alpha_loop});
$display{categorytop} = Links::SiteHTML::display ('print_cat_top', $display{category_loop_top});
$display{category} = Links::SiteHTML::display ('print_cat', $display{category_loop});
if (exists $display{category_sorted_loop}) {
$display{categorysorted} = Links::SiteHTML::display ('print_cat', $display{category_sorted_loop});
}
}
else {
$display{categoryalpha} = '';
$display{categorytop} = '';
$display{category} = '';
$display{categorysorted} = '';
shift @{$display{category_alpha_loop}};
shift @{$display{category_loop_top}};
shift @{$display{category_loop}}; # The loop var shouldn't have the root cat.
shift @{$display{category_sorted_loop}};
}
}

Last edited by:

qango: Jul 27, 2006, 3:49 AM
Quote Reply
Re: [qango] Alpha-bar global In reply to
Is this running on a site somewhere, a picture is worth a thousand words, at least to me :)


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Alpha-bar global In reply to
Pugdog,

Yes, here's a category page featuring all three:

http://www.qango.com/...onditions/index.html

At the top is the Alpha-bar, below is the Cat_Level = 1 subcats, and below are the regular Cat_Level = 2 subcats Smile
Quote Reply
Re: [qango] Alpha-bar global In reply to
I'm still confused. I think I had a completely different idea of what you were doing.

Your alpha bar is really that you set up 26 categories A..Z under the current level, and you are just linking to them. So it seems.

I don't understand the category levels 1 and two.

From what I see, they are simply sub cats under the current directory. Some are related categories, and such.


The alpha bar concept I had, was that links were in different directories, and subdirectories, and the alpha bar was a way to quickly find links within those categories by letter, rather than category *WITHOUT* actually having set up the A..Z categories. They were "virtual" as it were.

So I think I'm missing completely what you are trying to do.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Alpha-bar global In reply to
pugdog,

Sorry, I might not have explained this very well.

Yes, all of the sub-cats exist under the current category. I have created two custom Category fields: Alphabar and Cat_Level

If you look at the example category page I posted, you'll notice a row of single letter subcats across the top - these are just regular sub-cats with the field Alphabar = Yes

Basically "loop through the sub-cats and push all the ones with Alphabar = Yes into this part of the template"

... an underline ...

Next, you'll notice a small block of four sub-categories - above all of the other sub-cats - these are the ones with the field Cat_Level == 1

This is so I can promote (physically on the page) certain subcategories that are more popular than others, or that users might logically expect to find without trolling through a large list of sub-cats.

... an underline ...

Finally the remaining sub-cats (Cat_level == 2) are added to the page as normal.

Does that help better explain it?

Would it help if I posted the HTML from the category template?

Cheers,
Shaun