Bugzilla – Attachment 22007 Details for
Bug 10937
Advanced search: Hide itemtypes from search form & Group itemtypes together into one search option
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10937 - Options to group or hide items in adv. search
Bug-10937---Options-to-group-or-hide-items-in-adv-.patch (text/plain), 19.11 KB, created by
Blou
on 2013-10-15 18:47:49 UTC
(
hide
)
Description:
Bug 10937 - Options to group or hide items in adv. search
Filename:
MIME Type:
Creator:
Blou
Created:
2013-10-15 18:47:49 UTC
Size:
19.11 KB
patch
obsolete
>From fe50094baaad870f47988b52eefeecaa5f6c25c7 Mon Sep 17 00:00:00 2001 >From: Blou <philippe.blouin@inlibro.com> >Date: Tue, 15 Oct 2013 14:45:39 -0400 >Subject: [PATCH] Bug 10937 - Options to group or hide items in adv. search > >This allows to group certain item types in a category, to be displayed (and searched) as such in OPAC's advanced search. For example, you can group Reserve 2h and Reserve 12h into a Reserve category. The 2 and 12h types won't appear anymore. >This also allows to simply prevent an item type from displaying as a search option. > >Modified: > 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 > >Testing: > 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(-) > >diff --git a/C4/Koha.pm b/C4/Koha.pm >index c5b32a6..44f098e 100644 >--- a/C4/Koha.pm >+++ b/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 = @_; > >diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl >index ee70238..be777c6 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 e1e3e96..3d99001 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -2,7 +2,7 @@ > -- > -- Host: localhost Database: koha30test > -- ------------------------------------------------------ >--- Server version 4.1.22 >+-- Server version 4.1.22 > > /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; > /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; >@@ -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 */; >- >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 9f57eff..377a0e7 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/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) >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..43ae559 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,38 @@ Item types administration > [% ELSE %] > <label for="description">Description: </label><input type="text" id="description" name="description" size="48" value="[% description |html %]" /></li> > [% END %] >+ >+ <li> >+ [% IF ( itemtype ) %] >+ <span class="label">Search category</span> >+ <select id="searchcategory" name="searchcategory"> >+ <option value="">None</option> >+ [% FOREACH cat IN searchcategory %] >+ [% IF ( cat.selected ) %] >+ <option value="[% cat.authorised_value %]" selected="selected"> >+ [% cat.lib %] >+ </option> >+ [% ELSE %] >+ <option value="[% cat.authorised_value %]" > >+ [% cat.lib %] >+ </option> >+ [% END %] >+ [% END %] >+ </select> >+ </li> >+ [% ELSE %] >+ <span class="label">Search category</span> >+ <select id="searchcategory" name="searchcategory"> >+ <option value="" /> >+ [% FOREACH cat IN categorysearch %] >+ <option value="[% cat.authorised_value %]" > >+ [% cat.lib %] >+ </option> >+ [% END %] >+ </select> >+ </li> >+ [% END %] >+ > [% IF ( noItemTypeImages ) %] > <li><span class="label">Image: </span>Item type images are disabled. To enable them, turn off the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=noItemTypeImages">noItemTypeImages system preference</a></li></ol> > [% ELSE %]</ol> >@@ -214,6 +246,16 @@ Item types administration > </div> > <ol> > <li> >+ <label for="hideinopac">Hide in OPAC: </label> >+ [% IF ( hideinopac ) %] >+ <input type="checkbox" id="hideinopac" name="hideinopac" checked="checked" value="1" /> >+ [% ELSE %] >+ <input type="checkbox" id="hideinopac" name="hideinopac" value="1" /> >+ [% END %] >+ (if checked, items of this type will be hidden as filters in OPAC's Advanded Search) >+ </li> >+ <li> >+ > <label for="notforloan">Not for loan: </label> [% IF ( notforloan ) %] > <input type="checkbox" id="notforloan" name="notforloan" checked="checked" value="1" /> > [% ELSE %] >@@ -297,7 +339,9 @@ Item types administration > [% UNLESS ( noItemTypeImages ) %]<th>Image</th>[% END %] > <th>Code</th> > <th>Description</th> >+ <th>Search category</th> > <th>Not for loan</th> >+ <th>Hide in OPAC</th> > <th>Charge</th> > <th>Checkin message</th> > <th>Actions</th> >@@ -315,7 +359,9 @@ Item types administration > </a> > </td> > <td>[% loo.description %]</td> >+ <td>[% loo.searchcategory %]</td> > <td>[% IF ( loo.notforloan ) %]Yes[% ELSE %] [% END %]</td> >+ <td>[% IF ( loo.hideinopac ) %]Yes[% ELSE %] [% END %]</td> > <td> > [% UNLESS ( loo.notforloan ) %] > [% loo.rentalcharge %] >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..7f74c2b 100644 >--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-advsearch.tt >+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-advsearch.tt >@@ -186,12 +186,20 @@ > <fieldset> > <legend>Limit to any of the following:</legend> > <table> >- <tr> >- [% FOREACH itemtypeloo IN advsearchloo.code_loop %] >- <td><input type="checkbox" id="[% itemtypeloo.ccl FILTER remove(',') %]-[% itemtypeloo.number %]" name="limit" value="mc-[% itemtypeloo.ccl %]:[% itemtypeloo.code %]"/><label for="[% itemtypeloo.ccl FILTER remove(',') %]-[% itemtypeloo.number %]">[% UNLESS ( noItemTypeImages ) %][% IF ( itemtypeloo.imageurl ) %]<img border="0" src="[% itemtypeloo.imageurl %]" alt="[% itemtypeloo.description %]" />[% END %] [% END %] >- [% itemtypeloo.description %]</label></td> >- [% IF ( loop.last ) %]</tr>[% ELSE %][% UNLESS ( loop.count % 5 ) %]</tr><tr>[% END %][% END %] >- [% END %] >+ <tr>[% count = 0 %] >+ [% FOREACH itemtype IN advsearchloo.code_loop %] >+ [% IF ((!itemtype.searchcategory) AND (itemtype.cat == 0)) OR (itemtype.cat == 1) %] >+ [% count = (count + 1) %] >+ <td> >+ <input type="checkbox" id="[% itemtype.ccl FILTER remove(',') %]-[% itemtype.number %]" name="[% IF ( itemtype.cat == 1 ) %]searchcat[% ELSE %]limit[% END %]" value="[% IF ( itemtype.cat == 1 ) %][% itemtype.code %][% ELSE %]mc-[% itemtype.ccl %]:[% itemtype.code %][% END %]"/> >+ <label for="[% itemtype.ccl FILTER remove(',') %]-[% itemtype.number %]">[% UNLESS ( noItemTypeImages ) %][% IF ( itemtype.imageurl ) %]<img border="0" src="[% itemtype.imageurl %]" alt="[% itemtype.description %]" />[% END %] [% END %] >+ [% itemtype.description %]</label> >+ </td> >+ [% END %] >+ [% IF ( loop.last ) %]</tr> >+ [% ELSE %][% UNLESS ( count % 5 ) %]</tr><tr>[% END %] >+ [% END %] >+ [% END %] > </table> > </fieldset> > </div> >diff --git a/opac/opac-search.pl b/opac/opac-search.pl >index 2854da6..c067814 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'}, > ); >+ 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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 10937
:
22007
|
22276
|
24596
|
24597
|
24778
|
24779
|
24782
|
28571
|
28572
|
28573
|
28575
|
28576
|
28579
|
28624
|
28626
|
29383
|
30308
|
31896
|
34419
|
34635
|
34667
|
35452
|
36191
|
36240
|
36856
|
40884
|
42323