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