X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FScrips_Overlay.pm;fp=rt%2Flib%2FRT%2FScrips_Overlay.pm;h=d201480846a71102c2d463aab1ed68ebc6a5d60d;hb=289340780927b5bac2c7604d7317c3063c6dd8cc;hp=46e31c2a8778a34e50df3117fdb21c9946656cfe;hpb=945721f48f74d5cfffef7c7cf3a3d6bc2521f5dd;p=freeside.git diff --git a/rt/lib/RT/Scrips_Overlay.pm b/rt/lib/RT/Scrips_Overlay.pm index 46e31c2a8..d20148084 100644 --- a/rt/lib/RT/Scrips_Overlay.pm +++ b/rt/lib/RT/Scrips_Overlay.pm @@ -129,5 +129,80 @@ sub Next { } # }}} +sub Apply { + my ($self, %args) = @_; + + #We're really going to need a non-acled ticket for the scrips to work + my ($TicketObj, $TransactionObj); + + if ( ($TicketObj = $args{'TicketObj'}) ) { + $TicketObj->CurrentUser($self->CurrentUser); + } + else { + $TicketObj = RT::Ticket->new($self->CurrentUser); + $TicketObj->Load( $args{'Ticket'} ) + || $RT::Logger->err("$self couldn't load ticket $args{'Ticket'}\n"); + } + + if ( ($TransactionObj = $args{'TransactionObj'}) ) { + $TransactionObj->CurrentUser($self->CurrentUser); + } + else { + $TransactionObj = RT::Transaction->new($self->CurrentUser); + $TransactionObj->Load( $args{'Transaction'} ) + || $RT::Logger->err("$self couldn't load transaction $args{'Transaction'}\n"); + } + + # {{{ Deal with Scrips + + $self->LimitToQueue( $TicketObj->QueueObj->Id ) + ; #Limit it to $Ticket->QueueObj->Id + $self->LimitToGlobal() + unless $TicketObj->QueueObj->Disabled; # or to "global" + + + $self->Limit(FIELD => "Stage", VALUE => $args{'Stage'}); + + + my $ConditionsAlias = $self->NewAlias('ScripConditions'); + + $self->Join( + ALIAS1 => 'main', + FIELD1 => 'ScripCondition', + ALIAS2 => $ConditionsAlias, + FIELD2 => 'id' + ); + + #We only want things where the scrip applies to this sort of transaction + $self->Limit( + ALIAS => $ConditionsAlias, + FIELD => 'ApplicableTransTypes', + OPERATOR => 'LIKE', + VALUE => $args{'Type'}, + ENTRYAGGREGATOR => 'OR', + ) if $args{'Type'}; + + # Or where the scrip applies to any transaction + $self->Limit( + ALIAS => $ConditionsAlias, + FIELD => 'ApplicableTransTypes', + OPERATOR => 'LIKE', + VALUE => "Any", + ENTRYAGGREGATOR => 'OR', + ); + + #Iterate through each script and check it's applicability. + while ( my $Scrip = $self->Next() ) { + $Scrip->Apply (TicketObj => $TicketObj, + TransactionObj => $TransactionObj); + } + + $TicketObj->CurrentUser( $TicketObj->OriginalUser ); + $TransactionObj->CurrentUser( $TransactionObj->OriginalUser ); + + # }}} +} + + 1;