import rt 3.8.7
[freeside.git] / rt / lib / RT / ScripCondition_Overlay.pm
1 # BEGIN BPS TAGGED BLOCK {{{
2
3 # COPYRIGHT:
4
5 # This software is Copyright (c) 1996-2009 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/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
49 =head1 NAME
50
51   RT::ScripCondition - RT scrip conditional
52
53 =head1 SYNOPSIS
54
55   use RT::ScripCondition;
56
57
58 =head1 DESCRIPTION
59
60 This module should never be called directly by client code. it's an internal module which
61 should only be accessed through exported APIs in other modules.
62
63
64
65 =head1 METHODS
66
67 =cut
68
69
70 package RT::ScripCondition;
71
72 use strict;
73 no warnings qw(redefine);
74
75
76 # {{{  sub _Init 
77 sub _Init  {
78     my $self = shift; 
79     $self->{'table'} = "ScripConditions";
80     return ($self->SUPER::_Init(@_));
81 }
82 # }}}
83
84 # {{{ sub _Accessible 
85 sub _Accessible  {
86     my $self = shift;
87     my %Cols = ( Name  => 'read',
88                  Description => 'read',
89                  ApplicableTransTypes    => 'read',
90                  ExecModule  => 'read',
91                  Argument  => 'read',
92                  Creator => 'read/auto',
93                  Created => 'read/auto',
94                  LastUpdatedBy => 'read/auto',
95                  LastUpdated => 'read/auto'
96                );
97     return($self->SUPER::_Accessible(@_, %Cols));
98 }
99 # }}}
100
101 # {{{ sub Create 
102
103 =head2 Create
104   
105   Takes a hash. Creates a new Condition entry.
106   should be better documented.
107
108 =cut
109
110 sub Create  {
111     my $self = shift;
112     return($self->SUPER::Create(@_));
113 }
114 # }}}
115
116 # {{{ sub Delete 
117
118 =head2 Delete
119
120 No API available for deleting things just yet.
121
122 =cut
123
124 sub Delete  {
125     my $self = shift;
126     return(0, $self->loc('Unimplemented'));
127 }
128 # }}}
129
130 # {{{ sub Load 
131
132 =head2 Load IDENTIFIER
133
134 Loads a condition takes a name or ScripCondition id.
135
136 =cut
137
138 sub Load  {
139     my $self = shift;
140     my $identifier = shift;
141     
142     unless (defined $identifier) {
143         return (undef);
144     }       
145     
146     if ($identifier !~ /\D/) {
147         return ($self->SUPER::LoadById($identifier));
148     }
149     else {
150         return ($self->LoadByCol('Name', $identifier));
151     }
152 }
153 # }}}
154
155 # {{{ sub LoadCondition 
156
157 =head2 LoadCondition  HASH
158
159 takes a hash which has the following elements:  TransactionObj and TicketObj.
160 Loads the Condition module in question.
161
162 =cut
163
164
165 sub LoadCondition  {
166     my $self = shift;
167     my %args = ( TransactionObj => undef,
168                  TicketObj => undef,
169                  @_ );
170     
171     #TODO: Put this in an eval  
172     $self->ExecModule =~ /^(\w+)$/;
173     my $module = $1;
174     my $type = "RT::Condition::". $module;
175     
176     eval "require $type" || die "Require of $type failed.\n$@\n";
177     
178     $self->{'Condition'}  = $type->new ( 'ScripConditionObj' => $self, 
179                                          'TicketObj' => $args{'TicketObj'},
180                                          'ScripObj' => $args{'ScripObj'},
181                                          'TransactionObj' => $args{'TransactionObj'},
182                                          'Argument' => $self->Argument,
183                                      'ApplicableTransTypes' => $self->ApplicableTransTypes,
184                      CurrentUser => $self->CurrentUser 
185                                        );
186 }
187 # }}}
188
189 # {{{ The following methods call the Condition object
190
191
192 # {{{ sub Describe 
193
194 =head2 Describe 
195
196 Helper method to call the condition module\'s Describe method.
197
198 =cut
199
200 sub Describe  {
201     my $self = shift;
202     return ($self->{'Condition'}->Describe());
203     
204 }
205 # }}}
206
207 # {{{ sub IsApplicable 
208
209 =head2 IsApplicable
210
211 Helper method to call the condition module\'s IsApplicable method.
212
213 =cut
214
215 sub IsApplicable  {
216     my $self = shift;
217     return ($self->{'Condition'}->IsApplicable());
218     
219 }
220 # }}}
221
222 # }}}
223
224 # {{{ sub DESTROY
225 sub DESTROY {
226     my $self=shift;
227     $self->{'Condition'} = undef;
228 }
229 # }}}
230
231
232 1;
233
234