OPAC Browser: Display Public General Notes from authorities when possible
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 20 May 2013 20:09:20 +0000 (16:09 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 20 May 2013 20:09:20 +0000 (16:09 -0400)
When headings are linked to authority records, and those records have
680 fields, display them.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm
Open-ILS/src/templates/opac/browse.tt2
Open-ILS/src/templates/opac/css/style.css.tt2

index 98cfb98..97371c8 100644 (file)
@@ -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,
index f35cabd..fad65f0 100644 (file)
@@ -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
index aedce40..ac3a25d 100644 (file)
                             [% IF result.authorities %]
                             <ul class="browse-result-authority-headings">
                                 [% FOR a IN result.authorities;
-                                    NEXT UNLESS a.control_set;  # Can't deal.
+                                    PROCESS authority_notes authority=a;
+
+                                    # Other than displaying public general
+                                    # notes, we can go no further sans
+                                    # control_set.
+                                    NEXT UNLESS a.control_set;
 
                                     # get_authority_fields is fast and cache-y.
                                     acs = ctx.get_authority_fields(a.control_set);
             <div class="common-full-pad"></div>        
         </div>
     </div>
+
+    [% BLOCK authority_notes;
+        # Displays public general notes (sometimes called "scope notes" ?)
+        FOR note IN authority.notes %]
+            <div class="browse-public-general-note">
+                <span class="browse-public-general-note-label">
+                    [% l("Note:") %]
+                </span>
+                <span class="browse-public-general-note-body">
+            [% FOR piece IN note;
+                IF piece.heading;
+                    mkurl_args = {bterm => piece.bterm};
+                    IF piece.org_id;
+                        mkurl_args.locg = piece.org_id;
+                    END;
+                %]
+                <a href="[% mkurl('', mkurl_args, ['boffset','bpivot','bback']) %]">[% piece.heading | html %]</a>
+                [% ELSIF piece.institution %]
+                <span class="browse-public-general-note-institution">
+                    [% piece.institution | html %]
+                </span>
+                [% ELSE %]
+                    [% piece | html %]
+                [% END;
+            END %]
+                </span>
+            </div>
+        [% END;
+    END;    # end of BLOCK authority_notes %]
+
 [% END %]
index ef0ef64..16c6400 100644 (file)
@@ -1539,3 +1539,14 @@ a.preflib_change {
     font-style: italic;
     font-size: 110%;
 }
+.browse-public-general-note {
+    font-size: 110%;
+}
+.browse-public-general-note-label { }
+.browse-public-general-note-institution {
+    font-style: normal;
+    font-weight: bold;
+}
+.browse-public-general-note-body {
+    font-style: italic;
+}