Browse Source

Bug 17250 - Koha::AuthorisedValues - Remove GetAuthValCode

The subroutine C4::Koha::GetAuthValCode returned the authorised value
category for a given kohafield.
This can be acchieve easily using a new Koha::AuthorisedValues->search_by_koha_field
method which will mimic search_by_marc_field.

Test plan:
Confirm that the description is correctly displayed on the following
pages:
- detail and moredetail of a bibliographic page (itemlost, damaged, materials)
- Set AcqCreateItem=ordering and receiving items.
The description for notforloan, restricted, location, ccode, etc.
field should be displayed.
- Items search form
- On the checkout list from the circulation.pl and returns.pl
pages, the description for "materials" should be displayed

Note that GetKohaAuthorisedValuesMapping is going to be removed on bug
17251.

Followed test plan, works as expected.
Signed-off-by: Marc Véron <veron@veron.ch>

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
16.11.x
Jonathan Druart 6 years ago
committed by Kyle M Hall
parent
commit
d019f86f67
  1. 1
      C4/Circulation.pm
  2. 27
      C4/Items.pm
  3. 44
      C4/Koha.pm
  4. 3
      C4/Search.pm
  5. 22
      Koha/AuthorisedValues.pm
  6. 36
      acqui/orderreceive.pl
  7. 17
      catalogue/detail.pl
  8. 31
      catalogue/getitem-ajax.pl
  9. 13
      catalogue/itemsearch.pl
  10. 16
      catalogue/moredetail.pl
  11. 12
      circ/circulation.pl
  12. 7
      circ/returns.pl
  13. 11
      t/db_dependent/AuthorisedValues.t
  14. 6
      tools/inventory.pl

1
C4/Circulation.pm

@ -36,7 +36,6 @@ use C4::Debug;
use C4::Log; # logaction
use C4::Koha qw(
GetAuthorisedValueByCode
GetAuthValCode
);
use C4::Overdues qw(CalcFine UpdateFine get_chargeable_units);
use C4::RotatingCollections qw(GetCollectionItemBranches);

27
C4/Items.pm

@ -1379,27 +1379,22 @@ sub GetItemsInfo {
$serial ||= $data->{'serial'};
my $av;
# get notforloan complete status if applicable
if ( my $code = C4::Koha::GetAuthValCode( 'items.notforloan', $data->{frameworkcode} ) ) {
my $av = Koha::AuthorisedValues->search({ category => $code, authorised_value => $data->{itemnotforloan} });
$av = $av->count ? $av->next : undef;
$data->{notforloanvalue} = $av ? $av->lib : '';
$data->{notforloanvalueopac} = $av ? $av->opac_description : '';
}
$av = Koha::AuthorisedValues->search_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.notforloan', authorised_value => $data->{itemnotforloan} });
$av = $av->count ? $av->next : undef;
$data->{notforloanvalue} = $av ? $av->lib : '';
$data->{notforloanvalueopac} = $av ? $av->opac_description : '';
# get restricted status and description if applicable
if ( my $code = C4::Koha::GetAuthValCode( 'items.restricted', $data->{frameworkcode} ) ) {
my $av = Koha::AuthorisedValues->search({ category => $code, authorised_value => $data->{restricted} });
$av = $av->count ? $av->next : undef;
$data->{restricted} = $av ? $av->lib : '';
$data->{restrictedopac} = $av ? $av->opac_description : '';
}
$av = Koha::AuthorisedValues->search_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.restricted', authorised_value => $data->{restricted} });
$av = $av->count ? $av->next : undef;
$data->{restricted} = $av ? $av->lib : '';
$data->{restrictedopac} = $av ? $av->opac_description : '';
# my stack procedures
if ( my $code = C4::Koha::GetAuthValCode( 'items.stack', $data->{frameworkcode} ) ) {
my $av = Koha::AuthorisedValues->search({ category => $code, authorised_value => $data->{stack} });
$data->{stack} = $av->count ? $av->next->lib : '';
}
$av = Koha::AuthorisedValues->search_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.stack', authorised_value => $data->{stack} });
$data->{stack} = $av->count ? $av->next->lib : '';
# Find the last 3 people who borrowed this item.
my $sth2 = $dbh->prepare("SELECT * FROM old_issues,borrowers

44
C4/Koha.pm

@ -56,7 +56,6 @@ BEGIN {
&GetKohaAuthorisedValues
&GetKohaAuthorisedValuesMapping
&GetAuthorisedValueByCode
&GetAuthValCode
&GetNormalizedUPC
&GetNormalizedISBN
&GetNormalizedEAN
@ -880,22 +879,6 @@ SELECT lib,
return \%notforloan_label_of;
}
=head2 GetAuthValCode
$authvalcode = GetAuthValCode($kohafield,$frameworkcode);
=cut
sub GetAuthValCode {
my ($kohafield,$fwcode) = @_;
my $dbh = C4::Context->dbh;
$fwcode='' unless $fwcode;
my $sth = $dbh->prepare('select authorised_value from marc_subfield_structure where kohafield=? and frameworkcode=?');
$sth->execute($kohafield,$fwcode);
my ($authvalcode) = $sth->fetchrow_array;
return $authvalcode;
}
=head2 GetAuthorisedValues
$authvalues = GetAuthorisedValues([$category]);
@ -1017,21 +1000,18 @@ Returns undef if no authorised value category is defined for the kohafield.
=cut
sub GetKohaAuthorisedValues {
my ($kohafield,$fwcode,$opac) = @_;
$fwcode='' unless $fwcode;
my %values;
my $dbh = C4::Context->dbh;
my $avcode = GetAuthValCode($kohafield,$fwcode);
if ($avcode) {
my $sth = $dbh->prepare("select authorised_value, lib, lib_opac from authorised_values where category=? ");
$sth->execute($avcode);
while ( my ($val, $lib, $lib_opac) = $sth->fetchrow_array ) {
$values{$val} = ($opac && $lib_opac) ? $lib_opac : $lib;
}
return \%values;
} else {
return;
}
my ( $kohafield, $fwcode, $opac ) = @_;
$fwcode = '' unless $fwcode;
my %values;
my $dbh = C4::Context->dbh;
my $avs = Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $fwcode, kohafield => $kohafield } );
return {} unless $avs->count;
my $values;
while ( my $av = $avs->next ) {
$values->{ $av->authorised_value } = $opac ? $av->opac_description : $av->lib;
}
return $values;
}
=head2 GetKohaAuthorisedValuesMapping

