View | Details | Raw Unified | Return to bug 17252
Collapse All | Expand All

(-)a/C4/Circulation.pm (-4 / +3 lines)
Lines 34-48 use C4::ItemCirculationAlertPreference; Link Here
34
use C4::Message;
34
use C4::Message;
35
use C4::Debug;
35
use C4::Debug;
36
use C4::Log; # logaction
36
use C4::Log; # logaction
37
use C4::Koha qw(
38
    GetAuthorisedValueByCode
39
);
40
use C4::Overdues qw(CalcFine UpdateFine get_chargeable_units);
37
use C4::Overdues qw(CalcFine UpdateFine get_chargeable_units);
41
use C4::RotatingCollections qw(GetCollectionItemBranches);
38
use C4::RotatingCollections qw(GetCollectionItemBranches);
42
use Algorithm::CheckDigits;
39
use Algorithm::CheckDigits;
43
40
44
use Data::Dumper;
41
use Data::Dumper;
45
use Koha::Account;
42
use Koha::Account;
43
use Koha::AuthorisedValues;
46
use Koha::DateUtils;
44
use Koha::DateUtils;
47
use Koha::Calendar;
45
use Koha::Calendar;
48
use Koha::Items;
46
use Koha::Items;
Lines 901-907 sub CanBookBeIssued { Link Here
901
        $issuingimpossible{RESTRICTED} = 1;
899
        $issuingimpossible{RESTRICTED} = 1;
902
    }
900
    }
903
    if ( $item->{'itemlost'} && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
901
    if ( $item->{'itemlost'} && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
904
        my $code = GetAuthorisedValueByCode( 'LOST', $item->{'itemlost'} );
902
        my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $item->{itemlost} });
903
        my $code = $av->count ? $av->next->lib : '';
905
        $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' );
904
        $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' );
906
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
905
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
907
    }
906
    }
