From 47956053e679cb7a1ed295b3b26143ff3f96efbb Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 11 Dec 2012 12:08:14 -0500 Subject: [PATCH] Bug 9264 - Make getitems default sort to set by a preference instead of hard coded to homebranch. The sort order in GetItemsInfo has been switched from home branch to holding branch and then back again at different points in time. Some libraries liked it when it was by holding branch, rather than home branch. This patch makes the choice of sorting by home or holding branch a system preference. Test Plan: 1) Apply patch 2) Run updatedatabase.pl 3) Test the sorting order for items with the preference set each way. --- C4/Items.pm | 3 ++- installer/data/mysql/sysprefs.sql | 2 ++ installer/data/mysql/updatedatabase.pl | 9 +++++++++ .../en/modules/admin/preferences/searching.pref | 8 ++++++++ 4 files changed, 21 insertions(+), 1 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index aa5a954..e5e027d 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1203,6 +1203,7 @@ sub GetItemsInfo { my ( $biblionumber ) = @_; my $dbh = C4::Context->dbh; # note biblioitems.* must be avoided to prevent large marc and marcxml fields from killing performance. + my $branch = C4::Context->preference("DefaultItemSortOrder") || 'home'; my $query = " SELECT items.*, biblio.*, @@ -1230,7 +1231,7 @@ sub GetItemsInfo { LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber LEFT JOIN itemtypes ON itemtypes.itemtype = " . (C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype'); - $query .= " WHERE items.biblionumber = ? ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ; + $query .= " WHERE items.biblionumber = ? ORDER BY $branch.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ; my $sth = $dbh->prepare($query); $sth->execute($biblionumber); my $i = 0; diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 0cc5a54..3b75920 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -388,3 +388,5 @@ INSERT INTO systempreferences (variable, value, options, explanation, type) VALU INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('HoldsToPullStartDate','2','Set the default start date for the Holds to pull list to this many days ago',NULL,'Integer'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('alphabet','A B C D E F G H I J K L M N O P Q R S T U V W X Y Z','Alphabet than can be expanded into browse links, e.g. on Home > Patrons',NULL,'free'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('RefundLostItemFeeOnReturn', '1', 'If enabled, the lost item fee charged to a borrower will be refunded when the lost item is returned.', NULL, 'YesNo'); +INSERT INTO systempreferences ( variable, value, options, explanation, type ) VALUES ( 'DefaultItemSortOrder', 'home', 'home|holding', 'Define the default sort order for items.', 'Choice' ); + \ No newline at end of file diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 676bb3e..c5667c9 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6134,6 +6134,15 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "3.11.00.XXX"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do(q{ + INSERT INTO systempreferences ( variable, value, options, explanation, type ) VALUES ( 'DefaultItemSortOrder', 'home', 'home|holding', 'Define the default sort order for items.', 'Choice' ); + }); + print "Upgrade to $DBversion done (Bug 9167: Update the virtualshelves.sortfield column with 'copyrightdate' if needed)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref index 7b99173..b4bf390 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref @@ -160,3 +160,11 @@ Searching: - pref: FacetLabelTruncationLength class: integer - characters, in OPAC/staff interface. + - + - The default sort order for items should be by the item's + - pref: DefaultItemSortOrder + type: choice + default: home + choices: + home: home library + holding: "holding library" -- 1.7.2.5