Bug 26346: Add option to make public lists editable by all staff
[koha-ffzg.git] / Koha / Virtualshelves.pm
index 25a3b01..981e8e9 100644 (file)
@@ -22,6 +22,7 @@ use Koha::Database;
 
 use Koha::Virtualshelf;
 
+
 use base qw(Koha::Objects);
 
 =head1 NAME
@@ -46,7 +47,7 @@ sub get_private_shelves {
 
     $self->search(
         {
-            category => 1,
+            public => 0,
             -or => {
                 'virtualshelfshares.borrowernumber' => $borrowernumber,
                 'me.owner' => $borrowernumber,
@@ -69,7 +70,7 @@ sub get_public_shelves {
 
     $self->search(
         {
-            category => 2,
+            public => 1,
         },
         {
             distinct => 'shelfnumber',
@@ -82,23 +83,43 @@ sub get_public_shelves {
 sub get_some_shelves {
     my ( $self, $params ) = @_;
     my $borrowernumber = $params->{borrowernumber} || 0;
-    my $category = $params->{category} || 1;
+    my $public = $params->{public} || 0;
     my $add_allowed = $params->{add_allowed};
 
     my @conditions;
+    my $patron;
+    my $staffuser = 0;
+    if ( $borrowernumber != 0 ) {
+        $patron = Koha::Patrons->find( $borrowernumber );
+        $staffuser = $patron->can_patron_change_staff_only_lists;
+    }
     if ( $add_allowed ) {
-        push @conditions, {
-            -or =>
-            [
-                {
-                    "me.owner" => $borrowernumber,
-                    "me.allow_change_from_owner" => 1,
-                },
-                "me.allow_change_from_others" => 1,
-            ]
-        };
+        if ( $staffuser ) {
+            push @conditions, {
+                -or =>
+                [
+                    {
+                        "me.owner" => $borrowernumber,
+                        "me.allow_change_from_owner" => 1,
+                    },
+                    "me.allow_change_from_others" => 1,
+                    "me.allow_change_from_staff"  => 1
+                ]
+            };
+        } else {
+            push @conditions, {
+                -or =>
+                [
+                    {
+                        "me.owner" => $borrowernumber,
+                        "me.allow_change_from_owner" => 1,
+                    },
+                    "me.allow_change_from_others" => 1,
+                ]
+            };
+        }
     }
-    if ( $category == 1 ) {
+    if ( !$public ) {
         push @conditions, {
             -or =>
             {
@@ -110,7 +131,7 @@ sub get_some_shelves {
 
     $self->search(
         {
-            category => $category,
+            public => $public,
             ( @conditions ? ( -and => \@conditions ) : () ),
         },
         {
@@ -132,7 +153,7 @@ sub get_shelves_containing_record {
           {
               -or => [
                 {
-                    category => 1,
+                    public => 0,
                     -or      => {
                         'me.owner' => $borrowernumber,
                         -or        => {
@@ -140,11 +161,11 @@ sub get_shelves_containing_record {
                         },
                     }
                 },
-                { category => 2 },
+                { public => 1 },
             ]
           };
     } else {
-        push @conditions, { category => 2 };
+        push @conditions, { public => 1 };
     }
 
     return Koha::Virtualshelves->search(