import rt 3.4.6
[freeside.git] / rt / lib / RT / Templates_Overlay.pm
1 # BEGIN BPS TAGGED BLOCK {{{
2
3 # COPYRIGHT:
4 #  
5 # This software is Copyright (c) 1996-2005 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., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27
28 # CONTRIBUTION SUBMISSION POLICY:
29
30 # (The following paragraph is not intended to limit the rights granted
31 # to you to modify and distribute this software under the terms of
32 # the GNU General Public License and is only of importance to you if
33 # you choose to contribute your changes and enhancements to the
34 # community by submitting them to Best Practical Solutions, LLC.)
35
36 # By intentionally submitting any modifications, corrections or
37 # derivatives to this work, or any other work intended for use with
38 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 # you are the copyright holder for those contributions and you grant
40 # Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
41 # royalty-free, perpetual, license to use, copy, create derivative
42 # works based on those contributions, and sublicense and distribute
43 # those contributions and any derivatives thereof.
44
45 # END BPS TAGGED BLOCK }}}
46
47 =head1 NAME
48
49   RT::Templates - a collection of RT Template objects
50
51 =head1 SYNOPSIS
52
53   use RT::Templates;
54
55 =head1 DESCRIPTION
56
57
58 =head1 METHODS
59
60 =begin testing
61
62 ok (require RT::Templates);
63
64 =end testing
65
66 =cut
67
68
69 package RT::Templates;
70
71 use strict;
72 no warnings qw(redefine);
73
74
75 # {{{ sub _Init
76
77 =head2 _Init
78
79   Returns RT::Templates specific init info like table and primary key names
80
81 =cut
82
83 sub _Init {
84     
85     my $self = shift;
86     $self->{'table'} = "Templates";
87     $self->{'primary_key'} = "id";
88     return ($self->SUPER::_Init(@_));
89 }
90 # }}}
91
92 # {{{ LimitToNotInQueue
93
94 =head2 LimitToNotInQueue
95
96 Takes a queue id # and limits the returned set of templates to those which 
97 aren't that queue's templates.
98
99 =cut
100
101 sub LimitToNotInQueue {
102     my $self = shift;
103     my $queue_id = shift;
104     $self->Limit(FIELD => 'Queue',
105                  VALUE => "$queue_id",
106                  OPERATOR => '!='
107                 );
108 }
109 # }}}
110
111 # {{{ LimitToGlobal
112
113 =head2 LimitToGlobal
114
115 Takes no arguments. Limits the returned set to "Global" templates
116 which can be used with any queue.
117
118 =cut
119
120 sub LimitToGlobal {
121     my $self = shift;
122     my $queue_id = shift;
123     $self->Limit(FIELD => 'Queue',
124                  VALUE => "0",
125                  OPERATOR => '='
126                 );
127 }
128 # }}}
129
130 # {{{ LimitToQueue
131
132 =head2 LimitToQueue
133
134 Takes a queue id # and limits the returned set of templates to that queue's
135 templates
136
137 =cut
138
139 sub LimitToQueue {
140     my $self = shift;
141     my $queue_id = shift;
142     $self->Limit(FIELD => 'Queue',
143                  VALUE => "$queue_id",
144                  OPERATOR => '='
145                 );
146 }
147 # }}}
148
149 # {{{ sub NewItem 
150
151 =head2 NewItem
152
153 Returns a new empty Template object
154
155 =cut
156
157 sub NewItem  {
158   my $self = shift;
159
160   use RT::Template;
161   my $item = new RT::Template($self->CurrentUser);
162   return($item);
163 }
164 # }}}
165
166 # {{{ sub Next 
167
168 =head2 Next
169
170 Returns the next template that this user can see.
171
172 =cut
173   
174 sub Next {
175     my $self = shift;
176     
177     
178     my $templ = $self->SUPER::Next();
179     if ((defined($templ)) and (ref($templ))) {
180         
181         # If it's part of a queue, and the user can read templates in
182         # that queue, or the user can globally read templates, show it
183         if ($templ->Queue && $templ->CurrentUserHasQueueRight('ShowTemplate') or
184             $templ->CurrentUser->HasRight(Object => $RT::System, Right => 'ShowTemplate')) {
185             return($templ);
186         }
187         
188         #If the user doesn't have the right to show this template
189         else {  
190             return($self->Next());
191         }
192     }
193     #if there never was any template
194     else {
195         return(undef);
196     }   
197     
198 }
199 # }}}
200
201 1;
202