1 package Koha
::Virtualshelfshare
;
3 # This file is part of Koha.
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
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.
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.
22 use DateTime
::Duration
;
28 use base
qw(Koha::Object);
30 use constant SHARE_INVITATION_EXPIRY_DAYS
=> 14; #two weeks to accept
34 Koha::Virtualshelfshare - Koha Virtualshelfshare Object class
47 my ( $self, $invitekey, $borrowernumber ) = @_;
48 if ( $self->has_expired ) {
49 Koha
::Exceptions
::Virtualshelves
::ShareHasExpired
->throw;
51 if ( $self->invitekey ne $invitekey ) {
52 Koha
::Exceptions
::Virtualshelves
::InvalidInviteKey
->throw;
55 # If this borrower already has a share, there is no need to accept twice
56 # We solve this by 'pretending' to reaccept, but delete instead
57 my $search = Koha
::Virtualshelfshares
->search({ shelfnumber
=> $self->shelfnumber, borrowernumber
=> $borrowernumber, invitekey
=> undef });
58 if( $search->count ) {
62 $self->invitekey(undef);
63 $self->sharedate(dt_from_string
);
64 $self->borrowernumber($borrowernumber);
72 my $dt_sharedate = dt_from_string
( $self->sharedate, 'sql' );
73 my $today = dt_from_string
;
74 my $expiration_delay = DateTime
::Duration
->new( days
=> SHARE_INVITATION_EXPIRY_DAYS
);
75 my $has_expired = DateTime
->compare( $today, $dt_sharedate->add_duration($expiration_delay) );
76 # Note: has_expired = 0 if the share expires today
77 return $has_expired == 1 ?
1 : 0
81 return 'Virtualshelfshare';