From: Lebbeous Fogle-Weekley Date: Thu, 9 May 2013 22:29:10 +0000 (-0400) Subject: OPAC Browse: Fix authority counting X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=094584acd7874f70f9eaa22891844a5cffe685c9;p=working%2FEvergreen.git OPAC Browse: Fix authority counting Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index f98645bc03..98cfb9852a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -17,6 +17,7 @@ use UUID::Tiny; use Encode; use DateTime; use DateTime::Format::ISO8601; +use List::MoreUtils qw/uniq/; # --------------------------------------------------------------------------- # Pile of utilty methods used accross applications. @@ -2119,6 +2120,18 @@ sub strip_marc_fields { return $class->entityize($marcdoc->documentElement->toString); } +# Given a list of PostgreSQL arrays of numbers, +# unnest the numbers and return a unique set, skipping any list elements +# that are just '{NULL}'. +sub unique_unnested_numbers { + return uniq( + map( + int, + map { $_ eq 'NULL' ? undef : (split /,/, $_) } + map { substr($_, 1, -1) } @_ + ) + ); +} 1; 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 755687d16f..f35cabdcba 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm @@ -109,9 +109,9 @@ sub find_authority_headings { # 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 ($field->subfield('0') || "") =~ /(^|\))(\d+)$/; - $h->{target} = $2 if defined $2; push @headings, $h; } @@ -166,12 +166,22 @@ sub flesh_browse_results { # Get all linked authority records themselves my $linked = $self->editor->json_query({ select => { - are => [qw/id marc control_set/] + are => [qw/id marc control_set/], + aalink => [{column => "target", transform => "array_agg", + aggregate => 1}] + }, + from => { + are => { + aalink => { + type => "left", + fkey => "id", field => "source" + } + } }, - from => { are => { } }, where => {"+are" => {id => \@auth_ids}} }) or return; + $self->map_authority_headings_to_results($linked, $results); # Get use counts of authority records, i.e. number of bibs linked to @@ -185,16 +195,20 @@ sub flesh_browse_results { ] }, from => {abl => {}}, - where => {"+abl" => {authority => \@auth_ids}} + where => { + "+abl" => { + authority => [ + @auth_ids, $U->unique_unnested_numbers( + map { $_->{target} } @$linked + ) + ] + } + } }) or return; - my %counts_by_authority = - map { $_->{authority} => $_->{count} } @$counts; - foreach my $row(@$results) { - foreach my $auth (@{$row->{authorities}}) { - $auth->{count} = $counts_by_authority{$auth->{id}}; - } - } + $self->ctx->{authority_counts} = { + map { $_->{authority} => $_->{count} } @$counts + }; } return 1; diff --git a/Open-ILS/src/templates/opac/browse.tt2 b/Open-ILS/src/templates/opac/browse.tt2 index 8e4b1d69ba..6e806a6c63 100644 --- a/Open-ILS/src/templates/opac/browse.tt2 +++ b/Open-ILS/src/templates/opac/browse.tt2 @@ -107,17 +107,18 @@ field_id = field_group.keys.0; field = acs.$field_id; headings = field_group.values.0; - FOR h IN headings %] + FOR h IN headings; + target_auth_id = h.target %] -
  • [% field.name %] - [% IF h.target %] - [% h.heading | html %] +
  • [% field.name %] + [% IF target_auth_id %] + [% h.heading | html %] + ([% ctx.authority_counts.$target_auth_id %]) [% ELSE; h.heading | html; - END; - END %] - - ([% a.count %])
  • + END %] + + [% END %] [% END %] [% END %] diff --git a/Open-ILS/src/templates/opac/css/style.css.tt2 b/Open-ILS/src/templates/opac/css/style.css.tt2 index f645b21167..ef0ef64643 100644 --- a/Open-ILS/src/templates/opac/css/style.css.tt2 +++ b/Open-ILS/src/templates/opac/css/style.css.tt2 @@ -1531,6 +1531,10 @@ a.preflib_change { .browse-shortcuts { font-size: 120%; } +.browse-result-authority-field-name { + font-style: italic; + margin-right: 1em; +} .browse-leading-article-warning { font-style: italic; font-size: 110%;