This commit was manufactured by cvs2svn to create branch
[freeside.git] / rt / lib / RT / Record.pm
index 9ecad76..78bbe91 100755 (executable)
@@ -67,6 +67,7 @@ use strict;
 use warnings;
 
 use RT::Date;
+use RT::I18N;
 use RT::User;
 use RT::Attributes;
 use Encode qw();
@@ -803,6 +804,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);
     }
@@ -1171,8 +1173,37 @@ sub DependsOn {
 
 # }}}
 
+# {{{ Customers
+
+=head2 Customers
+
+  This returns an RT::Links object which references all the customers that this object is a member of.
+
+=cut
+
+sub Customers {
+    my( $self, %opt ) = @_;
+    my $Debug = $opt{'Debug'};
+
+    unless ( $self->{'Customers'} ) {
+
+      $self->{'Customers'} = $self->MemberOf->Clone;
+
+      $self->{'Customers'}->Limit(
+                                   FIELD    => 'Target',
+                                   OPERATOR => 'STARTSWITH',
+                                   VALUE    => 'freeside://freeside/cust_main/',
+                                 );
+    }
+
+    warn "->Customers method called on $self; returning ".
+         ref($self->{'Customers'}). ' object'
+      if $Debug;
 
+    return $self->{'Customers'};
+}
 
+# }}}
 
 # {{{ sub _Links 
 
@@ -1713,6 +1744,25 @@ sub _AddCustomFieldValue {
         }
 
         my $new_content = $new_value->Content;
+
+        # For date, we need to display them in "human" format in result message
+        if ($cf->Type eq 'Date') {
+            my $DateObj = new RT::Date( $self->CurrentUser );
+            $DateObj->Set(
+                Format => 'ISO',
+                Value  => $new_content,
+            );
+            $new_content = $DateObj->AsString;
+
+            if ( defined $old_content && length $old_content ) {
+                $DateObj->Set(
+                    Format => 'ISO',
+                    Value  => $old_content,
+                );
+                $old_content = $DateObj->AsString;
+            }
+        }
+
         unless ( defined $old_content && length $old_content ) {
             return ( $new_value_id, $self->loc( "[_1] [_2] added", $cf->Name, $new_content ));
         }
@@ -1801,11 +1851,21 @@ sub DeleteCustomFieldValue {
         return ( 0, $self->loc( "Couldn't create a transaction: [_1]", $Msg ) );
     }
 
+    my $old_value = $TransactionObj->OldValue;
+    # For date, we need to display them in "human" format in result message
+    if ( $cf->Type eq 'Date' ) {
+        my $DateObj = new RT::Date( $self->CurrentUser );
+        $DateObj->Set(
+            Format => 'ISO',
+            Value  => $old_value,
+        );
+        $old_value = $DateObj->AsString;
+    }
     return (
         $TransactionId,
         $self->loc(
             "[_1] is no longer a value for custom field [_2]",
-            $TransactionObj->OldValue, $cf->Name
+            $old_value, $cf->Name
         )
     );
 }