1 package OpenILS::WWW::EGCatLoader;
6 use OpenSRF::Utils::Logger qw/$logger/;
7 use OpenILS::Utils::CStoreEditor qw/:funcs/;
8 use OpenILS::Utils::Fieldmapper;
9 use OpenILS::Utils::Normalize qw/search_normalize/;
10 use OpenILS::Application::AppUtils;
11 use OpenSRF::Utils::JSON;
12 use OpenSRF::Utils::Cache;
13 use OpenSRF::Utils::SettingsClient;
15 use Digest::MD5 qw/md5_hex/;
16 use Apache2::Const -compile => qw/OK/;
18 use List::Util qw/first/;
20 #$Data::Dumper::Indent = 0;
22 my $U = 'OpenILS::Application::AppUtils';
26 # Object methods start here.
28 # Returns cache key and a list of parameters for DB proc metabib.browse().
29 sub prepare_browse_parameters {
32 no warnings 'uninitialized';
34 # XXX TODO add config.global_flag rows for browse limit-limit ?
37 browse_class => scalar($self->cgi->param('qtype')),
38 term => scalar($self->cgi->param('bterm')),
39 org_unit => $self->ctx->{copy_location_group_org} ||
40 $self->ctx->{aou_tree}->()->id,
41 copy_location_group => $self->ctx->{copy_location_group},
42 pivot => scalar($self->cgi->param('bpivot')),
44 $self->cgi->param('blimit') ||
45 $self->ctx->{opac_hits_per_page} || 10
50 # Find paging information, put it into $self->ctx, and return "real"
51 # rows from $results, excluding those that contain only paging
53 sub infer_browse_paging {
54 my ($self, $results) = @_;
57 if ($_->{pivot_point}) {
58 if ($_->{row_number} < 0) { # sic
59 $self->ctx->{forward_pivot} = $_->{pivot_point};
61 $self->ctx->{back_pivot} = $_->{pivot_point};
66 return [ grep { not defined $_->{pivot_point} } @$results ];
72 # If there's a user logged in, flesh extended user info so we can get
73 # her opac.hits_per_page setting, if any.
74 if ($self->ctx->{user}) {
75 $self->prepare_extended_user_info('settings');
76 if (my $setting = first { $_->name eq 'opac.hits_per_page' }
77 @{$self->ctx->{user}->settings}) {
79 $self->ctx->{opac_hits_per_page} =
80 int(OpenSRF::Utils::JSON->JSON2perl($setting->value));
84 my $pager_shortcuts = $self->ctx->{get_org_setting}->(
85 $self->ctx->{physical_loc} || $self->ctx->{search_ou} ||
86 $self->ctx->{aou_tree}->id, 'opac.browse.pager_shortcuts'
88 if ($pager_shortcuts) {
90 while ($pager_shortcuts =~ s/(\*(.+?)\*)//) {
91 push @pager_shortcuts, [substr($2, 0, 1), $2];
93 push @pager_shortcuts, map { [$_, $_] } split //, $pager_shortcuts;
94 $self->ctx->{pager_shortcuts} = \@pager_shortcuts;
97 if ($self->cgi->param('qtype') and defined $self->cgi->param('bterm')) {
99 my $method = 'open-ils.search.browse';
100 $method .= '.staff' if $self->ctx->{is_staff};
101 $method .= '.atomic';
103 my $results = $U->simplereq('open-ils.search',
104 $method, $self->prepare_browse_parameters);
107 $self->ctx->{browse_results} = $self->infer_browse_paging($results);
110 # We don't need an else clause to send the user a 5XX error or
111 # anything. Errors will have been logged, and $ctx will be
112 # prepared so a template can show a nicer error to the user.
115 return Apache2::Const::OK;