use Modern::Perl;
+use List::MoreUtils qw(any);
+
use C4::Context;
use C4::Items qw(GetItem ModItem);
use C4::Biblio qw(GetBiblioFromItemNumber);
) {
EnableOrDisableCourseItem(
ci_id => $course_reserve->{'ci_id'},
- enabled => 'yes',
);
}
}
) {
EnableOrDisableCourseItem(
ci_id => $course_reserve->{'ci_id'},
- enabled => 'no',
);
}
}
=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
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
$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;
}
-=head2 GetReservesInfo
+=head2 GetItemCourseReservesInfo
my $arrayref = GetItemCourseReservesInfo( itemnumber => $itemnumber );