import of rt 3.0.4
[freeside.git] / rt / lib / RT / ScripCondition_Overlay.pm
1 # BEGIN LICENSE BLOCK
2
3 # Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
4
5 # (Except where explictly superceded by other copyright notices)
6
7 # This work is made available to you under the terms of Version 2 of
8 # the GNU General Public License. A copy of that license should have
9 # been provided with this software, but in any event can be snarfed
10 # from www.gnu.org.
11
12 # This work is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # General Public License for more details.
16
17 # Unless otherwise specified, all modifications, corrections or
18 # extensions to this work which alter its source code become the
19 # property of Best Practical Solutions, LLC when submitted for
20 # inclusion in the work.
21
22
23 # END LICENSE BLOCK
24 =head1 NAME
25
26   RT::ScripCondition - RT scrip conditional
27
28 =head1 SYNOPSIS
29
30   use RT::ScripCondition;
31
32
33 =head1 DESCRIPTION
34
35 This module should never be called directly by client code. it's an internal module which
36 should only be accessed through exported APIs in other modules.
37
38
39 =begin testing
40
41 ok (require RT::ScripCondition);
42
43 =end testing
44
45 =head1 METHODS
46
47 =cut
48
49 use strict;
50 no warnings qw(redefine);
51
52
53 # {{{  sub _Init 
54 sub _Init  {
55     my $self = shift; 
56     $self->{'table'} = "ScripConditions";
57     return ($self->SUPER::_Init(@_));
58 }
59 # }}}
60
61 # {{{ sub _Accessible 
62 sub _Accessible  {
63     my $self = shift;
64     my %Cols = ( Name  => 'read',
65                  Description => 'read',
66                  ApplicableTransTypes    => 'read',
67                  ExecModule  => 'read',
68                  Argument  => 'read',
69                  Creator => 'read/auto',
70                  Created => 'read/auto',
71                  LastUpdatedBy => 'read/auto',
72                  LastUpdated => 'read/auto'
73                );
74     return($self->SUPER::_Accessible(@_, %Cols));
75 }
76 # }}}
77
78 # {{{ sub Create 
79
80 =head2 Create
81   
82   Takes a hash. Creates a new Condition entry.
83   should be better documented.
84
85 =cut
86
87 sub Create  {
88     my $self = shift;
89     return($self->SUPER::Create(@_));
90 }
91 # }}}
92
93 # {{{ sub Delete 
94
95 =head2 Delete
96
97 No API available for deleting things just yet.
98
99 =cut
100
101 sub Delete  {
102     my $self = shift;
103     return(0, $self->loc('Unimplemented'));
104 }
105 # }}}
106
107 # {{{ sub Load 
108
109 =head2 Load IDENTIFIER
110
111 Loads a condition takes a name or ScripCondition id.
112
113 =cut
114
115 sub Load  {
116     my $self = shift;
117     my $identifier = shift;
118     
119     unless (defined $identifier) {
120         return (undef);
121     }       
122     
123     if ($identifier !~ /\D/) {
124         return ($self->SUPER::LoadById($identifier));
125     }
126     else {
127         return ($self->LoadByCol('Name', $identifier));
128     }
129 }
130 # }}}
131
132 # {{{ sub LoadCondition 
133
134 =head2 LoadCondition  HASH
135
136 takes a hash which has the following elements:  TransactionObj and TicketObj.
137 Loads the Condition module in question.
138
139 =cut
140
141
142 sub LoadCondition  {
143     my $self = shift;
144     my %args = ( TransactionObj => undef,
145                  TicketObj => undef,
146                  @_ );
147     
148     #TODO: Put this in an eval  
149     $self->ExecModule =~ /^(\w+)$/;
150     my $module = $1;
151     my $type = "RT::Condition::". $module;
152     
153     eval "require $type" || die "Require of $type failed.\n$@\n";
154     
155     $self->{'Condition'}  = $type->new ( 'ScripConditionObj' => $self, 
156                                          'TicketObj' => $args{'TicketObj'},
157                                          'ScripObj' => $args{'ScripObj'},
158                                          'TransactionObj' => $args{'TransactionObj'},
159                                          'Argument' => $self->Argument,
160                                          'ApplicableTransTypes' => $self->ApplicableTransTypes,
161                                        );
162 }
163 # }}}
164
165 # {{{ The following methods call the Condition object
166
167
168 # {{{ sub Describe 
169
170 =head2 Describe 
171
172 Helper method to call the condition module\'s Describe method.
173
174 =cut
175
176 sub Describe  {
177     my $self = shift;
178     return ($self->{'Condition'}->Describe());
179     
180 }
181 # }}}
182
183 # {{{ sub IsApplicable 
184
185 =head2 IsApplicable
186
187 Helper method to call the condition module\'s IsApplicable method.
188
189 =cut
190
191 sub IsApplicable  {
192     my $self = shift;
193     return ($self->{'Condition'}->IsApplicable());
194     
195 }
196 # }}}
197
198 # }}}
199
200 # {{{ sub DESTROY
201 sub DESTROY {
202     my $self=shift;
203     $self->{'Condition'} = undef;
204 }
205 # }}}
206
207
208 1;
209
210