3
C4/Search.pm

@ -1852,7 +1852,8 @@ sub searchResults {
my $shelflocations =GetKohaAuthorisedValues('items.location','');
# get notforloan authorised value list (see $shelflocations FIXME)
my $notforloan_authorised_value = GetAuthValCode('items.notforloan','');
my $av = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.notforloan' });
my $notforloan_authorised_value = $av->count ? $av->next->authorised_value : undef;
#Get itemtype hash
my %itemtypes = %{ GetItemTypes() };

22
Koha/AuthorisedValues.pm

@ -80,6 +80,28 @@ sub search_by_marc_field {
);
}
sub search_by_koha_field {
my ( $self, $params ) = @_;
my $frameworkcode = $params->{frameworkcode} || '';
my $kohafield = $params->{kohafield};
my $category = $params->{category};
my $authorised_value = $params->{authorised_value};
return unless $kohafield;
return $self->SUPER::search(
{ 'marc_subfield_structures.frameworkcode' => $frameworkcode,
'marc_subfield_structures.kohafield' => $kohafield,
( defined $category ? ( category_name => $category ) : () ),
( $authorised_value ? ( authorised_value => $authorised_value ) : () ),
},
{ join => { category => 'marc_subfield_structures' },
select => ['authorised_value'],
distinct => 1,
}
);
}
sub categories {
my ( $self ) = @_;
my $rs = $self->_resultset->search(

36
acqui/orderreceive.pl

@ -128,26 +128,22 @@ if ($AcqCreateItem eq 'receiving') {
my @items;
foreach (@itemnumbers) {
my $item = GetItem($_);
if(my $code = GetAuthValCode("items.notforloan", $fw)) {
my $av = Koha::AuthorisedValues->search({ category => $code, authorised_value => $item->{notforloan} });
$item->{notforloan} = $av->count ? $av->next->lib : '';
}
if(my $code = GetAuthValCode("items.restricted", $fw)) {
my $av = Koha::AuthorisedValues->search({ category => $code, authorised_value => $item->{restricted} });
$item->{restricted} = $av->count ? $av->next->lib : '';
}
if(my $code = GetAuthValCode("items.location", $fw)) {
my $av = Koha::AuthorisedValues->search({ category => $code, authorised_value => $item->{location} });
$item->{location} = $av->count ? $av->next->lib : '';
}
if(my $code = GetAuthValCode("items.ccode", $fw)) {
my $av = Koha::AuthorisedValues->search({ category => $code, authorised_value => $item->{collection} });
$item->{collection} = $av->count ? $av->next->lib : '';
}
if(my $code = GetAuthValCode("items.materials", $fw)) {
my $av = Koha::AuthorisedValues->search({ category => $code, authorised_value => $item->{materials} });
$item->{materials} = $av->count ? $av->next->lib : '';
}
my $av;
$av = Koha::AuthorisedValues->search_by_koha_field({frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->{notforloan} });
$item->{notforloan} = $av->count ? $av->next->lib : '';
$av = Koha::AuthorisedValues->search_by_koha_field({frameworkcode => $fw, kohafield => 'items.restricted', authorised_value => $item->{restricted} });
$item->{restricted} = $av->count ? $av->next->lib : '';
$av = Koha::AuthorisedValues->search_by_koha_field({frameworkcode => $fw, kohafield => 'items.location', authorised_value => $item->{location} });
$item->{location} = $av->count ? $av->next->lib : '';
$av = Koha::AuthorisedValues->search_by_koha_field({frameworkcode => $fw, kohafield => 'items.collection', authorised_value => $item->{collection} });
$item->{collection} = $av->count ? $av->next->lib : '';
$av = Koha::AuthorisedValues->search_by_koha_field({frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->{materials} });
$item->{materials} = $av->count ? $av->next->lib : '';
my $itemtype = getitemtypeinfo($item->{itype});
$item->{itemtype} = $itemtype->{description};
push @items, $item;

17
catalogue/detail.pl

@ -41,6 +41,7 @@ use Koha::DateUtils;
use C4::HTML5Media;
use C4::CourseReserves qw(GetItemCourseReservesInfo);
use C4::Acquisition qw(GetOrdersByBiblionumber);
use Koha::AuthorisedValues;
use Koha::Virtualshelves;
my $query = CGI->new();
@ -194,17 +195,19 @@ my $copynumbers = GetKohaAuthorisedValues('items.copynumber', $fw);
my (@itemloop, @otheritemloop, %itemfields);
my $norequests = 1;
if ( my $lost_av = GetAuthValCode('items.itemlost', $fw) ) {
$template->param( itemlostloop => GetAuthorisedValues( $lost_av ) );
my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.itemlost' });
if ( $mss->count ) {
$template->param( itemlostloop => GetAuthorisedValues( $mss->next->authorised_value ) );
}
if ( my $damaged_av = GetAuthValCode('items.damaged', $fw) ) {
$template->param( itemdamagedloop => GetAuthorisedValues( $damaged_av ) );
$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.damaged' });
if ( $mss->count ) {
$template->param( itemdamagedloop => GetAuthorisedValues( $mss->next->authorised_value ) );
}
my $materials_authvalcode = GetAuthValCode('items.materials', $fw);
$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.materials' });
my %materials_map;
if ($materials_authvalcode) {
my $materials_authvals = GetAuthorisedValues($materials_authvalcode);
if ($mss->count) {
my $materials_authvals = GetAuthorisedValues($mss->next->authorised_value);
if ($materials_authvals) {
foreach my $value (@$materials_authvals) {
$materials_map{$value->{authorised_value}} = $value->{lib};

31
catalogue/getitem-ajax.pl

@ -55,30 +55,21 @@ if($itemnumber) {
$item->{holdingbranchname} = Koha::Libraries->find($item->{holdingbranch})->branchname;
}
if(my $code = GetAuthValCode("items.notforloan", $fw)) {
my $av = Koha::AuthorisedValues->search({ category => $code, authorised_values => $item->{notforloan} });
$item->{notforloan} = $av->count ? $av->next->lib : '';
}
my $av;
$av = Koha::AuthorisedValues->search_by_koha_field({ frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->{notforloan} });
$item->{notforloan} = $av->count ? $av->next->lib : '';
if(my $code = GetAuthValCode("items.restricted", $fw)) {
my $av = Koha::AuthorisedValues->search({ category => $code, authorised_values => $item->{restricted} });
$item->{restricted} = $av->count ? $av->next->lib : '';
}
$av = Koha::AuthorisedValues->search_by_koha_field({ frameworkcode => $fw, kohafield => 'items.restricted', authorised_value => $item->{restricted} });
$item->{restricted} = $av->count ? $av->next->lib : '';
if(my $code = GetAuthValCode("items.location", $fw)) {
my $av = Koha::AuthorisedValues->search({ category => $code, authorised_values => $item->{location} });
$item->{location} = $av->count ? $av->next->lib : '';
}
$av = Koha::AuthorisedValues->search_by_koha_field({ frameworkcode => $fw, kohafield => 'items.location', authorised_value => $item->{location} });
$item->{location} = $av->count ? $av->next->lib : '';
if(my $code = GetAuthValCode("items.ccode", $fw)) {
my $av = Koha::AuthorisedValues->search({ category => $code, authorised_values => $item->{collection} });
$item->{collection} = $av->count ? $av->next->lib : '';
}
$av = Koha::AuthorisedValues->search_by_koha_field({ frameworkcode => $fw, kohafield => 'items.collection', authorised_value => $item->{collection} });
$item->{collection} = $av->count ? $av->next->lib : '';
if(my $code = GetAuthValCode("items.materials", $fw)) {
my $av = Koha::AuthorisedValues->search({ category => $code, authorised_values => $item->{materials} });
$item->{materials} = $av->count ? $av->next->lib : '';
}
$av = Koha::AuthorisedValues->search_by_koha_field({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->{materials} });
$item->{materials} = $av->count ? $av->next->lib : '';
my $itemtype = getitemtypeinfo($item->{itype});
$item->{itemtype} = $itemtype->{description};

13
catalogue/itemsearch.pl

@ -27,6 +27,7 @@ use C4::Items;
use C4::Biblio;
use C4::Koha;
use Koha::AuthorisedValues;
use Koha::Item::Search::Field qw(GetItemSearchFields);
use Koha::ItemTypes;
use Koha::Libraries;
@ -87,11 +88,11 @@ my ($template, $borrowernumber, $cookie) = get_template_and_user({
flagsrequired => { catalogue => 1 },
});
my $notforloan_avcode = GetAuthValCode('items.notforloan');
my $notforloan_values = GetAuthorisedValues($notforloan_avcode);
my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.notforloan' });
my $notforloan_values = $mss->count ? GetAuthorisedValues($mss->next->authorised_value) : [];
my $location_avcode = GetAuthValCode('items.location');
my $location_values = GetAuthorisedValues($location_avcode);
$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.location' });
my $location_values = $mss->count ? GetAuthorisedValues($mss->next->authorised_value) : [];
if (scalar keys %params > 0) {
# Parameters given, it's a search
@ -262,7 +263,9 @@ if ($format eq 'html') {
label => $itemtype->translated_description,
};
}
my $ccode_avcode = GetAuthValCode('items.ccode') || 'CCODE';
my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.ccode' });
my $ccode_avcode = $mss->count ? $mss->next->authorised_value : 'CCODE';
my $ccodes = GetAuthorisedValues($ccode_avcode);
my @ccodes;
foreach my $ccode (@$ccodes) {

16
catalogue/moredetail.pl

@ -36,6 +36,7 @@ use C4::Members qw/GetHideLostItemsPreference/;
use C4::Reserves qw(GetReservesFromBiblionumber);
use Koha::Acquisition::Bookseller;
use Koha::AuthorisedValues;
use Koha::DateUtils;
use Koha::Items;
@ -193,14 +194,17 @@ foreach my $item (@items){
}
if ( my $lost_av = GetAuthValCode('items.itemlost', $fw) ) {
$template->param( itemlostloop => GetAuthorisedValues( $lost_av ) );
my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.itemlost' });
if ( $mss->count ) {
$template->param( itemlostloop => GetAuthorisedValues( $mss->next->authorisedvalue ) );
}
if ( my $damaged_av = GetAuthValCode('items.damaged', $fw) ) {
$template->param( itemdamagedloop => GetAuthorisedValues( $damaged_av ) );
$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.damaged' });
if ( $mss->count ) {
$template->param( itemdamagedloop => GetAuthorisedValues( $mss->next->authorisedvalue ) );
}
if ( my $withdrawn_av = GetAuthValCode('items.withdrawn', $fw) ) {
$template->param( itemwithdrawnloop => GetAuthorisedValues( $withdrawn_av ) );
$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.withdrawn' });
if ( $mss->count ) {
$template->param( itemwithdrawnloop => GetAuthorisedValues( $mss->next->authorisedvalue) );
}
$template->param(count => $data->{'count'},

12
circ/circulation.pl

@ -340,8 +340,9 @@ if (@$barcodes) {
# Get the item title for more information
my $getmessageiteminfo = GetBiblioFromItemNumber(undef,$barcode);
$template_params->{authvalcode_notforloan} =
C4::Koha::GetAuthValCode('items.notforloan', $getmessageiteminfo->{'frameworkcode'});
my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $getmessageiteminfo->{frameworkcode}, kohafield => 'items.notforloan' });
$template_params->{authvalcode_notforloan} = $mss->count ? $mss->next->authorisedvalue : undef;
# Fix for bug 7494: optional checkout-time fallback search for a book
@ -390,11 +391,8 @@ if (@$barcodes) {
unless($issueconfirmed){
# Get the item title for more information
my $materials = $iteminfo->{'materials'};
my $avcode = GetAuthValCode('items.materials');
if ($avcode) {
my $av = Koha::AuthorisedValues->search({ category => $avcode, authorised_value => $materials });
$materials = $av->count ? $av->next->lib : '';
}
my $av = Koha::AuthorisedValues->search_by_koha_field({ frameworkcode => $getmessageiteminfo->{frameworkcode}, kohafield => 'items.materials', authorised_value => $materials });
$materials = $av->count ? $av->next->lib : '';
$template_params->{additional_materials} = $materials;
$template_params->{itemhomebranch} = $iteminfo->{'homebranch'};

7
circ/returns.pl

@ -279,11 +279,8 @@ if ($barcode) {
$returnbranch = $biblio->{$hbr};
my $materials = $biblio->{'materials'};
my $avcode = GetAuthValCode('items.materials');
if ($avcode) {
my $av = Koha::AuthorisedValues->search({ category => $avcode, authorised_value => $materials });
$materials = $av->count ? $av->next->lib : '';
}
my $av = Koha::AuthorisedValues->search_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
$materials = $av->count ? $av->next->lib : '';
$template->param(
title => $biblio->{'title'},

11
t/db_dependent/AuthorisedValues.t

@ -102,7 +102,7 @@ is( $categories[0], $av4->category, 'The first category should be correct (order
is( $categories[1], $av1->category, 'The second category should be correct (ordered by category name)' );
subtest 'search_by_*_field' => sub {
plan tests => 1;
plan tests => 2;
my $loc_cat = Koha::AuthorisedValueCategories->find('LOC');
$loc_cat->delete if $loc_cat;
my $mss = Koha::MarcSubfieldStructures->search( { tagfield => 952, tagsubfield => 'c', frameworkcode => '' } );
@ -130,4 +130,13 @@ subtest 'search_by_*_field' => sub {
is( $avs->count, 3, 'default fk');
is( $avs->next->authorised_value, 'location_1', );
};
subtest 'search_by_koha_field' => sub {
plan tests => 3;
my $avs;
$avs = Koha::AuthorisedValues->search_by_koha_field();
is ( $avs, undef );
$avs = Koha::AuthorisedValues->search_by_koha_field( { kohafield => 'items.location', tagfield => 952, tagsubfield => 'c' } );
is( $avs->count, 3, );
is( $avs->next->authorised_value, 'location_1', );
};
};

6
tools/inventory.pl

@ -72,7 +72,8 @@ $frameworks->{''} = {frameworkcode => ''}; # Add the default framework
for my $fwk (keys %$frameworks){
my $fwkcode = $frameworks->{$fwk}->{'frameworkcode'};
my $authcode = GetAuthValCode('items.location', $fwkcode);
my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fwkcode, kohafield => 'items.location' });
my $authcode = $mss->count ? $mss->next->authorised_value : undef;
if ($authcode && $authorisedvalue_categories!~/\b$authcode\W/){
$authorisedvalue_categories.="$authcode ";
my $data=GetAuthorisedValues($authcode);
@ -87,7 +88,8 @@ my $statuses = [];
for my $statfield (qw/items.notforloan items.itemlost items.withdrawn items.damaged/){
my $hash = {};
$hash->{fieldname} = $statfield;
$hash->{authcode} = GetAuthValCode($statfield);
my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => $statfield });
$hash->{authcode} = $mss->count ? $mss->next->authorised_value : undef;
if ($hash->{authcode}){
my $arr = GetAuthorisedValues($hash->{authcode});
$hash->{values} = $arr;

Loading…
Cancel
Save