[freeside-commits] freeside/rt/lib/RT CustomField_Overlay.pm, 1.1.1.11, 1.2 Record.pm, 1.7, 1.8 Tickets_Overlay.pm, 1.1.1.12, 1.2

Ivan,,, ivan at wavetail.420.am
Mon Jul 19 17:59:03 PDT 2010


Update of /home/cvs/cvsroot/freeside/rt/lib/RT
In directory wavetail.420.am:/tmp/cvs-serv3908/lib/RT

Modified Files:
	CustomField_Overlay.pm Record.pm Tickets_Overlay.pm 
Log Message:
RT custom fields patch, RT#8449

Index: Record.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/rt/lib/RT/Record.pm,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -w -d -r1.7 -r1.8
--- Record.pm	18 May 2010 19:20:28 -0000	1.7
+++ Record.pm	20 Jul 2010 00:59:01 -0000	1.8
@@ -1744,6 +1744,25 @@
         }
 
         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 ));
         }
@@ -1832,11 +1851,21 @@
         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
         )
     );
 }

Index: CustomField_Overlay.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/rt/lib/RT/CustomField_Overlay.pm,v
retrieving revision 1.1.1.11
retrieving revision 1.2
diff -u -w -d -r1.1.1.11 -r1.2
--- CustomField_Overlay.pm	18 May 2010 18:40:52 -0000	1.1.1.11
+++ CustomField_Overlay.pm	20 Jul 2010 00:59:01 -0000	1.2
@@ -97,6 +97,11 @@
         'Enter one value with autocompletion',            # loc
         'Enter up to [_1] values with autocompletion',    # loc
     ],
+    Date => [
+        'Select multiple dates',	# loc
+        'Select date',			# loc
+        'Select up to [_1] dates',	# loc
+    ],
 );
 
 
@@ -829,7 +834,7 @@
 
 sub TypeComposites {
     my $self = shift;
-    return grep !/(?:[Tt]ext|Combobox)-0/, map { ("$_-1", "$_-0") } $self->Types;
+    return grep !/(?:[Tt]ext|Combobox|Date)-0/, map { ("$_-1", "$_-0") } $self->Types;
 }
 
 =head2 SetLookupType
@@ -1160,6 +1165,15 @@
             $extra_values--;
         }
     }
+    # For date, we need to store Content as ISO date
+    if ($self->Type eq 'Date') {
+        my $DateObj = new RT::Date( $self->CurrentUser );
+        $DateObj->Set(
+            Format => 'unknown',
+            Value  => $args{'Content'},
+        );
+        $args{'Content'} = $DateObj->ISO;
+    }
     my $newval = RT::ObjectCustomFieldValue->new( $self->CurrentUser );
     my $val    = $newval->Create(
         ObjectType   => ref($obj),

Index: Tickets_Overlay.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/rt/lib/RT/Tickets_Overlay.pm,v
retrieving revision 1.1.1.12
retrieving revision 1.2
diff -u -w -d -r1.1.1.12 -r1.2
--- Tickets_Overlay.pm	18 May 2010 18:40:48 -0000	1.1.1.12
+++ Tickets_Overlay.pm	20 Jul 2010 00:59:01 -0000	1.2
@@ -136,6 +136,7 @@
     QueueAdminCc     => [ 'WATCHERFIELD'    => 'AdminCc' => 'Queue', ], #loc_left_pair
     QueueWatcher     => [ 'WATCHERFIELD'    => undef     => 'Queue', ], #loc_left_pair
     CustomFieldValue => [ 'CUSTOMFIELD', ], #loc_left_pair
+    DateCustomFieldValue => [ 'DATECUSTOMFIELD', ],
     CustomField      => [ 'CUSTOMFIELD', ], #loc_left_pair
     CF               => [ 'CUSTOMFIELD', ], #loc_left_pair
     Updated          => [ 'TRANSDATE', ], #loc_left_pair
@@ -160,6 +161,7 @@
     WATCHERFIELD    => \&_WatcherLimit,
     MEMBERSHIPFIELD => \&_WatcherMembershipLimit,
     CUSTOMFIELD     => \&_CustomFieldLimit,
+    DATECUSTOMFIELD => \&_DateCustomFieldLimit,
     HASATTRIBUTE    => \&_HasAttributeLimit,
 );
 our %can_bundle = ();# WATCHERFIELD => "yes", );
