@@ -, +, @@
---
Koha/Virtualshelfshare.pm | 22 ++++++++++++-
.../bootstrap/en/modules/opac-shelves.tt | 31 ++++++++++++++++++
opac/opac-shelves.pl | 32 ++++++++++++++++++-
3 files changed, 83 insertions(+), 2 deletions(-)
--- a/Koha/Virtualshelfshare.pm
+++ a/Koha/Virtualshelfshare.pm
@@ -23,6 +23,7 @@ use DateTime::Duration;
use Koha::Database;
use Koha::DateUtils qw( dt_from_string );
use Koha::Exceptions;
+use Koha::Patron;
use base qw(Koha::Object);
@@ -38,7 +39,7 @@ Koha::Virtualshelfshare - Koha Virtualshelfshare Object class
=cut
-=head3 type
+=head3 accept
=cut
@@ -66,6 +67,10 @@ sub accept {
}
}
+=head3 has_expired
+
+=cut
+
sub has_expired {
my ($self) = @_;
my $dt_sharedate = dt_from_string( $self->sharedate, 'sql' );
@@ -76,6 +81,21 @@ sub has_expired {
return $has_expired == 1 ? 1 : 0
}
+=head3 patron
+
+ Returns related Koha::Patron object for this share.
+
+=cut
+
+sub patron {
+ my $self = shift;
+ return Koha::Patron->_new_from_dbic( $self->{_result}->borrowernumber );
+}
+
+=head3 _type
+
+=cut
+
sub _type {
return 'Virtualshelfshare';
}
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt
+++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt
@@ -182,8 +182,15 @@
You do not have permission to delete this list.
[% CASE 'unauthorized_on_add_biblio' %]
You do not have permission to add a record to this list.
+ [% CASE 'unauthorized_transfer' %]
+ You do not have permission to transfer ownership of this list.
[% CASE 'no_biblio_removed' %]
No record was removed.
+ [% CASE 'new_owner_not_found' %]
+ The new owner could not be found anymore.
+ [% CASE 'new_owner_has_no_share' %]
+ The new owner has no share for this list.
+
[% CASE 'Koha::Exceptions::Virtualshelf::DuplicateObject' %]
An error occurred when creating the list. The name [% shelfname | html %] already exists.
[% CASE 'DBIx::Class::Exception' %]
@@ -635,6 +642,30 @@
+ [% ELSIF op == 'transfer' %]
+
Transfer ownership of shared list '[% shelf.shelfname | html %]'
+
+
+
[% ELSIF op == 'list' %]
Lists
--- a/opac/opac-shelves.pl
+++ a/opac/opac-shelves.pl
@@ -38,9 +38,11 @@ use Koha::Biblios;
use Koha::Biblioitems;
use Koha::CirculationRules;
use Koha::CsvProfiles;
+use Koha::DateUtils qw/dt_from_string/;
use Koha::Items;
use Koha::ItemTypes;
use Koha::Patrons;
+use Koha::Virtualshelfshares;
use Koha::Virtualshelves;
use Koha::RecordProcessor;
@@ -257,7 +259,35 @@ if ( $op eq 'add_form' ) {
}
$op = 'view';
} elsif( $op eq 'transfer' ) {
- $op = 'list'; # TODO
+ $shelfnumber = $query->param('shelfnumber');
+ $shelf = Koha::Virtualshelves->find($shelfnumber) if $shelfnumber;
+ my $new_owner = $query->param('new_owner'); # borrowernumber or undef
+
+ $op = 'list';
+ if( !$shelf ) {
+ push @messages, { type => 'error', code => 'does_not_exist' };
+ } elsif( $shelf->public or !$shelf->is_shared or !$shelf->can_be_managed($loggedinuser) ) {
+ push @messages, { type => 'error', code => 'unauthorized_transfer' };
+ } elsif( !$new_owner ) {
+ my $patrons = [];
+ my $shares = $shelf->get_shares->search({ borrowernumber => { '!=' => undef } });
+ while( my $share = $shares->next ) {
+ push @$patrons, { email => $share->patron->notice_email_address, borrowernumber => $share->get_column('borrowernumber') };
+ }
+ $template->param( shared_users => $patrons );
+ $op = 'transfer';
+ } elsif( !Koha::Patrons->find($new_owner) ) {
+ push @messages, { type => 'error', code => 'new_owner_not_found' };
+ } elsif( !$shelf->get_shares->search({ borrowernumber => $new_owner })->count ) {
+ push @messages, { type => 'error', code => 'new_owner_has_no_share' };
+ } else {
+ # Remove from virtualshelfshares new_owner, add loggedinuser
+ $shelf->_result->result_source->schema->txn_do( sub {
+ $shelf->get_shares->search({ borrowernumber => $new_owner })->delete;
+ Koha::Virtualshelfshare->new({ shelfnumber => $shelfnumber, borrowernumber => $loggedinuser, sharedate => dt_from_string })->store;
+ $shelf->owner($new_owner)->store;
+ });
+ }
}
# PART 2: After a possible action, view one list or show a number of lists
--