(-)a/C4/Koha.pm (-22 lines)
Lines 55-61 BEGIN { Link Here
55
		&GetAuthorisedValues
55
		&GetAuthorisedValues
56
		&GetAuthorisedValueCategories
56
		&GetAuthorisedValueCategories
57
		&GetKohaAuthorisedValues
57
		&GetKohaAuthorisedValues
58
    &GetAuthorisedValueByCode
59
		&GetNormalizedUPC
58
		&GetNormalizedUPC
60
		&GetNormalizedISBN
59
		&GetNormalizedISBN
61
		&GetNormalizedEAN
60
		&GetNormalizedEAN
Lines 966-992 sub GetAuthorisedValueCategories { Link Here
966
    return \@results;
965
    return \@results;
967
}
966
}
968
967
969
=head2 GetAuthorisedValueByCode
970
971
$authorised_value = GetAuthorisedValueByCode( $category, $authvalcode, $opac );
972
973
Return the lib attribute from authorised_values from the row identified
974
by the passed category and code
975
976
=cut
977
978
sub GetAuthorisedValueByCode {
979
    my ( $category, $authvalcode, $opac ) = @_;
980
981
    my $field = $opac ? 'lib_opac' : 'lib';
982
    my $dbh = C4::Context->dbh;
983
    my $sth = $dbh->prepare("SELECT $field FROM authorised_values WHERE category=? AND authorised_value =?");
984
    $sth->execute( $category, $authvalcode );
985
    while ( my $data = $sth->fetchrow_hashref ) {
986
        return $data->{ $field };
987
    }
988
}
989
990
=head2 GetKohaAuthorisedValues
968
=head2 GetKohaAuthorisedValues
991
969
992
Takes $kohafield, $fwcode as parameters.
970
Takes $kohafield, $fwcode as parameters.
(-)a/C4/Letters.pm (-2 / +4 lines)
Lines 28-34 use Carp; Link Here
28
use Template;
28
use Template;
29
use Module::Load::Conditional qw(can_load);
29
use Module::Load::Conditional qw(can_load);
30
30
31
use C4::Koha qw(GetAuthorisedValueByCode);
32
use C4::Members;
31
use C4::Members;
33
use C4::Members::Attributes qw(GetBorrowerAttributes);
32
use C4::Members::Attributes qw(GetBorrowerAttributes);
34
use C4::Log;
33
use C4::Log;
Lines 829-835 sub _parseletter { Link Here
829
            #Therefore adding the test on biblio. This includes biblioitems,
828
            #Therefore adding the test on biblio. This includes biblioitems,
830
            #but excludes items. Removed unneeded global and lookahead.
829
            #but excludes items. Removed unneeded global and lookahead.
831
830
832
        $val = GetAuthorisedValueByCode ('ROADTYPE', $val, 0) if $table=~/^borrowers$/ && $field=~/^streettype$/;
831
        if ( $table=~/^borrowers$/ && $field=~/^streettype$/ ) {
832
            my $av = Koha::AuthorisedValues->search({ category => 'ROADTYPE', authorised_value => $val });
833
            $val = $av->count ? $av->next->lib : '';
834
        }
833
835
834
        # Dates replacement
836
        # Dates replacement
835
        my $replacedby   = defined ($val) ? $val : '';
837
        my $replacedby   = defined ($val) ? $val : '';
(-)a/Koha/Template/Plugin/AuthorisedValues.pm (-8 / +6 lines)
Lines 25-31 use C4::Koha; Link Here
25
25
26
sub GetByCode {
26
sub GetByCode {
27
    my ( $self, $category, $code, $opac ) = @_;
27
    my ( $self, $category, $code, $opac ) = @_;
28
    return GetAuthorisedValueByCode( $category, $code, $opac );
28
    my $av = Koha::AuthorisedValues->search({ category => $category, authorised_value => $code });
29
    return $av->count
30
            ? $opac
31
                ? $av->next->opac_description
32
                : $av->next->lib
33
            : '';
29
}
34
}
30
35
31
sub Get {
36
sub Get {
Lines 59-71 Koha::Template::Plugin::AuthorisedValues - TT Plugin for authorised values Link Here
59
In a template, you can get the description for an authorised value with
64
In a template, you can get the description for an authorised value with
60
the following TT code: [% AuthorisedValues.GetByCode( 'CATEGORY', 'AUTHORISED_VALUE_CODE', 'IS_OPAC' ) %]
65
the following TT code: [% AuthorisedValues.GetByCode( 'CATEGORY', 'AUTHORISED_VALUE_CODE', 'IS_OPAC' ) %]
61
66
62
The parameters are identical to those used by the subroutine C4::Koha::GetAuthorisedValueByCode.
63
64
sub GetByCode {
65
    my ( $self, $category, $code, $opac ) = @_;
66
    return GetAuthorisedValueByCode( $category, $code, $opac );
67
}
68
69
=head2 GetAuthValueDropbox
67
=head2 GetAuthValueDropbox
70
68
71
The parameters are identical to those used by the subroutine C4::Koha::GetAuthValueDropbox
69
The parameters are identical to those used by the subroutine C4::Koha::GetAuthValueDropbox
(-)a/admin/patron-attr-types.pl (-1 / +3 lines)
Lines 30-35 use C4::Output; Link Here
30
use C4::Koha;
30
use C4::Koha;
31
use C4::Members::AttributeTypes;
31
use C4::Members::AttributeTypes;
32
32
33
use Koha::AuthorisedValues;
33
use Koha::Libraries;
34
use Koha::Libraries;
34
use Koha::Patron::Categories;
35
use Koha::Patron::Categories;
35
36
Lines 298-304 sub patron_attribute_type_list { Link Here
298
            $attr->{branches} = $attr_type->branches;
299
            $attr->{branches} = $attr_type->branches;
299
            push @items, $attr;
300
            push @items, $attr;
300
        }
301
        }
301
        my $lib = GetAuthorisedValueByCode( 'PA_CLASS', $class ) || $class;
302
        my $av = Koha::AuthorisedValues->search({ category => 'PA_CLASS', authorised_value => $class });
303
        my $lib = $av->count ? $av->next->lib : $class;
302
        push @attributes_loop, {
304
        push @attributes_loop, {
303
            class => $class,
305
            class => $class,
304
            items => \@items,
306
            items => \@items,
(-)a/circ/circulation.pl (-1 / +2 lines)
Lines 609-615 my $relatives_issues_count = Link Here
609
  Koha::Database->new()->schema()->resultset('Issue')
609
  Koha::Database->new()->schema()->resultset('Issue')
610
  ->count( { borrowernumber => \@relatives } );
610
  ->count( { borrowernumber => \@relatives } );
611
611
612
my $roadtype = C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $borrower->{streettype} );
612
my $av = Koha::AuthorisedValues->search({ category => 'ROADTYPE', authorised_value => $borrower->{streettype} });
613
my $roadtype = $av->count ? $av->next->lib : '';
613
614
614
$template->param(%$borrower);
615
$template->param(%$borrower);
615
616
(-)a/members/memberentry.pl (-1 / +3 lines)
Lines 38-43 use C4::Koha; Link Here
38
use C4::Log;
38
use C4::Log;
39
use C4::Letters;
39
use C4::Letters;
40
use C4::Form::MessagingPreferences;
40
use C4::Form::MessagingPreferences;
41
use Koha::AuthorisedValues;
41
use Koha::Patron::Debarments;
42
use Koha::Patron::Debarments;
42
use Koha::Cities;
43
use Koha::Cities;
43
use Koha::DateUtils;
44
use Koha::DateUtils;
Lines 795-801 sub patron_attributes_form { Link Here
795
        }
796
        }
796
    }
797
    }
