Author: spadkins
Date: Fri Mar 6 09:19:58 2009
New Revision: 12573
Modified:
p5ee/trunk/App-Repository/lib/App/ValueDomain/Repository.pm
Log:
Added sub _load_label
Modified: p5ee/trunk/App-Repository/lib/App/ValueDomain/Repository.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/ValueDomain/Repository.pm (original)
+++ p5ee/trunk/App-Repository/lib/App/ValueDomain/Repository.pm Fri Mar 6
09:19:58 2009
@@ -199,6 +199,53 @@
&App::sub_exit() if ($App::trace);
}
+sub _load_label {
+ my ($self, $value) = @_;
+ &App::sub_entry if ($App::trace);
+
+ my $context = $self->{context};
+ my $rep = $context->repository($self->{repository});
+ my ($label);
+
+ if ($self->{table} && $self->{valuecolumn}) {
+ my $valuecolumn = $self->{valuecolumn};
+ my $labelcolumn = $self->{labelcolumn};
+
+ if (!$labelcolumn || $labelcolumn eq $valuecolumn) {
+ my $table = $self->{table};
+ $table = $self->substitute($table) if ($table =~ /\{/);
+ my $params = $self->{params};
+ my ($subst_params);
+ if ($params) {
+ $subst_params = $self->substitute($params, undef, {undef_value
=> "NULL"});
+ }
+ else {
+ $subst_params = {};
+ }
+ $subst_params->{$valuecolumn} = $value;
+ $label = $rep->get($table, $subst_params,
$labelcolumn);
+ }
+ else {
+ $label = $value;
+ }
+ }
+ elsif ($self->{sql}) {
+ my $sql = $self->{sql};
+ my $values_session_var = $self->{values_session_var};
+ if ($values_session_var) {
+ $sql =~ s/\{$values_session_var(:[^:{}]*)\}/$value/g;
+ }
+ $sql = $self->substitute($sql, undef, {undef_value => "NULL"});
+ my $rows = $rep->_do($sql);
+ if ($rows && $#$rows > -1) {
+ my $row = $rows->[0];
+ $label = (defined $row->[1]) ? $row->[1] :
$value;
+ }
+ }
+ &App::sub_exit($label) if ($App::trace);
+ return($label);
+}
+
=head1 ACKNOWLEDGEMENTS
* Author: Stephen Adkins <[email protected]>