Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Cvs P5ee > [svn:p5ee] r111...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 692 of 694
Post > Topic >>

[svn:p5ee] r11123 - p5ee/trunk/App-Repository/lib/App

by spadkins@[EMAIL PROTECTED] Apr 20, 2008 at 06:12 PM

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
@[EMAIL PROTECTED]
 -2774,7 +2774,7 @[EMAIL PROTECTED]
 
     $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
@[EMAIL PROTECTED]
 -3316,38 +3316,56 @[EMAIL PROTECTED]
         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, @[EMAIL PROTECTED]
 %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 (@[EMAIL PROTECTED]
) {
-                    push(@[EMAIL PROTECTED]
 $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(@[EMAIL PROTECTED]
 $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(@[EMAIL PROTECTED]
 $custom_class);
+                    }
+                    push(@[EMAIL PROTECTED]
 $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 (@[EMAIL PROTECTED]
) {
+                        push(@[EMAIL PROTECTED]
 $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(@[EMAIL PROTECTED]
 $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(@[EMAIL PROTECTED]
 $i);
                 $contains_expr = 1;
             }
@[EMAIL PROTECTED]
 -3518,6 +3536,17 @[EMAIL PROTECTED]
             $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 (@[EMAIL PROTECTED]
) {
+                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 = [ @[EMAIL PROTECTED]
 ];
@[EMAIL PROTECTED]
 -4614,60 +4643,3 @[EMAIL PROTECTED]
 
 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 (@[EMAIL PROTECTED]
);
-        $row = $rows->[0];
-        foreach $column (keys %$row) {
-            $value = $row->{$column};
-            if ($column_def->{$column}{expr}) {
-                push(@[EMAIL PROTECTED]
 $column);
-                push(@[EMAIL PROTECTED]
 $column);
-                $contains_expr = 1;
-            }
-            elsif ($column_def->{$column}{is_key}) {
-                # do nothing
-            }
-            elsif (defined $value && $value =~ /^-?[0-9\.]+$/) {
-                push(@[EMAIL PROTECTED]
 $column);
-                push(@[EMAIL PROTECTED]
 $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 (@[EMAIL PROTECTED]
) {
-                        $summary_row->{$column} = $row->{$column};
-                    }
-                    foreach $column (@[EMAIL PROTECTED]
) {
-                        $summary_row->{$column} = 0;
-                    }
-                }
-                $summary_row{$key} = $summary_row;
-                push(@[EMAIL PROTECTED]
 $key);
-            }
-            foreach $column (@[EMAIL PROTECTED]
) {
-                $summary_row->{$column} += $row->{$column};
-            }
-        }
-        # put the summarized rows in the results array
-        foreach $key (@[EMAIL PROTECTED]
) {
-            push(@[EMAIL PROTECTED]
 $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);
-        }
-    }




 1 Posts in Topic:
[svn:p5ee] r11123 - p5ee/trunk/App-Repository/lib/App
spadkins@[EMAIL PROTECTED  2008-04-20 18:12:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 19:07:06 CDT 2008.