package Plugins::CategoryList; use strict; use GT::Base; use GT::Plugins qw/STOP CONTINUE/; use Links qw/:objects/; # Inherit from base class for debug and error methods @Plugins::CategoryList::ISA = qw(GT::Base); use Links::Plugins; # PLUGIN HOOKS # sub handle { my $base_cat_id = $_[0] || 0; my $Category = $DB->table("Category"); $Category->select_options("ORDER BY Name ASC"); my $sth = $Category->select( { FatherID => $base_cat_id } ) || die $GT::SQL::error; my @loop; while (my $cat = $sth->fetchrow_hashref) { $cat->{URL} = $CFG->{build_root_url} . "/". $Category->as_url( $cat->{Full_Name} ) . "/"; # add in any sub-cats, if we have any my @loop2; if ($Category->count({ FatherID => $cat->{ID} }) > 0) { $Category->select_options("ORDER BY Name ASC"); my $sth_2 = $Category->select( { FatherID => $cat->{ID} } ) || die $GT::SQL::error; while (my $cat_2 = $sth_2->fetchrow_hashref) { $cat_2->{URL} = $CFG->{build_root_url} . "/". $Category->as_url( $cat_2->{Full_Name} ) . "/"; # do the 3rd level deep now my @loop3; if ($Category->count({ FatherID => $cat_2->{ID} }) > 0) { $Category->select_options("ORDER BY Name ASC"); my $sth_3 = $Category->select( { FatherID => $cat_2->{ID} } ) || die $GT::SQL::error; while (my $cat_3 = $sth_3->fetchrow_hashref) { $cat_3->{URL} = $CFG->{build_root_url} . "/". $Category->as_url( $cat_3->{Full_Name} ) . "/"; $cat_3->{links_loop3} = get_links($cat_3->{ID}); push @loop3, $cat_3; } } $cat_2->{sub_cat_loop2} = \@loop3; $cat_2->{links_loop2} = get_links($cat_2->{ID}); push @loop2, $cat_2; } } $cat->{sub_cat_loop1} = \@loop2; $cat->{links_loop1} = get_links($cat->{ID}); push @loop, $cat; } return { all_cat_loop => \@loop }; } sub get_links { my $tbl = $DB->table("CatLinks","Links"); $tbl->select_options("ORDER BY Title ASC"); my $sth = $tbl->select( { "CatLinks.CategoryID" => $_[0], isValidated => "Yes" } ) || die $GT::SQL::error; my @links; while (my $link = $sth->fetchrow_hashref) { push @links, $link; } return \@links; } 1;