import rt 3.6.4
[freeside.git] / rt / lib / RT / Templates_Overlay.pm
1 # BEGIN BPS TAGGED BLOCK {{{
2
3 # COPYRIGHT:
4 #  
5 # This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC 
6 #                                          <jesse@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/copyleft/gpl.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 =head1 NAME
49
50   RT::Templates - a collection of RT Template objects
51
52 =head1 SYNOPSIS
53
54   use RT::Templates;
55
56 =head1 DESCRIPTION
57
58
59 =head1 METHODS
60
61 =begin testing
62
63 ok (require RT::Templates);
64
65 =end testing
66
67 =cut
68
69
70 package RT::Templates;
71
72 use strict;
73 no warnings qw(redefine);
74
75
76 # {{{ sub _Init
77
78 =head2 _Init
79
80   Returns RT::Templates specific init info like table and primary key names
81
82 =cut
83
84 sub _Init {
85     
86     my $self = shift;
87     $self->{'table'} = "Templates";
88     $self->{'primary_key'} = "id";
89     return ($self->SUPER::_Init(@_));
90 }
91 # }}}
92
93 # {{{ LimitToNotInQueue
94
95 =head2 LimitToNotInQueue
96
97 Takes a queue id # and limits the returned set of templates to those which 
98 aren't that queue's templates.
99
100 =cut
101
102 sub LimitToNotInQueue {
103     my $self = shift;
104     my $queue_id = shift;
105     $self->Limit(FIELD => 'Queue',
106                  VALUE => "$queue_id",
107                  OPERATOR => '!='
108                 );
109 }
110 # }}}
111
112 # {{{ LimitToGlobal
113
114 =head2 LimitToGlobal
115
116 Takes no arguments. Limits the returned set to "Global" templates
117 which can be used with any queue.
118
119 =cut
120
121 sub LimitToGlobal {
122     my $self = shift;
123     my $queue_id = shift;
124     $self->Limit(FIELD => 'Queue',
125                  VALUE => "0",
126                  OPERATOR => '='
127                 );
128 }
129 # }}}
130
131 # {{{ LimitToQueue
132
133 =head2 LimitToQueue
134
135 Takes a queue id # and limits the returned set of templates to that queue's
136 templates
137
138 =cut
139
140 sub LimitToQueue {
141     my $self = shift;
142     my $queue_id = shift;
143     $self->Limit(FIELD => 'Queue',
144                  VALUE => "$queue_id",
145                  OPERATOR => '='
146                 );
147 }
148 # }}}
149
150 # {{{ sub NewItem 
151
152 =head2 NewItem
153
154 Returns a new empty Template object
155
156 =cut
157
158 sub NewItem  {
159   my $self = shift;
160
161   use RT::Template;
162   my $item = new RT::Template($self->CurrentUser);
163   return($item);
164 }
165 # }}}
166
167 # {{{ sub Next 
168
169 =head2 Next
170
171 Returns the next template that this user can see.
172
173 =cut
174   
175 sub Next {
176     my $self = shift;
177     
178     
179     my $templ = $self->SUPER::Next();
180     if ((defined($templ)) and (ref($templ))) {
181         
182         # If it's part of a queue, and the user can read templates in
183         # that queue, or the user can globally read templates, show it
184         if ($templ->Queue && $templ->CurrentUserHasQueueRight('ShowTemplate') or
185             $templ->CurrentUser->HasRight(Object => $RT::System, Right => 'ShowTemplate')) {
186             return($templ);
187         }
188         
189         #If the user doesn't have the right to show this template
190         else {  
191             return($self->Next());
192         }
193     }
194     #if there never was any template
195     else {
196         return(undef);
197     }   
198     
199 }
200 # }}}
201
202 1;
203