use C4::Log; # logaction
use C4::Koha qw(
GetAuthorisedValueByCode
- GetAuthValCode
);
use C4::Overdues qw(CalcFine UpdateFine get_chargeable_units);
use C4::RotatingCollections qw(GetCollectionItemBranches);
$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
&GetKohaAuthorisedValues
&GetKohaAuthorisedValuesMapping
&GetAuthorisedValueByCode
- &GetAuthValCode
&GetNormalizedUPC
&GetNormalizedISBN
&GetNormalizedEAN
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]);
=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
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() };
);
}
+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(
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;
use C4::HTML5Media;
use C4::CourseReserves qw(GetItemCourseReservesInfo);
use C4::Acquisition qw(GetOrdersByBiblionumber);
+use Koha::AuthorisedValues;
use Koha::Virtualshelves;
my $query = CGI->new();
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};
$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};
use C4::Biblio;
use C4::Koha;
+use Koha::AuthorisedValues;
use Koha::Item::Search::Field qw(GetItemSearchFields);
use Koha::ItemTypes;
use Koha::Libraries;
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
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) {
use C4::Reserves qw(GetReservesFromBiblionumber);
use Koha::Acquisition::Bookseller;
+use Koha::AuthorisedValues;
use Koha::DateUtils;
use Koha::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'},
# 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
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'};
$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'},
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 => '' } );
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', );
+ };
};
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);
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;