@@ -1340,6 +1342,101 @@
     return ($TicketCFs, $CFs);
 }
 
+=head2 _DateCustomFieldLimit
+
+Limit based on CustomFields of type Date
+
+Meta Data:
+  none
+
+=cut
+
+sub _DateCustomFieldLimit {
+    my ( $self, $_field, $op, $value, %rest ) = @_;
+
+    my $field = $rest{'SUBKEY'} || die "No field specified";
+
+    # For our sanity, we can only limit on one queue at a time
+
+    my ($queue, $cfid, $column);
+    ($queue, $field, $cfid, $column) = $self->_CustomFieldDecipher( $field );
+
+# If we're trying to find custom fields that don't match something, we
+# want tickets where the custom field has no value at all.  Note that
+# we explicitly don't include the "IS NULL" case, since we would
+# otherwise end up with a redundant clause.
+
+    my $null_columns_ok;
+    if ( ( $op =~ /^NOT LIKE$/i ) or ( $op eq '!=' ) ) {
+        $null_columns_ok = 1;
+    }
+
+    my $cfkey = $cfid ? $cfid : "$queue.$field";
+    my ($TicketCFs, $CFs) = $self->_CustomFieldJoin( $cfkey, $cfid, $field );
+
+    $self->_OpenParen;
+
+    if ( $CFs && !$cfid ) {
+        $self->SUPER::Limit(
+            ALIAS           => $CFs,
+            FIELD           => 'Name',
+            VALUE           => $field,
+            ENTRYAGGREGATOR => 'AND',
+        );
+    }
+
+    $self->_OpenParen if $null_columns_ok;
+
+    my $date = RT::Date->new( $self->CurrentUser );
+    $date->Set( Format => 'unknown', Value => $value );
+
+    if ( $op eq "=" ) {
+
+        # if we're specifying =, that means we want everything on a
+        # particular single day.  in the database, we need to check for >
+        # and < the edges of that day.
+
+        $date->SetToMidnight( Timezone => 'server' );
+        my $daystart = $date->ISO;
+        $date->AddDay;
+        my $dayend = $date->ISO;
+
+        $self->_OpenParen;
+
+        $self->_SQLLimit(
+            ALIAS    => $TicketCFs,
+            FIELD    => 'Content',
+            OPERATOR => ">=",
+            VALUE    => $daystart,
+            %rest,
+        );
+
+        $self->_SQLLimit(
+            ALIAS    => $TicketCFs,
+            FIELD    => 'Content',
+            OPERATOR => "<=",
+            VALUE    => $dayend,
+            %rest,
+            ENTRYAGGREGATOR => 'AND',
+        );
+
+        $self->_CloseParen;
+
+    }
+    else {
+        $self->_SQLLimit(
+            ALIAS    => $TicketCFs,
+            FIELD    => 'Content',
+            OPERATOR => $op,
+            VALUE    => $date->ISO,
+            %rest,
+        );
+    }
+
+    $self->_CloseParen;
+
+}
+
 =head2 _CustomFieldLimit
 
 Limit based on CustomFields
@@ -2667,6 +2764,11 @@
         $args{CUSTOMFIELD} = $CF->Id;
     }
 
+    # Handle special customfields types
+    if ($CF->Type eq 'Date') {
+        $args{FIELD} = 'DateCustomFieldValue';
+    }
+
     #If we are looking to compare with a null value.
     if ( $args{'OPERATOR'} =~ /^is$/i ) {
         $args{'DESCRIPTION'}



More information about the freeside-commits mailing list