From 8a712ede2872243776cd4a1775381a288cc67a49 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 3 May 2022 22:05:58 +0200 Subject: [PATCH] Bug 30650: OPAC view Sponsored-by: Association KohaLa - https://koha-fr.org/ Signed-off-by: Koha Team University Lyon 3 Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- .../bootstrap/en/includes/usermenu.inc | 9 + .../en/modules/opac-curbside-pickups.tt | 354 ++++++++++++++++++ opac/opac-curbside-pickups.pl | 128 +++++++ 3 files changed, 491 insertions(+) create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt create mode 100755 opac/opac-curbside-pickups.pl diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc index 433b80db82..d172132cb7 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc @@ -139,6 +139,15 @@ your interlibrary loan requests [% END %] + [% IF Koha.Preference( 'CurbsidePickup' ) %] + [% IF ( ermview ) %] +
  • + [% ELSE %] +
  • + [% END %] + your curbside pickups
  • + [% END %] + [% IF Koha.Preference('UseRecalls') %] [% IF ( recallsview ) %]
  • diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt new file mode 100644 index 0000000000..68a29987f6 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt @@ -0,0 +1,354 @@ +[% USE raw %] +[% USE To %] +[% USE Koha %] +[% USE KohaDates %] +[% USE Branches %] +[% USE AdditionalContents %] +[% SET OpacNav = AdditionalContents.get( location => "OpacNav", lang => lang, library => logged_in_user.branchcode || default_branch, blocktitle => 0 ) %] +[% SET OpacNavBottom = AdditionalContents.get( location => "OpacNavBottom", lang => lang, library => logged_in_user.branchcode || default_branch, blocktitle => 0 ) %] +[% INCLUDE 'doc-head-open.inc' %] +Your curbside pickups › [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog + + + +[% INCLUDE 'doc-head-close.inc' %] +[% BLOCK cssinclude %][% END %] + +[% INCLUDE 'bodytag.inc' bodyid='opac-curside-pickups' bodyclass='scrollto' %] +[% INCLUDE 'masthead.inc' %] +
    + + +
    +
    +
    + +
    +
    +
    +

    Curbside pickups

    + + [% FOR m IN messages %] +
    + [% SWITCH m.code %] + [% CASE 'too_many_pickups' %] + You already have a scheduled pickup for this library. + [% CASE 'cannot_checkout' %] + Unable to check the items out. Please contact the library. + [% CASE 'library_notified' %] + The library has been notified of your arrival. + [% CASE %] + [% m.code | html %] + [% END %] +
    + [% END %] + +
    + + +
    +
    + [% IF patron_curbside_pickups.count %] + + + + + + + + + + [% FOR p IN patron_curbside_pickups %] + + + + + + + [% END %] + +
    Pickup library + ScheduleNotesActions
    [% Branches.GetName(p.branchcode) | html %][% p.scheduled_pickup_datetime | $KohaDates with_hours => 1 %][% p.notes | html %] +
    + + + [% IF ! p.staged_datetime || p.arrival_datetime %] + +
    +

    +

    + + + [% IF p.delivered_datetime %] + +
    +
    + [% ELSE %] +
    No curbside pickups.
    + [% END %] +
    + + [% IF policies.count %] +
    +
    +
    +
      +
    1. + + + You already have a pickup scheduled for this library. +
    2. +
    3. + + + Required +
    4. + +
    5. + +
    6. + + +
    7. +
    +
    + +
    + + +
    +
    +
    + [% END %] +
    +
    +
    +
    +
    +
    +
    + +[% INCLUDE 'opac-bottom.inc' %] + +[% BLOCK jsinclude %] + [% Asset.js("lib/dayjs/dayjs.min.js") | $raw %] + [% Asset.js("lib/dayjs/plugin/isSameOrAfter.js") | $raw %] + + [% INCLUDE 'calendar.inc' %] + +[% END %] diff --git a/opac/opac-curbside-pickups.pl b/opac/opac-curbside-pickups.pl new file mode 100755 index 0000000000..e2801aaf9a --- /dev/null +++ b/opac/opac-curbside-pickups.pl @@ -0,0 +1,128 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# 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 Try::Tiny; +use C4::Members; +use C4::Auth qw( get_template_and_user ); +use C4::Output qw( output_html_with_http_headers ); + +use Koha::DateUtils qw( dt_from_string ); +use Koha::CurbsidePickups; +use Koha::CurbsidePickupPolicies; +use Koha::Libraries; +use Koha::Patrons; + +my $input = CGI->new; +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => "opac-curbside-pickups.tt", + query => $input, + type => "opac", + } +); + +unless( C4::Context->preference('CurbsidePickup') ) { + print $input->redirect("/cgi-bin/koha/errors/404.pl"); + exit; +} + +my $op = $input->param('op') || 'list'; + +my $logged_in_patron = Koha::Patrons->find($borrowernumber); +my $branchcode = $input->param('pickup_branch'); +my @messages; + +if ( $op eq 'create-pickup' ) { + my $scheduled_pickup_datetime = $input->param('pickup_time'); + my $notes = $input->param('notes'); + + try { + Koha::CurbsidePickup->new( + { + branchcode => $branchcode, + borrowernumber => $borrowernumber, + scheduled_pickup_datetime => dt_from_string($scheduled_pickup_datetime), + notes => $notes, + } + )->store(); + } catch { + if ( $_->isa('Koha::Exceptions::CurbsidePickup::TooManyPickups') ) { + push @messages, { + type => 'error', + code => 'too_many_pickups', + patron => Koha::Patrons->find($borrowernumber) + }; + } else { + warn $_; + push @messages, { + type => 'error', + code => 'something_wrong_happened', + }; + } + } + # $self->_notify_new_pickup($curbside_pickup); TODO +} +elsif ( $op eq 'cancel-pickup' ) { + my $id = $input->param('pickup_id'); + my $curbside_pickup = Koha::CurbsidePickups->search( + { borrowernumber => $borrowernumber } )->find($id); + $curbside_pickup->delete + if $curbside_pickup + && !$curbside_pickup->delivered_datetime; +} +elsif ( $op eq 'arrival-alert' ) { + my $id = $input->param('pickup_id'); + my $curbside_pickup = Koha::CurbsidePickups->search( + { borrowernumber => $borrowernumber } )->find($id); + $curbside_pickup->mark_patron_has_arrived if $curbside_pickup; + push @messages, { + type => 'message', + code => 'library_notified', + } +} + +$template->param( + policies => Koha::CurbsidePickupPolicies->search( + { + enabled => 1, + patron_scheduled_pickup => 1, + } + ), + patron_curbside_pickups => Koha::CurbsidePickups->search( + { + borrowernumber => $logged_in_patron->borrowernumber, + scheduled_pickup_datetime => { '>' => \'DATE(NOW())' }, + }, + { + order_by => { -asc => 'scheduled_pickup_datetime' } + } + ), + curbside_pickups => Koha::CurbsidePickups->search( + { + scheduled_pickup_datetime => { '>' => \'DATE(NOW())' }, + }, + { + order_by => { -asc => 'scheduled_pickup_datetime' } + } + ), +); + +output_html_with_http_headers $input, $cookie, $template->output, undef, + { force_no_caching => 1 }; -- 2.39.5