Merge branch 'master' of https://github.com/jgoodman/Freeside
[freeside.git] / rt / lib / RT / ScripCondition.pm
1 # BEGIN BPS TAGGED BLOCK {{{
2 #
3 # COPYRIGHT:
4 #
5 # This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
6 #                                          <sales@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/licenses/old-licenses/gpl-2.0.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
49 =head1 NAME
50
51   RT::ScripCondition - RT scrip conditional
52
53 =head1 SYNOPSIS
54
55   use RT::ScripCondition;
56
57
58 =head1 DESCRIPTION
59
60 This module should never be called directly by client code. it's an internal module which
61 should only be accessed through exported APIs in other modules.
62
63
64
65 =head1 METHODS
66
67 =cut
68
69
70 package RT::ScripCondition;
71
72 use strict;
73 use warnings;
74
75
76 use base 'RT::Record';
77
78 sub Table {'ScripConditions'}
79
80
81
82 sub _Init  {
83     my $self = shift; 
84     $self->{'table'} = "ScripConditions";
85     return ($self->SUPER::_Init(@_));
86 }
87
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 =head2 Create
105   
106   Takes a hash. Creates a new Condition entry.
107   should be better documented.
108
109 =cut
110
111 sub Create  {
112     my $self = shift;
113     return($self->SUPER::Create(@_));
114 }
115
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 =head2 Load IDENTIFIER
130
131 Loads a condition takes a name or ScripCondition id.
132
133 =cut
134
135 sub Load  {
136     my $self = shift;
137     my $identifier = shift;
138     
139     unless (defined $identifier) {
140         return (undef);
141     }       
142     
143     if ($identifier !~ /\D/) {
144         return ($self->SUPER::LoadById($identifier));
145     }
146     else {
147         return ($self->LoadByCol('Name', $identifier));
148     }
149 }
150
151
152 =head2 LoadCondition  HASH
153
154 takes a hash which has the following elements:  TransactionObj and TicketObj.
155 Loads the Condition module in question.
156
157 =cut
158
159
160 sub LoadCondition  {
161     my $self = shift;
162     my %args = ( TransactionObj => undef,
163                  TicketObj => undef,
164                  @_ );
165     
166     #TODO: Put this in an eval  
167     $self->ExecModule =~ /^(\w+)$/;
168     my $module = $1;
169     my $type = "RT::Condition::". $module;
170     
171     eval "require $type" || die "Require of $type failed.\n$@\n";
172     
173     $self->{'Condition'}  = $type->new ( 'ScripConditionObj' => $self, 
174                                          'TicketObj' => $args{'TicketObj'},
175                                          'ScripObj' => $args{'ScripObj'},
176                                          'TransactionObj' => $args{'TransactionObj'},
177                                          'Argument' => $self->Argument,
178                                      'ApplicableTransTypes' => $self->ApplicableTransTypes,
179                      CurrentUser => $self->CurrentUser 
180                                        );
181 }
182
183
184
185
186 =head2 Describe 
187
188 Helper method to call the condition module's Describe method.
189
190 =cut
191
192 sub Describe  {
193     my $self = shift;
194     return ($self->{'Condition'}->Describe());
195     
196 }
197
198
199 =head2 IsApplicable
200
201 Helper method to call the condition module's IsApplicable method.
202
203 =cut
204
205 sub IsApplicable  {
206     my $self = shift;
207     return ($self->{'Condition'}->IsApplicable());
208     
209 }
210
211
212 sub DESTROY {
213     my $self=shift;
214     $self->{'Condition'} = undef;
215 }
216
217
218
219
220
221
222
223 =head2 id
224
225 Returns the current value of id.
226 (In the database, id is stored as int(11).)
227
228
229 =cut
230
231
232 =head2 Name
233
234 Returns the current value of Name.
235 (In the database, Name is stored as varchar(200).)
236
237
238
239 =head2 SetName VALUE
240
241
242 Set Name to VALUE.
243 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
244 (In the database, Name will be stored as a varchar(200).)
245
246
247 =cut
248
249
250 =head2 Description
251
252 Returns the current value of Description.
253 (In the database, Description is stored as varchar(255).)
254
255
256
257 =head2 SetDescription VALUE
258
259
260 Set Description to VALUE.
261 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
262 (In the database, Description will be stored as a varchar(255).)
263
264
265 =cut
266
267
268 =head2 ExecModule
269
270 Returns the current value of ExecModule.
271 (In the database, ExecModule is stored as varchar(60).)
272
273
274
275 =head2 SetExecModule VALUE
276
277
278 Set ExecModule to VALUE.
279 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
280 (In the database, ExecModule will be stored as a varchar(60).)
281
282
283 =cut
284
285
286 =head2 Argument
287
288 Returns the current value of Argument.
289 (In the database, Argument is stored as varbinary(255).)
290
291
292
293 =head2 SetArgument VALUE
294
295
296 Set Argument to VALUE.
297 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
298 (In the database, Argument will be stored as a varbinary(255).)
299
300
301 =cut
302
303
304 =head2 ApplicableTransTypes
305
306 Returns the current value of ApplicableTransTypes.
307 (In the database, ApplicableTransTypes is stored as varchar(60).)
308
309
310
311 =head2 SetApplicableTransTypes VALUE
312
313
314 Set ApplicableTransTypes to VALUE.
315 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
316 (In the database, ApplicableTransTypes will be stored as a varchar(60).)
317
318
319 =cut
320
321
322 =head2 Creator
323
324 Returns the current value of Creator.
325 (In the database, Creator is stored as int(11).)
326
327
328 =cut
329
330
331 =head2 Created
332
333 Returns the current value of Created.
334 (In the database, Created is stored as datetime.)
335
336
337 =cut
338
339
340 =head2 LastUpdatedBy
341
342 Returns the current value of LastUpdatedBy.
343 (In the database, LastUpdatedBy is stored as int(11).)
344
345
346 =cut
347
348
349 =head2 LastUpdated
350
351 Returns the current value of LastUpdated.
352 (In the database, LastUpdated is stored as datetime.)
353
354
355 =cut
356
357
358
359 sub _CoreAccessible {
360     {
361
362         id =>
363                 {read => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => ''},
364         Name =>
365                 {read => 1, write => 1, sql_type => 12, length => 200,  is_blob => 0,  is_numeric => 0,  type => 'varchar(200)', default => ''},
366         Description =>
367                 {read => 1, write => 1, sql_type => 12, length => 255,  is_blob => 0,  is_numeric => 0,  type => 'varchar(255)', default => ''},
368         ExecModule =>
369                 {read => 1, write => 1, sql_type => 12, length => 60,  is_blob => 0,  is_numeric => 0,  type => 'varchar(60)', default => ''},
370         Argument =>
371                 {read => 1, write => 1, sql_type => 12, length => 255,  is_blob => 0,  is_numeric => 0,  type => 'varbinary(255)', default => ''},
372         ApplicableTransTypes =>
373                 {read => 1, write => 1, sql_type => 12, length => 60,  is_blob => 0,  is_numeric => 0,  type => 'varchar(60)', default => ''},
374         Creator =>
375                 {read => 1, auto => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
376         Created =>
377                 {read => 1, auto => 1, sql_type => 11, length => 0,  is_blob => 0,  is_numeric => 0,  type => 'datetime', default => ''},
378         LastUpdatedBy =>
379                 {read => 1, auto => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
380         LastUpdated =>
381                 {read => 1, auto => 1, sql_type => 11, length => 0,  is_blob => 0,  is_numeric => 0,  type => 'datetime', default => ''},
382
383  }
384 };
385
386 RT::Base->_ImportOverlays();
387
388 1;