use C4::Message;
use C4::Debug;
use C4::Log; # logaction
-use C4::Koha qw(
- GetAuthorisedValueByCode
-);
use C4::Overdues qw(CalcFine UpdateFine get_chargeable_units);
use C4::RotatingCollections qw(GetCollectionItemBranches);
use Algorithm::CheckDigits;
use Data::Dumper;
use Koha::Account;
+use Koha::AuthorisedValues;
use Koha::DateUtils;
use Koha::Calendar;
use Koha::Items;
$issuingimpossible{RESTRICTED} = 1;
}
if ( $item->{'itemlost'} && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
- my $code = GetAuthorisedValueByCode( 'LOST', $item->{'itemlost'} );
+ my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $item->{itemlost} });
+ my $code = $av->count ? $av->next->lib : '';
$needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' );
$alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
}
&GetAuthorisedValues
&GetAuthorisedValueCategories
&GetKohaAuthorisedValues
- &GetAuthorisedValueByCode
&GetNormalizedUPC
&GetNormalizedISBN
&GetNormalizedEAN
return \@results;
}
-=head2 GetAuthorisedValueByCode
-
-$authorised_value = GetAuthorisedValueByCode( $category, $authvalcode, $opac );
-
-Return the lib attribute from authorised_values from the row identified
-by the passed category and code
-
-=cut
-
-sub GetAuthorisedValueByCode {
- my ( $category, $authvalcode, $opac ) = @_;
-
- my $field = $opac ? 'lib_opac' : 'lib';
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("SELECT $field FROM authorised_values WHERE category=? AND authorised_value =?");
- $sth->execute( $category, $authvalcode );
- while ( my $data = $sth->fetchrow_hashref ) {
- return $data->{ $field };
- }
-}
-
=head2 GetKohaAuthorisedValues
Takes $kohafield, $fwcode as parameters.
use Template;
use Module::Load::Conditional qw(can_load);
-use C4::Koha qw(GetAuthorisedValueByCode);
use C4::Members;
use C4::Members::Attributes qw(GetBorrowerAttributes);
use C4::Log;
#Therefore adding the test on biblio. This includes biblioitems,
#but excludes items. Removed unneeded global and lookahead.
- $val = GetAuthorisedValueByCode ('ROADTYPE', $val, 0) if $table=~/^borrowers$/ && $field=~/^streettype$/;
+ if ( $table=~/^borrowers$/ && $field=~/^streettype$/ ) {
+ my $av = Koha::AuthorisedValues->search({ category => 'ROADTYPE', authorised_value => $val });
+ $val = $av->count ? $av->next->lib : '';
+ }
# Dates replacement
my $replacedby = defined ($val) ? $val : '';
sub GetByCode {
my ( $self, $category, $code, $opac ) = @_;
- return GetAuthorisedValueByCode( $category, $code, $opac );
+ my $av = Koha::AuthorisedValues->search({ category => $category, authorised_value => $code });
+ return $av->count
+ ? $opac
+ ? $av->next->opac_description
+ : $av->next->lib
+ : '';
}
sub Get {
In a template, you can get the description for an authorised value with
the following TT code: [% AuthorisedValues.GetByCode( 'CATEGORY', 'AUTHORISED_VALUE_CODE', 'IS_OPAC' ) %]
-The parameters are identical to those used by the subroutine C4::Koha::GetAuthorisedValueByCode.
-
-sub GetByCode {
- my ( $self, $category, $code, $opac ) = @_;
- return GetAuthorisedValueByCode( $category, $code, $opac );
-}
-
=head2 GetAuthValueDropbox
The parameters are identical to those used by the subroutine C4::Koha::GetAuthValueDropbox
use C4::Koha;
use C4::Members::AttributeTypes;
+use Koha::AuthorisedValues;
use Koha::Libraries;
use Koha::Patron::Categories;
$attr->{branches} = $attr_type->branches;
push @items, $attr;
}
- my $lib = GetAuthorisedValueByCode( 'PA_CLASS', $class ) || $class;
+ my $av = Koha::AuthorisedValues->search({ category => 'PA_CLASS', authorised_value => $class });
+ my $lib = $av->count ? $av->next->lib : $class;
push @attributes_loop, {
class => $class,
items => \@items,
Koha::Database->new()->schema()->resultset('Issue')
->count( { borrowernumber => \@relatives } );
-my $roadtype = C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $borrower->{streettype} );
+my $av = Koha::AuthorisedValues->search({ category => 'ROADTYPE', authorised_value => $borrower->{streettype} });
+my $roadtype = $av->count ? $av->next->lib : '';
$template->param(%$borrower);
use C4::Log;
use C4::Letters;
use C4::Form::MessagingPreferences;
+use Koha::AuthorisedValues;
use Koha::Patron::Debarments;
use Koha::Cities;
use Koha::DateUtils;
}
}
while ( my ($class, @items) = each %items_by_class ) {
- my $lib = GetAuthorisedValueByCode( 'PA_CLASS', $class ) || $class;
+ my $av = Koha::AuthorisedValues->search({ category => 'PA_CLASS', authorised_value => $class });
+ my $lib = $av->count ? $av->next->lib : $class;
push @attribute_loop, {
class => $class,
items => @items,
use C4::Form::MessagingPreferences;
use List::MoreUtils qw/uniq/;
use C4::Members::Attributes qw(GetBorrowerAttributes);
+use Koha::AuthorisedValues;
use Koha::Patron::Debarments qw(GetDebarments);
use Koha::Patron::Images;
use Module::Load;
for my $attr (@$attributes) {
push @items, $attr if $attr->{class} eq $class
}
- my $lib = GetAuthorisedValueByCode( 'PA_CLASS', $class ) || $class;
+ my $av = Koha::AuthorisedValues->search({ category => 'PA_CLASS', authorised_value => $class });
+ my $lib = $av->count ? $av->next->lib : $class;
+
push @attributes_loop, {
class => $class,
items => \@items,
use C4::Auth;
use C4::Context;
use C4::Koha;
-use Koha::DateUtils;
use C4::Acquisition;
use C4::Output;
use C4::Reports;
use C4::Circulation;
use C4::Members::AttributeTypes;
+use Koha::AuthorisedValues;
+use Koha::DateUtils;
use Koha::Libraries;
use Koha::Patron::Categories;
my @attribute_loop;
foreach my $class ( sort keys %items_by_class ) {
- my $lib = GetAuthorisedValueByCode( 'PA_CLASS', $class ) || $class;
+ my $av = Koha::AuthorisedValues->search({ category => 'PA_CLASS', authorised_value => $class });
+ my $lib = $av->count ? $av->next->lib : $class;
push @attribute_loop, {
class => $class,
items => $items_by_class{$class},
use C4::Debug;
use Koha::DateUtils qw( dt_from_string );
+use Koha::AuthorisedValues;
use Koha::Acquisition::Currencies;
use Koha::Libraries;
my ($criteriumvalue,$displayby)=@_;
if ($displayby =~ /status/i) {
unless ( grep { /$criteriumvalue/ } qw(ASKED ACCEPTED REJECTED CHECKED ORDERED AVAILABLE) ) {
- return GetAuthorisedValueByCode('SUGGEST_STATUS', $criteriumvalue ) || "Unknown";
+ my $av = Koha::AuthorisedValues->search({ category => 'SUGGEST_STATUS', authorised_value => $criteriumvalue });
+ return $av->count ? $av->next->lib : 'Unkown';
}
return ($criteriumvalue eq 'ASKED'?"Pending":ucfirst(lc( $criteriumvalue))) if ($displayby =~/status/i);
}
return Koha::Libraries->find($criteriumvalue)->branchname
if $displayby =~ /branchcode/;
- return GetAuthorisedValueByCode('SUGGEST_FORMAT', $criteriumvalue) || "Unknown" if ($displayby =~/itemtype/);
+ if ( $displayby =~ /itemtype/ ) {
+ my $av = Koha::AuthorisedValues->search({ category => 'SUGGEST_FORMAT', authorised_value => $criteriumvalue });
+ return $av->count ? $av->next->lib : 'Unkown';
+ }
if ($displayby =~/suggestedby/||$displayby =~/managedby/||$displayby =~/acceptedby/){
my $borr=C4::Members::GetMember(borrowernumber=>$criteriumvalue);
return "" unless $borr;
use C4::Auth qw(check_cookie_auth haspermission get_session);
use C4::Biblio qw(GetMarcBiblio GetFrameworkCode GetRecordValue );
use C4::Circulation qw(GetIssuingCharges CanBookBeRenewed GetRenewCount GetSoonestRenewDate);
-use C4::Koha qw(GetAuthorisedValueByCode);
use C4::Overdues qw(GetFine);
use C4::Context;
+use Koha::AuthorisedValues;
use Koha::DateUtils;
my $input = new CGI;
GetRenewCount( $c->{borrowernumber}, $c->{itemnumber} );
my $itemtype = C4::Koha::getitemtypeinfo( $item_level_itypes ? $c->{itype} : $c->{itemtype} );
+ my $location;
+ if ( $c->{location} ) {
+ my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $c->{location} });
+ $location = $av->count ? $av->next->lib : '';
+ }
+ my $lost;
+ if ( $c->{itemlost} ) {
+ my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $c->{itemlost} });
+ $lost = $av->count ? $av->next->lib : '';
+ }
+ my $damaged;
+ if ( $c->{damaged} ) {
+ my $av = Koha::AuthorisedValues->search({ category => 'DAMAGED', authorised_value => $c->{damaged} });
+ $damaged = $av->count ? $av->next->lib : '';
+ }
my $checkout = {
DT_RowId => $c->{itemnumber} . '-' . $c->{borrowernumber},
title => $c->{title},
barcode => $c->{barcode},
itemtype => $item_level_itypes ? $c->{itype} : $c->{itemtype},
itemtype_description => $itemtype->{translated_description},
- location => $c->{location} ? GetAuthorisedValueByCode( 'LOC', $c->{location} ) : q{},
+ location => $location,
homebranch => $c->{homebranch},
itemnotes => $c->{itemnotes},
itemnotes_nonpublic => $c->{itemnotes_nonpublic},
),
subtitle =>
GetRecordValue( 'subtitle', GetMarcBiblio( $c->{biblionumber} ), GetFrameworkCode( $c->{biblionumber} ) ),
- lost => $c->{itemlost} ? GetAuthorisedValueByCode( 'LOST', $c->{itemlost} ) : undef,
- damaged => $c->{damaged} ? GetAuthorisedValueByCode( 'DAMAGED', $c->{damaged} ) : undef,
+ lost => $lost,
+ damaged => $damaged,
borrower => {
surname => $c->{surname},
firstname => $c->{firstname},
use Koha::AuthorisedValue;
use Koha::AuthorisedValueCategories;
-use Test::More tests => 9;
+use Test::More tests => 8;
use DateTime::Format::MySQL;
BEGIN {
ok( $insert_success, "Insert data in database" );
-# Tests
- SKIP: {
- skip "INSERT failed", 1 unless $insert_success;
-
- is ( GetAuthorisedValueByCode($data->{category}, $data->{authorised_value}), $data->{lib}, "GetAuthorisedValueByCode" );
- }
-
# Clean up
if($insert_success){
my $query = "DELETE FROM authorised_values WHERE category=? AND authorised_value=? AND lib=? AND lib_opac=? AND imageurl=?;";