[Rt-commit] r20105 - in rt/3.8/trunk: lib/RT/Report share/html/Search
ruz at bestpractical.com
ruz at bestpractical.com
Mon Jul 6 21:48:35 EDT 2009
Author: ruz
Date: Mon Jul 6 21:48:35 2009
New Revision: 20105
Modified:
rt/3.8/trunk/lib/RT/Report/Tickets.pm
rt/3.8/trunk/share/html/Search/Chart
rt/3.8/trunk/share/html/Search/Elements/Chart
Log:
* add SetupGroupings method in RT::Report::Tickets class
to avoid code duplication and extend to make it possible
to group by multiple columns
Modified: rt/3.8/trunk/lib/RT/Report/Tickets.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/Report/Tickets.pm (original)
+++ rt/3.8/trunk/lib/RT/Report/Tickets.pm Mon Jul 6 21:48:35 2009
@@ -119,6 +119,23 @@
return $self->CurrentUser->loc($field);
}
+sub SetupGroupings {
+ my $self = shift;
+ my %args = (Query => undef, GroupBy => undef, @_);
+
+ $self->FromSQL( $args{'Query'} );
+ my @group_by = ref( $args{'GroupBy'} )? @{ $args{'GroupBy'} } : ($args{'GroupBy'});
+ $self->GroupBy( FIELD => $_ ) foreach @group_by;
+
+ # UseSQLForACLChecks may add late joins
+ my $joined = ($self->_isJoined || RT->Config->Get('UseSQLForACLChecks')) ? 1 : 0;
+
+ my @res;
+ push @res, $self->Column( FUNCTION => ($joined? 'DISTINCT COUNT' : 'COUNT'), FIELD => 'id' );
+ push @res, map $self->Column( FIELD => $_ ), @group_by;
+ return @res;
+}
+
sub GroupBy {
my $self = shift;
my %args = ref $_[0]? %{ $_[0] }: (@_);
Modified: rt/3.8/trunk/share/html/Search/Chart
==============================================================================
--- rt/3.8/trunk/share/html/Search/Chart (original)
+++ rt/3.8/trunk/share/html/Search/Chart Mon Jul 6 21:48:35 2009
@@ -68,10 +68,9 @@
use RT::Report::Tickets;
my $tix = RT::Report::Tickets->new( $session{'CurrentUser'} );
-$tix->FromSQL( $Query );
-my $count_name = $tix->Column( FUNCTION => 'COUNT', FIELD => 'id' );
-$tix->GroupBy( FIELD => $PrimaryGroupBy );
-my $value_name = $tix->Column( FIELD => $PrimaryGroupBy );
+my ($count_name, $value_name) = $tix->SetupGroupings(
+ Query => $Query, GroupBy => $PrimaryGroupBy,
+);
my $chart = $chart_class->new( 600 => 400 );
Modified: rt/3.8/trunk/share/html/Search/Elements/Chart
==============================================================================
--- rt/3.8/trunk/share/html/Search/Elements/Chart (original)
+++ rt/3.8/trunk/share/html/Search/Elements/Chart Mon Jul 6 21:48:35 2009
@@ -54,10 +54,9 @@
<%init>
use RT::Report::Tickets;
my $tix = RT::Report::Tickets->new( $session{'CurrentUser'} );
-$tix->FromSQL( $Query );
-my $count_name = $tix->Column( FUNCTION => 'COUNT', FIELD => 'id' );
-$tix->GroupBy( FIELD => $PrimaryGroupBy );
-my $value_name = $tix->Column( FIELD => $PrimaryGroupBy );
+my ($count_name, $value_name) = $tix->SetupGroupings(
+ Query => $Query, GroupBy => $PrimaryGroupBy,
+);
my %class = (
Queue => 'RT::Queue',
More information about the Rt-commit
mailing list