]>
Commit | Line | Data |
---|---|---|
84fb5b46 MKG |
1 | %# BEGIN BPS TAGGED BLOCK {{{ |
2 | %# | |
3 | %# COPYRIGHT: | |
4 | %# | |
5 | %# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC | |
6 | %# <sales@bestpractical.com> | |
7 | %# | |
8 | %# (Except where explicitly superseded by other copyright notices) | |
9 | %# | |
10 | %# | |
11 | %# LICENSE: | |
12 | %# | |
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 | |
16 | %# from www.gnu.org. | |
17 | %# | |
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. | |
22 | %# | |
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. | |
28 | %# | |
29 | %# | |
30 | %# CONTRIBUTION SUBMISSION POLICY: | |
31 | %# | |
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.) | |
37 | %# | |
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. | |
46 | %# | |
47 | %# END BPS TAGGED BLOCK }}} | |
48 | <& /Elements/Header, Title => loc('Browse by topic') &> | |
49 | <& /Elements/Tabs &> | |
50 | ||
51 | <a href="Topics.html"><&|/l&>All topics</&></a> | |
52 | % if (defined $class) { | |
53 | > <a href="Topics.html?class=<%$currclass_id%>"><% $currclass_name %></a> | |
54 | % } | |
55 | ||
56 | % if ($id != 0) { | |
57 | > <& /Articles/Elements/ShowTopic, topic => $currtopic &> | |
58 | % } | |
59 | <br /> | |
60 | <h1><&|/l&>Browse by topic</&></h1> | |
61 | % if (defined $class) { | |
62 | <h2><a href="<% RT->Config->Get('WebPath') %>/Articles/Topics.html?class=<% $currclass_id %>"><% $currclass_name %></a></h2> | |
63 | % my $rtopic = RT::Topic->new( $session{'CurrentUser'} ); | |
64 | % $rtopic->Load($id); | |
65 | % unless ( $rtopic->Id() | |
66 | % && $rtopic->ObjectId() == $currclass->Id ) | |
67 | % { | |
68 | % # Show all of them | |
69 | % $ProduceTree->( 0 ); | |
70 | % } else { | |
71 | % my @showtopics = ( $rtopic ); | |
72 | % my $parent = $rtopic->ParentObj; | |
73 | % while ( $parent->Id ) { | |
74 | % unshift @showtopics, $parent; | |
75 | % $parent = $parent->ParentObj; | |
76 | % } | |
77 | % # List the topics. | |
78 | % for my $t ( @showtopics ) { | |
79 | <ul><li><& /Articles/Elements/ShowTopicLink, Topic => $t, Class => $currclass_id &> | |
80 | % $ProduceTree->( $id ) if $t->Id == $id; | |
81 | % } | |
82 | % for ( @showtopics ) { | |
83 | </li></ul> | |
84 | % } | |
85 | % } | |
86 | % } else { | |
87 | <ul> | |
88 | % while (my $c = $Classes->Next) { | |
89 | <li><h2><a href="<% RT->Config->Get('WebPath') %>/Articles/Topics.html?class=<% $c->Id %>"><% $c->Name %></a></h2></li> | |
90 | % } | |
91 | <li><h2><a href="<% RT->Config->Get('WebPath') %>/Articles/Topics.html?class=0"><&|/l&>Global Topics</&></a></h2></li> | |
92 | </ul> | |
93 | % } | |
94 | ||
95 | <br /> | |
96 | ||
97 | % if (@articles) { | |
98 | % if ($id) { | |
99 | <h2><&|/l, $currtopic->Name&>Articles in [_1]</&></h2> | |
100 | % } elsif ($class) { | |
101 | <h2><&|/l&>Articles with no topics</&></h2> | |
102 | % } | |
103 | <ul> | |
104 | % for my $a (@articles) { | |
105 | <li><a href="Article/Display.html?id=<% $a->Id %>"><% $a->Name || loc("(no name)") %></a></li> | |
106 | % } | |
107 | </ul> | |
108 | % } | |
109 | ||
110 | <%init> | |
111 | my $Classes; | |
112 | my $currclass; | |
113 | my $currclass_id; | |
114 | my $currclass_name; | |
115 | my $currtopic; | |
116 | ||
117 | if ( defined $class ) { | |
118 | if ($class) { | |
119 | $currclass = RT::Class->new( $session{'CurrentUser'} ); | |
120 | $currclass->Load($class); | |
121 | $currclass_id = $currclass->Id; | |
122 | $currclass_name = $currclass->Name; | |
123 | } else { | |
124 | $currclass = $RT::System; | |
125 | $currclass_id = 0; | |
126 | $currclass_name = 'Global Topics'; | |
127 | } | |
128 | } else { | |
129 | $Classes = RT::Classes->new( $session{'CurrentUser'} ); | |
130 | $Classes->LimitToEnabled(); | |
131 | } | |
132 | ||
133 | if ($id) { | |
134 | $currtopic = RT::Topic->new( $session{'CurrentUser'} ); | |
135 | $currtopic->Load($id); | |
136 | } | |
137 | ||
138 | my $ProduceTree; | |
139 | $ProduceTree = sub { | |
140 | my ( $parentid ) = @_; | |
141 | my $topics = RT::Topics->new( $session{'CurrentUser'} ); | |
142 | $topics->LimitToObject($currclass); | |
143 | $topics->LimitToKids($parentid || 0); | |
144 | $topics->OrderBy( FIELD => 'Name' ); | |
145 | return unless $topics->Count; | |
146 | $m->out("<ul>"); | |
147 | while ( my $t = $topics->Next ) { | |
148 | $m->out("<li>"); | |
149 | $m->comp("/Articles/Elements/ShowTopicLink", | |
150 | Topic => $t, | |
151 | Class => $currclass_id, | |
152 | ); | |
153 | $ProduceTree->( $t->Id ) if $t->Children->Count; | |
154 | $m->out("</li>"); | |
155 | } | |
156 | $m->out("</ul>"); | |
157 | }; | |
158 | ||
159 | my @articles; | |
160 | if ($id) { | |
161 | my $Articles = RT::ObjectTopics->new($session{'CurrentUser'}); | |
162 | $Articles->Limit(FIELD => 'ObjectType', VALUE => 'RT::Article'); | |
163 | $Articles->Limit(FIELD => 'Topic', VALUE => $id); | |
164 | while (my $objtopic = $Articles->Next) { | |
165 | my $a = RT::Article->new($session{'CurrentUser'}); | |
166 | $a->Load($objtopic->ObjectId); | |
167 | push @articles, $a; | |
168 | } | |
169 | } elsif ($class) { | |
170 | my $Articles = RT::Articles->new($session{'CurrentUser'}); | |
171 | my $TopicsAlias = $Articles->Join( | |
172 | TYPE => 'left', | |
173 | ALIAS1 => 'main', | |
174 | FIELD1 => 'id', | |
175 | TABLE2 => 'ObjectTopics', | |
176 | FIELD2 => 'ObjectId', | |
177 | ); | |
178 | $Articles->Limit( | |
179 | LEFTJOIN => $TopicsAlias, | |
180 | FIELD => 'ObjectType', | |
181 | VALUE => 'RT::Article', | |
182 | ); | |
183 | $Articles->Limit( | |
184 | ALIAS => $TopicsAlias, | |
185 | FIELD => 'Topic', | |
186 | OPERATOR => 'IS', | |
187 | VALUE => 'NULL', | |
188 | QUOTEVALUE => 0, | |
189 | ); | |
190 | $Articles->Limit( | |
191 | FIELD => 'Class', | |
192 | OPERATOR => '=', | |
193 | VALUE => $class, | |
194 | ); | |
195 | @articles = @{$Articles->ItemsArrayRef}; | |
196 | } | |
197 | </%init> | |
198 | ||
199 | <%args> | |
200 | $id => 0 | |
201 | $class => undef | |
202 | $showall => undef | |
203 | </%args> |