From fbb738a2ac62b3eb9b40d758612c2ac99ae7131c Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Mon, 20 May 2013 16:09:20 -0400 Subject: [PATCH] OPAC Browser: Display Public General Notes from authorities when possible When headings are linked to authority records, and those records have 680 fields, display them. Signed-off-by: Lebbeous Fogle-Weekley --- .../perlmods/lib/OpenILS/Application/AppUtils.pm | 4 ++ .../perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm | 59 ++++++++++++++++++---- Open-ILS/src/templates/opac/browse.tt2 | 37 +++++++++++++- Open-ILS/src/templates/opac/css/style.css.tt2 | 11 ++++ 4 files changed, 99 insertions(+), 12 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index 98cfb9852a..97371c81d0 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -2124,6 +2124,10 @@ sub strip_marc_fields { # unnest the numbers and return a unique set, skipping any list elements # that are just '{NULL}'. sub unique_unnested_numbers { + my $class = shift; + + no warnings 'numeric'; + return uniq( map( int, diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm index f35cabdcba..fad65f0141 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm @@ -6,6 +6,7 @@ use warnings; use OpenSRF::Utils::Logger qw/$logger/; use OpenILS::Utils::CStoreEditor qw/:funcs/; use OpenILS::Utils::Fieldmapper; +use OpenILS::Utils::Normalize qw/search_normalize/; use OpenILS::Application::AppUtils; use OpenSRF::Utils::JSON; use OpenSRF::Utils::Cache; @@ -69,7 +70,46 @@ sub prepare_browse_parameters { ); } -sub find_authority_headings { +# Break out any Public General Notes (field 680) for display and +# hyperlinking. These are sometimes (erroneously?) called "scope notes." +# I say erroneously, tentatively, because LoC doesn't seem to document +# a "scope notes" field for authority records, while it does so for +# classification records, which are something else. But I am not a +# librarian. +sub extract_public_general_notes { + my ($self, $record, $row) = @_; + + my @notes; + foreach my $note ($record->field('680')) { + my @note; + my $last_heading; + + foreach my $subfield ($note->subfields) { + my ($code, $value) = @$subfield; + + if ($code eq 'i') { + push @note, $value; + } elsif ($code eq '5') { + if ($last_heading) { + my $org = $self->ctx->{get_aou_by_shortname}->($value); + $last_heading->{org_id} = $org->id if $org; + } + push @note, { institution => $value }; + } elsif ($code eq 'a') { + $last_heading = { + heading => $value, bterm => search_normalize($value) + }; + push @note, $last_heading; + } + } + + push @notes, \@note if @note; + } + + $row->{notes} = \@notes; +} + +sub find_authority_headings_and_notes { my ($self, $row) = @_; my $acsaf_table = @@ -88,7 +128,11 @@ sub find_authority_headings { # a fuss. } - foreach my $acsaf (values(%$acsaf_table)) { + $self->extract_public_general_notes($record, $row); + + # By applying grep in this way, we get acsaf objects that *have* and + # therefore *aren't* main entries, which is what we want. + foreach my $acsaf (grep { $_->main_entry } values(%$acsaf_table)) { my @fields = $record->field($acsaf->tag); my @headings; @@ -115,14 +159,7 @@ sub find_authority_headings { push @headings, $h; } - # Remember: main_entry is a link field, so for it to evaluate - # to true means that we *have* (and therefore *aren't*) a main - # entry. The rest of the time when main_entry is undef we - # *are* a main entry. - # - # For this, we only want non-main entries. - push @{$row->{headings}}, {$acsaf->id => \@headings} - if @headings and $acsaf->main_entry; + push @{$row->{headings}}, {$acsaf->id => \@headings} if @headings; } return $row; @@ -135,7 +172,7 @@ sub map_authority_headings_to_results { # out non-main-entry headings. Build the headings and make a # combined data structure for the template's use. my %linked_headings_by_auth_id = map { - $_->{id} => $self->find_authority_headings($_) + $_->{id} => $self->find_authority_headings_and_notes($_) } @$linked; # Graft this authority heading data onto our main result set at the diff --git a/Open-ILS/src/templates/opac/browse.tt2 b/Open-ILS/src/templates/opac/browse.tt2 index aedce40ca1..ac3a25de59 100644 --- a/Open-ILS/src/templates/opac/browse.tt2 +++ b/Open-ILS/src/templates/opac/browse.tt2 @@ -94,7 +94,12 @@ [% IF result.authorities %]