From 0636596d6bd43913f948b705ba02b95cab1468c0 Mon Sep 17 00:00:00 2001 From: Blou Date: Tue, 21 Jan 2014 08:50:28 -0500 Subject: [PATCH] Conflicts: installer/data/mysql/updatedatabase.pl http://bugs.koha-community.org/show_bug.cgi?id=10937 --- C4/Koha.pm | 51 +++++++++++++++++++- admin/authorised_values.pl | 2 +- admin/itemtypes.pl | 14 +++++- installer/data/mysql/kohastructure.sql | 2 + installer/data/mysql/updatedatabase.pl | 8 +++ .../prog/en/modules/admin/itemtypes.tt | 46 ++++++++++++++++++ .../bootstrap/en/modules/opac-advsearch.tt | 3 +- .../opac-tmpl/prog/en/modules/opac-advsearch.tt | 6 ++- opac/opac-search.pl | 28 +++++++++-- 9 files changed, 148 insertions(+), 12 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index 4202957..603ff0d 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -41,7 +41,7 @@ BEGIN { &slashifyDate &subfield_is_koha_internal_p &GetPrinters &GetPrinter - &GetItemTypes &getitemtypeinfo + &GetItemTypes &GetItemTypesCategorized &GetItemTypesByCategory &getitemtypeinfo &GetSupportName &GetSupportList &get_itemtypeinfos_of &getframeworks &getframeworkinfo @@ -270,6 +270,55 @@ sub GetItemTypes { } } +=head2 GetItemTypes + +Returns item types but grouped by category if available. +The categories must be part of Authorized Values (DOCTYPECAT) + +=cut + +sub GetItemTypesCategorized { + my $dbh = C4::Context->dbh; + 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 > '' + |; + my $sth = $dbh->prepare($query); + $sth->execute; + + my %itemtypes; + while ( my $IT = $sth->fetchrow_hashref ) { + $itemtypes{ $IT->{'itemtype'} } = $IT; + } + + return ( \%itemtypes ); +} + +=head2 GetItemTypesByCategory + + $category = category filter + +Returns the itemtypes that are grouped into the category. + +=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 = @_; diff --git a/admin/authorised_values.pl b/admin/authorised_values.pl index 332f09a..47847f9 100755 --- a/admin/authorised_values.pl +++ b/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{$_}; } diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl index 3c33073..c902c0f 100755 --- a/admin/itemtypes.pl +++ b/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'), ); } diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 136104f..a894f16 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1241,6 +1241,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; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 1311068..07fe083 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7930,6 +7930,14 @@ if(CheckVersion($DBversion)) { SetVersion($DBversion); } +$DBversion = "3.15.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 diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt index 57847eb..bfc8ea4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt @@ -159,6 +159,39 @@ Item types administration [% ELSE %] [% END %] + +
  • + [% IF ( itemtype ) %] + Search category + + (Options are defined as the authorized values for the DOCTYPECAT 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 +247,15 @@ Item types administration
    1. + + [% IF ( hideinopac ) %] + + [% ELSE %] + + [% END %] + (if checked, items of this type will be hidden as filters in OPAC's advanced 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 %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt index c55eccc..cc47324 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt @@ -142,9 +142,10 @@ Limit to any of the following:
      [% FOREACH itemtypeloo IN advsearchloo.code_loop %] -
      [% ELSE %][% UNLESS ( loop.count % 4 ) %]
      [% END %][% END %] + [% END %] [% END %]
      diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-advsearch.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-advsearch.tt index 4c1c552..922edfe 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-advsearch.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-advsearch.tt @@ -188,8 +188,10 @@ [% FOREACH itemtypeloo IN advsearchloo.code_loop %] - + [% IF ((!itemtypeloo.searchcategory) AND (itemtypeloo.cat == 0)) OR (itemtypeloo.cat == 1) %] + + [% END %] [% IF ( loop.last ) %][% ELSE %][% UNLESS ( loop.count % 5 ) %][% END %][% END %] [% END %]
      diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 617d67e..f855881 100755 --- a/opac/opac-search.pl +++ b/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'}, ); - push @itypesloop, \%row; + 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'}) { -- 1.7.10.4