diff --git a/Koha/Virtualshelves.pm b/Koha/Virtualshelves.pm index 75ccfa8297..2469167448 100644 --- a/Koha/Virtualshelves.pm +++ b/Koha/Virtualshelves.pm @@ -119,6 +119,44 @@ sub get_some_shelves { ); } +sub get_shelves_containing_record { + my ( $self, $params ) = @_; + my $borrowernumber = $params->{borrowernumber}; + my $biblionumber = $params->{biblionumber}; + + my @conditions = ( 'virtualshelfcontents.biblionumber' => $biblionumber ); + if ($borrowernumber) { + push @conditions, + { + -or => [ + { + category => 1, + -or => { + 'me.owner' => $borrowernumber, + -or => { + 'virtualshelfshares.borrowernumber' => $borrowernumber, + }, + } + }, + { category => 2 }, + ] + }; + } else { + push @conditions, { category => 2 }; + } + + return Koha::Virtualshelves->search( + { + -and => \@conditions + }, + { + join => [ 'virtualshelfcontents', 'virtualshelfshares' ], + group_by => 'shelfnumber', + order_by => { -asc => 'shelfname' }, + } + ); +} + sub _type { return 'Virtualshelve'; }