1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
6 %# <sales@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 %# General Public License for more details.
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 %# CONTRIBUTION SUBMISSION POLICY:
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
47 %# END BPS TAGGED BLOCK }}}
48 <& /Elements/Header, Title => loc('Browse by topic') &>
51 <& /Elements/ListActions, actions => \@Actions &>
52 <a href="Topics.html"><&|/l&>All topics</&></a>
53 % if (defined $class) {
54 > <a href="Topics.html?class=<%$currclass_id%>"><% $currclass_name %></a>
58 > <& /Articles/Elements/ShowTopic, topic => $currtopic &>
61 <h1><&|/l&>Browse by topic</&></h1>
64 $m->print('<h2>'.'<a href="'.
65 RT->Config->Get('WebPath')."/Articles/Topics.html?class=" . $currclass_id
66 .'">'.$currclass_name."</a></h2>\n");
67 ProduceTree(\@Actions, $currclass, $currclass_id, $currclass_name, 0, $id);
70 while (my $c = $Classes->Next) {
71 $m->print('<li><h2>'.'<a href="'.
72 RT->Config->Get('WebPath')."/Articles/Topics.html?class=" . $c->Id
73 .'">'.$c->Name."</a></h2>\n");
74 $m->print("\n</li>\n");
76 $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|);
84 if ($id or $showall) {
85 my $Articles = RT::ObjectTopics->new($session{'CurrentUser'});
86 $Articles->Limit(FIELD => 'ObjectType', VALUE => 'RT::Article');
88 $Articles->Limit(FIELD => 'Topic', VALUE => $id, ENTRYAGGREGATOR => 'OR');
90 my $kids = $currtopic->Children;
91 while (my $k = $kids->Next) {
92 $Articles->Limit(FIELD => 'Topic', VALUE => $k->Id,
93 ENTRYAGGREGATOR => 'OR');
97 @articles = map {$a = RT::Article->new($session{'CurrentUser'}); $a->Load($_->ObjectId); $a} @{$Articles->ItemsArrayRef}
99 my $Articles = RT::Articles->new($session{'CurrentUser'});
100 my $TopicsAlias = $Articles->Join(
104 TABLE2 => 'ObjectTopics',
105 FIELD2 => 'ObjectId',
108 LEFTJOIN => $TopicsAlias,
109 FIELD => 'ObjectType',
110 VALUE => 'RT::Article',
113 ALIAS => $TopicsAlias,
124 @articles = @{$Articles->ItemsArrayRef};
130 <h2><&|/l, $currtopic->Name&>Articles in [_1]</&></h2>
132 <h2><&|/l&>Articles with no topics</&></h2>
135 % for my $a (@articles) {
136 <li><a href="Article/Display.html?id=<% $a->Id %>"><% $a->Name || loc("(no name)") %></a></li>
149 if ( defined $class ) {
151 $currclass = RT::Class->new( $session{'CurrentUser'} );
152 $currclass->Load($class);
153 $currclass_id = $currclass->Id;
154 $currclass_name = $currclass->Name;
156 $currclass = $RT::System;
158 $currclass_name = 'Global Topics';
161 $Classes = RT::Classes->new( $session{'CurrentUser'} );
162 $Classes->LimitToEnabled();
166 $currtopic = RT::Topic->new( $session{'CurrentUser'} );
167 $currtopic->Load($id);
170 # A subroutine that iterates through topics and their children, producing
171 # the necessary ul, li, and href links for the table of contents. Thank
172 # heaven for query caching. The $restrict variable is used to display only
173 # the branch of the hierarchy which contains that topic ID.
176 my ( $Actions, $currclass, $currclass_id, $currclass_name, $parentid, $restrictid ) = @_;
177 $parentid = 0 unless $parentid;
179 # Deal with tree restriction, if any.
181 my $rtopic = RT::Topic->new( $session{'CurrentUser'} );
182 $rtopic->Load($restrictid);
183 unless ( $rtopic->Id()
184 && $rtopic->ObjectId() == $currclass_id )
186 push( @{$Actions},"Could not restrict view to topic $restrictid");
188 # Start over, without the restriction.
189 &ProduceTree( $Actions, $currclass, $currclass_id, $currclass_name, $parentid, undef );
192 push( @showtopics, $rtopic );
193 my $parent = $rtopic->ParentObj;
194 while ( $parent->Id ) {
195 push( @showtopics, $parent );
196 my $newparent = $parent->ParentObj;
197 $parent = $newparent;
201 my $indents = @showtopics;
202 while ( my $t = pop @showtopics ) {
204 print &MakeLinks( $t, $currclass, $currclass_id, $currclass_name, $t->Children->Count );
205 if ( $t->Id == $restrictid ) {
206 &ProduceTree( $Actions, $currclass, $currclass_id, $currclass_name, $restrictid, undef );
209 print "</ul>" x $indents;
213 # No restriction in place. Build the entire tree.
214 my $topics = RT::Topics->new( $session{'CurrentUser'} );
215 $topics->LimitToObject($currclass);
216 $topics->LimitToKids($parentid);
217 $topics->OrderBy( FIELD => 'Name' );
218 print "<ul>" if $topics->Count;
219 while ( my $t = $topics->Next ) {
220 if ( $t->Children->Count ) {
221 print &MakeLinks( $t, $currclass, $currclass_id, $currclass_name, 1 );
222 &ProduceTree( $Actions, $currclass, $currclass_id, $currclass_name, $t->Id );
224 print &MakeLinks( $t, $currclass, $currclass_id, $currclass_name, 0 );
227 print "</ul>\n" if $topics->Count;
232 my ( $topic, $currclass, $currclass_id, $currclass_name, $haschild ) = @_;
236 if ( ref($topic) eq 'RT::Topic' ) {
238 my $topic_info = $topic->Name() || loc("(no name)");
239 $topic_info .= ": " . $topic->Description() if $topic->Description;
241 if ($haschild) { # has topics below it
242 $query = "Topics.html?id=" . $topic->Id . "&class=" . $currclass_id;
243 $output = qq(<li><a href="$query">$topic_info</a>);
245 $output = qq(<li>$topic_info);
248 my $Articles = RT::ObjectTopics->new( $session{'CurrentUser'} );
249 $Articles->Limit( FIELD => 'ObjectType', VALUE => 'RT::Article' );
250 $Articles->Limit( FIELD => 'Topic', VALUE => $topic->Id );
251 if ( $Articles->Count ) {
252 my $article_text = " (" . loc( "[quant,_1,article]", $Articles->Count ) . ")";
253 my $query = "Topics.html?id=" . $topic->Id . "&class=$currclass_id&showall=1";
254 $output .= qq(<a href="$query">$article_text</a>);
257 $output .= "</li>\n";
261 # This builds a link for the class specified, with no particular topic.
262 $query = "Topics.html?class=" . $currclass_id;
263 $output = "<li><a href=\"$query\">" . $currclass_name . "</a>";
264 $output .= ": " . $currclass->Description if $currclass->Description;