From e92605dae1db4c5af912fd3ea238c1e7da5d3e9a Mon Sep 17 00:00:00 2001 From: Liam Whalen Date: Sat, 10 Dec 2011 04:43:52 -0500 Subject: [PATCH] Preliminary use of config.metabib_field values in misc_util.tt2 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 --- .../perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm | 4 +++- .../perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm | 3 +++ .../perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm | 22 ++++++++++++++++++++++ .../xxx.add-display-field-to_config-metabib_field | 1 + Open-ILS/src/templates/opac/parts/misc_util.tt2 | 21 ++++++++++++++++++++- 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/xxx.add-display-field-to_config-metabib_field diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm index 0f714c9a1d..faba424140 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm @@ -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; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm index 93f90b68a6..0392b34cc2 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm @@ -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} = []; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index 1199d9ae38..bc224077f7 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -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 index 0000000000..f40f69430b --- /dev/null +++ b/Open-ILS/src/sql/Pg/xxx.add-display-field-to_config-metabib_field @@ -0,0 +1 @@ +ALTER TABLE config.metabib_field ADD COLUMN display_field BOOL NOT NULL DEFAULT TRUE; diff --git a/Open-ILS/src/templates/opac/parts/misc_util.tt2 b/Open-ILS/src/templates/opac/parts/misc_util.tt2 index db30d6b3d7..a89aa222e9 100644 --- a/Open-ILS/src/templates/opac/parts/misc_util.tt2 +++ b/Open-ILS/src/templates/opac/parts/misc_util.tt2 @@ -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 = []; -- 2.11.0