diff options
Diffstat (limited to 'rt/share/html/Articles/Topics.html')
-rw-r--r-- | rt/share/html/Articles/Topics.html | 249 |
1 files changed, 88 insertions, 161 deletions
diff --git a/rt/share/html/Articles/Topics.html b/rt/share/html/Articles/Topics.html index 9a07c089a..5187315f7 100644 --- a/rt/share/html/Articles/Topics.html +++ b/rt/share/html/Articles/Topics.html @@ -48,7 +48,6 @@ <& /Elements/Header, Title => loc('Browse by topic') &> <& /Elements/Tabs &> -<& /Elements/ListActions, actions => \@Actions &> <a href="Topics.html"><&|/l&>All topics</&></a> % if (defined $class) { > <a href="Topics.html?class=<%$currclass_id%>"><% $currclass_name %></a> @@ -59,71 +58,41 @@ % } <br /> <h1><&|/l&>Browse by topic</&></h1> -<%perl> -if (defined $class) { - $m->print('<h2>'.'<a href="'. - RT->Config->Get('WebPath')."/Articles/Topics.html?class=" . $currclass_id - .'">'.$currclass_name."</a></h2>\n"); - ProduceTree(\@Actions, $currclass, $currclass_id, $currclass_name, 0, $id); -} else { - $m->print("<ul>\n"); - while (my $c = $Classes->Next) { - $m->print('<li><h2>'.'<a href="'. - RT->Config->Get('WebPath')."/Articles/Topics.html?class=" . $c->Id - .'">'.$c->Name."</a></h2>\n"); - $m->print("\n</li>\n"); - } - $m->print(qq|<li><h2><a href="|.RT->Config->Get('WebPath').qq|/Articles/Topics.html?class=0">|.loc('Global Topics').qq|</a></h2></li>\n|); - $m->print("</ul>\n"); -} -</%perl> +% if (defined $class) { +<h2><a href="<% RT->Config->Get('WebPath') %>/Articles/Topics.html?class=<% $currclass_id %>"><% $currclass_name %></a></h2> +% my $rtopic = RT::Topic->new( $session{'CurrentUser'} ); +% $rtopic->Load($id); +% unless ( $rtopic->Id() +% && $rtopic->ObjectId() == $currclass->Id ) +% { +% # Show all of them +% $ProduceTree->( 0 ); +% } else { +% my @showtopics = ( $rtopic ); +% my $parent = $rtopic->ParentObj; +% while ( $parent->Id ) { +% unshift @showtopics, $parent; +% $parent = $parent->ParentObj; +% } +% # List the topics. +% for my $t ( @showtopics ) { +<ul><li><& /Articles/Elements/ShowTopicLink, Topic => $t, Class => $currclass_id &> +% $ProduceTree->( $id ) if $t->Id == $id; +% } +% for ( @showtopics ) { + </li></ul> +% } +% } +% } else { +<ul> +% while (my $c = $Classes->Next) { +<li><h2><a href="<% RT->Config->Get('WebPath') %>/Articles/Topics.html?class=<% $c->Id %>"><% $c->Name %></a></h2></li> +% } +<li><h2><a href="<% RT->Config->Get('WebPath') %>/Articles/Topics.html?class=0"><&|/l&>Global Topics</&></a></h2></li> +</ul> +% } <br /> -<%perl> -my @articles; -if ($id or $showall) { - my $Articles = RT::ObjectTopics->new($session{'CurrentUser'}); - $Articles->Limit(FIELD => 'ObjectType', VALUE => 'RT::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'); - } - } - } - @articles = map {$a = RT::Article->new($session{'CurrentUser'}); $a->Load($_->ObjectId); $a} @{$Articles->ItemsArrayRef} -} elsif ($class) { - my $Articles = RT::Articles->new($session{'CurrentUser'}); - my $TopicsAlias = $Articles->Join( - TYPE => 'left', - ALIAS1 => 'main', - FIELD1 => 'id', - TABLE2 => 'ObjectTopics', - FIELD2 => 'ObjectId', - ); - $Articles->Limit( - LEFTJOIN => $TopicsAlias, - FIELD => 'ObjectType', - VALUE => 'RT::Article', - ); - $Articles->Limit( - ALIAS => $TopicsAlias, - FIELD => 'Topic', - OPERATOR => 'IS', - VALUE => 'NULL', - QUOTEVALUE => 0, - ); - $Articles->Limit( - FIELD => 'Class', - OPERATOR => '=', - VALUE => $class, - ); - @articles = @{$Articles->ItemsArrayRef}; -} -</%perl> % if (@articles) { % if ($id) { @@ -139,7 +108,6 @@ if ($id or $showall) { % } <%init> -my @Actions; my $Classes; my $currclass; my $currclass_id; @@ -167,106 +135,65 @@ if ($id) { $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, $currclass, $currclass_id, $currclass_name, $parentid, $restrictid ) = @_; - $parentid = 0 unless $parentid; - - # Deal with tree restriction, if any. - if ($restrictid) { - my $rtopic = RT::Topic->new( $session{'CurrentUser'} ); - $rtopic->Load($restrictid); - unless ( $rtopic->Id() - && $rtopic->ObjectId() == $currclass_id ) - { - push( @{$Actions},"Could not restrict view to topic $restrictid"); - - # Start over, without the restriction. - &ProduceTree( $Actions, $currclass, $currclass_id, $currclass_name, $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. - my $indents = @showtopics; - while ( my $t = pop @showtopics ) { - print "<ul>"; - print &MakeLinks( $t, $currclass, $currclass_id, $currclass_name, $t->Children->Count ); - if ( $t->Id == $restrictid ) { - &ProduceTree( $Actions, $currclass, $currclass_id, $currclass_name, $restrictid, undef ); - } - } - print "</ul>" x $indents; - } - } else { - - # No restriction in place. Build the entire tree. - my $topics = RT::Topics->new( $session{'CurrentUser'} ); - $topics->LimitToObject($currclass); - $topics->LimitToKids($parentid); - $topics->OrderBy( FIELD => 'Name' ); - print "<ul>" if $topics->Count; - while ( my $t = $topics->Next ) { - if ( $t->Children->Count ) { - print &MakeLinks( $t, $currclass, $currclass_id, $currclass_name, 1 ); - &ProduceTree( $Actions, $currclass, $currclass_id, $currclass_name, $t->Id ); - } else { - print &MakeLinks( $t, $currclass, $currclass_id, $currclass_name, 0 ); - } - } - print "</ul>\n" if $topics->Count; +my $ProduceTree; +$ProduceTree = sub { + my ( $parentid ) = @_; + my $topics = RT::Topics->new( $session{'CurrentUser'} ); + $topics->LimitToObject($currclass); + $topics->LimitToKids($parentid || 0); + $topics->OrderBy( FIELD => 'Name' ); + return unless $topics->Count; + $m->out("<ul>"); + while ( my $t = $topics->Next ) { + $m->out("<li>"); + $m->comp("/Articles/Elements/ShowTopicLink", + Topic => $t, + Class => $currclass_id, + ); + $ProduceTree->( $t->Id ) if $t->Children->Count; + $m->out("</li>"); } -} - -sub MakeLinks { - my ( $topic, $currclass, $currclass_id, $currclass_name, $haschild ) = @_; - my $query; - my $output; - - if ( ref($topic) eq 'RT::Topic' ) { - - my $topic_info = $topic->Name() || loc("(no name)"); - $topic_info .= ": " . $topic->Description() if $topic->Description; - - if ($haschild) { # has topics below it - $query = "Topics.html?id=" . $topic->Id . "&class=" . $currclass_id; - $output = qq(<li><a href="$query">$topic_info</a>); - } else { - $output = qq(<li>$topic_info); - } + $m->out("</ul>"); +}; - my $Articles = RT::ObjectTopics->new( $session{'CurrentUser'} ); - $Articles->Limit( FIELD => 'ObjectType', VALUE => 'RT::Article' ); - $Articles->Limit( FIELD => 'Topic', VALUE => $topic->Id ); - if ( $Articles->Count ) { - my $article_text = " (" . loc( "[quant,_1,article]", $Articles->Count ) . ")"; - my $query = "Topics.html?id=" . $topic->Id . "&class=$currclass_id&showall=1"; - $output .= qq(<a href="$query">$article_text</a>); - } - - $output .= "</li>\n"; - - } else { - - # This builds a link for the class specified, with no particular topic. - $query = "Topics.html?class=" . $currclass_id; - $output = "<li><a href=\"$query\">" . $currclass_name . "</a>"; - $output .= ": " . $currclass->Description if $currclass->Description; +my @articles; +if ($id) { + my $Articles = RT::ObjectTopics->new($session{'CurrentUser'}); + $Articles->Limit(FIELD => 'ObjectType', VALUE => 'RT::Article'); + $Articles->Limit(FIELD => 'Topic', VALUE => $id); + while (my $objtopic = $Articles->Next) { + my $a = RT::Article->new($session{'CurrentUser'}); + $a->Load($objtopic->ObjectId); + push @articles, $a; } - - return $output; +} elsif ($class) { + my $Articles = RT::Articles->new($session{'CurrentUser'}); + my $TopicsAlias = $Articles->Join( + TYPE => 'left', + ALIAS1 => 'main', + FIELD1 => 'id', + TABLE2 => 'ObjectTopics', + FIELD2 => 'ObjectId', + ); + $Articles->Limit( + LEFTJOIN => $TopicsAlias, + FIELD => 'ObjectType', + VALUE => 'RT::Article', + ); + $Articles->Limit( + ALIAS => $TopicsAlias, + FIELD => 'Topic', + OPERATOR => 'IS', + VALUE => 'NULL', + QUOTEVALUE => 0, + ); + $Articles->Limit( + FIELD => 'Class', + OPERATOR => '=', + VALUE => $class, + ); + @articles = @{$Articles->ItemsArrayRef}; } - </%init> <%args> |