deb 8 perl path for make dev target
[freeside.git] / rt / lib / RT / Condition / CustomFieldChange.pm
1 package RT::Condition::CustomFieldChange;
2 use base 'RT::Condition';
3 use strict;
4
5 =head2 IsApplicable
6
7 If a custom field has a particular value.
8
9 =cut
10
11 # Based on Chuck Boeheim's code posted on the RT Wiki 3/13/06
12
13 sub IsApplicable {
14     my $self = shift;
15     my $trans = $self->TransactionObj;
16     my $scrip = $self->ScripObj;
17     my %Rules = $self->Rules;
18     my ($field, $value) = @Rules{'field', 'value'};
19     return if !defined($field) or !defined($value);
20
21     if ($trans->Type eq 'Create') {
22         return 1 if $trans->TicketObj->FirstCustomFieldValue($field) eq $value;
23     }
24     if ($trans->Type eq 'CustomField') {
25         my $cf = RT::CustomField->new($self->CurrentUser);
26         $cf->Load($field);
27         return 1 if $trans->Field == $cf->Id and $trans->NewValue eq $value;
28     }
29     return undef;
30 }
31
32 sub Options {
33   my $self = shift;
34   my %args = ( 'QueueObj' => undef, @_ );
35   my $QueueObj = $args{'QueueObj'};
36   my $cfs = $QueueObj->TicketCustomFields();
37   my @fieldnames;
38   while ( my $cf = $cfs->Next ) {
39     push @fieldnames, $cf->Name, $cf->Name;
40   }
41   return (
42     { 
43       'name'    => 'field',
44       'label'   => 'Custom Field',
45       'type'    => 'select',
46       'options' => \@fieldnames,
47     },
48     {
49       'name'    => 'value',
50       'label'   => 'Value',
51       'type'    => 'text',
52     },
53   );
54 }
55 1;
56