[svn:p5ee] r8525 - in p5ee/trunk/App-Repository/lib/App: . ValueDomain

[email protected]
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
Author: spadkins
Date: Mon Jan  8 14:30:13 2007
New Revision: 8525

Modified:
   p5ee/trunk/App-Repository/lib/App/Repository.pm
   p5ee/trunk/App-Repository/lib/App/ValueDomain/RepositoryTableColumns.pm

Log:
support for alternate column labels and sorting

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	Mon Jan  8 14:30:13 2007
@@ -2324,9 +2324,20 @@
 =cut
 
 sub get_column_labels {
-    my ($self, $table) = @_;
+    my ($self, $table, $labelcolumn) = @_;
     $self->_load_table_metadata($table) if (! defined $self->{table}{$table}{loaded});
-    $self->{table}{$table}{column_labels};
+    my ($labels);
+    if (!$labelcolumn) {
+        $labels = $self->{table}{$table}{column_labels};
+    }
+    else {
+        $labels = {};
+        my $column_defs = $self->{table}{$table}{column};
+        foreach my $column (keys %$column_defs) {
+            $labels->{$column} = $column_defs->{$column}{$labelcolumn};
+        }
+    }
+    return($labels);
 }
 
 #############################################################################

Modified: p5ee/trunk/App-Repository/lib/App/ValueDomain/RepositoryTableColumns.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/ValueDomain/RepositoryTableColumns.pm	(original)
+++ p5ee/trunk/App-Repository/lib/App/ValueDomain/RepositoryTableColumns.pm	Mon Jan  8 14:30:13 2007
@@ -76,16 +76,20 @@
     my $rep = $context->repository($self->{repository});
     my $table = $self->{table} || die "No table specified in $self->{name} ValueDomain";
     my $values = $rep->get_column_names($table);
-    my $labels = $rep->get_column_labels($table);
+    my $labels = $rep->get_column_labels($table, $self->{labelcolumn});
+    my $column_defs = $rep->{table}{$table}{column};
     $values = [ @$values ];    # make a copy
     $labels = { %$labels };    # make a copy
-    if ($self->{sort}) {
+    if ($self->{sortcolumn}) {
+        my $sortcolumn = $self->{sortcolumn};
+        @$values = sort { $column_defs->{$a}{$sortcolumn} <=> $column_defs->{$b}{$sortcolumn} } @$values;
+    }
+    elsif ($self->{sort}) {
         @$values = sort { $labels->{$a} cmp $labels->{$b} } @$values;
     }
     if (defined $self->{is_key}) {
         my $is_key = $self->{is_key};
         my @values = ();
-        my $column_defs = $rep->{table}{$table}{column};
         foreach my $col (@$values) {
             if (($is_key && $column_defs->{$col}{is_key}) ||
                 (!$is_key && !$column_defs->{$col}{is_key})) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.