[Koha-patches] [PATCH] DisallowItemLevelOnShelfHolds
Kyle M Hall
kyle.m.hall at gmail.com
Fri Nov 13 17:29:08 CET 2009
If AllowOnShelfHolds is Off, a borrower can still place a title level hold on any items currently checked out. Turning this preference on will prevent adding holds for any items on a record where at least one item is available at any library.
---
C4/Items.pm | 37 ++++++++++++++++++++
C4/Reserves.pm | 6 ++-
installer/data/mysql/en/mandatory/sysprefs.sql | 1 +
.../1-Obligatoire/unimarc_standard_systemprefs.sql | 1 +
installer/data/mysql/updatedatabase.pl | 7 ++++
5 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/C4/Items.pm b/C4/Items.pm
index 3f550ef..a7f99d6 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -63,6 +63,7 @@ BEGIN {
GetItemsInfo
get_itemnumbers_of
GetItemnumberFromBarcode
+ GetItemsAvailableCount
CartToShelf
);
@@ -1611,6 +1612,42 @@ sub GetMarcItem {
}
+=head2 GetItemsAvailableCount
+
+=over 4
+
+my $count = GetItemsAvailableCount( $biblionumber [,$itemnumber] );
+
+If $itemnumber is passed, it will use the biblionumber for the given itemnumber instead of $biblionumber.
+
+=back
+
+Returns the number of items available to issue for a given biblionumber
+
+=cut
+
+sub GetItemsAvailableCount {
+ my ( $biblionumber, $itemnumber ) = @_;
+
+ my $sql;
+ if ( $itemnumber ) {
+ $sql = "SELECT COUNT(*) AS available FROM items WHERE items.onloan IS NULL AND items.biblionumber = ( SELECT biblionumber FROM items WHERE itemnumber = ? )"
+ } else {
+ $sql = "SELECT COUNT(*) AS available FROM items WHERE items.onloan IS NULL AND items.biblionumber = ?";
+ }
+
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare( $sql );
+ if ( $itemnumber ) {
+ $sth->execute( $itemnumber );
+ } else {
+ $sth->execute( $biblionumber );
+ }
+
+ my $row = $sth->fetchrow_hashref();
+ return $row->{'available'};
+}
+
=head1 PRIVATE FUNCTIONS AND VARIABLES
The following functions are not meant to be called
diff --git a/C4/Reserves.pm b/C4/Reserves.pm
index 8610036..640baeb 100644
--- a/C4/Reserves.pm
+++ b/C4/Reserves.pm
@@ -1159,9 +1159,11 @@ sub IsAvailableForItemLevelRequest {
if (C4::Context->preference('AllowOnShelfHolds')) {
- return $available_per_item;
+ return $available_per_item;
+ } elsif ( C4::Context->preference('DisallowItemLevelOnShelfHolds') && GetItemsAvailableCount( '', $itemnumber ) ) {
+ return 0;
} else {
- return ($available_per_item and $item->{onloan});
+ return ($available_per_item and $item->{onloan});
}
}
diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql
index 6f60fa7..4ee73a7 100644
--- a/installer/data/mysql/en/mandatory/sysprefs.sql
+++ b/installer/data/mysql/en/mandatory/sysprefs.sql
@@ -262,3 +262,4 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('DisplayOPACiconsXSLT', '1', '', 'If ON, displays the format, audience, type icons in XSLT MARC21 results and display pages.', 'YesNo');
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowAllMessageDeletion','0','Allow any Library to delete any message','','YesNo');
INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('ShowPatronImageInWebBasedSelfCheck', '0', 'If ON, displays patron image when a patron uses web-based self-checkout', '', 'YesNo');
+INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'DisallowItemLevelOnShelfHolds', '0', '', 'If AllowOnShelfHolds is Off, a borrower can still place a title level hold on any items currently checked out. Turning this preference on will prevent adding holds for any items on a record where at least one item is available at any library.', 'YesNo' );
diff --git a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
index bee360a..5421f24 100644
--- a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
+++ b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
@@ -261,3 +261,4 @@ INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('H
INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('DisplayOPACiconsXSLT', '1', '', 'Si activé, affiche le format, le type de public et les icônes de type en XSLT (MARC21)).', 'YesNo');
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowAllMessageDeletion','0','Allow any Library to delete any message','','YesNo');
INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('ShowPatronImageInWebBasedSelfCheck', '0', 'Si activé, affiche la photo de l''adhérent lors de l''utilisation de la console de prêt auto-contrôlé', '', 'YesNo');
+INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'DisallowItemLevelOnShelfHolds', '0', '', 'If AllowOnShelfHolds is Off, a borrower can still place a title level hold on any items currently checked out. Turning this preference on will prevent adding holds for any items on a record where at least one item is available at any library.', 'YesNo' );
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 10c3451..4a15d20 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -2675,6 +2675,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
SetVersion ($DBversion);
}
+$DBversion = '3.01.00.062';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'DisallowItemLevelOnShelfHolds', '0', '', 'If AllowOnShelfHolds is Off, a borrower can still place a title level hold on any items currently checked out. Turning this preference on will prevent adding holds for any items on a record where at least one item is available at any library.', 'YesNo' )");
+ print "Upgrade to $DBversion done ( Added DisallowItemLevelOnShelfHolds system preference )\n";
+ SetVersion ($DBversion);
+}
+
=item DropAllForeignKeys($table)
Drop all foreign keys of the table $table
--
1.5.6.5
More information about the Koha-patches
mailing list