<link field="record" reltype="has_a" key="id" map="" class="are"/>
</links>
</class>
+ <class id="aalink" controller="open-ils.cstore" oils_obj:fieldmapper="authority::authority_linking" oils_persist:tablename="authority.authority_linking" reporter:label="Authority to Authority Linking">
+ <fields oils_persist:primary="id" oils_persist:sequence="authority.authority_linking_id_seq">
+ <field name="id" reporter:label="ID" reporter:datatype="id" />
+ <field name="source" reporter:label="Source Record" reporter:datatype="link" />
+ <field name="target" reporter:label="Target Record" reporter:datatype="link" />
+ <field name="field" reporter:label="Authority Field" reporter:datatype="link" />
+ </fields>
+ <links>
+ <link field="source" reltype="has_a" key="id" map="" class="are"/>
+ <link field="target" reltype="has_a" key="id" map="" class="are"/>
+ <link field="field" reltype="has_a" key="id" map="" class="acsaf"/>
+ </links>
+ </class>
<class id="cnct" controller="open-ils.cstore" oils_obj:fieldmapper="config::non_cataloged_type" oils_persist:tablename="config.non_cataloged_type" reporter:label="Non-cataloged Type">
<fields oils_persist:primary="id" oils_persist:sequence="config.non_cataloged_type_id_seq">
<field reporter:label="Circulation Duration" name="circ_duration" reporter:datatype="interval"/>
use Digest::MD5 qw/md5_hex/;
use Apache2::Const -compile => qw/OK/;
+use MARC::Record;
use Data::Dumper;
$Data::Dumper::Indent = 0;
);
}
-# This changes $results and returns 1 for success, undef for failure.
-# $results must be an arrayref of result rows from the DB's metabib.browse().
+# 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).
+# $results must be an arrayref of result rows from the DB's metabib.browse()
sub flesh_browse_results {
my ($self, $results) = @_;
- my @auth_ids = map { split /,/, $_->{authorities} } @$results;
+ # Turn all comma-seprated strings of numbers into array.
+ $_->{authorities} = [split /,/, $_->{authorities}] foreach @$results;
+ # Group them in one arrray, not worrying about dupes because IN () takes
+ # care of that.
+ my @auth_ids = map { @{$_->{authorities}} } @$results;
+
+ open FH, ">/tmp/lfw-auth-" . time() or die "LFW XXX $!";
+ print FH Dumper(\@auth_ids), "\n";
+ print FH Dumper($results), "\n";
if (@auth_ids) {
- # select ash.*
- # from authority.record_entry are
- # join authority.control_set acs on (are.control_set = acs.id)
- # join authority.control_set_authority_field
- # XXX wait what am I doing here?
- my $authorities = $self->editor->json_query({
- ""
+ # Get all linked authority records themselves
+ my $linked_authorities = $self->editor->json_query({
+ select => {are => [qw/id marc control_set/], aalink => ["target"]},
+ from => {
+ aalink => {
+ are => { field => "id", fkey => "source" }
+ }
+ },
+ where => {"+aalink" => {target => \@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_target;
+
+ foreach my $row (@$linked_authorities) {
+ my $acsaf_list =
+ $self->ctx->{get_authority_fields}->($row->{control_set});
+
+ $row->{headings} = [];
+ # BEGIN isolate in eval?
+ my $record = new_from_xml MARC::Record($row->{marc});
+ foreach my $acsaf (@$acsaf_list) {
+ 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;
+ }
+
+ push @{$row->{headings}}, {$acsaf->id => \@headings};
+ }
+ # END isolate in eval?
+
+ $linked_headings_by_target{$row->{target}} = $row;
+ }
+
+ # XXX TODO count bibs linked to each linked auth record?
+ print FH Dumper(\%linked_headings_by_target), "\n";
}
+ close FH;
return 1;
}
$self->ctx->{browse_error} = 1;
return;
- }#elsif (not $self->flesh_browse_results($results)) {
-# $logger->warn(
-# "error in browse (flesh): " . $self->editor->event->{textcode}
-# );
-# $self->ctx->{browse_error} = 1;
-#
-# return;
-# }
+ } elsif (not $self->flesh_browse_results($results)) {
+ $logger->warn(
+ "error in browse (flesh): " . $self->editor->event->{textcode}
+ );
+ $self->ctx->{browse_error} = 1;
+
+ return;
+ }
return $results;
}
search_filter_groups => {en_us => {}},
aou_tree => {en_us => undef},
aouct_tree => {},
- eg_cache_hash => undef
+ eg_cache_hash => undef,
+ authority_fields => {en_us => {}}
);
sub init_ro_object_cache {
return $cache{org_settings}{$ctx->{locale}}{$org_id}{$setting};
};
+ # retrieve and cache acsaf values
+ $ro_object_subs->{get_authority_fields} = sub {
+ my ($control_set) = @_;
+
+ $cache{authority_fields}{$ctx->{locale}}{$control_set} =
+ $e->search_authority_control_set_authority_field({control_set => $control_set})
+ unless exists $cache{authority_fields}{$ctx->{locale}}{$control_set};
+
+ return $cache{authority_fields}{$ctx->{locale}}{$control_set};
+ };
+
$ctx->{$_} = $ro_object_subs->{$_} for keys %$ro_object_subs;
}