@@ -, +, @@ --- Koha/CurbsidePickupOpeningSlot.pm | 44 +++++++++ Koha/CurbsidePickupOpeningSlots.pm | 50 ++++++++++ Koha/CurbsidePickupPolicy.pm | 28 ++++++ admin/curbside_pickup.pl | 28 ++---- .../prog/en/modules/admin/curbside_pickup.tt | 98 ++++++++----------- 5 files changed, 170 insertions(+), 78 deletions(-) create mode 100644 Koha/CurbsidePickupOpeningSlot.pm create mode 100644 Koha/CurbsidePickupOpeningSlots.pm --- a/Koha/CurbsidePickupOpeningSlot.pm +++ a/Koha/CurbsidePickupOpeningSlot.pm @@ -0,0 +1,44 @@ +package Koha::CurbsidePickupOpeningSlot; + +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +CurbsidePickupOpeningSlot - Koha Curbside Pickup Slot Object class + +=head1 API + +=head2 Class methods + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'CurbsidePickupOpeningSlot'; +} + +1; --- a/Koha/CurbsidePickupOpeningSlots.pm +++ a/Koha/CurbsidePickupOpeningSlots.pm @@ -0,0 +1,50 @@ +package Koha::CurbsidePickupOpeningSlots; + +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::CurbsidePickupOpeningSlot; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::CurbsidePickupOpeningSlots - Koha Curbside Pickup Opening Slots Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'CurbsidePickupOpeningSlot'; +} + +sub object_class { + return 'Koha::CurbsidePickupOpeningSlot'; +} + +1; --- a/Koha/CurbsidePickupPolicy.pm +++ a/Koha/CurbsidePickupPolicy.pm @@ -20,6 +20,8 @@ use Modern::Perl; use Carp; use Koha::Database; +use Koha::Library; +use Koha::CurbsidePickupOpeningSlots; use base qw(Koha::Object); @@ -44,6 +46,32 @@ sub library { return Koha::Library->_new_from_dbic( $rs ); } +sub opening_slots { + my ( $self ) = @_; + my $rs = $self->_result->curbside_pickup_opening_slots; + return unless $rs; + return Koha::CurbsidePickupOpeningSlots->_new_from_dbic( $rs ); +} + +sub add_opening_slot { + my ( $self, $slot ) = @_; + + my ( $day, $start, $end ) = split '-', $slot; + my ( $start_hour, $start_minute ) = split ':', $start; + my ( $end_hour, $end_minute ) = split ':', $end; + + return Koha::CurbsidePickupOpeningSlot->new( + { + curbside_pickup_policy_id => $self->id, + day => $day, + start_hour => $start_hour, + start_minute => $start_minute, + end_hour => $end_hour, + end_minute => $end_minute, + } + )->store; +} + =head2 Internal methods =head3 _type --- a/admin/curbside_pickup.pl +++ a/admin/curbside_pickup.pl @@ -43,7 +43,6 @@ if ( $op eq 'save' ) { my $branchcode = $library->branchcode; my $params = { - branchcode => $branchcode, enabled => scalar $input->param("enable-$branchcode") || 0, pickup_interval => scalar $input->param("interval-$branchcode"), @@ -51,28 +50,15 @@ if ( $op eq 'save' ) { patron_scheduled_pickup => scalar $input->param("patron-scheduled-$branchcode") || 0, }; - for my $day ( - qw( sunday monday tuesday wednesday thursday friday saturday )) - { - for my $start_end (qw( start end )) { - for my $hour_min (qw( hour minute )) { - - my $value = $input->param( - "pickup-$start_end-$hour_min-$day-$branchcode"); - $value = undef if $value eq q{}; - - my $key = $day . '_' . $start_end . '_' . $hour_min; + my $policy = + Koha::CurbsidePickupPolicies->find_or_create( { branchcode => $branchcode } ); + $policy->update($params); - $params->{$key} = $value; - } - } + $policy->opening_slots->delete; + my @pickup_slots = $input->multi_param("pickup-slot-" . $branchcode); + for my $pickup_slot ( @pickup_slots ) { + $policy->add_opening_slot($pickup_slot); } - - my $CurbsidePickupPolicy = - Koha::CurbsidePickupPolicies->find( { branchcode => $branchcode } ); - $CurbsidePickupPolicy->delete if $CurbsidePickupPolicy; - - Koha::CurbsidePickupPolicy->new($params)->store(); } $op = 'list'; } --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/curbside_pickup.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/curbside_pickup.tt @@ -9,8 +9,9 @@ [% INCLUDE 'doc-head-close.inc' %] @@ -117,31 +118,9 @@