From 1aa9a8a6755aa6dc43b9c24a7d975eaa8084b860 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 13 Dec 2012 11:34:50 -0500 Subject: [PATCH] Show local call number in TPAC My Lists display If an opac-visible call number exists that is owned by an org unit relevant to the patron, show the (most relevant) call number label in the My Lists display for each record in the list. Call number is displayed in both saved and temporary lists. A call number is considered relevant if its owner is one of: physical location library preferred library (plib, home, etc.) search library This code leverages the new "exclude_invisible_acn" unapi filter to ensure that we are only required to retrieve 1 call number in the unapi output instead of an arbitrarily large set of call numbers, against which we may have to filter non-visible call numbers. This commit also addresses and outstanding TODO item in the tpac Perl: Replace the last use of fetch_marc_xml_by_id with get_records_and_facets and remove fetch_marc_xml_by_id Signed-off-by: Bill Erickson Signed-off-by: Ben Shum --- .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 13 +++++++- .../lib/OpenILS/WWW/EGCatLoader/Container.pm | 26 ++++++++++++++- .../perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm | 37 ++++------------------ Open-ILS/src/templates/opac/myopac/lists.tt2 | 18 +++++++++++ Open-ILS/src/templates/opac/parts/anon_list.tt2 | 20 ++++++++++-- Open-ILS/src/templates/opac/parts/misc_util.tt2 | 5 +-- 6 files changed, 83 insertions(+), 36 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm index 337ee52f31..ec7bb9658a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -1755,6 +1755,7 @@ sub load_myopac_bookbags { # transaction rollback under the covers. $e->rollback; + my $query = $self->_prepare_bookbag_container_query( $bookbag->id, $sorter, $modifier ); @@ -1769,11 +1770,21 @@ sub load_myopac_bookbags { my $items = $U->bib_container_items_via_search($bookbag->id, $query, $args) or return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR; + # capture pref_ou for callnumber filter/display + $ctx->{pref_ou} = $self->_get_pref_lib() || $ctx->{search_ou}; + + # search for local callnumbers for display + my $focus_ou = $ctx->{physical_loc} || $ctx->{pref_ou}; my (undef, @recs) = $self->get_records_and_facets( [ map {$_->target_biblio_record_entry->id} @$items ], undef, - {flesh => '{mra}'} + { + flesh => '{mra,holdings_xml,acp,exclude_invisible_acn}', + flesh_depth => 1, + site => $ctx->{get_aou}->($focus_ou)->shortname, + pref_lib => $ctx->{pref_ou} + } ); $ctx->{bookbags_marc_xml}{$_->{id}} = $_->{marc_xml} for @recs; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm index 445654dbea..b61ac06df0 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm @@ -28,9 +28,33 @@ sub fetch_mylist { } } + { # sanitize + no warnings qw/numeric/; + $list = [map { int $_ } @$list]; + $list = [grep { $_ > 0} @$list]; + }; + my $marc_xml; if ($with_marc_xml) { - $marc_xml = $self->fetch_marc_xml_by_id($list); + my $ctx = $self->ctx; + + # capture pref_ou for callnumber filter/display + $ctx->{pref_ou} = $self->_get_pref_lib() || $ctx->{search_ou}; + + # search for local callnumbers for display + my $focus_ou = $ctx->{physical_loc} || $ctx->{pref_ou}; + + my (undef, @recs) = $self->get_records_and_facets( + $list, undef, { + flesh => '{mra,holdings_xml,acp,exclude_invisible_acn}', + flesh_depth => 1, + site => $ctx->{get_aou}->($focus_ou)->shortname, + pref_lib => $ctx->{pref_ou} + } + ); + + # make it look like the caller is expecting + $marc_xml = { map {$_->{id} => $_->{marc_xml}} @recs }; } # Leverage QueryParser to sort the items by values of config.metabib_fields 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 ec8b6be850..39f986fdc7 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -137,6 +137,13 @@ sub init_ro_object_cache { return [ values %{$cache{map}{$ctx->{locale}}{aou}} ]; }; + # returns the org unit object by shortname + $ro_object_subs->{get_aou_by_shortname} = sub { + my $sn = shift or return undef; + my $list = $ro_object_subs->{aou_list}->(); + return (grep {$_->shortname eq $sn} @$list)[0]; + }; + $ro_object_subs->{aouct_tree} = sub { # fetch the org unit tree @@ -340,36 +347,6 @@ sub get_records_and_facets { return ($facets, @data); } -# TODO: blend this code w/ ^-- get_records_and_facets -sub fetch_marc_xml_by_id { - my ($self, $id_list) = @_; - $id_list = [$id_list] unless ref($id_list); - - { - no warnings qw/numeric/; - $id_list = [map { int $_ } @$id_list]; - $id_list = [grep { $_ > 0} @$id_list]; - }; - - return {} if scalar(@$id_list) < 1; - - # I'm just sure there needs to be some more efficient way to get all of - # this. - my $results = $self->editor->json_query({ - "select" => {"bre" => ["id", "marc"]}, - "from" => {"bre" => {}}, - "where" => {"id" => $id_list} - }, {substream => 1}) or return $self->editor->die_event; - - my $marc_xml = {}; - for my $r (@$results) { - $marc_xml->{$r->{"id"}} = - (new XML::LibXML)->parse_string($r->{"marc"}); - } - - return $marc_xml; -} - sub _get_search_lib { my $self = shift; my $ctx = $self->ctx; diff --git a/Open-ILS/src/templates/opac/myopac/lists.tt2 b/Open-ILS/src/templates/opac/myopac/lists.tt2 index 5347d34885..b43ad42ca9 100644 --- a/Open-ILS/src/templates/opac/myopac/lists.tt2 +++ b/Open-ILS/src/templates/opac/myopac/lists.tt2 @@ -238,6 +238,9 @@ [% l('Author(s)') %] + + [% l('Local Call Number') %] + [% l('Publication Date') %] @@ -285,6 +288,21 @@ -%]">[% attrs.author | html %] + [% + copy = attrs.holdings.0; + IF copy; + # only show a relevant call number + org = ctx.get_aou_by_shortname(copy.owner); + IF org.id == ctx.search_ou OR + org.id == ctx.pref_ou OR + org.id == ctx.user.home_ou OR + org.id == ctx.physical_loc; + l('[_1] ([_2])', copy.label, org.name) | html; + END; + END; + %] + + [% attrs.pubdate | html %] diff --git a/Open-ILS/src/templates/opac/parts/anon_list.tt2 b/Open-ILS/src/templates/opac/parts/anon_list.tt2 index 89e771c758..cd39bbc4eb 100644 --- a/Open-ILS/src/templates/opac/parts/anon_list.tt2 +++ b/Open-ILS/src/templates/opac/parts/anon_list.tt2 @@ -23,8 +23,9 @@ for (i = 0; i < inputs.length; i++) { if (inputs[i].name == 'record' && !inputs[i].disabled) inputs[i].checked = this.checked;}"/> - [% l('Title') %] - [% l('Author(s)') %] + [% l('Title') %] + [% l('Author(s)') %] + [% l('Local Call Number') %]