1 package OpenILS::WWW::EGCatLoader;
2 use strict; use warnings;
3 use Apache2::Const -compile => qw(OK DECLINED FORBIDDEN HTTP_INTERNAL_SERVER_ERROR REDIRECT HTTP_BAD_REQUEST);
4 use OpenSRF::Utils::Logger qw/$logger/;
5 use OpenILS::Utils::CStoreEditor qw/:funcs/;
6 use OpenILS::Utils::Fieldmapper;
7 use OpenILS::Application::AppUtils;
8 my $U = 'OpenILS::Application::AppUtils';
10 use constant COOKIE_ANON_CACHE => 'anoncache';
11 use constant ANON_CACHE_MYLIST => 'mylist';
13 # Retrieve the users cached records AKA 'My List'
14 # Returns an empty list if there are no cached records
16 my ($self, $with_marc_xml) = @_;
19 my $cache_key = $self->cgi->cookie(COOKIE_ANON_CACHE);
23 $list = $U->simplereq(
25 'open-ils.actor.anon_cache.get_value',
26 $cache_key, ANON_CACHE_MYLIST);
36 $marc_xml = $self->fetch_marc_xml_by_id($list);
39 return ($cache_key, $list, $marc_xml);
43 # Adds a record (by id) to My List, creating a new anon cache + list if necessary.
46 my $rec_id = $self->cgi->param('record');
48 my ($cache_key, $list) = $self->fetch_mylist;
49 push(@$list, $rec_id);
51 $cache_key = $U->simplereq(
53 'open-ils.actor.anon_cache.set_value',
54 $cache_key, ANON_CACHE_MYLIST, $list);
56 return $self->mylist_action_redirect($cache_key);
59 # Removes a record ID from My List, or moves to an actual bookbag
60 sub load_mylist_move {
62 my @rec_ids = $self->cgi->param('record');
63 my $action = $self->cgi->param('action') || '';
65 return $self->load_myopac_bookbag_update('place_hold', undef, @rec_ids)
66 if $action eq 'place_hold';
68 my ($cache_key, $list) = $self->fetch_mylist;
69 return $self->mylist_action_redirect unless $cache_key;
72 foreach my $id (@$list) { push(@keep, $id) unless grep { $id eq $_ } @rec_ids; }
74 $cache_key = $U->simplereq(
76 'open-ils.actor.anon_cache.set_value',
77 $cache_key, ANON_CACHE_MYLIST, \@keep
80 if ($self->ctx->{user} and $action =~ /^\d+$/) {
81 # in this case, action becomes list_id
82 $self->load_myopac_bookbag_update('add_rec', $self->cgi->param('action'));
83 # XXX TODO: test for failure of above
86 return $self->mylist_action_redirect($cache_key);
89 sub load_cache_clear {
91 $self->clear_anon_cache;
92 return $self->mylist_action_redirect;
95 # Wipes the entire anonymous cache, including My List
96 sub clear_anon_cache {
100 my $cache_key = $self->cgi->cookie(COOKIE_ANON_CACHE) or return;
104 'open-ils.actor.anon_cache.delete_session', $cache_key)
109 # Called after an anon-cache / My List action occurs. Redirect
110 # to the redirect_url (cgi param) or referrer or home.
111 sub mylist_action_redirect {
113 my $cache_key = shift;
115 return $self->generic_redirect(
118 -name => COOKIE_ANON_CACHE,
120 -value => ($cache_key) ? $cache_key : '',
121 -expires => ($cache_key) ? undef : '-1h'
128 (undef, $self->ctx->{mylist}, $self->ctx->{mylist_marc_xml}) =
129 $self->fetch_mylist(1);
131 return Apache2::Const::OK;