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