Bug 30650: Be more flexible with opening slots
[koha.git] / Koha / CurbsidePickupPolicy.pm
1 package Koha::CurbsidePickupPolicy;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 use Modern::Perl;
19
20 use Carp;
21
22 use Koha::Database;
23 use Koha::Library;
24 use Koha::CurbsidePickupOpeningSlots;
25
26 use base qw(Koha::Object);
27
28 =head1 NAME
29
30 Koha::CurbsidePickupPolicy - Koha Curbside Pickup Policy Object class
31
32 =head1 API
33
34 =head2 Class methods
35
36 =head3 library
37
38 Return the branch associated with this policy
39
40 =cut
41
42 sub library {
43     my ( $self ) = @_;
44     my $rs = $self->_result->branchcode;
45     return unless $rs;
46     return Koha::Library->_new_from_dbic( $rs );
47 }
48
49 sub opening_slots {
50     my ( $self ) = @_;
51     my $rs = $self->_result->curbside_pickup_opening_slots;
52     return unless $rs;
53     return Koha::CurbsidePickupOpeningSlots->_new_from_dbic( $rs );
54 }
55
56 sub add_opening_slot {
57     my ( $self, $slot ) = @_;
58
59     my ( $day, $start, $end ) = split '-', $slot;
60     my ( $start_hour, $start_minute ) = split ':', $start;
61     my ( $end_hour,   $end_minute )   = split ':', $end;
62
63     return Koha::CurbsidePickupOpeningSlot->new(
64         {
65             curbside_pickup_policy_id => $self->id,
66             day                       => $day,
67             start_hour                => $start_hour,
68             start_minute              => $start_minute,
69             end_hour                  => $end_hour,
70             end_minute                => $end_minute,
71         }
72     )->store;
73 }
74
75 =head2 Internal methods
76
77 =head3 _type
78
79 =cut
80
81 sub _type {
82     return 'CurbsidePickupPolicy';
83 }
84
85 1;