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

(-)a/C4/Items.pm (-5 / +13 lines)
Lines 1047-1053 sub GetLostItems { Link Here
1047
  offset       => $offset,
1047
  offset       => $offset,
1048
  size         => $size,
1048
  size         => $size,
1049
  statushash   => $statushash,
1049
  statushash   => $statushash,
1050
  interface    => $interface,
1051
} );
1050
} );
1052
1051
1053
Retrieve a list of title/authors/barcode/callnumber, for biblio inventory.
1052
Retrieve a list of title/authors/barcode/callnumber, for biblio inventory.
Lines 1078-1084 sub GetItemsForInventory { Link Here
1078
    my $offset       = $parameters->{'offset'}       // '';
1077
    my $offset       = $parameters->{'offset'}       // '';
1079
    my $size         = $parameters->{'size'}         // '';
1078
    my $size         = $parameters->{'size'}         // '';
1080
    my $statushash   = $parameters->{'statushash'}   // '';
1079
    my $statushash   = $parameters->{'statushash'}   // '';
1081
    my $interface    = $parameters->{'interface'}    // '';
1082
1080
1083
    my $dbh = C4::Context->dbh;
1081
    my $dbh = C4::Context->dbh;
1084
    my ( @bind_params, @where_strings );
1082
    my ( @bind_params, @where_strings );
Lines 1158-1166 sub GetItemsForInventory { Link Here
1158
    $sth->execute( @bind_params );
1156
    $sth->execute( @bind_params );
1159
    my ($iTotalRecords) = $sth->fetchrow_array();
1157
    my ($iTotalRecords) = $sth->fetchrow_array();
1160
1158
1161
    my $avmapping = C4::Koha::GetKohaAuthorisedValuesMapping( {
1159
    my @avs = Koha::AuthorisedValues->search(
1162
                      interface => $interface
1160
        {   'marc_subfield_structures.kohafield' => { '>' => '' },
1163
                    } );
1161
            'me.authorised_value'                => { '>' => '' },
1162
        },
1163
        {   join     => { category => 'marc_subfield_structures' },
1164
            distinct => ['marc_subfield_structures.kohafield, me.category, frameworkcode, me.authorised_value'],
1165
            '+select' => [ 'marc_subfield_structures.kohafield', 'marc_subfield_structures.frameworkcode', 'me.authorised_value', 'me.lib' ],
1166
            '+as'     => [ 'kohafield',                          'frameworkcode',                          'authorised_value',    'lib' ],
1167
        }
1168
    );
1169
1170
    my $avmapping = { map { $_->get_column('kohafield') . ',' . $_->get_column('frameworkcode') . ',' . $_->get_column('authorised_value') => $_->get_column('lib') } @avs };
1171
1164
    foreach my $row (@$tmpresults) {
1172
    foreach my $row (@$tmpresults) {
1165
1173
1166
        # Auth values
1174
        # Auth values
(-)a/C4/Koha.pm (-45 / +1 lines)
Lines 27-32 use C4::Context; Link Here
27
use C4::Branch; # Can be removed?
27
use C4::Branch; # Can be removed?
28
use Koha::Cache;
28
use Koha::Cache;
29
use Koha::DateUtils qw(dt_from_string);
29
use Koha::DateUtils qw(dt_from_string);
30
use Koha::AuthorisedValues;
30
use Koha::Libraries;
31
use Koha::Libraries;
31
use Koha::MarcSubfieldStructures;
32
use Koha::MarcSubfieldStructures;
32
use DateTime::Format::MySQL;
33
use DateTime::Format::MySQL;
Lines 56-62 BEGIN { Link Here
56
		&GetAuthorisedValues
57
		&GetAuthorisedValues
57
		&GetAuthorisedValueCategories
58
		&GetAuthorisedValueCategories
58
		&GetKohaAuthorisedValues
59
		&GetKohaAuthorisedValues
59
    &GetKohaAuthorisedValuesMapping
60
    &GetAuthorisedValueByCode
60
    &GetAuthorisedValueByCode
61
		&GetNormalizedUPC
61
		&GetNormalizedUPC
62
		&GetNormalizedISBN
62
		&GetNormalizedISBN
Lines 1089-1138 sub GetKohaAuthorisedValues { Link Here
1089
    return $values;
1089
    return $values;
1090
}
1090
}
1091
1091
1092
=head2 GetKohaAuthorisedValuesMapping
1093
1094
Takes a hash as a parameter. The interface key indicates the
1095
description to use in the mapping.
1096
1097
Returns hashref of:
1098
 "{kohafield},{frameworkcode},{authorised_value}" => "{description}"
1099
for all the kohafields, frameworkcodes, and authorised values.
1100
1101
Returns undef if nothing is found.
1102
1103
=cut
1104
1105
sub GetKohaAuthorisedValuesMapping {
1106
    my ($parameter) = @_;
1107
    my $interface = $parameter->{'interface'} // '';
1108
1109
    my $query_mapping = q{
1110
SELECT TA.kohafield,TA.authorised_value AS category,
1111
       TA.frameworkcode,TB.authorised_value,
1112
       IF(TB.lib_opac>'',TB.lib_opac,TB.lib) AS OPAC,
1113
       TB.lib AS Intranet,TB.lib_opac
1114
FROM marc_subfield_structure AS TA JOIN
1115
     authorised_values as TB ON
1116
     TA.authorised_value=TB.category
1117
WHERE TA.kohafield>'' AND TA.authorised_value>'';
1118
    };
1119
    my $dbh = C4::Context->dbh;
1120
    my $sth = $dbh->prepare($query_mapping);
1121
    $sth->execute();
1122
    my $avmapping;
1123
    if ($interface eq 'opac') {
1124
        while (my $row = $sth->fetchrow_hashref) {
1125
            $avmapping->{$row->{kohafield}.",".$row->{frameworkcode}.",".$row->{authorised_value}} = $row->{OPAC};
1126
        }
1127
    }
1128
    else {
1129
        while (my $row = $sth->fetchrow_hashref) {
1130
            $avmapping->{$row->{kohafield}.",".$row->{frameworkcode}.",".$row->{authorised_value}} = $row->{Intranet};
1131
        }
1132
    }
1133
    return $avmapping;
1134
}
1135
1136
=head2 xml_escape
1092
=head2 xml_escape
1137
1093
1138
  my $escaped_string = C4::Koha::xml_escape($string);
1094
  my $escaped_string = C4::Koha::xml_escape($string);
(-)a/Koha/AuthorisedValues.pm (-2 / +4 lines)
Lines 45-51 my @objects = Koha::AuthorisedValues->search($params); Link Here
45
=cut
45
=cut
46
46
47
sub search {
47
sub search {
48
    my ( $self, $params ) = @_;
48
    my ( $self, $params, $attributes ) = @_;
49
49
50
    my $branchcode = $params->{branchcode};
50
    my $branchcode = $params->{branchcode};
51
    delete( $params->{branchcode} );
51
    delete( $params->{branchcode} );
Lines 60-66 sub search { Link Here
60
      }
60
      }
61
      : {};
61
      : {};
62
    my $join = $branchcode ? { join => 'authorised_values_branches' } : {};
62
    my $join = $branchcode ? { join => 'authorised_values_branches' } : {};
63
    return $self->SUPER::search( { %$params, %$or, }, $join );
63
    $attributes //= {};
64
    $attributes = { %$attributes, %$join };
65
    return $self->SUPER::search( { %$params, %$or, }, $attributes );
64
}
66
}
65
67
66
sub search_by_marc_field {
68
sub search_by_marc_field {
(-)a/t/db_dependent/Items/GetItemsForInventory.t (-2 / +1 lines)
Lines 38-44 $dbh->{AutoCommit} = 0; Link Here
38
$dbh->{RaiseError} = 1;
38
$dbh->{RaiseError} = 1;
39
39
40
my ($oldResults, $oldCount) = OldWay($dbh);
40
my ($oldResults, $oldCount) = OldWay($dbh);
41
my ($newResults, $newCount) = GetItemsForInventory( { interface => 'staff' } );
41
my ($newResults, $newCount) = GetItemsForInventory;
42
42
43
is_deeply($newResults,$oldResults,"Inventory results unchanged.");
43
is_deeply($newResults,$oldResults,"Inventory results unchanged.");
44
44
Lines 58-64 sub OldWay { Link Here
58
    my $offset       = '';
58
    my $offset       = '';
59
    my $size         = '';
59
    my $size         = '';
60
    my $statushash   = '';
60
    my $statushash   = '';
61
    my $interface    = '';
62
61
63
    my ( @bind_params, @where_strings );
62
    my ( @bind_params, @where_strings );
64
63
(-)a/t/db_dependent/Koha/GetKohaAuthorisedValuesMapping.t (-54 lines)
Lines 1-54 Link Here
1
#!/usr/bin/perl
2
#
3
# This file is part of Koha.
4
#
5
# Copyright (c) 2015   Mark Tompsett
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use C4::Context;
23
24
use Test::More tests => 8;
25
26
BEGIN {
27
    use_ok('C4::Context');
28
    use_ok('C4::Koha');
29
}
30
31
can_ok('C4::Koha','GetKohaAuthorisedValuesMapping');
32
33
my $avMappingOPAC;
34
my $avMappingStaff;
35
my $avMappingUndef1;
36
my $avMappingUndef2;
37
my $avMappingUndef3;
38
SKIP: {
39
    my $dbh = C4::Context->dbh;
40
    my $count = $dbh->selectrow_arrayref("SELECT COUNT(*) FROM marc_subfield_structure WHERE kohafield LIKE 'item%';");
41
    skip "Lacking item mappings in marc_subfield_structure",5 unless ($count && $count->[0]>0);
42
    $count = $dbh->selectrow_arrayref("SELECT COUNT(*) FROM authorised_values;");
43
    skip "Lacking authorised_values",5 unless ($count && $count->[0]>0);
44
    $avMappingOPAC   = GetKohaAuthorisedValuesMapping( { interface => 'opac' });
45
    $avMappingStaff  = GetKohaAuthorisedValuesMapping( { interface => 'staff' });
46
    $avMappingUndef1 = GetKohaAuthorisedValuesMapping( { interface => undef });
47
    $avMappingUndef2 = GetKohaAuthorisedValuesMapping( { } );
48
    $avMappingUndef3 = GetKohaAuthorisedValuesMapping();
49
    is_deeply($avMappingUndef1,$avMappingStaff,"Undefined interface = Staff test 1");
50
    is_deeply($avMappingUndef2,$avMappingStaff,"Undefined interface = Staff test 2");
51
    is_deeply($avMappingUndef3,$avMappingStaff,"Undefined interface = Staff test 3");
52
    isnt($avMappingOPAC ,undef,"OPAC has a mapping");
53
    isnt($avMappingStaff,undef,"Staff has a mapping");
54
}
(-)a/tools/inventory.pl (-3 lines)
Lines 258-264 if ( $markseen or $op ) { Link Here
258
      offset       => 0,
258
      offset       => 0,
259
      size         => undef,
259
      size         => undef,
260
      statushash   => $staton,
260
      statushash   => $staton,
261
      interface    => 'staff',
262
    } );
261
    } );
263
262
264
    # For the items that may be marked as "wrong place", we only check the location (callnumbers, location and branch)
263
    # For the items that may be marked as "wrong place", we only check the location (callnumbers, location and branch)
Lines 274-280 if ( $markseen or $op ) { Link Here
274
      offset       => 0,
273
      offset       => 0,
275
      size         => undef,
274
      size         => undef,
276
      statushash   => undef,
275
      statushash   => undef,
277
      interface    => 'staff',
278
    } );
276
    } );
279
277
280
}
278
}
281
- 

Return to bug 17251