Author: spadkins
Date: Fri Sep 11 06:50:28 2009
New Revision: 13305

Modified:
   p5ee/trunk/App-Context/lib/App/Service.pm

Log:
added get_sym_label() method for various uses in turning a symbol into a label

Modified: p5ee/trunk/App-Context/lib/App/Service.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Service.pm   (original)
+++ p5ee/trunk/App-Context/lib/App/Service.pm   Fri Sep 11 06:50:28 2009
@@ -407,6 +407,54 @@
 }
 
 #############################################################################
+# get_sym_label()
+#############################################################################
+
+=head2 get_sym_label()
+
+    * Signature: $label = $service->get_sym_label($sym);
+    * Signature: $label = $service->get_sym_label($sym, $include_breaks, 
$label_dict, $lang_dict);
+    * Param:     $sym            string
+    * Param:     $include_breaks boolean
+    * Param:     $label_dict     HASH
+    * Param:     $lang_dict      HASH
+    * Return:    $label          string
+
+The get_sym_label() method turns a symbol (i.e. "begin_eff_dt") into a label
+(i.e. "Begin <br>Effective <br>Date"). This label is suitable for use in
+HTML drop-down lists and table column headings.
+
+=cut
+
+sub get_sym_label {
+    &App::sub_entry if ($App::trace);
+    my ($self, $sym, $include_breaks, $label_dict, $lang_dict) = @_;
+    my ($label);
+    $label = $label_dict->{$sym}{label} if ($label_dict && exists 
$label_dict->{$sym});
+    if (! defined $label) {
+        if (!$lang_dict) {
+            my $context = $self->{context};
+            my $default_object = $context->session_object();
+            my $lang = $default_object->{lang} || "en";
+            $lang_dict = $default_object->{dict}{$lang};
+        }
+        if ($lang_dict) {
+            $label = $lang_dict->{$sym};
+        }
+    }
+    if (! defined $label) {
+        my @part = split(/_/, $sym);
+        my $separator = $include_breaks ? " <br>" : " ";
+        for (my $i = 0; $i <= $#part; $i++) {
+            $part[$i] = $lang_dict->{$part[$i]} || ucfirst($part[$i]);
+        }
+        $label = join($separator, @part);
+    }
+    &App::sub_exit($label) if ($App::trace);
+    return ($label);
+}
+
+#############################################################################
 # PROTECTED METHODS
 #############################################################################
 

Reply via email to