From ac69ee0eb83568d78252aa553cfd9ea97a219d17 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Thu, 9 May 2013 17:50:16 -0400 Subject: [PATCH] OPAC Browse: Improve authority code to show more headings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- .../perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm | 70 ++++++++++++++-------- Open-ILS/src/templates/opac/browse.tt2 | 17 ++++-- 2 files changed, 58 insertions(+), 29 deletions(-) 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 3917bc2921..755687d16f 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm @@ -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. diff --git a/Open-ILS/src/templates/opac/browse.tt2 b/Open-ILS/src/templates/opac/browse.tt2 index 9e03d1e47e..8e4b1d69ba 100644 --- a/Open-ILS/src/templates/opac/browse.tt2 +++ b/Open-ILS/src/templates/opac/browse.tt2 @@ -103,11 +103,20 @@ # 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 %] -
  • [% field.name %] [% headings_themselves.join(";") %] + headings = field_group.values.0; + FOR h IN headings %] + +
  • [% field.name %] + [% IF h.target %] + [% h.heading | html %] + [% ELSE; + h.heading | html; + END; + END %] + ([% a.count %])
  • [% END %] [% END %] -- 2.11.0