@@ -, +, @@ all list editors --- C4/Utils/DataTables/VirtualShelves.pm | 21 +++++++++++- Koha/Virtualshelf.pm | 40 +++++++++++++++++++++- Koha/Virtualshelves.pm | 38 +++++++++++++++++--- .../en/modules/virtualshelves/addbybiblionumber.tt | 1 + .../prog/en/modules/virtualshelves/shelves.tt | 28 +++++++++++++-- virtualshelves/shelves.pl | 4 +++ 6 files changed, 123 insertions(+), 9 deletions(-) --- a/C4/Utils/DataTables/VirtualShelves.pm +++ a/C4/Utils/DataTables/VirtualShelves.pm @@ -15,12 +15,30 @@ sub search { my $dt_params = $params->{dt_params}; # public is default - $type = 2 if not $type or $type != 1; + $type = 2 unless $type && ( $type == 1 || $type == 3 ); # If not logged in user, be carreful and set the borrowernumber to 0 # to prevent private lists lack my $loggedinuser = C4::Context->userenv->{'number'} || 0; + if ( $type == 3 ) { + my $permissions = + C4::Auth::haspermission( C4::Context->userenv->{id}, { lists => '*' } ); + + unless ( + $permissions + && ( $permissions->{superlibrarian} == 1 + || $permissions->{lists} == 1 ) + ) + { + return { + iTotalRecords => 0, + iTotalDisplayRecords => 0, + shelves => [], + }; + } + } + my ($iTotalRecords, $iTotalDisplayRecords); my $dbh = C4::Context->dbh; @@ -125,6 +143,7 @@ sub search { $shelf->{can_delete_shelf} = $s->can_be_deleted( $loggedinuser ); $shelf->{is_shared} = $s->is_shared; } + return { iTotalRecords => $iTotalRecords, iTotalDisplayRecords => $iTotalDisplayRecords, --- a/Koha/Virtualshelf.pm +++ a/Koha/Virtualshelf.pm @@ -47,7 +47,8 @@ Koha::Virtualshelf - Koha Virtualshelf Object class =cut our $PRIVATE = 1; -our $PUBLIC = 2; +our $PUBLIC = 2; +our $STAFF = 3; sub store { my ( $self ) = @_; @@ -71,16 +72,45 @@ sub store { return $self->SUPER::store( $self ); } +=head3 is_public + + my $bool = $shelf->is_public; + + Returns true if shelf has been made public. + +=cut + sub is_public { my ( $self ) = @_; return $self->category == $PUBLIC; } +=head3 is_private + + my $bool = $shelf->is_private; + + Returns true if shelf is a private shelf. + +=cut + sub is_private { my ( $self ) = @_; return $self->category == $PRIVATE; } +=head3 is_staff + + my $bool = $shelf->is_staff; + + Returns true if shelf is available to staff only. + +=cut + +sub is_staff { + my ( $self ) = @_; + return $self->category == $STAFF; +} + sub is_shelfname_valid { my ( $self ) = @_; @@ -221,6 +251,7 @@ sub can_be_viewed { return 1 if $self->is_public; return 0 unless $borrowernumber; return 1 if $self->owner == $borrowernumber; + return 1 if $self->category == 3; return $self->get_shares->search( { borrowernumber => $borrowernumber, @@ -243,8 +274,15 @@ sub can_be_deleted { sub can_be_managed { my ( $self, $borrowernumber ) = @_; + return 1 if $borrowernumber and $self->owner == $borrowernumber; + + my $patron = Koha::Patrons->find( $borrowernumber ); + my $permissions = C4::Auth::haspermission( $patron->userid, { lists => '*' } ); + return 1 + if $borrowernumber and $self->category == 3 and $permissions and $permissions->{lists} == 1; + return 0; } --- a/Koha/Virtualshelves.pm +++ a/Koha/Virtualshelves.pm @@ -35,10 +35,6 @@ Koha::Virtualshelf - Koha Virtualshelf Object class =cut -=head3 type - -=cut - sub get_private_shelves { my ( $self, $params ) = @_; my $page = $params->{page}; @@ -62,7 +58,6 @@ sub get_private_shelves { ); } - sub get_public_shelves { my ( $self, $params ) = @_; my $page = $params->{page}; @@ -80,6 +75,31 @@ sub get_public_shelves { ); } +=head3 get_staff_shelves + + my $shelves = $virtual_shelves->get_staff_shelves( { page => $page, rows => $rowss ); + + Returns item lists that are visible to all staff that can manage patron lists + +=cut + +sub get_staff_shelves { + my ( $self, $params ) = @_; + my $page = $params->{page}; + my $rows = $params->{rows}; + + $self->search( + { + category => 3, + }, + { + group_by => 'shelfnumber', + order_by => 'shelfname', + ( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ), + } + ); +} + sub get_some_shelves { my ( $self, $params ) = @_; my $borrowernumber = $params->{borrowernumber} || 0; @@ -160,10 +180,18 @@ sub get_shelves_containing_record { ); } +=head3 _type + +=cut + sub _type { return 'Virtualshelve'; } +=head3 object_class + +=cut + sub object_class { return 'Koha::Virtualshelf'; } --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt @@ -97,6 +97,7 @@ --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt @@ -3,7 +3,8 @@ [% USE Koha %] [% USE KohaDates %] [% SET PRIVATE = 1 %] -[% SET PUBLIC = 2 %] +[% SET PUBLIC = 2 %] +[% SET STAFF = 3 %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %]