1 package Koha::Virtualshelves;
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>.
24 use Koha::Virtualshelf;
27 use base qw(Koha::Objects);
31 Koha::Virtualshelf - Koha Virtualshelf Object class
37 =head3 disown_or_delete
39 $lists->disown_or_delete;
41 This method will transfer public/shared lists to the appropriate patron or
42 just delete them if not possible.
46 sub disown_or_delete {
49 $self->_resultset->result_source->schema->txn_do(
51 if ( C4::Context->preference('ListOwnershipUponPatronDeletion') eq 'transfer' ) {
54 $new_owner = C4::Context->preference('ListOwnerDesignated')
55 if C4::Context->preference('ListOwnerDesignated')
56 and Koha::Patrons->find( C4::Context->preference('ListOwnerDesignated') );
58 if( !$new_owner && C4::Context->userenv ) {
59 $new_owner = C4::Context->userenv->{number};
62 while ( my $list = $self->next ) {
63 if ( $new_owner && ( $list->is_public or $list->is_shared ) ) {
64 $list->transfer_ownership($new_owner);
70 $_->delete for $self->as_list;
78 =head3 get_private_shelves
82 sub get_private_shelves {
83 my ( $self, $params ) = @_;
84 my $page = $params->{page};
85 my $rows = $params->{rows};
86 my $borrowernumber = $params->{borrowernumber} || 0;
92 'virtualshelfshares.borrowernumber' => $borrowernumber,
93 'me.owner' => $borrowernumber,
97 join => [ 'virtualshelfshares' ],
98 distinct => 'shelfnumber',
99 order_by => 'shelfname',
100 ( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ),
105 =head3 get_public_shelves
109 sub get_public_shelves {
110 my ( $self, $params ) = @_;
111 my $page = $params->{page};
112 my $rows = $params->{rows};
119 distinct => 'shelfnumber',
120 order_by => 'shelfname',
121 ( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ),
126 =head3 get_some_shelves
130 sub get_some_shelves {
131 my ( $self, $params ) = @_;
132 my $borrowernumber = $params->{borrowernumber} || 0;
133 my $public = $params->{public} || 0;
134 my $add_allowed = $params->{add_allowed};
139 if ( $borrowernumber != 0 ) {
140 $patron = Koha::Patrons->find( $borrowernumber );
141 $staffuser = $patron->can_patron_change_staff_only_lists;
143 if ( $add_allowed ) {
149 "me.owner" => $borrowernumber,
150 "me.allow_change_from_owner" => 1,
152 "me.allow_change_from_others" => 1,
153 "me.allow_change_from_staff" => 1
161 "me.owner" => $borrowernumber,
162 "me.allow_change_from_owner" => 1,
164 "me.allow_change_from_others" => 1,
173 "virtualshelfshares.borrowernumber" => $borrowernumber,
174 "me.owner" => $borrowernumber,
182 ( @conditions ? ( -and => \@conditions ) : () ),
185 join => [ 'virtualshelfshares' ],
186 distinct => 'shelfnumber',
187 order_by => { -desc => 'lastmodified' },
192 =head3 get_shelves_containing_record
196 sub get_shelves_containing_record {
197 my ( $self, $params ) = @_;
198 my $borrowernumber = $params->{borrowernumber};
199 my $biblionumber = $params->{biblionumber};
201 my @conditions = ( 'virtualshelfcontents.biblionumber' => $biblionumber );
202 if ($borrowernumber) {
209 'me.owner' => $borrowernumber,
211 'virtualshelfshares.borrowernumber' => $borrowernumber,
219 push @conditions, { public => 1 };
222 return Koha::Virtualshelves->search(
227 join => [ 'virtualshelfcontents', 'virtualshelfshares' ],
228 distinct => 'shelfnumber',
229 order_by => { -asc => 'shelfname' },
239 return 'Virtualshelve';
247 return 'Koha::Virtualshelf';