@@ -, +, @@ suggestions ----------- - 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 --- C4/Koha.pm | 105 +++++++++----------- .../prog/en/modules/suggestion/suggestion.tt | 12 +-- .../opac-tmpl/prog/en/modules/opac-suggestions.tt | 6 +- opac/opac-suggestions.pl | 2 +- suggestion/suggestion.pl | 8 +- 5 files changed, 61 insertions(+), 72 deletions(-) --- a/C4/Koha.pm +++ a/C4/Koha.pm @@ -25,6 +25,7 @@ use strict; use C4::Context; use C4::Branch qw(GetBranchesCount); +use C4::ItemType; use Memoize; use DateTime; use DateTime::Format::MySQL; @@ -124,84 +125,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(); --- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt @@ -176,8 +176,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 ) %] @@ -276,9 +276,9 @@ $(document).ready(function() { calcNewsuggTotal(); });
  • @@ -481,7 +481,7 @@ $(document).ready(function() { calcNewsuggTotal(); }); --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tt +++ a/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tt @@ -110,10 +110,10 @@ $.tablesorter.addParser({
  • -
  • - [% FOREACH itemtypeloo IN itemtypeloop %] - [% IF ( itemtypeloo.selected ) %] + [% FOREACH supports_loo IN supports_loop %] + [% IF ( supports_loo.selected ) %] [% END %]
  • [% IF ( branch_loop ) %] --- a/opac/opac-suggestions.pl +++ a/opac/opac-suggestions.pl @@ -137,7 +137,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, --- a/suggestion/suggestion.pl +++ a/suggestion/suggestion.pl @@ -289,16 +289,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'}); --