+=head2 LabelValue
+
+If you're pulling a value out of this collection and using it as a label,
+you may want the "cleaned up" version. This includes scrubbing 1970 dates
+and ensuring that dates are in local not DB timezones.
+
+=cut
+
+sub LabelValue {
+ my $self = shift;
+ my $name = shift;
+
+ my $raw = $self->RawValue( $name, @_ );
+
+ if ( my $code = $self->Report->LabelValueCode( $name ) ) {
+ $raw = $code->( $self, %{ $self->Report->ColumnInfo( $name ) }, VALUE => $raw );
+ return $self->loc('(no value)') unless defined $raw && length $raw;
+ return $raw;
+ }
+
+ unless ( ref $raw ) {
+ return $self->loc('(no value)') unless defined $raw && length $raw;
+ return $self->loc($raw) if $self->Report->ColumnInfo( $name )->{'META'}{'Localize'};
+ return $raw;
+ } else {
+ my $loc = $self->Report->ColumnInfo( $name )->{'META'}{'Localize'};
+ my %res = %$raw;
+ if ( $loc ) {
+ $res{ $self->loc($_) } = delete $res{ $_ } foreach keys %res;
+ $_ = $self->loc($_) foreach values %res;
+ }
+ $_ = $self->loc('(no value)') foreach grep !defined || !length, values %res;
+ return \%res;
+ }
+}
+
+sub RawValue {
+ return (shift)->__Value( @_ );
+}
+
+sub ObjectType {
+ return 'RT::Ticket';
+}
+
+sub CustomFieldLookupType {
+ RT::Ticket->CustomFieldLookupType
+}
+
+sub Query {
+ my $self = shift;
+
+ my @parts;
+ foreach my $column ( $self->Report->ColumnsList ) {
+ my $info = $self->Report->ColumnInfo( $column );
+ next unless $info->{'TYPE'} eq 'grouping';
+
+ my $custom = $info->{'META'}{'Query'};
+ if ( $custom and my $code = $self->Report->FindImplementationCode( $custom ) ) {
+ push @parts, $code->( $self, COLUMN => $column, %$info );
+ }
+ else {
+ my $field = join '.', grep $_, $info->{KEY}, $info->{SUBKEY};
+ my $value = $self->RawValue( $column );
+ my $op = '=';
+ if ( defined $value ) {
+ unless ( $value =~ /^\d+$/ ) {
+ $value =~ s/(['\\])/\\$1/g;
+ $value = "'$value'";
+ }
+ }
+ else {
+ ($op, $value) = ('IS', 'NULL');
+ }
+ unless ( $field =~ /^[{}\w\.]+$/ ) {
+ $field =~ s/(['\\])/\\$1/g;
+ $field = "'$field'";
+ }
+ push @parts, "$field $op $value";
+ }
+ }
+ return () unless @parts;
+ return join ' AND ', map "($_)", grep defined && length, @parts;
+}
+
+sub Report {
+ return $_[0]->{'report'};
+}