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