1 package Koha::Virtualshelfshare;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use DateTime::Duration;
24 use Koha::DateUtils qw( dt_from_string );
27 use base qw(Koha::Object);
29 use constant SHARE_INVITATION_EXPIRY_DAYS => 14; #two weeks to accept
33 Koha::Virtualshelfshare - Koha Virtualshelfshare Object class
46 my ( $self, $invitekey, $borrowernumber ) = @_;
47 if ( $self->has_expired ) {
48 Koha::Exceptions::Virtualshelf::ShareHasExpired->throw;
50 if ( $self->invitekey ne $invitekey ) {
51 Koha::Exceptions::Virtualshelf::InvalidInviteKey->throw;
54 # If this borrower already has a share, there is no need to accept twice
55 # We solve this by 'pretending' to reaccept, but delete instead
56 my $search = Koha::Virtualshelfshares->search({ shelfnumber => $self->shelfnumber, borrowernumber => $borrowernumber, invitekey => undef });
57 if( $search->count ) {
61 $self->invitekey(undef);
62 $self->sharedate(dt_from_string);
63 $self->borrowernumber($borrowernumber);
71 my $dt_sharedate = dt_from_string( $self->sharedate, 'sql' );
72 my $today = dt_from_string;
73 my $expiration_delay = DateTime::Duration->new( days => SHARE_INVITATION_EXPIRY_DAYS );
74 my $has_expired = DateTime->compare( $today, $dt_sharedate->add_duration($expiration_delay) );
75 # Note: has_expired = 0 if the share expires today
76 return $has_expired == 1 ? 1 : 0
80 return 'Virtualshelfshare';