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

(-)a/C4/Circulation.pm (-4 / +3 lines)
Lines 34-47 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;
42
use Koha::AuthorisedValues;
45
use Koha::DateUtils;
43
use Koha::DateUtils;
46
use Koha::Calendar;
44
use Koha::Calendar;
47
use Koha::Items;
45
use Koha::Items;
Lines 900-906 sub CanBookBeIssued { Link Here
900
        $issuingimpossible{RESTRICTED} = 1;
898
        $issuingimpossible{RESTRICTED} = 1;
901
    }
899
    }
902
    if ( $item->{'itemlost'} && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
900
    if ( $item->{'itemlost'} && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
903
        my $code = GetAuthorisedValueByCode( 'LOST', $item->{'itemlost'} );
901
        my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $item->{itemlost} });
902
        my $code = $av->count ? $av->next->lib : '';
904
        $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' );
903
        $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' );
905
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
904
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
906
    }
905
    }
(-)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 607-613 my $relatives_issues_count = Link Here
607
  Koha::Database->new()->schema()->resultset('Issue')
607
  Koha::Database->new()->schema()->resultset('Issue')
608
  ->count( { borrowernumber => \@relatives } );
608
  ->count( { borrowernumber => \@relatives } );
609
609
610
my $roadtype = C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $borrower->{streettype} );
610
my $av = Koha::AuthorisedValues->search({ category => 'ROADTYPE', authorised_value => $borrower->{streettype} });
611
my $roadtype = $av->count ? $av->next->lib : '';
611
612
612
$template->param(%$borrower);
613
$template->param(%$borrower);
613
614
(-)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 796-802 sub patron_attributes_form { Link Here
796
        }
797
        }
797
    }
798
    }
798
    while ( my ($class, @items) = each %items_by_class ) {
799
    while ( my ($class, @items) = each %items_by_class ) {
799
        my $lib = GetAuthorisedValueByCode( 'PA_CLASS', $class ) || $class;
800
        my $av = Koha::AuthorisedValues->search({ category => 'PA_CLASS', authorised_value => $class });
801
        my $lib = $av->count ? $av->next->lib : $class;
800
        push @attribute_loop, {
802
        push @attribute_loop, {
801
            class => $class,
803
            class => $class,
802
            items => @items,
804
            items => @items,
(-)a/members/moremember.pl (-1 / +4 lines)
Lines 50-55 use C4::Biblio; Link Here
50
use C4::Form::MessagingPreferences;
50
use C4::Form::MessagingPreferences;
51
use List::MoreUtils qw/uniq/;
51
use List::MoreUtils qw/uniq/;
52
use C4::Members::Attributes qw(GetBorrowerAttributes);
52
use C4::Members::Attributes qw(GetBorrowerAttributes);
53
use Koha::AuthorisedValues;
53
use Koha::Patron::Debarments qw(GetDebarments);
54
use Koha::Patron::Debarments qw(GetDebarments);
54
use Koha::Patron::Images;
55
use Koha::Patron::Images;
55
use Module::Load;
56
use Module::Load;
Lines 282-288 if (C4::Context->preference('ExtendedPatronAttributes')) { Link Here
282
        for my $attr (@$attributes) {
283
        for my $attr (@$attributes) {
283
            push @items, $attr if $attr->{class} eq $class
284
            push @items, $attr if $attr->{class} eq $class
284
        }
285
        }
285
        my $lib = GetAuthorisedValueByCode( 'PA_CLASS', $class ) || $class;
286
        my $av = Koha::AuthorisedValues->search({ category => 'PA_CLASS', authorised_value => $class });
287
        my $lib = $av->count ? $av->next->lib : $class;
288
286
        push @attributes_loop, {
289
        push @attributes_loop, {
287
            class => $class,
290
            class => $class,
288
            items => \@items,
291
            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 146-151 while ( my $c = $sth->fetchrow_hashref() ) { Link Here
146
      GetRenewCount( $c->{borrowernumber}, $c->{itemnumber} );
146
      GetRenewCount( $c->{borrowernumber}, $c->{itemnumber} );
147
147
148
    my $itemtype = C4::Koha::getitemtypeinfo( $item_level_itypes ? $c->{itype} : $c->{itemtype} );
148
    my $itemtype = C4::Koha::getitemtypeinfo( $item_level_itypes ? $c->{itype} : $c->{itemtype} );
149
    my $location;
150
    if ( $c->{location} ) {
151
        my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $c->{location} });
152
        $location = $av->count ? $av->next->lib : '';
153
    }
154
    my $lost;
155
    if ( $c->{itemlost} ) {
156
        my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $c->{itemlost} });
157
        $lost = $av->count ? $av->next->lib : '';
158
    }
159
    my $damaged;
160
    if ( $c->{damaged} ) {
161
        my $av = Koha::AuthorisedValues->search({ category => 'DAMAGED', authorised_value => $c->{damaged} });
162
        $damaged = $av->count ? $av->next->lib : '';
163
    }
149
    my $checkout = {
164
    my $checkout = {
150
        DT_RowId             => $c->{itemnumber} . '-' . $c->{borrowernumber},
165
        DT_RowId             => $c->{itemnumber} . '-' . $c->{borrowernumber},
151
        title                => $c->{title},
166
        title                => $c->{title},
Lines 153-159 while ( my $c = $sth->fetchrow_hashref() ) { Link Here
153
        barcode              => $c->{barcode},
168
        barcode              => $c->{barcode},
154
        itemtype             => $item_level_itypes ? $c->{itype} : $c->{itemtype},
169
        itemtype             => $item_level_itypes ? $c->{itype} : $c->{itemtype},
155
        itemtype_description => $itemtype->{translated_description},
170
        itemtype_description => $itemtype->{translated_description},
156
        location             => $c->{location} ? GetAuthorisedValueByCode( 'LOC', $c->{location} ) : q{},
171
        location             => $location
157
        itemnotes            => $c->{itemnotes},
172
        itemnotes            => $c->{itemnotes},
158
        itemnotes_nonpublic  => $c->{itemnotes_nonpublic},
173
        itemnotes_nonpublic  => $c->{itemnotes_nonpublic},
159
        branchcode           => $c->{branchcode},
174
        branchcode           => $c->{branchcode},
Lines 190-197 while ( my $c = $sth->fetchrow_hashref() ) { Link Here
190
        ),
205
        ),
191
        subtitle =>
206
        subtitle =>
192
          GetRecordValue( 'subtitle', GetMarcBiblio( $c->{biblionumber} ), GetFrameworkCode( $c->{biblionumber} ) ),
207
          GetRecordValue( 'subtitle', GetMarcBiblio( $c->{biblionumber} ), GetFrameworkCode( $c->{biblionumber} ) ),
193
        lost    => $c->{itemlost} ? GetAuthorisedValueByCode( 'LOST',    $c->{itemlost} ) : undef,
208
        lost    => $lost,
194
        damaged => $c->{damaged}  ? GetAuthorisedValueByCode( 'DAMAGED', $c->{damaged} )  : undef,
209
        damaged => $damaged,
195
        borrower => {
210
        borrower => {
196
            surname    => $c->{surname},
211
            surname    => $c->{surname},
197
            firstname  => $c->{firstname},
212
            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