woo! final part of #1160! yup, auto-associating tickets with customers now. whew!
authorivan <ivan>
Mon, 24 Mar 2008 03:08:00 +0000 (03:08 +0000)
committerivan <ivan>
Mon, 24 Mar 2008 03:08:00 +0000 (03:08 +0000)
rt/html/Elements/EditCustomers
rt/html/Ticket/Elements/EditCustomers
rt/html/Ticket/Elements/ShowCustomers
rt/lib/RT/Record.pm
rt/lib/RT/Ticket_Overlay.pm

index 57eb905..68efb5f 100644 (file)
   </tr>
   <tr>
     <td class="value">
-% #while (my $link = $Object->MemberOf->Next) {
-% foreach my $link (
-%   grep { $_->TargetURI->Resolver->{'fstable'} eq 'cust_main' }
-%   grep { $_->TargetURI->Scheme eq 'freeside' }
-%        @{ $Object->_Links('Base')->ItemsArrayRef }
-% ) {
+% foreach my $link ( @{ $Object->Customers->ItemsArrayRef } ) {
 
       <INPUT TYPE=CHECKBOX NAME="DeleteLink--<%$link->Type%>-<%$link->Target%>">
 %#        <& ShowLink, URI => $link->TargetURI &><br>
index c5a6f70..0ba6e44 100644 (file)
@@ -1,4 +1,5 @@
 %# Copyright (c) 2004 Ivan Kohler <ivan-rt@420.am>
+%# Copyright (c) 2008 Freeside Internet Services, Inc.
 %# 
 %# This work is made available to you under the terms of Version 2 of
 %# the GNU General Public License. A copy of that license should have
   </tr>
   <tr>
     <td class="value">
-% #while (my $link = $Ticket->MemberOf->Next) {
-% foreach my $link (
-%   grep { $_->TargetURI->Resolver->{'fstable'} eq 'cust_main' }
-%   grep { $_->TargetURI->Scheme eq 'freeside' }
-%        @{ $Ticket->_Links('Base')->ItemsArrayRef }
-% ) {
+% foreach my $link ( @{ $Ticket->Customers->ItemsArrayRef } ) {
 
       <INPUT TYPE=CHECKBOX NAME="DeleteLink--<%$link->Type%>-<%$link->Target%>">
 %#        <& ShowLink, URI => $link->TargetURI &><br>
index 612727e..3acf92d 100644 (file)
 %# General Public License for more details.
 <table>
 % my $cust = 0;
-% foreach my $customerURI (
-%   grep { $_->Resolver->{'fstable'} eq 'cust_main' }
-%   grep { $_->Scheme eq 'freeside' }
-%    map { $_->TargetURI }
-%        @{ $Ticket->_Links('Base')->ItemsArrayRef }
-% ) {
+% foreach my $custResolver ( map { $_->TargetURI->Resolver }
+%                                @{ $Ticket->Customers->ItemsArrayRef }
+%                          )
+% {
 %   $cust++;
 %   my $cust_main = '';
   <tr>
     <td class="value">
-      <A HREF="<% $customerURI->Resolver->HREF %>"><% $customerURI->Resolver->AsStringLong |n %></A>
+      <A HREF="<% $custResolver->HREF %>"><% $custResolver->AsStringLong |n %></A>
     </td>
   </tr>
 % }
index f7100c5..b32ef55 100755 (executable)
@@ -74,6 +74,7 @@ our @ISA;
 use base qw(RT::Base);
 
 use RT::Date;
+use RT::I18N;
 use RT::User;
 use RT::Attributes;
 use DBIx::SearchBuilder::Record::Cachable;
@@ -862,6 +863,7 @@ sub _DecodeLOB {
     elsif ( $ContentEncoding && $ContentEncoding ne 'none' ) {
         return ( $self->loc( "Unknown ContentEncoding [_1]", $ContentEncoding ) );
     }
+
     if ( RT::I18N::IsTextualContentType($ContentType) ) {
        $Content = Encode::decode_utf8($Content) unless Encode::is_utf8($Content);
     }
index b4e3259..1916bc4 100644 (file)
@@ -716,6 +716,43 @@ sub Create {
 
     # }}}
 
+    # {{{ Deal with auto-customer association
+
+    #unless we already have (a) customer(s)...
+    unless ( $self->Customers->Count ) {
+
+      #find any requestors with customer targets
+  
+      my %cust_target = ();
+  
+      my @Requestors =
+        grep { $_->Customers->Count }
+             @{ $self->Requestors->UserMembersObj->ItemsArrayRef };
+  
+      foreach my $Requestor ( @Requestors ) {
+        foreach my $cust_link ( @{ $Requestor->Customers->ItemsArrayRef } ) {
+          $cust_target{ $cust_link->Target } = 1;
+        }
+      }
+  
+      #and then auto-associate this ticket with those customers
+  
+      foreach my $cust_target ( keys %cust_target ) {
+  
+        my @link = ( 'Type'   => 'MemberOf',
+                     #'Target' => "freeside://freeside/cust_main/$custnum",
+                     'Target' => $cust_target,
+                   );
+  
+        my( $val, $msg ) = $self->AddLink(@link);
+        push @non_fatal_errors, $msg;
+  
+      }
+
+    }
+
+    # }}}
+
     # {{{ Add all the custom fields
 
     foreach my $arg ( keys %args ) {