use Encode;
use DateTime;
use DateTime::Format::ISO8601;
+use List::MoreUtils qw/uniq/;
# ---------------------------------------------------------------------------
# Pile of utilty methods used accross applications.
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;
# 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;
}
# 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
]
},
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;
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 %]
- <li>[% field.name %]
- [% IF h.target %]
- <a href="[% mkurl(ctx.opac_root _ '/results', {query => 'identifier|authority_id[' _ h.target _ ']'}) %]">[% h.heading | html %]</a>
+ <li><span class="browse-result-authority-field-name">[% field.name %]</span>
+ [% IF target_auth_id %]
+ <a href="[% mkurl(ctx.opac_root _ '/results', {query => 'identifier|authority_id[' _ target_auth_id _ ']'}) %]">[% h.heading | html %]</a>
+ <span class="browse-result-authority-bib-links">([% ctx.authority_counts.$target_auth_id %])</span>
[% ELSE;
h.heading | html;
- END;
- END %]
-
- <span class="browse-result-authority-bib-links">([% a.count %])</span></li>
+ END %]
+ </li>
+ [% END %]
[% END %]
[% END %]
</ul>