From 17cd735ee5358a9c10fb4a039a48b4f5686f0bd6 Mon Sep 17 00:00:00 2001 From: Fridolyn SOMERS Date: Fri, 4 Jan 2013 16:46:38 +0100 Subject: [PATCH] Bug 9223: Multiple values of AdvancedSearchTypes in suggestions Content-Type: text/plain; charset="utf-8" Suggestion form uses C4::Koha::GetSupportList to get a list of supports that can come from itemtypes or authoritized values LOC or CCODE. C4::Koha::GetSupportList uses AdvancedSearchTypes syspref like it has only one value. But this syspref can contain several values separated by a pipe. This patch introduces a new syspref SupportsAuthorizedValues to select wich authorized values category that represents the physical support (itemtypes by default, loc or ccode). These authorized values will be used in suggestion management, known as 'document type'. (Note that database field is still 'itemtype'). Test plan : ----------- - Set SupportsAuthorizedValues with itemtypes or loc or ccode - Get to suggestion form (OPAC or intranet) - Look at "Document type" combobox, it must contains descriptions of selected authorized values - Save the suggestion - Get to intranet suggestions management - Organize suggestions by document type => your suggestion must appear in a tab with its document type description http://bugs.koha-community.org/show_bug.cgi?id=6473 --- C4/Koha.pm | 105 +++++++++----------- .../prog/en/modules/suggestion/suggestion.tt | 10 +- .../opac-tmpl/prog/en/modules/opac-suggestions.tt | 6 +- opac/opac-suggestions.pl | 2 +- suggestion/suggestion.pl | 8 +- 5 files changed, 60 insertions(+), 71 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index ea8c2a6..89da573 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -26,6 +26,7 @@ use strict; use C4::Context; use C4::Branch qw(GetBranchesCount); use Koha::DateUtils qw(dt_from_string); +use C4::ItemType; use Memoize; use DateTime::Format::MySQL; use autouse 'Data::Dumper' => qw(Dumper); @@ -126,84 +127,72 @@ sub subfield_is_koha_internal_p { =head2 GetSupportName - $itemtypename = &GetSupportName($codestring); + $lib = &GetSupportName($authorised_value); -Returns a string with the name of the itemtype. +Returns the name of the support corresponding to specified authorised value. =cut -sub GetSupportName{ - my ($codestring)=@_; - return if (! $codestring); - my $resultstring; - my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes"); - if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { - my $query = qq| - SELECT description - FROM itemtypes - WHERE itemtype=? - order by description - |; - my $sth = C4::Context->dbh->prepare($query); - $sth->execute($codestring); - ($resultstring)=$sth->fetchrow; - return $resultstring; - } else { - my $sth = - C4::Context->dbh->prepare( - "SELECT lib FROM authorised_values WHERE category = ? AND authorised_value = ?" - ); - $sth->execute( $advanced_search_types, $codestring ); - my $data = $sth->fetchrow_hashref; - return $$data{'lib'}; - } - +sub GetSupportName { + my $authorised_value = shift; + return '' unless $authorised_value; + my $supports_av = C4::Context->preference("SupportsAuthorizedValues") || 'itemtypes'; + if ( $supports_av eq 'itemtypes' ) { + my $itemtype = getitemtypeinfo($authorised_value); + return $itemtype->{'description'} if $itemtype; + } + else { + my $lib = GetKohaAuthorisedValueLib( $supports_av, $authorised_value ); + return $lib if $lib; + } + return ''; } + =head2 GetSupportList - $itemtypes = &GetSupportList(); + $supports = &GetSupportList(); -Returns an array ref containing informations about Support (since itemtype is rather a circulation code when item-level-itypes is used). +Returns an array ref containing informations about support : authorised_value, lib, imageurl build a HTML select with the following code : =head3 in PERL SCRIPT - my $itemtypes = GetSupportList(); - $template->param(itemtypeloop => $itemtypes); + my $supports = GetSupportList(); + $template->param(supportsloop => $supports); =head3 in TEMPLATE -
- - "> - -
+ =cut -sub GetSupportList{ - my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes"); - if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { - my $query = qq| - SELECT * - FROM itemtypes - order by description - |; - my $sth = C4::Context->dbh->prepare($query); - $sth->execute; - return $sth->fetchall_arrayref({}); - } else { - my $advsearchtypes = GetAuthorisedValues($advanced_search_types); - my @results= map {{itemtype=>$$_{authorised_value},description=>$$_{lib},imageurl=>$$_{imageurl}}} @$advsearchtypes; - return \@results; - } +sub GetSupportList { + my $supports_av = C4::Context->preference("SupportsAuthorizedValues") || 'itemtypes'; + if ( $supports_av eq 'itemtypes' ) { + my @supports = map { + { + authorised_value => $_->{'itemtype'}, + lib => $_->{'description'}, + imageurl => $_->{'imageurl'} + } + } C4::ItemType->all; + return \@supports; + } + else { + return GetAuthorisedValues($supports_av); + } } + =head2 GetItemTypes $itemtypes = &GetItemTypes( style => $style ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt index 0b4a4ab..ec737d3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt @@ -178,8 +178,8 @@ $(document).ready(function() { calcNewsuggTotal(); });
  • Publication place:[% place %]
  • Collection title:[% collectiontitle %]
  • Document type: - [% FOREACH itemtypeloo IN itemtypeloop %] - [% IF ( itemtypeloo.selected ) %][% itemtypeloo.description %][% END %] + [% FOREACH supports_loo IN supports_loop %] + [% IF ( supports_loo.selected ) %][% supports_loo.lib %][% END %] [% END %]
  • [% IF ( patron_reason_loop ) %] @@ -294,9 +294,9 @@ $(document).ready(function() { calcNewsuggTotal(); });
  • diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tt index a17372f..2789573 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tt @@ -112,10 +112,10 @@ $.tablesorter.addParser({
  • -
  • - [% FOREACH itemtypeloo IN itemtypeloop %] - [% IF ( itemtypeloo.selected ) %] + [% FOREACH supports_loo IN supports_loop %] + [% IF ( supports_loo.selected ) %] [% END %]
  • [% IF ( branchloop ) %] diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl index 32b5c3d..106748f 100755 --- a/opac/opac-suggestions.pl +++ b/opac/opac-suggestions.pl @@ -141,7 +141,7 @@ if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) { $template->param( %$suggestion, - itemtypeloop=> $supportlist, + supports_loop => $supportlist, suggestions_loop => $suggestions_loop, patron_reason_loop => $patron_reason_loop, showall => $allsuggestions, diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index fd9a9c2..21ad6c7 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -303,16 +303,16 @@ $template->param( branchloop => \@branchloop, my $supportlist = GetSupportList(); foreach my $support (@$supportlist) { - $$support{'selected'} = (defined $$suggestion_ref{'itemtype'}) - ? $$support{'itemtype'} eq $$suggestion_ref{'itemtype'} - : 0; + if ( defined $$suggestion_ref{'itemtype'} && $support->{'authorised_value'} eq $$suggestion_ref{'itemtype'}) { + $$support{'selected'} = 1; + } if ( $$support{'imageurl'} ) { $$support{'imageurl'} = getitemtypeimagelocation( 'intranet', $$support{'imageurl'} ); } else { delete $$support{'imageurl'}; } } -$template->param(itemtypeloop=>$supportlist); +$template->param( supports_loop => $supportlist); $template->param( returnsuggestedby => $returnsuggestedby ); my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG",$$suggestion_ref{'patronreason'}); -- 1.7.9.5