View | Details | Raw Unified | Return to bug 17252
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 26-31 use strict; Link Here
26
use C4::Context;
26
use C4::Context;
27
use Koha::Caches;
27
use Koha::Caches;
28
use Koha::DateUtils qw(dt_from_string);
28
use Koha::DateUtils qw(dt_from_string);
29
use Koha::AuthorisedValues;
29
use Koha::Libraries;
30
use Koha::Libraries;
30
use Koha::MarcSubfieldStructures;
31
use Koha::MarcSubfieldStructures;
31
use DateTime::Format::MySQL;
32
use DateTime::Format::MySQL;
Lines 54-60 BEGIN { Link Here
54
		&GetAuthorisedValues
55
		&GetAuthorisedValues
55
		&GetAuthorisedValueCategories
56
		&GetAuthorisedValueCategories
56
		&GetKohaAuthorisedValues
57
		&GetKohaAuthorisedValues
57
    &GetKohaAuthorisedValuesMapping
58
    &GetAuthorisedValueByCode
58
    &GetAuthorisedValueByCode
59
		&GetNormalizedUPC
59
		&GetNormalizedUPC
60
		&GetNormalizedISBN
60
		&GetNormalizedISBN
Lines 1014-1063 sub GetKohaAuthorisedValues { Link Here
1014
    return $values;
1014
    return $values;
1015
}
1015
}
1016
1016
1017
=head2 GetKohaAuthorisedValuesMapping
1018
1019
Takes a hash as a parameter. The interface key indicates the
1020
description to use in the mapping.
1021
1022
Returns hashref of:
1023
 "{kohafield},{frameworkcode},{authorised_value}" => "{description}"
1024
for all the kohafields, frameworkcodes, and authorised values.
1025
1026
Returns undef if nothing is found.
1027
1028
=cut
1029
1030
sub GetKohaAuthorisedValuesMapping {
1031
    my ($parameter) = @_;
1032
    my $interface = $parameter->{'interface'} // '';
1033
1034
    my $query_mapping = q{
1035
SELECT TA.kohafield,TA.authorised_value AS category,
1036
       TA.frameworkcode,TB.authorised_value,
1037
       IF(TB.lib_opac>'',TB.lib_opac,TB.lib) AS OPAC,
1038
       TB.lib AS Intranet,TB.lib_opac
1039
FROM marc_subfield_structure AS TA JOIN
1040
     authorised_values as TB ON
1041
     TA.authorised_value=TB.category
1042
WHERE TA.kohafield>'' AND TA.authorised_value>'';
1043
    };
1044
    my $dbh = C4::Context->dbh;
1045
    my $sth = $dbh->prepare($query_mapping);
1046
    $sth->execute();
1047
    my $avmapping;
1048
    if ($interface eq 'opac') {
1049
        while (my $row = $sth->fetchrow_hashref) {
1050
            $avmapping->{$row->{kohafield}.",".$row->{frameworkcode}.",".$row->{authorised_value}} = $row->{OPAC};
1051
        }
1052
    }
1053
    else {
1054
        while (my $row = $sth->fetchrow_hashref) {
1055
            $avmapping->{$row->{kohafield}.",".$row->{frameworkcode}.",".$row->{authorised_value}} = $row->{Intranet};
1056
        }
1057
    }
1058
    return $avmapping;
1059
}
1060
1061
=head2 xml_escape
1017
=head2 xml_escape
1062
1018
1063
  my $escaped_string = C4::Koha::xml_escape($string);
1019
  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 246-252 if ( $markseen or $op ) { Link Here
246
      offset       => 0,
246
      offset       => 0,
247
      size         => undef,
247
      size         => undef,
248
      statushash   => $staton,
248
      statushash   => $staton,
249
      interface    => 'staff',
250
    } );
249
    } );
251
250
252
    # For the items that may be marked as "wrong place", we only check the location (callnumbers, location and branch)
251
    # For the items that may be marked as "wrong place", we only check the location (callnumbers, location and branch)
Lines 262-268 if ( $markseen or $op ) { Link Here
262
      offset       => 0,
261
      offset       => 0,
263
      size         => undef,
262
      size         => undef,
264
      statushash   => undef,
263
      statushash   => undef,
265
      interface    => 'staff',
266
    } );
264
    } );
267
265
268
}
266
}
269
- 

Return to bug 17252