import rt 2.0.14
[freeside.git] / rt / lib / RT / ScripCondition.pm
1 # Copyright 1999-2000 Jesse Vincent <jesse@fsck.com>
2 # Released under the terms of the GNU Public License
3 # $Header: /home/cvs/cvsroot/freeside/rt/lib/RT/ScripCondition.pm,v 1.1 2002-08-12 06:17:07 ivan Exp $
4
5 =head1 NAME
6
7   RT::ScripCondition - RT scrip conditional
8
9 =head1 SYNOPSIS
10
11   use RT::ScripCondition;
12
13
14 =head1 DESCRIPTION
15
16 This module should never be called directly by client code. it's an internal module which
17 should only be accessed through exported APIs in other modules.
18
19
20 =begin testing
21
22 ok (require RT::TestHarness);
23 ok (require RT::ScripCondition);
24
25 =end testing
26
27 =head1 METHODS
28
29 =cut
30
31 package RT::ScripCondition;
32 use RT::Record;
33 @ISA= qw(RT::Record);
34
35 # {{{  sub _Init 
36 sub _Init  {
37     my $self = shift; 
38     $self->{'table'} = "ScripConditions";
39     return ($self->SUPER::_Init(@_));
40 }
41 # }}}
42
43 # {{{ sub _Accessible 
44 sub _Accessible  {
45     my $self = shift;
46     my %Cols = ( Name  => 'read',
47                  Description => 'read',
48                  ApplicableTransTypes    => 'read',
49                  ExecModule  => 'read',
50                  Argument  => 'read',
51                  Creator => 'read/auto',
52                  Created => 'read/auto',
53                  LastUpdatedBy => 'read/auto',
54                  LastUpdated => 'read/auto'
55                );
56     return($self->SUPER::_Accessible(@_, %Cols));
57 }
58 # }}}
59
60 # {{{ sub Create 
61
62 =head2 Create
63   
64   Takes a hash. Creates a new Condition entry.
65   should be better documented.
66
67 =cut
68
69 sub Create  {
70     my $self = shift;
71     return($self->SUPER::Create(@_));
72 }
73 # }}}
74
75 # {{{ sub Delete 
76
77 =head2 Delete
78
79 No API available for deleting things just yet.
80
81 =cut
82
83 sub Delete  {
84     my $self = shift;
85     return(0,'Unimplemented');
86 }
87 # }}}
88
89 # {{{ sub Load 
90
91 =head2 Load IDENTIFIER
92
93 Loads a condition takes a name or ScripCondition id.
94
95 =cut
96
97 sub Load  {
98     my $self = shift;
99     my $identifier = shift;
100     
101     unless (defined $identifier) {
102         return (undef);
103     }       
104     
105     if ($identifier !~ /\D/) {
106         return ($self->SUPER::LoadById($identifier));
107     }
108     else {
109         return ($self->LoadByCol('Name', $identifier));
110     }
111 }
112 # }}}
113
114 # {{{ sub LoadCondition 
115
116 =head2 LoadCondition  HASH
117
118 takes a hash which has the following elements:  TransactionObj and TicketObj.
119 Loads the Condition module in question.
120
121 =cut
122
123
124 sub LoadCondition  {
125     my $self = shift;
126     my %args = ( TransactionObj => undef,
127                  TicketObj => undef,
128                  @_ );
129     
130     #TODO: Put this in an eval  
131     $self->ExecModule =~ /^(\w+)$/;
132     my $module = $1;
133     my $type = "RT::Condition::". $module;
134     
135     $RT::Logger->debug("now requiring $type\n"); 
136     eval "require $type" || die "Require of $type failed.\n$@\n";
137     
138     $self->{'Condition'}  = $type->new ( 'ScripConditionObj' => $self, 
139                                          'TicketObj' => $args{'TicketObj'},
140                                          'TransactionObj' => $args{'TransactionObj'},
141                                          'Argument' => $self->Argument,
142                                          'ApplicableTransTypes' => $self->ApplicableTransTypes,
143                                        );
144 }
145 # }}}
146
147 # {{{ The following methods call the Condition object
148
149
150 # {{{ sub Describe 
151
152 =head2 Describe 
153
154 Helper method to call the condition module\'s Describe method.
155
156 =cut
157
158 sub Describe  {
159     my $self = shift;
160     return ($self->{'Condition'}->Describe());
161     
162 }
163 # }}}
164
165 # {{{ sub IsApplicable 
166
167 =head2 IsApplicable
168
169 Helper method to call the condition module\'s IsApplicable method.
170
171 =cut
172
173 sub IsApplicable  {
174     my $self = shift;
175     return ($self->{'Condition'}->IsApplicable());
176     
177 }
178 # }}}
179
180 # }}}
181
182 # {{{ sub DESTROY
183 sub DESTROY {
184     my $self=shift;
185     $self->{'Condition'} = undef;
186 }
187 # }}}
188
189
190 1;
191
192