From 70d1271448b165e9d7a6bf521583db1acccd1a31 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 Signed-off-by: Olli-Antti Kivilahti --- 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 bca12d6..4b4c7e3 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); @@ -130,84 +131,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 b3fedc4..da5b3fd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt @@ -213,8 +213,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 ) %] @@ -337,9 +337,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 09032e4..cb3df83 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt @@ -42,16 +42,16 @@
  • -
  • +
  • diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl index 6b7f8d4..fae1b26 100755 --- a/opac/opac-suggestions.pl +++ b/opac/opac-suggestions.pl @@ -189,7 +189,7 @@ if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) { $template->param( %$suggestion, - itemtypeloop=> $supportlist, + supports_loop => $supportlist, suggestions_loop => $suggestions_loop, patron_reason_loop => $patron_reason_loop, "op_$op" => 1, diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index 43834f6..f87af87 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -328,16 +328,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.10.4