From eae02d674319774c103a9819176ddf55cd1f2934 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Mon, 13 Nov 2017 01:09:23 +0000 Subject: [PATCH] Bug 19532: Recall an item in OPAC This patch: - adds the 'Recall' button to the item on it's detail page - adds ability to place a recall - the recall is stored in the recalls table - the due date for the checkout is updated to whatever has been set in the issuing rule under recall_due_date_interval - error messages for if the user isn't logged in, the user tries to place a recall on an item they have already recalled, or if storing the recall in the db fails for any reason Signed-off-by: Nick Clemens --- Koha/Recall.pm | 41 ++++++++- Koha/Recalls.pm | 2 +- .../bootstrap/en/includes/item-status.inc | 1 + .../opac-tmpl/bootstrap/en/modules/opac-recall.tt | 62 ++++++++++++++ opac/opac-recall.pl | 96 ++++++++++++++++++++++ 5 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-recall.tt create mode 100755 opac/opac-recall.pl diff --git a/Koha/Recall.pm b/Koha/Recall.pm index 7be9bad..596aafa 100644 --- a/Koha/Recall.pm +++ b/Koha/Recall.pm @@ -37,10 +37,49 @@ Koha::Recall - Koha Recall Object class =cut -sub type { +sub _type { return 'Recall'; } +=head3 is_waiting + +Returns true if recall is awaiting pickup + +=cut + +sub is_waiting { + my ($self) = @_; + + my $status = $self->status; + return $status && $status eq 'W'; +} + +=head3 has_expired + +Returns true if recall has expired + +=cut + +sub has_expired { + my ($self) = @_; + + my $status = $self->status; + return $status && $status eq 'E'; +} + +=head3 is_requested + +Returns true if recall has been requested + +=cut + +sub is_requested { + my ($self) = @_; + + my $status = $self->status; + return $status && $status eq 'R'; +} + =head1 AUTHOR Aleisha Amohia diff --git a/Koha/Recalls.pm b/Koha/Recalls.pm index 067af85..578f7c8 100644 --- a/Koha/Recalls.pm +++ b/Koha/Recalls.pm @@ -38,7 +38,7 @@ Koha::Recalls - Koha Recalls Object Set class =cut -sub type { +sub _type { return 'Recall'; } diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/item-status.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/item-status.inc index ffb4d52..3c8400c 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/item-status.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/item-status.inc @@ -38,6 +38,7 @@ Checked out [% END %] [% END %] + [% IF loggedinusername %]Recall[% END %] [% END %] [% IF NOT ( item.isa('Koha::Item') ) AND item.transfertwhen %] [%# transfertwhen is set in C4::Search, do not have it for course reserves %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-recall.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-recall.tt new file mode 100644 index 0000000..e5c5805 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-recall.tt @@ -0,0 +1,62 @@ +[% USE Koha %] +[% INCLUDE 'doc-head-open.inc' %] +[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog › Recall +[% INCLUDE 'doc-head-close.inc' %] +[% BLOCK cssinclude %][% END %] + + +[% INCLUDE 'masthead.inc' %] + +
+ + +
+
+
+ +
+
+
+

Recall an item

+ [% IF error %] +
+ [% IF error == 'notloggedin' %] + Please log in to place a recall. + [% ELSIF error == 'duplicate' %] + You have already placed a recall on this item. + [% ELSE %] + An error has occurred while attempting to place a recall. Please contact your library. + [% END %] +
+ [% END %] + + [% IF success %] +

Your recall has been placed. The user the item is currently checked out to has been asked to return the item within [% due_interval %] [% due_unit %].

+

You will be notified when your item is waiting to be picked up at the library.

+ [% ELSIF not error %] +

All borrowable material is subject to recall if checked out and needed by someone else. We will ask the person who has checked out this item to return it so you may use it.

+

Warning: Your library does not allow recalls for x item types.

+
+ [% IF loggedinusername %] +
+

Place a recall on [% biblio.title %] ([% biblio.author %])?

Confirm   Cancel +
+ [% ELSE %] +
You must be logged in to place a recall.
+ [% END %] + + [% END %] +
+
+
+
+
+ +[% INCLUDE 'opac-bottom.inc' %] +[% BLOCK jsinclude %][% END %] diff --git a/opac/opac-recall.pl b/opac/opac-recall.pl new file mode 100755 index 0000000..72602a5 --- /dev/null +++ b/opac/opac-recall.pl @@ -0,0 +1,96 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Copyright 2017 Aleisha Amohia +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use CGI qw ( -utf8 ); +use DateTime; +use C4::Auth; +use C4::Output; +use C4::Context; +use Koha::Items; +use Koha::Recall; +use Koha::Recalls; +use Koha::DateUtils; +use Koha::IssuingRules; +use Koha::Patrons; + +my $query = new CGI; +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => "opac-recall.tt", + query => $query, + type => "opac", + authnotrequired => 0, + } +); + +my $op = $query->param('op') || ''; + +my $itemnumber = $query->param('itemnumber'); +my $item = Koha::Items->find($itemnumber); +my $biblio = Koha::Biblios->find($item->biblionumber); +my $recalled = Koha::Recalls->find({ itemnumber => $itemnumber }); +my $error; + +if ($op eq 'request'){ + if (!defined($borrowernumber)){ + # can't place recall if not logged in + $error = 'notloggedin'; + print $query->redirect('/cgi-bin/koha/opac-detail.pl?biblionumber='.$item->biblionumber); + } elsif (defined $recalled && $recalled->borrowernumber == $borrowernumber){ + # can't place a recall on an item that this borrower has already recalled + $error = 'duplicate'; + } else { + # can recall + my $borrower = Koha::Patrons->find($borrowernumber); + my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrower->categorycode, itemtype => $item->itype, branchcode => $item->holdingbranch }); + my $recall_request = Koha::Recall->new({ + borrowernumber => $borrowernumber, + recalldate => dt_from_string(), + biblionumber => $biblio->biblionumber, + branchcode => $item->holdingbranch, + status => 'R', + itemnumber => $itemnumber, + itemtype => $item->itype, + })->store; + if (defined $recall_request->recall_id){ # successful recall + my $recall = Koha::Recalls->find($recall_request->recall_id); + # updating due date on checkout + my $timestamp = dt_from_string($recall->timestamp); + my $due_date = $timestamp->add( $issuing_rule->lengthunit => $issuing_rule->recall_due_date_interval ); + Koha::Checkouts->find({ itemnumber => $itemnumber })->update({ date_due => $due_date }); + + $template->param( + success => 1, + due_interval => $issuing_rule->recall_due_date_interval, + due_unit => $issuing_rule->lengthunit + ); + } else { + $error = 'failed'; + } + } +} + +$template->param( + biblio => $biblio, + itemnumber => $itemnumber, + error => $error +); + +output_with_http_headers $query, $cookie, $template->output, 'html'; -- 2.1.4