Bug 11091: revamp search limit options for new subscription bib search form
authorFridolyn SOMERS <fridolyn.somers@biblibre.com>
Mon, 21 Oct 2013 09:54:16 +0000 (11:54 +0200)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 5 Dec 2013 16:14:53 +0000 (16:14 +0000)
When creating a new subscription, you can click on "Search for Bilbio"
to search into catalog.

A popup opens with a text field for search terms and a combo-box to
limit search. This combo-box uses the syspref AdvancedSearchTypes to
know what list of values display.

The bug is that the code acts as if AdvancedSearchTypes has always one
value, but since Bug 7031, this syspref can have several values
(item types, collection codes and locations).

This patch removes the use of AdvancedSearchTypes syspref and defines
search form with 2 limits: item types and collection codes (from
authorised values CCODE).

One or both of this information can be on biblio. [RM note: this isn't a
true statement for the default configuration used by MARC21 libraries.]

Searching by location seems to be useless because this information is always
on item.  If CCODE authorised value does not exist or is empty, the collection
code filter is not displayed.

Test plan :
- Check CCODE authorised value exists with some values
- Choose a biblio indexed with both itemtype and ccode indexes
- Go to Serials module and click on "New subscription"
- In form, click on "Search for Biblio"
=> The popup "serials/subscription-bib-search.pl" appears with two limits
- Enter a word of biblio title, select its item type and select its collection code
- Click on "Search"
=> You get the biblio

Signed-off-by: David Noe <drnoe@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
While I am not sure how useful the collection code is for most libraries, where this
is an item level value, this fixes a broken feature and works as described.
Passes all tests and QA script.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-bib-search.tt
serials/subscription-bib-search.pl

index f78d5e0..6c710e8 100644 (file)
 <form name="f" action="/cgi-bin/koha/serials/subscription-bib-search.pl" method="get">
     <input type="hidden" name="op" value="do_search" />
     <input type="hidden" name="type" value="intranet" />
-       <fieldset class="rows">
-       <ol>
-    <li><label for="q">Keyword: </label>
-    <input type="text" id="q"  name="q" /></li>
-    
-    <!-- ITEMTYPE LIMITS -->
-        <li><label for="itemtypelimit">Limit type to: </label>
-        <select name="itemtypelimit" id="itemtypelimit">
-           <option value="">All</option>
-        [% FOREACH itemtypeloo IN itemtypeloop %]
-            <option value="[% itemtypeloo.code %]">
-                [% itemtypeloo.description |html %]
-            </option>
-        [% END %]
-        </select>
+    <fieldset class="brief">
+    <ol>
+        <li>
+            <label for="q">Keyword: </label>
+            <input type="text" id="q"  name="q" />
         </li>
-    <!-- /ITEMTYPE LIMITS -->
-       </ol>
-</fieldset>
-<fieldset class="action"><input type="submit" value="Search" /></fieldset>
-
-
+        <li>
+            <label for="itemtypelimit">Limit item type to: </label>
+            <select name="itemtypelimit" id="itemtypelimit">
+                <option value="">All</option>
+                [%- FOREACH itemtypeloo IN itemtypeloop %]
+                <option value="[% itemtypeloo.code %]">
+                    [% itemtypeloo.description |html %]
+                </option>
+                [%- END %]
+            </select>
+        </li>
+        [%- IF ccodeloop %]
+        <li>
+            <label for="ccodelimit">Limit collection code to: </label>
+            <select name="ccodelimit" id="ccodelimit">
+                <option value="">All</option>
+                [%- FOREACH ccodeloo IN ccodeloop %]
+                <option value="[% ccodeloo.code %]">
+                    [% ccodeloo.description |html %]
+                </option>
+                [%- END %]
+            </select>
+        </li>
+        [%- END %]
+    </ol>
+    </fieldset>
+    <fieldset class="action">
+        <input type="submit" value="Search" />
+    </fieldset>
 </form>
 
 </div>
index 95e4aa7..c512ac4 100755 (executable)
@@ -70,7 +70,6 @@ $startfrom=0 unless $startfrom;
 my ($template, $loggedinuser, $cookie);
 my $resultsperpage;
 
-my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes");
 my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype';
 
 my $query = $input->param('q');
@@ -87,23 +86,12 @@ if ($op eq "do_search" && $query) {
         }
     );
 
-    # add the itemtype limit if applicable
+    # add the limits if applicable
     my $itemtypelimit = $input->param('itemtypelimit');
-    if ( $itemtypelimit ) {
-        my $QParser;
-        $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
-        my $op;
-        if ($QParser) {
-            $op = '&&';
-        } else {
-            $op = 'and';
-        }
-        if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
-            $query .= " $op $itype_or_itemtype:$itemtypelimit";
-        } else {
-            $query .= " $op $advanced_search_types:$itemtypelimit";
-        }
-    }
+    my $ccodelimit = $input->param('ccodelimit');
+    my $op = C4::Context->preference('UseQueryParser') ? '&&' : 'and';
+    $query .= " $op $itype_or_itemtype:$itemtypelimit" if $itemtypelimit;
+    $query .= " $op ccode:$ccodelimit" if $ccodelimit;
     $debug && warn $query;
     $resultsperpage= $input->param('resultsperpage');
     $resultsperpage = 20 if(!defined $resultsperpage);
@@ -200,50 +188,34 @@ else {
                 flagsrequired => {catalogue => 1, serials => '*'},
                 debug => 1,
                 });
+
     # load the itemtypes
-    my $itemtypes = GetItemTypes;
+    my $itemtypes = GetItemTypes();
     my @itemtypesloop;
-    if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
-       # load the itemtypes
-       my $itemtypes = GetItemTypes;
-       my $selected=1;
-       my $cnt;
        foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
            my %row =(
                        code => $thisitemtype,
-                       selected => $selected,
                        description => $itemtypes->{$thisitemtype}->{'description'},
                    );
-           $selected = 0 if ($selected) ;
            push @itemtypesloop, \%row;
        }
 
-
-    } else {
-       my $advsearchtypes = GetAuthorisedValues($advanced_search_types);
-       my $cnt;
-       my $selected=1;
-       for my $thisitemtype (sort {$a->{'lib'} cmp $b->{'lib'}} @$advsearchtypes) {
+    # load Collection Codes
+       my $authvalues = GetAuthorisedValues('CCODE');
+       my @ccodesloop;
+       for my $thisauthvalue (sort {$a->{'lib'} cmp $b->{'lib'}} @$authvalues) {
            my %row =(
-                   number=>$cnt++,
-                   ccl => $advanced_search_types,
-                   code => $thisitemtype->{authorised_value},
-                   selected => $selected,
-                   description => $thisitemtype->{'lib'},
-                   count5 => $cnt % 4,
-                   imageurl=> getitemtypeimagelocation( 'intranet', $thisitemtype->{'imageurl'} ),
+                   code => $thisauthvalue->{'authorised_value'},
+                   description => $thisauthvalue->{'lib'},
                );
-           push @itemtypesloop, \%row;
+           push @ccodesloop, \%row;
        }
-    }
-
 
-    if ($op eq "do_search") {
-       $template->param("no_query" => 1);
-    } else {
-       $template->param("no_query" => 0);
-    }
-    $template->param(itemtypeloop => \@itemtypesloop);
+    $template->param(
+        itemtypeloop => \@itemtypesloop,
+        ccodeloop    => \@ccodesloop,
+        no_query     => $op eq "do_search" ? 1 : 0,
+    );
 }
 # Print the page
 output_html_with_http_headers $input, $cookie, $template->output;