Author: spadkins
Date: Sun Apr 20 18:12:34 2008
New Revision: 11123
Modified:
p5ee/trunk/App-Repository/lib/App/Repository.pm
Log:
support custom summarizations
Modified: p5ee/trunk/App-Repository/lib/App/Repository.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/Repository.pm (original)
+++ p5ee/trunk/App-Repository/lib/App/Repository.pm Sun Apr 20 18:12:34 2008
@@ -2774,7 +2774,7 @@
$table_def = $self->get_table_def($table) if (!$table_def);
my $column_def = $table_def->{column}{$column};
- my $relationship_name = $column_def->{relationship_name};
+ my $relationship_name = $column_def->{relationship};
if (!$relationship_name) {
# Determine the order in which we will process relationships
@@ -3316,38 +3316,56 @@
my ($alternate_aggregate_key_idx, $alternate_aggregate_row_idx,
$alternate_aggregate_key);
# determine which columns should be summable and which have expressions
- my $sum_column_idx = [];
- my $expr_column_idx = [];
- my $contains_expr = 0;
+ my $sum_column_idx = [];
+ my $expr_column_idx = [];
+ my $custom_column_idx = [];
+ my $contains_expr = 0;
+ my ($custom_class, @custom_class, %custom_idx_subset);
$row = $rows->[0];
- my ($rel_name, %rel_aggregate, $key_column);
+ my ($rel_name, %rel_aggregate, $key_column, $is_custom);
for ($i = 0; $i <= $#$columns; $i++) {
$column = $columns->[$i];
$value = $row->[$i];
+ $is_custom = 0;
$rel_name = $self->get_relationship_name($table, $column,
$table_def);
- if ($rel_name && !defined $rel_aggregate{$rel_name} &&
$table_def->{relationship}{$rel_name}{qualifying_keys}) {
- # TODO: should this block be made a separate method?
- my $key_idx = [];
- my %key_idx_used = ();
- foreach $key_column (@$summary_keys) {
- push(@$key_idx, $colidx{$key_column});
- $key_idx_used{$key_column} = 1;
- }
- for (my $j = 0; $j <= $#$columns; $j++) {
- $key_column = $columns->[$j];
- if ($column_defs->{$key_column}{is_key} &&
-
$table_def->{relationship}{$rel_name}{qualifying_keys}{$key_column} &&
- !$key_idx_used{$key_column}) {
- push(@$key_idx, $j);
+ if ($rel_name && !defined $rel_aggregate{$rel_name}) {
+ if ($table_def->{relationship}{$rel_name}{class}) {
+ $custom_class =
$table_def->{relationship}{$rel_name}{class};
+ if (! defined $custom_idx_subset{$custom_class}) {
+ $custom_idx_subset{$custom_class} = [];
+ push(@custom_class, $custom_class);
+ }
+ push(@{$custom_idx_subset{$custom_class}}, $i);
+ $is_custom = 1;
+ }
+ elsif ($table_def->{relationship}{$rel_name}{qualifying_keys})
{
+ # TODO: should this block be made a separate method?
+ my $key_idx = [];
+ my %key_idx_used = ();
+ foreach $key_column (@$summary_keys) {
+ push(@$key_idx, $colidx{$key_column});
$key_idx_used{$key_column} = 1;
}
+ for (my $j = 0; $j <= $#$columns; $j++) {
+ $key_column = $columns->[$j];
+ if ($column_defs->{$key_column}{is_key} &&
+
$table_def->{relationship}{$rel_name}{qualifying_keys}{$key_column} &&
+ !$key_idx_used{$key_column}) {
+ push(@$key_idx, $j);
+ $key_idx_used{$key_column} = 1;
+ }
+ }
+ $rel_aggregate{$rel_name} = {
+ key_idx => $key_idx,
+ row_idx => {},
+ };
}
- $rel_aggregate{$rel_name} = {
- key_idx => $key_idx,
- row_idx => {},
- };
}
- if ($column_defs->{$column}{expr}) {
+
+ if ($is_custom) {
+ # do nothing
+ }
+ elsif ($column_defs->{$column}{expr}) {
push(@$expr_column_idx, $i);
$contains_expr = 1;
}
@@ -3518,6 +3536,17 @@
$self->evaluate_expressions($table, $params, $columns, [EMAIL
PROTECTED], $options);
}
+ # evaluate the custom columns of the summarized rows (if they exist)
+ if ($#custom_class > -1) {
+ my $context = $self->{context};
+ my %options = %$options;
+ $options{column_idx_subset} = $custom_idx_subset{$custom_class};
+ foreach $custom_class (@custom_class) {
+ my $custom_session_object =
$context->session_object("temporary", class => $custom_class);
+ $custom_session_object->summarize_repository_rows($self,
$table, [EMAIL PROTECTED], $columns, $summary_keys, \%options);
+ }
+ }
+
# if we started out summarizing HASH rows, convert back from ARRAY to
HASH
if ($row_type eq "HASH") {
$rows = [ @summary_rows ];
@@ -4614,60 +4643,3 @@
1;
-__END__
-
- if (0) { # HASH (or object of some type)
- # determine which columns should be summable and which have expressions
- my $agg_columns = [];
- my $sum_columns = [];
- my $expr_columns = [];
- my $contains_expr = 0;
- my (@summary_keys);
- $row = $rows->[0];
- foreach $column (keys %$row) {
- $value = $row->{$column};
- if ($column_def->{$column}{expr}) {
- push(@$agg_columns, $column);
- push(@$expr_columns, $column);
- $contains_expr = 1;
- }
- elsif ($column_def->{$column}{is_key}) {
- # do nothing
- }
- elsif (defined $value && $value =~ /^-?[0-9\.]+$/) {
- push(@$agg_columns, $column);
- push(@$sum_columns, $column);
- }
- }
- # accumulate the sums of the summable columns
- for ($rowidx = 0; $rowidx <= $#$rows; $rowidx++) {
- $row = $rows->[$rowidx];
- $key = ($#$summary_keys > -1) ? join("|", @[EMAIL PROTECTED]) : "";
- $summary_row = $summary_row{$key};
- if (!$summary_row) {
- $summary_row = {};
- if ($#$summary_keys > -1) {
- foreach $column (@$summary_keys) {
- $summary_row->{$column} = $row->{$column};
- }
- foreach $column (@$sum_columns) {
- $summary_row->{$column} = 0;
- }
- }
- $summary_row{$key} = $summary_row;
- push(@summary_keys, $key);
- }
- foreach $column (@$sum_columns) {
- $summary_row->{$column} += $row->{$column};
- }
- }
- # put the summarized rows in the results array
- foreach $key (@summary_keys) {
- push(@summary_rows, $summary_row{$key});
- }
- # evaluate the expressions of the summarized rows (if they exist)
- if ($contains_expr) {
- my $params = {};
- $self->evaluate_expressions($table, $params, $columns, [EMAIL
PROTECTED], $options);
- }
- }