797
    while ( my ($class, @items) = each %items_by_class ) {
798
    while ( my ($class, @items) = each %items_by_class ) {
798
        my $lib = GetAuthorisedValueByCode( 'PA_CLASS', $class ) || $class;
799
        my $av = Koha::AuthorisedValues->search({ category => 'PA_CLASS', authorised_value => $class });
800
        my $lib = $av->count ? $av->next->lib : $class;
799
        push @attribute_loop, {
801
        push @attribute_loop, {
800
            class => $class,
802
            class => $class,
801
            items => @items,
803
            items => @items,
(-)a/members/moremember.pl (-1 / +4 lines)
Lines 51-56 use C4::Biblio; Link Here
51
use C4::Form::MessagingPreferences;
51
use C4::Form::MessagingPreferences;
52
use List::MoreUtils qw/uniq/;
52
use List::MoreUtils qw/uniq/;
53
use C4::Members::Attributes qw(GetBorrowerAttributes);
53
use C4::Members::Attributes qw(GetBorrowerAttributes);
54
use Koha::AuthorisedValues;
54
use Koha::Patron::Debarments qw(GetDebarments);
55
use Koha::Patron::Debarments qw(GetDebarments);
55
use Koha::Patron::Images;
56
use Koha::Patron::Images;
56
use Module::Load;
57
use Module::Load;
Lines 292-298 if (C4::Context->preference('ExtendedPatronAttributes')) { Link Here
292
        for my $attr (@$attributes) {
293
        for my $attr (@$attributes) {
293
            push @items, $attr if $attr->{class} eq $class
294
            push @items, $attr if $attr->{class} eq $class
294
        }
295
        }
295
        my $lib = GetAuthorisedValueByCode( 'PA_CLASS', $class ) || $class;
296
        my $av = Koha::AuthorisedValues->search({ category => 'PA_CLASS', authorised_value => $class });
297
        my $lib = $av->count ? $av->next->lib : $class;
298
296
        push @attributes_loop, {
299
        push @attributes_loop, {
297
            class => $class,
300
            class => $class,
298
            items => \@items,
301
            items => \@items,
(-)a/reports/borrowers_stats.pl (-2 / +4 lines)
Lines 24-36 use List::MoreUtils qw/uniq/; Link Here
24
use C4::Auth;
24
use C4::Auth;
25
use C4::Context;
25
use C4::Context;
26
use C4::Koha;
26
use C4::Koha;
27
use Koha::DateUtils;
28
use C4::Acquisition;
27
use C4::Acquisition;
29
use C4::Output;
28
use C4::Output;
30
use C4::Reports;
29
use C4::Reports;
31
use C4::Circulation;
30
use C4::Circulation;
32
use C4::Members::AttributeTypes;
31
use C4::Members::AttributeTypes;
33
32
33
use Koha::AuthorisedValues;
34
use Koha::DateUtils;
34
use Koha::Libraries;
35
use Koha::Libraries;
35
use Koha::Patron::Categories;
36
use Koha::Patron::Categories;
36
37
Lines 533-539 sub patron_attributes_form { Link Here
533
534
534
    my @attribute_loop;
535
    my @attribute_loop;
535
    foreach my $class ( sort keys %items_by_class ) {
536
    foreach my $class ( sort keys %items_by_class ) {
536
        my $lib = GetAuthorisedValueByCode( 'PA_CLASS', $class ) || $class;
537
        my $av = Koha::AuthorisedValues->search({ category => 'PA_CLASS', authorised_value => $class });
538
        my $lib = $av->count ? $av->next->lib : $class;
537
        push @attribute_loop, {
539
        push @attribute_loop, {
538
            class => $class,
540
            class => $class,
539
            items => $items_by_class{$class},
541
            items => $items_by_class{$class},
(-)a/suggestion/suggestion.pl (-2 / +7 lines)
Lines 31-36 use C4::Members; Link Here
31
use C4::Debug;
31
use C4::Debug;
32
32
33
use Koha::DateUtils qw( dt_from_string );
33
use Koha::DateUtils qw( dt_from_string );
34
use Koha::AuthorisedValues;
34
use Koha::Acquisition::Currencies;
35
use Koha::Acquisition::Currencies;
35
use Koha::Libraries;
36
use Koha::Libraries;
36
37
Lines 56-68 sub GetCriteriumDesc{ Link Here
56
    my ($criteriumvalue,$displayby)=@_;
57
    my ($criteriumvalue,$displayby)=@_;
57
    if ($displayby =~ /status/i) {
58
    if ($displayby =~ /status/i) {
58
        unless ( grep { /$criteriumvalue/ } qw(ASKED ACCEPTED REJECTED CHECKED ORDERED AVAILABLE) ) {
59
        unless ( grep { /$criteriumvalue/ } qw(ASKED ACCEPTED REJECTED CHECKED ORDERED AVAILABLE) ) {
59
            return GetAuthorisedValueByCode('SUGGEST_STATUS', $criteriumvalue ) || "Unknown";
60
            my $av = Koha::AuthorisedValues->search({ category => 'SUGGEST_STATUS', authorised_value => $criteriumvalue });
61
            return $av->count ? $av->next->lib : 'Unkown';
60
        }
62
        }
61
        return ($criteriumvalue eq 'ASKED'?"Pending":ucfirst(lc( $criteriumvalue))) if ($displayby =~/status/i);
63
        return ($criteriumvalue eq 'ASKED'?"Pending":ucfirst(lc( $criteriumvalue))) if ($displayby =~/status/i);
62
    }
64
    }
63
    return Koha::Libraries->find($criteriumvalue)->branchname
65
    return Koha::Libraries->find($criteriumvalue)->branchname
64
        if $displayby =~ /branchcode/;
66
        if $displayby =~ /branchcode/;
65
    return GetAuthorisedValueByCode('SUGGEST_FORMAT', $criteriumvalue) || "Unknown" if ($displayby =~/itemtype/);
67
    if ( $displayby =~ /itemtype/ ) {
68
        my $av = Koha::AuthorisedValues->search({ category => 'SUGGEST_FORMAT', authorised_value => $criteriumvalue });
69
        return $av->count ? $av->next->lib : 'Unkown';
70
    }
66
    if ($displayby =~/suggestedby/||$displayby =~/managedby/||$displayby =~/acceptedby/){
71
    if ($displayby =~/suggestedby/||$displayby =~/managedby/||$displayby =~/acceptedby/){
67
        my $borr=C4::Members::GetMember(borrowernumber=>$criteriumvalue);
72
        my $borr=C4::Members::GetMember(borrowernumber=>$criteriumvalue);
68
        return "" unless $borr;
73
        return "" unless $borr;
(-)a/svc/checkouts (-4 / +19 lines)
Lines 26-35 use JSON qw(to_json); Link Here
26
use C4::Auth qw(check_cookie_auth haspermission get_session);
26
use C4::Auth qw(check_cookie_auth haspermission get_session);
27
use C4::Biblio qw(GetMarcBiblio GetFrameworkCode GetRecordValue );
27
use C4::Biblio qw(GetMarcBiblio GetFrameworkCode GetRecordValue );
28
use C4::Circulation qw(GetIssuingCharges CanBookBeRenewed GetRenewCount GetSoonestRenewDate);
28
use C4::Circulation qw(GetIssuingCharges CanBookBeRenewed GetRenewCount GetSoonestRenewDate);
29
use C4::Koha qw(GetAuthorisedValueByCode);
30
use C4::Overdues qw(GetFine);
29
use C4::Overdues qw(GetFine);
31
use C4::Context;
30
use C4::Context;
32
31
32
use Koha::AuthorisedValues;
33
use Koha::DateUtils;
33
use Koha::DateUtils;
34
34
35
my $input = new CGI;
35
my $input = new CGI;
Lines 149-154 while ( my $c = $sth->fetchrow_hashref() ) { Link Here
149
      GetRenewCount( $c->{borrowernumber}, $c->{itemnumber} );
149
      GetRenewCount( $c->{borrowernumber}, $c->{itemnumber} );
150
150
151
    my $itemtype = C4::Koha::getitemtypeinfo( $item_level_itypes ? $c->{itype} : $c->{itemtype} );
151
    my $itemtype = C4::Koha::getitemtypeinfo( $item_level_itypes ? $c->{itype} : $c->{itemtype} );
152
    my $location;
153
    if ( $c->{location} ) {
154
        my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $c->{location} });
155
        $location = $av->count ? $av->next->lib : '';
156
    }
157
    my $lost;
158
    if ( $c->{itemlost} ) {
159
        my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $c->{itemlost} });
160
        $lost = $av->count ? $av->next->lib : '';
161
    }
162
    my $damaged;
163
    if ( $c->{damaged} ) {
164
        my $av = Koha::AuthorisedValues->search({ category => 'DAMAGED', authorised_value => $c->{damaged} });
165
        $damaged = $av->count ? $av->next->lib : '';
166
    }
152
    my $checkout = {
167
    my $checkout = {
153
        DT_RowId             => $c->{itemnumber} . '-' . $c->{borrowernumber},
168
        DT_RowId             => $c->{itemnumber} . '-' . $c->{borrowernumber},
154
        title                => $c->{title},
169
        title                => $c->{title},
Lines 156-162 while ( my $c = $sth->fetchrow_hashref() ) { Link Here
156
        barcode              => $c->{barcode},
171
        barcode              => $c->{barcode},
157
        itemtype             => $item_level_itypes ? $c->{itype} : $c->{itemtype},
172
        itemtype             => $item_level_itypes ? $c->{itype} : $c->{itemtype},
158
        itemtype_description => $itemtype->{translated_description},
173
        itemtype_description => $itemtype->{translated_description},
159
        location             => $c->{location} ? GetAuthorisedValueByCode( 'LOC', $c->{location} ) : q{},
174
        location             => $location,
160
        homebranch           => $c->{homebranch},
175
        homebranch           => $c->{homebranch},
161
        itemnotes            => $c->{itemnotes},
176
        itemnotes            => $c->{itemnotes},
162
        itemnotes_nonpublic  => $c->{itemnotes_nonpublic},
177
        itemnotes_nonpublic  => $c->{itemnotes_nonpublic},
Lines 195-202 while ( my $c = $sth->fetchrow_hashref() ) { Link Here
195
        ),
210
        ),
196
        subtitle =>
211
        subtitle =>
197
          GetRecordValue( 'subtitle', GetMarcBiblio( $c->{biblionumber} ), GetFrameworkCode( $c->{biblionumber} ) ),
212
          GetRecordValue( 'subtitle', GetMarcBiblio( $c->{biblionumber} ), GetFrameworkCode( $c->{biblionumber} ) ),
198
        lost    => $c->{itemlost} ? GetAuthorisedValueByCode( 'LOST',    $c->{itemlost} ) : undef,
213
        lost    => $lost,
199
        damaged => $c->{damaged}  ? GetAuthorisedValueByCode( 'DAMAGED', $c->{damaged} )  : undef,
214
        damaged => $damaged,
200
        borrower => {
215
        borrower => {
201
            surname    => $c->{surname},
216
            surname    => $c->{surname},
202
            firstname  => $c->{firstname},
217
            firstname  => $c->{firstname},
(-)a/t/db_dependent/Koha.t (-9 / +1 lines)
Lines 9-15 use Koha::DateUtils qw(dt_from_string); Link Here
9
use Koha::AuthorisedValue;
9
use Koha::AuthorisedValue;
10
use Koha::AuthorisedValueCategories;
10
use Koha::AuthorisedValueCategories;
11
11
12
use Test::More tests => 9;
12
use Test::More tests => 8;
13
use DateTime::Format::MySQL;
13
use DateTime::Format::MySQL;
14
14
15
BEGIN {
15
BEGIN {
Lines 46-58 subtest 'Authorized Values Tests' => sub { Link Here
46
    ok( $insert_success, "Insert data in database" );
46
    ok( $insert_success, "Insert data in database" );
47
47
48
48
49
# Tests
50
    SKIP: {
51
        skip "INSERT failed", 1 unless $insert_success;
52
53
        is ( GetAuthorisedValueByCode($data->{category}, $data->{authorised_value}), $data->{lib}, "GetAuthorisedValueByCode" );
54
    }
55
56
# Clean up
49
# Clean up
57
    if($insert_success){
50
    if($insert_success){
58
        my $query = "DELETE FROM authorised_values WHERE category=? AND authorised_value=? AND lib=? AND lib_opac=? AND imageurl=?;";
51
        my $query = "DELETE FROM authorised_values WHERE category=? AND authorised_value=? AND lib=? AND lib_opac=? AND imageurl=?;";
59
- 

Return to bug 17252