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