69dedcbcab0636fc2faa4945b6b1ae749344a095
[freeside.git] / rt / lib / RT / Condition / CustomFieldEquals.pm
1 package RT::Condition::CustomFieldEquals;
2 use base 'RT::Condition';
3 use strict;
4
5 =head2 IsApplicable
6
7 If a custom field has a value equal to some specified value.
8
9 =cut
10
11 # Based on Chuck Boeheim's code posted on the RT Wiki 3/13/06
12 # Simplified to avoid carrying old schema around. The new mechanics are that
13 # the ScripCondition's "Argument" is the custom field name = value. If the 
14 # transaction initially sets the CF value to a the specified value, or 
15 # changes it from not equaling to equaling the specified value, the condition
16 # returns true.
17 # Don't use this on custom fields that allow multiple values.
18
19 sub IsApplicable {
20     my $self = shift;
21     my $trans = $self->TransactionObj;
22     my $scrip = $self->ScripObj;
23     my ($field, $value) = split('=', $self->Argument, 2);
24
25     if ($trans->Type eq 'Create') {
26         return ($trans->TicketObj->FirstCustomFieldValue($field) eq $value);
27     }
28     if ($trans->Type eq 'CustomField') {
29         my $cf = RT::CustomField->new($self->CurrentUser);
30         $cf->Load($field);
31         return $trans->Field == $cf->Id
32                and ($trans->NewValue eq $value)
33                and ($trans->OldValue ne $value)
34     }
35     return undef;
36 }
37
38 1;
39