@@ -, +, @@ C4/Koha.pm GetItemTypesCategorized admin/itemtypes.pl koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt koha-tmpl/opac-tmpl/prog/en/modules/opac-advsearch.tt opac/opac-search.pl installer/data/mysql/kohastructure.sql Added two columns, hideinopac and searchcategory installer/data/mysql/updatedatabase.pl 0) run updatedatabase.pl to add the two columns to itemtypes 1) In Intranet/Koha Admin/Authorized values, select DOCTYPECAT in the category dropdown 2) Click button "New authorized value for DOCTYPECAT" 3) Enter HARDWARE as Atuhorize value, ANything as Description and Hardware as OPAC description then click SAVE. 4) In Intranet/Koha Amind/Item types, select (at least) two different items and proceed with the following steps a) Click action/Edit on the right column b) Third row is the search category list box, select Hardware c) click Save changes at the bottom 5) In Intranet/Koha Admin/Item types (again), select a different item type and click the checkbox "Hide in OPAC" 6) Go to OPAC/Adv search. 7) Validate that all items modified above do not appear in Item type list 8) Validate that new item type Hardware does appear instead. 9) Select item Hardware, start Search. 10) Validate returned items are the of the two types that were grouped into the Hardware category in step 4. --- C4/Koha.pm | 40 ++++++++++++++++- admin/itemtypes.pl | 14 +++++- installer/data/mysql/kohastructure.sql | 25 ++++++----- installer/data/mysql/updatedatabase.pl | 9 ++++ .../prog/en/modules/admin/itemtypes.tt | 46 ++++++++++++++++++++ .../opac-tmpl/prog/en/modules/opac-advsearch.tt | 20 ++++++--- opac/opac-search.pl | 26 +++++++++-- 7 files changed, 155 insertions(+), 25 deletions(-) --- a/C4/Koha.pm +++ a/C4/Koha.pm @@ -40,7 +40,7 @@ BEGIN { &slashifyDate &subfield_is_koha_internal_p &GetPrinters &GetPrinter - &GetItemTypes &getitemtypeinfo + &GetItemTypes &GetItemTypesCategorized &GetItemTypesByCategory &getitemtypeinfo &GetSupportName &GetSupportList &get_itemtypeinfos_of &getframeworks &getframeworkinfo @@ -269,6 +269,44 @@ sub GetItemTypes { } } +# Returns item types but grouped by category if available. +# The categories must be part of Authorized Values (DOCTYPECAT) +sub GetItemTypesCategorized { + my $dbh = C4::Context->dbh; + my $query = qq| + SELECT itemtype, description, imageurl, hideinopac, 0 as 'iscat' FROM itemtypes WHERE ISNULL(searchcategory) + 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 > '' + |; + my $sth = $dbh->prepare($query); + $sth->execute; + + my %itemtypes; + while ( my $IT = $sth->fetchrow_hashref ) { + $itemtypes{ $IT->{'itemtype'} } = $IT; + } + + return ( \%itemtypes ); +} + +# Returns the itemtypes that are grouped into the category. +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/itemtypes.pl +++ a/admin/itemtypes.pl @@ -109,6 +109,8 @@ if ( $op eq 'add_form' ) { $remote_image = $data->{imageurl}; } + my $searchcategory = GetAuthorisedValues("DOCTYPECAT", $data->{'searchcategory'}); + $template->param( itemtype => $itemtype, description => $data->{'description'}, @@ -121,6 +123,8 @@ if ( $op eq 'add_form' ) { checkinmsgtype => $data->{'checkinmsgtype'}, imagesets => $imagesets, remote_image => $remote_image, + hideinopac => $data->{'hideinopac'}, + searchcategory => $searchcategory, ); # END $OP eq ADD_FORM @@ -145,6 +149,8 @@ elsif ( $op eq 'add_validate' ) { , summary = ? , checkinmsg = ? , checkinmsgtype = ? + , hideinopac = ? + , searchcategory = ? WHERE itemtype = ? '; $sth = $dbh->prepare($query2); @@ -162,15 +168,17 @@ elsif ( $op eq 'add_validate' ) { $input->param('summary'), $input->param('checkinmsg'), $input->param('checkinmsgtype'), + ( $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) + (itemtype,description,rentalcharge, notforloan, imageurl, summary, checkinmsg, checkinmsgtype, hideinopac,searchcategory) VALUES - (?,?,?,?,?,?,?,?); + (?,?,?,?,?,?,?,?,?,?); "; my $sth = $dbh->prepare($query); my $image = $input->param('image'); @@ -185,6 +193,8 @@ elsif ( $op eq 'add_validate' ) { $input->param('summary'), $input->param('checkinmsg'), $input->param('checkinmsgtype'), + $input->param('hideinopac') ? 1 : 0, + $input->param('searchcategory'), ); } --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -2,7 +2,7 @@ -- -- Host: localhost Database: koha30test -- ------------------------------------------------------ --- Server version 4.1.22 +++ Server version @@ -1214,6 +1214,8 @@ CREATE TABLE `itemtypes` ( -- defines the item types summary text, -- information from the summary field, may include HTML 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" + hideinopac tinyint(1) NOT NULL DEFAULT 0, -- Hide the item type from the search options in OPAC + searchcategory varchar(15) 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; @@ -2109,10 +2111,10 @@ CREATE TABLE `suggestions` ( -- purchase suggestions branchcode VARCHAR(10) default NULL, -- foreign key linking the suggested branch to the branches table collectiontitle text default NULL, -- collection name for the suggested item itemtype VARCHAR(30) default NULL, -- suggested item type - quantity SMALLINT(6) default NULL, -- suggested quantity to be purchased - currency VARCHAR(3) default NULL, -- suggested currency for the suggested price - price DECIMAL(28,6) default NULL, -- suggested price - total DECIMAL(28,6) default NULL, -- suggested total cost (price*quantity updated for currency) + quantity SMALLINT(6) default NULL, -- suggested quantity to be purchased + currency VARCHAR(3) default NULL, -- suggested currency for the suggested price + price DECIMAL(28,6) default NULL, -- suggested price + total DECIMAL(28,6) default NULL, -- suggested total cost (price*quantity updated for currency) PRIMARY KEY (`suggestionid`), KEY `suggestedby` (`suggestedby`), KEY `managedby` (`managedby`) @@ -2410,12 +2412,12 @@ CREATE TABLE `permissions` ( DROP TABLE IF EXISTS `serialitems`; CREATE TABLE `serialitems` ( - `itemnumber` int(11) NOT NULL, - `serialid` int(11) NOT NULL, - UNIQUE KEY `serialitemsidx` (`itemnumber`), - KEY `serialitems_sfk_1` (`serialid`), - CONSTRAINT `serialitems_sfk_1` FOREIGN KEY (`serialid`) REFERENCES `serial` (`serialid`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `serialitems_sfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE + `itemnumber` int(11) NOT NULL, + `serialid` int(11) NOT NULL, + UNIQUE KEY `serialitemsidx` (`itemnumber`), + KEY `serialitems_sfk_1` (`serialid`), + CONSTRAINT `serialitems_sfk_1` FOREIGN KEY (`serialid`) REFERENCES `serial` (`serialid`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `serialitems_sfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- @@ -3284,4 +3286,3 @@ ALTER TABLE `patron_list_patrons` /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -7306,6 +7306,15 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.13.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do(q{ + ALTER TABLE itemtypes + ADD hideinopac TINYINT(1) NOT NULL DEFAULT 0, + ADD searchcategory VARCHAR(15) DEFAULT NULL; + }); +} + =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 @@ -159,6 +159,38 @@ Item types administration [% ELSE %] [% END %] + +
  • + [% IF ( itemtype ) %] + Search category + +
  • + [% ELSE %] + Search category + + + [% END %] + [% IF ( noItemTypeImages ) %]
  • Image: Item type images are disabled. To enable them, turn off the noItemTypeImages system preference
  • [% ELSE %] @@ -214,6 +246,16 @@ Item types administration
    1. + + [% IF ( hideinopac ) %] + + [% ELSE %] + + [% END %] + (if checked, items of this type will be hidden as filters in OPAC's Advanded Search) +
    2. +
    3. + [% IF ( notforloan ) %] [% ELSE %] @@ -297,7 +339,9 @@ Item types administration [% UNLESS ( noItemTypeImages ) %]Image[% END %] Code Description + Search category Not for loan + Hide in OPAC Charge Checkin message Actions @@ -315,7 +359,9 @@ Item types administration [% loo.description %] + [% loo.searchcategory %] [% IF ( loo.notforloan ) %]Yes[% ELSE %] [% END %] + [% IF ( loo.hideinopac ) %]Yes[% ELSE %] [% END %] [% UNLESS ( loo.notforloan ) %] [% loo.rentalcharge %] --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-advsearch.tt +++ a/koha-tmpl/opac-tmpl/prog/en/modules/opac-advsearch.tt @@ -186,12 +186,20 @@
      Limit to any of the following: - - [% FOREACH itemtypeloo IN advsearchloo.code_loop %] - - [% IF ( loop.last ) %][% ELSE %][% UNLESS ( loop.count % 5 ) %][% END %][% END %] - [% END %] + [% count = 0 %] + [% FOREACH itemtype IN advsearchloo.code_loop %] + [% IF ((!itemtype.searchcategory) AND (itemtype.cat == 0)) OR (itemtype.cat == 1) %] + [% count = (count + 1) %] + + [% END %] + [% IF ( loop.last ) %] + [% ELSE %][% UNLESS ( count % 5 ) %][% END %] + [% END %] + [% END %]
      + + +
      --- a/opac/opac-search.pl +++ a/opac/opac-search.pl @@ -95,17 +95,17 @@ my $lang = C4::Templates::getlanguage($cgi, 'opac'); my $template_name; my $template_type = 'basic'; my @params = $cgi->param("limit"); - +my @searchCategories = $cgi->param('searchcat'); my $format = $cgi->param("format") || ''; my $build_grouped_results = C4::Context->preference('OPACGroupResults'); if ($format =~ /(rss|atom|opensearchdescription)/) { $template_name = 'opac-opensearch.tmpl'; } -elsif (@params && $build_grouped_results) { +elsif ((@params || @searchCategories) && $build_grouped_results) { $template_name = 'opac-results-grouped.tmpl'; } -elsif ((@params>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) ) { +elsif (((@params>=1) || (@searchCategories>=1)) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) ) { $template_name = 'opac-results.tmpl'; } else { @@ -202,7 +202,7 @@ my $languages_limit_loop = getAllLanguages($lang); $template->param(search_languages_loop => $languages_limit_loop,); # load the Type stuff -my $itemtypes = GetItemTypes; +my $itemtypes = GetItemTypesCategorized; # the index parameter is different for item-level itemtypes my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype'; my @advancedsearchesloop; @@ -220,8 +220,13 @@ foreach my $advanced_srch_type (@advanced_search_types) { code => $thisitemtype, description => $itemtypes->{$thisitemtype}->{'description'}, imageurl=> getitemtypeimagelocation( 'opac', $itemtypes->{$thisitemtype}->{'imageurl'} ), + cat => $itemtypes->{$thisitemtype}->{'iscat'}, + hideinopac => $itemtypes->{$thisitemtype}->{'hideinopac'}, + searchcategory => $itemtypes->{$thisitemtype}->{'searchcategory'}, ); + if ( !$itemtypes->{$thisitemtype}->{'hideinopac'} ) { push @itypesloop, \%row; + } } my %search_code = ( advanced_search_type => $advanced_srch_type, code_loop => \@itypesloop ); @@ -236,6 +241,7 @@ foreach my $advanced_srch_type (@advanced_search_types) { ccl => $advanced_srch_type, code => $thisitemtype->{authorised_value}, description => $thisitemtype->{'lib_opac'} || $thisitemtype->{'lib'}, + searchcategory => $itemtypes->{$thisitemtype}->{'searchcategory'}, imageurl => getitemtypeimagelocation( 'opac', $thisitemtype->{'imageurl'} ), ); push @authvalueloop, \%row; @@ -400,6 +406,18 @@ if ($operands[0] && !$operands[1]) { # limits are use to limit to results to a pre-defined category such as branch or language my @limits = $cgi->param('limit'); + +if (@searchCategories > 0) { + my @tabcat; + foreach my $typecategory (@searchCategories) { + push (@tabcat, GetItemTypesByCategory($typecategory)); + } + + foreach my $itemtypeInCategory (@tabcat) { + push (@limits, "mc-$itype_or_itemtype,phr:".$itemtypeInCategory); + } +} + @limits = map { uri_unescape($_) } @limits; if($params->{'multibranchlimit'}) { --