Preliminary use of config.metabib_field values in misc_util.tt2
authorLiam Whalen <liam@liamwhalen.com>
Sat, 10 Dec 2011 09:43:52 +0000 (04:43 -0500)
committerLiam Whalen <liam@liamwhalen.com>
Sat, 10 Dec 2011 09:43:52 +0000 (04:43 -0500)
Currently, in misc_util.tt2 various record details like isbn,
title, author, etc are loaded by using hard coded XPath expressoins.
Similar XPath expressions already exist in config.metabib_field.xpath.
This code demonstrates that the database variables can be used in place
of the hard coded XPath expressions.  Thanks to Dan Scott for providing
me with the regex needed to make the database XPath values work
within TPAC.  As the code stands now, it loads an array of values
from config.metabib_field into the ctx variable.  This gets done in
the fetch_metabib_field_xpath_and_label function within
OpenILS/WWW/EGCatLoader/Util.pm file.  This function is called in both
EGCatLoader/Record.pm and EGCatLoader/Search.pm.  In the file
misc_util.tt2 the values loaded in Util.pm are looped over until
the entry for ISBN is found.  Then, the XPath value for ISBN is
used after applying the previously mentioned regex, so the TPAC
code can grab the various ISBNs for a record.
Signed-off-by: Liam Whalen <liam@liamwhalen.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/src/sql/Pg/xxx.add-display-field-to_config-metabib_field [new file with mode: 0644]
Open-ILS/src/templates/opac/parts/misc_util.tt2

index 0f714c9..faba424 100644 (file)
@@ -12,7 +12,9 @@ my $U = 'OpenILS::Application::AppUtils';
 sub load_record {
     my $self = shift;
     my $ctx = $self->ctx;
-    $ctx->{page} = 'record';  
+    $ctx->{page} = 'record'; 
+    #load metabib_field variables
+    $self->fetch_metabib_field_xpath_and_label;
 
     my $org = $self->cgi->param('loc') || $ctx->{aou_tree}->()->id;
     my $depth = $self->cgi->param('depth') || 0;
index 93f90b6..0392b34 100644 (file)
@@ -149,6 +149,9 @@ sub load_rresults {
     my $cgi = $self->cgi;
     my $ctx = $self->ctx;
     my $e = $self->editor;
+    
+    #load metabib_field variables
+    $self->fetch_metabib_field_xpath_and_label;
 
     $ctx->{page} = 'rresult' unless $internal;
     $ctx->{ids} = [];
index 1199d9a..bc22407 100644 (file)
@@ -269,4 +269,26 @@ sub fetch_marc_xml_by_id {
     return $marc_xml;
 }
 
+#Not sure if Util.pm is the place for this.  However since Search.pm
+#and Record.pm need to use fetch_metabib_field_xpath_and_label
+#I decided to put it in Util.pm
+sub fetch_metabib_field_xpath_and_label {
+    my $self = shift;
+    my $ctx = $self->ctx;
+    $ctx->{metabib_field_xpath} = [];
+    my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
+    my $xpath = $_storage->request(
+           'open-ils.cstore.direct.config.metabib_field.search.atomic',
+        {'display_field' => 'true'}
+       )->gather(1);
+
+    #push the xpath and label data into $ctx
+    foreach my $row (@$xpath) {
+        #I could not figure out how to push hashes onto the $ctx->{metabib_field_xpath} variable,
+        #so to get this working I made $ctx->{metabib_field_xpath} and array and pushed
+        #the metabib_field data onto it
+        push(@{$ctx->{metabib_field_xpath}}, { xpath => $row->xpath , label => $row->label });
+    }
+}
+
 1;
diff --git a/Open-ILS/src/sql/Pg/xxx.add-display-field-to_config-metabib_field b/Open-ILS/src/sql/Pg/xxx.add-display-field-to_config-metabib_field
new file mode 100644 (file)
index 0000000..f40f694
--- /dev/null
@@ -0,0 +1 @@
+ALTER TABLE config.metabib_field ADD COLUMN display_field BOOL NOT NULL DEFAULT TRUE;
index db30d6b..a89aa22 100644 (file)
@@ -4,7 +4,26 @@
     BLOCK get_marc_attrs;
         xml = args.marc_xml;
         args.isbns = [];
-        FOR isbn IN xml.findnodes('//*[@tag="020"]/*[@code="a"]');
+        #ideally these variables would be available as
+        #ctx.metabib_field_xpath.identifier.isbn.
+        #I could not get ctx to work like this, so I
+        #have turned it into an array, and here
+        #I am looping over the array until I find ISBN
+        #as the label.  This loop to find ISBN is only
+        #a proof of concept to show that the database
+        #values can be used inisde misc_utils.  Ideally
+        #there would be no loop and each findnode
+        #could reference ctx.metabib_field_xpath.identifer.*
+        #or whatever keys are appropriate to retrieve the
+        #needed xpath
+        FOREACH xpath_and_label IN ctx.metabib_field_xpath;
+            IF xpath_and_label.label == 'ISBN';
+                isbn_xpath = xpath_and_label.xpath;
+                isbn_xpath = isbn_xpath.replace('marc:([a-z]*)', '*[local-name()="$1"]');
+            END;
+        END;
+
+        FOR isbn IN xml.findnodes(isbn_xpath);
             args.isbns.push(isbn.textContent);
         END;
         args.upcs = [];