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 );
24 use Koha::Exception::DuplicateObject;
26 use base qw(Koha::Object);
30 Koha::Virtualshelf - Koha Virtualshelf Object class
48 unless ( $self->is_shelfname_valid ) {
49 Koha::Exceptions::Virtualshelves::DuplicateObject->throw;
53 unless defined $self->allow_add;
54 $self->allow_delete_own( 1 )
55 unless defined $self->allow_delete_own;
56 $self->allow_delete_other( 0 )
57 unless defined $self->allow_delete_other;
59 $self->created_on( dt_from_string );
61 return $self->SUPER::store( $self );
64 sub is_shelfname_valid {
68 shelfname => $self->shelfname,
69 ( $self->shelfnumber ? ( "me.shelfnumber" => { '!=', $self->shelfnumber } ) : () ),
72 if ( $self->category == $PRIVATE and defined $self->owner ) {
73 $conditions->{-or} = {
74 "virtualshelfshares.borrowernumber" => $self->owner,
75 "me.owner" => $self->owner,
77 $conditions->{category} = $PRIVATE;
79 elsif ( $self->category == $PRIVATE and not defined $self->owner ) {
80 $conditions->{owner} = undef;
81 $conditions->{category} = $PRIVATE;
84 $conditions->{category} = $PUBLIC;
87 my $count = Koha::Virtualshelves->search(
90 join => 'virtualshelfshares',
93 return $count ? 0 : 1;
97 return 'Virtualshelve';