OPAC Browse: Improve authority code to show more headings
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 9 May 2013 21:50:16 +0000 (17:50 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 9 May 2013 21:50:16 +0000 (17:50 -0400)
Before this, we were only showing authority headings where those fields
in authority records already had subfields ‡0 to link them to other
authority records.

When we have a subfield ‡0, we can link, but without it we can at least
show the (non-main entry) heading.

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

index 3917bc2..755687d 100644 (file)
@@ -92,12 +92,27 @@ sub find_authority_headings {
         my @fields = $record->field($acsaf->tag);
         my @headings;
 
-        foreach (@fields) {
-            my $heading = "";
-            foreach my $sf (split "", $acsaf->sf_list) {
-                $heading .= $_->subfield($sf) || "";
-            }
-            push @headings, $heading;
+        foreach my $field (@fields) {
+            my $h = {
+                heading => join(
+                    "", grep(
+                        defined,
+                        map { $field->subfield($_) } split("", $acsaf->sf_list)
+                    )
+                )
+            };
+
+            # XXX I was getting "target" from authority.authority_linking, but
+            # that makes no sense: that table can only tell you that one
+            # authority record as a whole points at another record.  It does
+            # not record when a specific *field* in one authority record
+            # points to another record (not that it makes much sense for
+            # one authority record to have links to multiple others, but I can't
+            # say there definitely aren't cases for that).
+            ($field->subfield('0') || "") =~ /(^|\))(\d+)$/;
+
+            $h->{target} = $2 if defined $2;
+            push @headings, $h;
         }
 
         # Remember: main_entry is a link field, so for it to evaluate
@@ -113,6 +128,25 @@ sub find_authority_headings {
     return $row;
 }
 
+sub map_authority_headings_to_results {
+    my ($self, $linked, $results) = @_;
+
+    # Use the linked authority records' control sets to find and pick
+    # 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($_)
+    } @$linked;
+
+    # Graft this authority heading data onto our main result set at the
+    # "authorities" column.
+    foreach my $row (@$results) {
+        $row->{authorities} = [
+            map { $linked_headings_by_auth_id{$_} } @{$row->{authorities}}
+        ];
+    }
+}
+
 # flesh_browse_results() attaches data from authority records. It
 # changes $results and returns 1 for success, undef for failure (in which
 # case $self->editor->event should always point to the reason for failure).
@@ -131,28 +165,14 @@ sub flesh_browse_results {
     if (@auth_ids) {
         # Get all linked authority records themselves
         my $linked = $self->editor->json_query({
-            select => {are => [qw/id marc control_set/], aalink => ["target"]},
-            from => {
-                aalink => {
-                    are => { field => "id", fkey => "source" }
-                }
+            select => {
+                are => [qw/id marc control_set/]
             },
-            where => {"+aalink" => {target => \@auth_ids}}
+            from => { are => { } },
+            where => {"+are" => {id => \@auth_ids}}
         }) or return;
 
-        # Then use the linked authority records' control sets to find and
-        # pick 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($_) } @$linked;
-
-        # Graft this authority heading data onto our main result set at the
-        # "authorities" column.
-        foreach my $row (@$results) {
-            $row->{authorities} = [
-                map { $linked_headings_by_auth_id{$_} } @{$row->{authorities}}
-            ];
-        }
+        $self->map_authority_headings_to_results($linked, $results);
 
         # Get use counts of authority records, i.e. number of bibs linked to
         # them. - XXX refine later to consider holdings visibility.
index 9e03d1e..8e4b1d6 100644 (file)
 
                                     # get_authority_fields is fast and cache-y.
                                     acs = ctx.get_authority_fields(a.control_set);
-                                    FOR h IN a.headings;
-                                        field_id = h.keys.0;
+                                    FOR field_group IN a.headings;
+                                        field_id = field_group.keys.0;
                                         field = acs.$field_id;
-                                        headings_themselves = h.values.0 %]
-                                        <li>[% field.name %] <a href="[% mkurl(ctx.opac_root _ '/results', {query => 'identifier|authority_id[' _ a.target _ ']'}) %]">[% headings_themselves.join(";") %]</a>
+                                        headings = field_group.values.0;
+                                        FOR h IN headings %]
+
+                                            <li>[% field.name %]
+                                            [% IF h.target %]
+                                            <a href="[% mkurl(ctx.opac_root _ '/results', {query => 'identifier|authority_id[' _ h.target _ ']'}) %]">[% h.heading | html %]</a>
+                                            [% ELSE;
+                                                h.heading | html;
+                                            END;
+                                        END %]
+
                                             <span class="browse-result-authority-bib-links">([% a.count %])</span></li>
                                     [% END %]
                                 [% END %]