1 package Koha::Virtualshelf;
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.
23 use Koha::DateUtils qw( dt_from_string );
25 use Koha::Virtualshelfshare;
26 use Koha::Virtualshelfshares;
28 use base qw(Koha::Object);
32 Koha::Virtualshelf - Koha Virtualshelf Object class
50 unless ( $self->is_shelfname_valid ) {
51 Koha::Exceptions::Virtualshelves::DuplicateObject->throw;
55 unless defined $self->allow_add;
56 $self->allow_delete_own( 1 )
57 unless defined $self->allow_delete_own;
58 $self->allow_delete_other( 0 )
59 unless defined $self->allow_delete_other;
61 $self->created_on( dt_from_string );
63 return $self->SUPER::store( $self );
66 sub is_shelfname_valid {
70 shelfname => $self->shelfname,
71 ( $self->shelfnumber ? ( "me.shelfnumber" => { '!=', $self->shelfnumber } ) : () ),
74 if ( $self->category == $PRIVATE and defined $self->owner ) {
75 $conditions->{-or} = {
76 "virtualshelfshares.borrowernumber" => $self->owner,
77 "me.owner" => $self->owner,
79 $conditions->{category} = $PRIVATE;
81 elsif ( $self->category == $PRIVATE and not defined $self->owner ) {
82 $conditions->{owner} = undef;
83 $conditions->{category} = $PRIVATE;
86 $conditions->{category} = $PUBLIC;
89 my $count = Koha::Virtualshelves->search(
92 join => 'virtualshelfshares',
95 return $count ? 0 : 1;
100 return $self->{_result}->virtualshelfshares;
104 my ( $self, $key ) = @_;
106 Koha::Exceptions::Virtualshelves::InvalidKeyOnSharing->throw;
108 Koha::Virtualshelfshare->new(
110 shelfnumber => $self->shelfnumber,
112 sharedate => dt_from_string,
119 return $self->get_shares->search(
121 borrowernumber => { '!=' => undef },
127 my ( $self, $borrowernumber ) = @_;
128 my $shelves = Koha::Virtualshelfshares->search(
130 shelfnumber => $self->shelfnumber,
131 borrowernumber => $borrowernumber,
134 return 0 unless $shelves->count;
136 # Only 1 share with 1 patron can exist
137 return $shelves->next->delete;
141 return 'Virtualshelve';