Browse Source
Signed-off-by: Alex Arnaud <alex.arnaud@biblibre.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>3.22.x
10 changed files with 318 additions and 188 deletions
@ -0,0 +1,34 @@ |
|||
package Koha::Exceptions; |
|||
|
|||
use Modern::Perl; |
|||
|
|||
use Exception::Class ( |
|||
|
|||
'Koha::Exceptions::Exception' => { |
|||
description => 'Something went wrong!', |
|||
}, |
|||
|
|||
'Koha::Exceptions::DuplicateObject' => { |
|||
isa => 'Koha::Exceptions::Exception', |
|||
description => 'Same object already exists', |
|||
}, |
|||
|
|||
'Koha::Exceptions::Virtualshelves::DuplicateObject' => { |
|||
isa => 'Koha::Exceptions::DuplicateObject', |
|||
description => "poeut", |
|||
}, |
|||
'Koha::Exceptions::Virtualshelves::InvalidInviteKey' => { |
|||
isa => 'Koha::Exceptions::Exception', |
|||
description => 'Invalid key on accepting the share', |
|||
}, |
|||
'Koha::Exceptions::Virtualshelves::InvalidKeyOnSharing' => { |
|||
isa => 'Koha::Exceptions::Exception', |
|||
description=> 'Invalid key on sharing a shelf', |
|||
}, |
|||
'Koha::Exceptions::Virtualshelves::ShareHasExpired' => { |
|||
isa => 'Koha::Exceptions::Exception', |
|||
description=> 'Cannot share this shelf, the share has expired', |
|||
} |
|||
); |
|||
|
|||
1; |
@ -0,0 +1,74 @@ |
|||
package Koha::Virtualshelfshare; |
|||
|
|||
# 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 DateTime; |
|||
use DateTime::Duration; |
|||
|
|||
use Koha::Database; |
|||
use Koha::DateUtils; |
|||
use Koha::Exceptions; |
|||
|
|||
use base qw(Koha::Object); |
|||
|
|||
use constant SHARE_INVITATION_EXPIRY_DAYS => 14; #two weeks to accept |
|||
|
|||
=head1 NAME |
|||
|
|||
Koha::Virtualshelfshare - Koha Virtualshelfshare Object class |
|||
|
|||
=head1 API |
|||
|
|||
=head2 Class Methods |
|||
|
|||
=cut |
|||
|
|||
=head3 type |
|||
|
|||
=cut |
|||
|
|||
sub accept { |
|||
my ( $self, $invitekey, $borrowernumber ) = @_; |
|||
if ( $self->has_expired ) { |
|||
Koha::Exceptions::Virtualshelves::ShareHasExpired->throw; |
|||
} |
|||
if ( $self->invitekey ne $invitekey ) { |
|||
Koha::Exceptions::Virtualshelves::InvalidInviteKey->throw; |
|||
} |
|||
$self->invitekey(undef); |
|||
$self->sharedate(dt_from_string); |
|||
$self->borrowernumber($borrowernumber); |
|||
$self->store; |
|||
} |
|||
|
|||
sub has_expired { |
|||
my ($self) = @_; |
|||
my $dt_sharedate = dt_from_string( $self->sharedate, 'sql' ); |
|||
my $today = dt_from_string; |
|||
my $expiration_delay = DateTime::Duration->new( days => SHARE_INVITATION_EXPIRY_DAYS ); |
|||
my $has_expired = DateTime->compare( $today, $dt_sharedate->add_duration($expiration_delay) ); |
|||
# Note: has_expired = 0 if the share expires today |
|||
return $has_expired == 1 ? 1 : 0 |
|||
} |
|||
|
|||
sub type { |
|||
return 'Virtualshelfshare'; |
|||
} |
|||
|
|||
1; |
@ -0,0 +1,50 @@ |
|||
package Koha::Virtualshelfshares; |
|||
|
|||
# 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::Virtualshelf; |
|||
|
|||
use base qw(Koha::Objects); |
|||
|
|||
=head1 NAME |
|||
|
|||
Koha::Virtualshelfshares - Koha Virtualshelfshares Object class |
|||
|
|||
=head1 API |
|||
|
|||
=head2 Class Methods |
|||
|
|||
=cut |
|||
|
|||
=head3 type |
|||
|
|||
=cut |
|||
|
|||
sub type { |
|||
return 'Virtualshelfshare'; |
|||
} |
|||
|
|||
sub object_class { |
|||
return 'Koha::Virtualshelfshare'; |
|||
} |
|||
|
|||
1; |
Loading…
Reference in new issue