Bug 9569: Update warning message
[koha.git] / C4 / CourseReserves.pm
index 39cd3d2..4215422 100644 (file)
@@ -2,27 +2,29 @@ package C4::CourseReserves;
 
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
 
+use List::MoreUtils qw(any);
+
 use C4::Context;
 use C4::Items qw(GetItem ModItem);
 use C4::Biblio qw(GetBiblioFromItemNumber);
 use C4::Circulation qw(GetOpenIssue);
 
-use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG @FIELDS);
+use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG @FIELDS);
 
 BEGIN {
     require Exporter;
@@ -46,7 +48,7 @@ BEGIN {
 
       &SearchCourses
 
-      &GetItemReservesInfo
+      &GetItemCourseReservesInfo
     );
     %EXPORT_TAGS = ( 'all' => \@EXPORT_OK );
 
@@ -259,7 +261,6 @@ sub EnableOrDisableCourseItems {
               ) {
                 EnableOrDisableCourseItem(
                     ci_id   => $course_reserve->{'ci_id'},
-                    enabled => 'yes',
                 );
             }
         }
@@ -274,7 +275,6 @@ sub EnableOrDisableCourseItems {
               ) {
                 EnableOrDisableCourseItem(
                     ci_id   => $course_reserve->{'ci_id'},
-                    enabled => 'no',
                 );
             }
         }
@@ -283,10 +283,7 @@ sub EnableOrDisableCourseItems {
 
 =head2 EnableOrDisableCourseItem
 
-    EnableOrDisableCourseItem( ci_id => $ci_id, enabled => $enabled );
-
-    enabled => 'yes' to enable course items
-    enabled => 'no' to disable course items
+    EnableOrDisableCourseItem( ci_id => $ci_id );
 
 =cut
 
@@ -295,13 +292,16 @@ sub EnableOrDisableCourseItem {
     warn identify_myself(%params) if $DEBUG;
 
     my $ci_id   = $params{'ci_id'};
-    my $enabled = $params{'enabled'};
 
-    return unless ( $ci_id && $enabled );
-    return unless ( $enabled eq 'yes' || $enabled eq 'no' );
+    return unless ( $ci_id );
 
     my $course_item = GetCourseItem( ci_id => $ci_id );
 
+    my $info = GetItemCourseReservesInfo( itemnumber => $course_item->{itemnumber} );
+
+    my $enabled = any { $_->{course}->{enabled} eq 'yes' } @$info;
+    $enabled = $enabled ? 'yes' : 'no';
+
     ## We don't want to 'enable' an already enabled item,
     ## or disable and already disabled item,
     ## as that would cause the fields to swap
@@ -828,10 +828,8 @@ sub ModCourseReserve {
         $cr_id = $dbh->last_insert_id( undef, undef, 'course_reserves', 'cr_id' );
     }
 
-    my $course = GetCourse($course_id);
     EnableOrDisableCourseItem(
         ci_id   => $params{'ci_id'},
-        enabled => $course->{'enabled'}
     );
 
     return $cr_id;
@@ -932,16 +930,16 @@ sub DelCourseReserve {
 
 }
 
-=head2 GetReservesInfo
+=head2 GetItemCourseReservesInfo
 
-    my $arrayref = GetItemReservesInfo( itemnumber => $itemnumber );
+    my $arrayref = GetItemCourseReservesInfo( itemnumber => $itemnumber );
 
     For a given item, returns an arrayref of reserves hashrefs,
     with a course hashref under the key 'course'
 
 =cut
 
-sub GetItemReservesInfo {
+sub GetItemCourseReservesInfo {
     my (%params) = @_;
     warn identify_myself(%params) if $DEBUG;
 
@@ -1052,6 +1050,7 @@ sub SearchCourses {
         GROUP BY c.course_id
     ";
 
+    $term //= '';
     $term   = "%$term%";
     @params = ($term) x 10;