From c04404c2fb2ffe3ae504e8055cd16eaba120d206 Mon Sep 17 00:00:00 2001 From: Ian Walls Date: Wed, 27 Jul 2011 14:08:23 -0400 Subject: [PATCH] Enh 7031: More options for Advanced Search Adds the ability to perform advanced searches in both the OPAC and staff client on more than a single AdvancedSearchType at a time. Support included for Itemtype, Collection Code and Shelving Location. AdvancedSearchTypes syspref preference is repurposed; no longer a single value, it can now take multiple item code fields separated by "|". The order of these fields will determine the order of the tabs in the OPAC and staff client advanced search screens. Values within the search type are OR'ed together, while each different search type is AND'ed together in the query limits. The current stored values are supported without any required modification. Each set of advanced search fields are displayed in tabs in both the OPAC and staff client. The first value in the AdvancedSearchTypes syspref is the selected tab; if no values are present, "itemtypes" is used. For non-itemtype values, the value in AdvancedSearchTypes must match the Authorised Value name, and must be indexed with 'mc-' prefixing that name.
  • elements in tab are assigned unique IDs, so the text of the tab can be altered to match the library's needs (using JQuery) The logic to handle the 5 element row limit has been moved from the Perl to the templates, since Template::Toolkit has a simple method for extracting the count of an element in a loop and performing 'modulus' on it. 2011-12-21: Incorporated changes recommend by Owen Leonard on bug report. Signed-off-by: Owen Leonard --- C4/Search.pm | 17 +++--- catalogue/search.pl | 60 ++++++++++--------- .../prog/en/css/staff-global.css | 16 +++-- .../modules/admin/preferences/searching.pref | 9 ++- .../prog/en/modules/catalogue/advsearch.tt | 50 ++++++++++------ koha-tmpl/opac-tmpl/prog/en/css/opac.css | 9 +-- .../prog/en/modules/opac-advsearch.tt | 29 ++++++++- opac/opac-search.pl | 59 ++++++++++-------- 8 files changed, 151 insertions(+), 98 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 05a860c322..f994e9a90a 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1296,7 +1296,7 @@ sub buildQuery { warn "QUERY BEFORE LIMITS: >$query<" if $DEBUG; # add limits - my $group_OR_limits; + my %group_OR_limits; my $availability_limit; foreach my $this_limit (@limits) { if ( $this_limit =~ /available/ ) { @@ -1313,17 +1313,16 @@ sub buildQuery { # group_OR_limits, prefixed by mc- # OR every member of the group elsif ( $this_limit =~ /mc/ ) { - - if ( $this_limit =~ /mc-ccode:/ ) { + my ($k,$v) = split(/:/, $this_limit,2); + if ( $k !~ /mc-i(tem)?type/ ) { # in case the mc-ccode value has complicating chars like ()'s inside it we wrap in quotes $this_limit =~ tr/"//d; - my ($k,$v) = split(/:/, $this_limit,2); $this_limit = $k.":\"".$v."\""; } - $group_OR_limits .= " or " if $group_OR_limits; - $limit_desc .= " or " if $group_OR_limits; - $group_OR_limits .= "$this_limit"; + $group_OR_limits{$k} .= " or " if $group_OR_limits{$k}; + $limit_desc .= " or " if $group_OR_limits{$k}; + $group_OR_limits{$k} .= "$this_limit"; $limit_cgi .= "&limit=$this_limit"; $limit_desc .= " $this_limit"; } @@ -1346,9 +1345,9 @@ sub buildQuery { } } } - if ($group_OR_limits) { + foreach my $k (keys (%group_OR_limits)) { $limit .= " and " if ( $query || $limit ); - $limit .= "($group_OR_limits)"; + $limit .= "($group_OR_limits{$k})"; } if ($availability_limit) { $limit .= " and " if ( $query || $limit ); diff --git a/catalogue/search.pl b/catalogue/search.pl index 49e63bcb71..20d21f1a7e 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -238,45 +238,51 @@ my $categories = GetBranchCategories(undef,'searchdomain'); $template->param(branchloop => \@branch_loop, searchdomainloop => $categories); -# load the Type stuff # load the Type stuff my $itemtypes = GetItemTypes; # the index parameter is different for item-level itemtypes my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype'; -my @itemtypesloop; -my $selected=1; +my @advancedsearchesloop; my $cnt; -my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes"); - -if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) { - my %row =( number=>$cnt++, - ccl => qq($itype_or_itemtype,phr), +my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes") || "itemtypes"; +my @advanced_search_types = split(/\|/, $advanced_search_types); + +foreach my $advanced_srch_type (@advanced_search_types) { + if ($advanced_srch_type eq 'itemtypes') { + # itemtype is a special case, since it's not defined in authorized values + my @itypesloop; + foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) { + my %row =( number=>$cnt++, + ccl => "$itype_or_itemtype,phr", code => $thisitemtype, - selected => $selected, description => $itemtypes->{$thisitemtype}->{'description'}, - count5 => $cnt % 4, - imageurl=> getitemtypeimagelocation( 'intranet', $itemtypes->{$thisitemtype}->{'imageurl'} ), + imageurl=> getitemtypeimagelocation( 'opac', $itemtypes->{$thisitemtype}->{'imageurl'} ), ); - $selected = 0 if ($selected) ; - push @itemtypesloop, \%row; - } - $template->param(itemtypeloop => \@itemtypesloop); -} else { - my $advsearchtypes = GetAuthorisedValues($advanced_search_types); - for my $thisitemtype (sort {$a->{'lib'} cmp $b->{'lib'}} @$advsearchtypes) { - my %row =( - number=>$cnt++, - ccl => $advanced_search_types, + push @itypesloop, \%row; + } + my %search_code = ( advanced_search_type => $advanced_srch_type, + code_loop => \@itypesloop ); + push @advancedsearchesloop, \%search_code; + } else { + # covers all the other cases: non-itemtype authorized values + my $advsearchtypes = GetAuthorisedValues($advanced_srch_type, '', 'opac'); + my @authvalueloop; + for my $thisitemtype (@$advsearchtypes) { + my %row =( + number=>$cnt++, + ccl => $advanced_srch_type, code => $thisitemtype->{authorised_value}, - selected => $selected, description => $thisitemtype->{'lib'}, - count5 => $cnt % 4, - imageurl=> getitemtypeimagelocation( 'intranet', $thisitemtype->{'imageurl'} ), - ); - push @itemtypesloop, \%row; + imageurl => getitemtypeimagelocation( 'intranet', $thisitemtype->{'imageurl'} ), + ); + push @authvalueloop, \%row; + } + my %search_code = ( advanced_search_type => $advanced_srch_type, + code_loop => \@authvalueloop ); + push @advancedsearchesloop, \%search_code; } - $template->param(itemtypeloop => \@itemtypesloop); } +$template->param(advancedsearchesloop => \@advancedsearchesloop); # The following should only be loaded if we're bringing up the advanced search template if ( $template_type eq 'advsearch' ) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css index fec66d6275..010399b7a8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -2054,32 +2054,36 @@ fieldset.rows+h3 {clear:both;padding-top:.5em;} padding-left:20px } -#advanced-search fieldset { +.adsearch { + margin: 0; +} + +.advsearch fieldset { border : 1px solid #EEE; -moz-border-radius : 3px; border-radius : 3px; } -#advanced-search fieldset.action { +.advsearch fieldset.action { border : 0; } -#advanced-search fieldset fieldset { +.advsearch fieldset fieldset { border : 1px solid #EEE; margin : 0; padding : .3em .5em; -moz-border-radius : 0; border-radius : 0; } -#advanced-search fieldset fieldset+fieldset { +.advsearch fieldset fieldset+fieldset { border-top : 0; } -#advanced-search table { +.advsearch table { border-spacing : 5px; border-collapse : separate; border-width : 0; } -#advanced-search td { +.advsearch td { border : 1px solid #EEE; padding : 0.3em 0.4em; } 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 12075ecaab..f4b02ccf16 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 @@ -71,12 +71,11 @@ Searching: - subdivisions for searches generated by clicking on subject tracings. Search Form: - - - Show checkboxes to search by + - Show tabs in OPAC and staff-side advanced search for limiting searches on the - pref: AdvancedSearchTypes - choices: - itemtypes: itemtype - ccode: collection code - - on the OPAC and staff advanced search pages. + class: long + - "fields (separate values with |). Tabs appear in the order listed.
    " + - "Currently supported values: Item types (itemtypes), Collection Codes (ccode) and Shelving Location (loc)." - - By default, - pref: expandedSearchOption diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt index 7e6b5addcd..acf133d88e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt @@ -15,6 +15,7 @@ } $(document).ready(function() { $("input[name=q]:eq(0)").focus(); + $('#advsearches > ul').tabs(); }); @@ -92,27 +93,40 @@ [New search] - - -
    - Limit to any of the following + + +
    +
    + + [% FOREACH advsearchloo IN advancedsearchesloop %] +
    +
    + Limit to any of the following: - [% FOREACH itemtypeloo IN itemtypeloop %] - - [% UNLESS ( itemtypeloo.count5 ) %][% END %] - [% END %] - - + [% FOREACH itemtypeloo IN advsearchloo.code_loop %] + + [% UNLESS ( loop.count % 5 ) %][% END %] + [% END %] +
    - [% UNLESS ( noItemTypeImages ) %] - [% IF ( itemtypeloo.imageurl ) %][% itemtypeloo.description %][% END %] - [% END %] -   -
    -
    - - +
    + + [% END %] + [% IF ( expanded_options ) %]
    diff --git a/koha-tmpl/opac-tmpl/prog/en/css/opac.css b/koha-tmpl/opac-tmpl/prog/en/css/opac.css index 3e4fb00f5c..88d18b0b46 100644 --- a/koha-tmpl/opac-tmpl/prog/en/css/opac.css +++ b/koha-tmpl/opac-tmpl/prog/en/css/opac.css @@ -672,7 +672,7 @@ input.deleteshelf:active { } /* the itemtype list in advanced search */ -#advsearch-itemtype table { +.advsearch table { border-collapse : separate; border-spacing : 3px; border : 0px; @@ -681,14 +681,14 @@ input.deleteshelf:active { border : 0px solid #D8DEB8; } -#advsearch-itemtype table tr td { +.advsearch table tr td { background-color : #F8F8EB; border : 0px; margin : 0px; width : 700px; } -#advsearch-itemtype td { +.advsearch td { font-size : 0.8em; background-color : #F8F8EB; } @@ -2258,6 +2258,7 @@ a.localimage img { margin : 0 .5em; padding : .3em; } + p.patronimage { border:1px solid #EEE; border-bottom-color:#000; @@ -2268,4 +2269,4 @@ p.patronimage { p.patronimage.edit { border-color:#E8E8E8; margin: 1em 1em 1em 0; -} \ No newline at end of file +} 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 216ce8e1a3..4847ae30ac 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-advsearch.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-advsearch.tt @@ -2,6 +2,12 @@ [% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha Online[% END %] Catalog › Advanced Search [% INCLUDE 'doc-head-close.inc' %] +
    @@ -130,21 +136,38 @@
    +
    + -
    + [% FOREACH advsearchloo IN advancedsearchesloop %] +
    Limit to any of the following: - [% FOREACH itemtypeloo IN itemtypeloop %] + [% FOREACH itemtypeloo IN advsearchloo.code_loop %] - [% UNLESS ( itemtypeloo.count5 ) %][% UNLESS ( loop.last ) %][% END %][% END %] + [% UNLESS ( loop.count % 5 ) %][% END %] [% END %]
    + [% END %] +
    Language diff --git a/opac/opac-search.pl b/opac/opac-search.pl index a70b152edc..eb9ee51de9 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -165,40 +165,47 @@ $template->param(search_languages_loop => $languages_limit_loop,); my $itemtypes = GetItemTypes; # the index parameter is different for item-level itemtypes my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype'; -my @itemtypesloop; -my $selected=1; +my @advancedsearchesloop; my $cnt; -my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes"); - -if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { - foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) { - my %row =( number=>$cnt++, - ccl => "$itype_or_itemtype,phr", +my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes") || "itemtypes"; +my @advanced_search_types = split(/\|/, $advanced_search_types); + +foreach my $advanced_srch_type (@advanced_search_types) { + if ($advanced_srch_type eq 'itemtypes') { + # itemtype is a special case, since it's not defined in authorized values + my @itypesloop; + foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) { + my %row =( number=>$cnt++, + ccl => "$itype_or_itemtype,phr", code => $thisitemtype, - selected => $selected, description => $itemtypes->{$thisitemtype}->{'description'}, - count5 => $cnt % 4, imageurl=> getitemtypeimagelocation( 'opac', $itemtypes->{$thisitemtype}->{'imageurl'} ), ); - $selected = 0; # set to zero after first pass through - push @itemtypesloop, \%row; - } -} else { - my $advsearchtypes = GetAuthorisedValues($advanced_search_types, '', 'opac'); - for my $thisitemtype (@$advsearchtypes) { - my %row =( - number=>$cnt++, - ccl => $advanced_search_types, + push @itypesloop, \%row; + } + my %search_code = ( advanced_search_type => $advanced_srch_type, + code_loop => \@itypesloop ); + push @advancedsearchesloop, \%search_code; + } else { + # covers all the other cases: non-itemtype authorized values + my $advsearchtypes = GetAuthorisedValues($advanced_srch_type, '', 'opac'); + my @authvalueloop; + for my $thisitemtype (@$advsearchtypes) { + my %row =( + number=>$cnt++, + ccl => $advanced_srch_type, code => $thisitemtype->{authorised_value}, - selected => $selected, - description => $thisitemtype->{'lib'}, - count5 => $cnt % 4, - imageurl=> getitemtypeimagelocation( 'opac', $thisitemtype->{'imageurl'} ), - ); - push @itemtypesloop, \%row; + description => $thisitemtype->{'lib_opac'} || $thisitemtype->{'lib'}, + imageurl => getitemtypeimagelocation( 'opac', $thisitemtype->{'imageurl'} ), + ); + push @authvalueloop, \%row; + } + my %search_code = ( advanced_search_type => $advanced_srch_type, + code_loop => \@authvalueloop ); + push @advancedsearchesloop, \%search_code; } } -$template->param(itemtypeloop => \@itemtypesloop); +$template->param(advancedsearchesloop => \@advancedsearchesloop); # # load the itypes (Called item types in the template -- just authorized values for searching) # my ($itypecount,@itype_loop) = GetCcodes(); -- 2.39.5