%# BEGIN LICENSE BLOCK %# %# Copyright (c) 2002-2003 Jesse Vincent %# %# This program is free software; you can redistribute it and/or modify %# it under the terms of version 2 of the GNU General Public License %# as published by the Free Software Foundation. %# %# A copy of that license should have arrived with this %# software, but in any event can be snarfed from www.gnu.org. %# %# This program is distributed in the hope that it will be useful, %# but WITHOUT ANY WARRANTY; without even the implied warranty of %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %# GNU General Public License for more details. %# %# END LICENSE BLOCK <& /RTFM/Elements/Tabs, current_toptab => "RTFM/Topics.html", Title => loc('Browse by topic'), class => $class, topic => $id &> <& /Elements/ListActions, actions => \@Actions &> <&|/l&>All topics % if (defined $class) { > <% $currclass->Name %> % } % if ($id != 0) { > <& /RTFM/Elements/ShowTopic, topic => $currtopic &> % }

<&|/l&>Browse by topic

% if ($id || $showall) { %# TODO: Eventually it would be nice to show all for classes too. Thus %# the condition above.
<%perl> my $Articles = RT::FM::ObjectTopicCollection->new($session{'CurrentUser'}); $Articles->Limit(FIELD => 'ObjectType', VALUE => 'RT::FM::Article'); if ($id) { $Articles->Limit(FIELD => 'Topic', VALUE => $id, ENTRYAGGREGATOR => 'OR'); if ($showall) { my $kids = $currtopic->Children; while (my $k = $kids->Next) { $Articles->Limit(FIELD => 'Topic', VALUE => $k->Id, ENTRYAGGREGATOR => 'OR'); } } } % if ($Articles->Count) {

Articles in this topic

% } else { %#<&|/l&>No articles found in this topic % } % } <%init> my @Actions; my $Classes; my $currclass; my $currtopic; if ($class) { $currclass = RT::FM::Class->new($session{'CurrentUser'}); $currclass->Load($class); } else { $Classes = RT::FM::ClassCollection->new($session{'CurrentUser'}); $Classes->UnLimit; } if ($id) { $currtopic = RT::FM::Topic->new($session{'CurrentUser'}); $currtopic->Load($id); } # A subroutine that iterates through topics and their children, producing # the necessary ul, li, and href links for the table of contents. Thank # heaven for query caching. The $restrict variable is used to display only # the branch of the hierarchy which contains that topic ID. sub ProduceTree { my ($Actions, $c, $parentid, $restrictid) = @_; $parentid = 0 unless $parentid; # Deal with tree restriction, if any. if ($restrictid) { my $rtopic = RT::FM::Topic->new($session{'CurrentUser'}); $rtopic->Load($restrictid); unless ($rtopic->Id() && $rtopic->ObjectId() == $c->Id) { push(@{$Actions}, "Could not restrict view to topic $restrictid"); # Start over, without the restriction. &ProduceTree($Actions, $c, $parentid, undef); } else { my @showtopics; push(@showtopics, $rtopic); my $parent = $rtopic->ParentObj; while ($parent->Id) { push(@showtopics, $parent); my $newparent = $parent->ParentObj; $parent = $newparent; } # List the topics. while (my $t = pop @showtopics) { print "";# x scalar(@showtopics); } } } else { # No restriction in place. Build the entire tree. my $topics = RT::FM::TopicCollection->new($session{'CurrentUser'}); $topics->LimitToObject($c); $topics->LimitToKids($parentid); while (my $t = $topics->Next) { print "\n"; } } } sub MakeLinks { my ($topic, $c, $haschild) = @_; my $query; my $output; if (ref($topic) eq 'RT::FM::Topic') { if ($haschild) { $query = "Topics.html?id=" . $topic->Id . "&class=" . $c->Id; } else { $query = "Topics.html?id=" . $topic->Id . "&class=" . $c->Id . "&showall=1"; } $output = "
  • " . $topic->Name(); $output .= ": " . $topic->Description() if $topic->Description(); $output .= ""; if ($haschild) { # Commented out by Jesse, since it seems confusing # # $output .= "    [ Show all articles ]"; } $output .= "
  • \n"; } else { # This builds a link for the class specified, with no particular # topic. $query = "Topics.html?class=" . $c->Id; $output = "
  • " . $c->Name . ""; $output .= ": " . $c->Description if $c->Description; } return $output; } <%args> $id => 0 $class => undef $showall => undef