From c9c2b5b0993fb5300b4bd65cc6962a948ca78a42 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 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 --- C4/Koha.pm | 90 ++++++++++------------ .../prog/en/modules/suggestion/suggestion.tt | 10 +-- .../bootstrap/en/modules/opac-suggestions.tt | 12 +-- opac/opac-suggestions.pl | 2 +- suggestion/suggestion.pl | 8 +- 5 files changed, 55 insertions(+), 67 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index ec65be9..8e0ed6c 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -27,6 +27,7 @@ use C4::Context; use C4::Branch qw(GetBranchesCount); use Koha::Cache; use Koha::DateUtils qw(dt_from_string); +use C4::ItemType; use DateTime::Format::MySQL; use Business::ISBN; use autouse 'Data::Dumper' => qw(Dumper); @@ -129,84 +130,71 @@ 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 =~ /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 aeb8946..81cf6c1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt @@ -216,8 +216,8 @@ h4.local_collapse a { font-size : 80%; text-decoration: none; } fieldset.brief o
  • Publication place:[% place |html %]
  • Collection title:[% collectiontitle |html %]
  • 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 ) %] @@ -340,9 +340,9 @@ h4.local_collapse a { font-size : 80%; text-decoration: none; } fieldset.brief o
  • diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt index 46d0031..8bd6b36 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt @@ -41,16 +41,16 @@
  • -
  • +
  • diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl index 16aadf8..74b4e2f 100755 --- a/opac/opac-suggestions.pl +++ b/opac/opac-suggestions.pl @@ -166,7 +166,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 b54703a..52913c7 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -326,16 +326,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'}); -- 2.1.0