@@ -, +, @@ on latest master. --- C4/Koha.pm | 66 ++++++++++++++++++++ admin/authorised_values.pl | 2 +- admin/itemtypes.pl | 14 ++++- installer/data/mysql/kohastructure.sql | 2 + installer/data/mysql/updatedatabase.pl | 13 ++++ .../prog/en/modules/admin/itemtypes.tt | 32 ++++++++++ .../bootstrap/en/modules/opac-advsearch.tt | 20 +++++- .../opac-tmpl/prog/en/modules/opac-advsearch.tt | 20 +++++- opac/opac-search.pl | 24 ++++++- t/db_dependent/Koha.t | 47 +++++++++++++- 10 files changed, 228 insertions(+), 12 deletions(-) --- a/C4/Koha.pm +++ a/C4/Koha.pm @@ -43,6 +43,7 @@ BEGIN { &subfield_is_koha_internal_p &GetPrinters &GetPrinter &GetItemTypes &getitemtypeinfo + &GetItemTypesCategorized &GetItemTypesByCategory &GetSupportName &GetSupportList &get_itemtypeinfos_of &getframeworks &getframeworkinfo @@ -275,6 +276,71 @@ sub GetItemTypes { } } +=head2 GetItemTypesCategorized + + $categories = GetItemTypesCategorized(); + +Returns a hashref containing search categories. +A search category will be put in the hash if at least one of its itemtypes is visible in OPAC. +The categories must be part of Authorized Values (DOCTYPECAT) + +=cut + +sub GetItemTypesCategorized { + my $dbh = C4::Context->dbh; + # Order is important, so that partially hidden (some items are not visible in OPAC) search + # categories will be visible. hideinopac=0 must be last. + my $query = qq| + SELECT itemtype, description, imageurl, hideinopac, 0 as 'iscat' FROM itemtypes WHERE ISNULL(searchcategory) or length(searchcategory) = 0 + UNION + SELECT DISTINCT searchcategory AS `itemtype`, + authorised_values.lib_opac AS description, + authorised_values.imageurl AS imageurl, + hideinopac, 1 as 'iscat' + FROM itemtypes + LEFT JOIN authorised_values ON searchcategory = authorised_value + WHERE searchcategory > '' and hideinopac=1 + UNION + SELECT DISTINCT searchcategory AS `itemtype`, + authorised_values.lib_opac AS description, + authorised_values.imageurl AS imageurl, + hideinopac, 1 as 'iscat' + FROM itemtypes + LEFT JOIN authorised_values ON searchcategory = authorised_value + WHERE searchcategory > '' and hideinopac=0 + |; + my $sth = $dbh->prepare($query); + $sth->execute; + + my %itemtypes; + while ( my $IT = $sth->fetchrow_hashref ) { + $itemtypes{ $IT->{'itemtype'} } = $IT; + } + return ( \%itemtypes ); +} + +=head2 GetItemTypesByCategory + + @results = GetItemTypesByCategory( $searchcategory ); + +Returns the itemtype code of all itemtypes included in a searchcategory. + +=cut + +sub GetItemTypesByCategory { + my ($category) = @_; + my $count = 0; + my @results; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("SELECT itemtype FROM itemtypes WHERE searchcategory=?"); + $sth->execute($category); + + while ( my $data = $sth->fetchrow ) { + push ( @results, $data ); + } + return @results; +} + sub get_itemtypeinfos_of { my @itemtypes = @_; --- a/admin/authorised_values.pl +++ a/admin/authorised_values.pl @@ -247,7 +247,7 @@ sub default_form { } # push koha system categories - foreach (qw(Asort1 Asort2 Bsort1 Bsort2 SUGGEST DAMAGED LOST REPORT_GROUP REPORT_SUBGROUP DEPARTMENT TERM SUGGEST_STATUS)) { + foreach (qw(Asort1 Asort2 Bsort1 Bsort2 SUGGEST DAMAGED LOST REPORT_GROUP REPORT_SUBGROUP DEPARTMENT TERM SUGGEST_STATUS DOCTYPECAT)) { push @category_list, $_ unless $categories{$_}; } --- a/admin/itemtypes.pl +++ a/admin/itemtypes.pl @@ -112,6 +112,8 @@ if ( $op eq 'add_form' ) { $remote_image = $data->{imageurl}; } + my $searchcategory = GetAuthorisedValues("DOCTYPECAT", $data->{'searchcategory'}); + $template->param( itemtype => $itemtype, description => $data->{'description'}, @@ -125,6 +127,8 @@ if ( $op eq 'add_form' ) { imagesets => $imagesets, remote_image => $remote_image, sip_media_type => $data->{sip_media_type}, + hideinopac => $data->{'hideinopac'}, + searchcategory => $searchcategory, ); # END $OP eq ADD_FORM @@ -150,6 +154,8 @@ elsif ( $op eq 'add_validate' ) { , checkinmsg = ? , checkinmsgtype = ? , sip_media_type = ? + , hideinopac = ? + , searchcategory = ? WHERE itemtype = ? '; $sth = $dbh->prepare($query2); @@ -168,15 +174,17 @@ elsif ( $op eq 'add_validate' ) { $input->param('checkinmsg'), $input->param('checkinmsgtype'), $sip_media_type, + $input->param('hideinopac') ? 1 : 0, + $input->param('searchcategory'), $input->param('itemtype') ); } else { # add a new itemtype & not modif an old my $query = " INSERT INTO itemtypes - (itemtype,description,rentalcharge, notforloan, imageurl, summary, checkinmsg, checkinmsgtype, sip_media_type) + (itemtype,description,rentalcharge, notforloan, imageurl, summary, checkinmsg, checkinmsgtype, sip_media_type, hideinopac, searchcategory) VALUES - (?,?,?,?,?,?,?,?,?); + (?,?,?,?,?,?,?,?,?,?,?); "; my $sth = $dbh->prepare($query); my $image = $input->param('image'); @@ -192,6 +200,8 @@ elsif ( $op eq 'add_validate' ) { $input->param('checkinmsg'), $input->param('checkinmsgtype'), $sip_media_type, + $input->param('hideinopac') ? 1 : 0, + $input->param('searchcategory'), ); } --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -1247,6 +1247,8 @@ CREATE TABLE `itemtypes` ( -- defines the item types checkinmsg VARCHAR(255), -- message that is displayed when an item with the given item type is checked in checkinmsgtype CHAR(16) DEFAULT 'message' NOT NULL, -- type (CSS class) for the checkinmsg, can be "alert" or "message" sip_media_type VARCHAR(3) DEFAULT NULL, -- SIP2 protocol media type for this itemtype + hideinopac tinyint(1) NOT NULL DEFAULT 0, -- Hide the item type from the search options in OPAC + searchcategory varchar(20) default NULL, -- Group this item type with others with the same value on OPAC search options PRIMARY KEY (`itemtype`), UNIQUE KEY `itemtype` (`itemtype`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -8589,6 +8589,19 @@ if ( CheckVersion($DBversion) ) { SetVersion ($DBversion); } +$DBversion = "3.17.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do(q{ + ALTER TABLE itemtypes + ADD hideinopac TINYINT(1) NOT NULL DEFAULT 0 + AFTER sip_media_type, + ADD searchcategory VARCHAR(20) DEFAULT NULL + AFTER hideinopac; + }); + print "Upgrade to $DBversion done (Bug 10937 - Option to hide and group itemtypes from advanced search)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt @@ -109,6 +109,25 @@ Item types administration [% END %]
+ [% IF ((!itemtypeloo.searchcategory) AND (itemtypeloo.cat == 0)) OR (itemtypeloo.cat == 1) %] + | + + + | + [% END %] [% IF ( loop.last ) %]