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

(-)a/C4/Items.pm (-3 / +24 lines)
Lines 977-986 sub GetItemsByBiblioitemnumber { Link Here
977
977
978
=head2 GetItemsInfo
978
=head2 GetItemsInfo
979
979
980
  @results = GetItemsInfo($biblionumber);
980
  @results = GetItemsInfo($biblionumber, $order_by);
981
981
982
Returns information about items with the given biblionumber.
982
Returns information about items with the given biblionumber.
983
983
984
The list is ordered by home branch name and some complex criteria
985
within it (see the code), unless $order_by is specified.
986
Currently only "cn_sort" is supported.
987
984
C<GetItemsInfo> returns a list of references-to-hash. Each element
988
C<GetItemsInfo> returns a list of references-to-hash. Each element
985
contains a number of keys. Most of them are attributes from the
989
contains a number of keys. Most of them are attributes from the
986
C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
990
C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
Lines 1018-1024 If this is set, it is set to C<One Order>. Link Here
1018
=cut
1022
=cut
1019
1023
1020
sub GetItemsInfo {
1024
sub GetItemsInfo {
1021
    my ( $biblionumber ) = @_;
1025
    my ( $biblionumber, $order_by ) = @_;
1026
1022
    my $dbh   = C4::Context->dbh;
1027
    my $dbh   = C4::Context->dbh;
1023
    require C4::Languages;
1028
    require C4::Languages;
1024
    my $language = C4::Languages::getlanguage();
1029
    my $language = C4::Languages::getlanguage();
Lines 1073-1079 sub GetItemsInfo { Link Here
1073
        AND localization.lang = ?
1078
        AND localization.lang = ?
1074
    |;
1079
    |;
1075
1080
1076
    $query .= " WHERE items.biblionumber = ? ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
1081
    $query .= " WHERE items.biblionumber = ? ORDER BY ";
1082
    my $order_by_cause = "home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
1083
    if ($order_by) {
1084
        if ($order_by eq 'cn_sort') {
1085
            $order_by_cause = "cn_sort ASC";
1086
        }
1087
        else {
1088
            warn qq{Unsupported order by "$order_by"};
1089
        }
1090
    }
1091
    $query .= $order_by_cause;
1092
1077
    my $sth = $dbh->prepare($query);
1093
    my $sth = $dbh->prepare($query);
1078
    $sth->execute($language, $biblionumber);
1094
    $sth->execute($language, $biblionumber);
1079
    my $i = 0;
1095
    my $i = 0;
Lines 1104-1109 sub GetItemsInfo { Link Here
1104
        $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.stack', authorised_value => $data->{stack} });
1120
        $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.stack', authorised_value => $data->{stack} });
1105
        $data->{stack}          = $descriptions->{lib} // '';
1121
        $data->{stack}          = $descriptions->{lib} // '';
1106
1122
1123
        my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $data->{location} });
1124
        $av = $av->count ? $av->next : undef;
1125
        $data->{location_intranet} = $av ? $av->lib : '';
1126
        $data->{location_opac}     = $av ? $av->opac_description : '';
1127
1107
        # Find the last 3 people who borrowed this item.
1128
        # Find the last 3 people who borrowed this item.
1108
        my $sth2 = $dbh->prepare("SELECT * FROM old_issues,borrowers
1129
        my $sth2 = $dbh->prepare("SELECT * FROM old_issues,borrowers
1109
                                    WHERE itemnumber = ?
1130
                                    WHERE itemnumber = ?
(-)a/C4/Search.pm (-14 / +5 lines)
Lines 2052-2058 sub searchResults { Link Here
2052
        my $items_count           = scalar(@fields);
2052
        my $items_count           = scalar(@fields);
2053
        my $maxitems_pref = C4::Context->preference('maxItemsinSearchResults');
2053
        my $maxitems_pref = C4::Context->preference('maxItemsinSearchResults');
2054
        my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1;
2054
        my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1;
2055
        my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref
2056
2055
2057
        # loop through every item
2056
        # loop through every item
2058
        foreach my $field (@fields) {
2057
        foreach my $field (@fields) {
Lines 2074-2080 sub searchResults { Link Here
2074
                # hidden based on OpacHiddenItems syspref
2073
                # hidden based on OpacHiddenItems syspref
2075
                my @hi = C4::Items::GetHiddenItemnumbers($item);
2074
                my @hi = C4::Items::GetHiddenItemnumbers($item);
2076
                if (scalar @hi) {
2075
                if (scalar @hi) {
2077
                    push @hiddenitems, @hi;
2078
                    $hideatopac_count++;
2076
                    $hideatopac_count++;
2079
                    next;
2077
                    next;
2080
                }
2078
                }
Lines 2091-2097 sub searchResults { Link Here
2091
                $item->{'branchname'} = $branches{$item->{$otherbranch}};
2089
                $item->{'branchname'} = $branches{$item->{$otherbranch}};
2092
            }
2090
            }
2093
2091
2094
			my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber};
2092
            my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber};
2095
# For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item
2093
# For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item
2096
            my $userenv = C4::Context->userenv;
2094
            my $userenv = C4::Context->userenv;
2097
            if ( $item->{onloan}
2095
            if ( $item->{onloan}
Lines 2101-2112 sub searchResults { Link Here
2101
            {
2099
            {
2102
                $onloan_count++;
2100
                $onloan_count++;
2103
                my $key = $prefix . $item->{onloan} . $item->{barcode};
2101
                my $key = $prefix . $item->{onloan} . $item->{barcode};
2102
                $onloan_items->{$key} = { %$item };
2104
                $onloan_items->{$key}->{due_date} = $item->{onloan};
2103
                $onloan_items->{$key}->{due_date} = $item->{onloan};
2105
                $onloan_items->{$key}->{count}++ if $item->{$hbranch};
2104
                $onloan_items->{$key}->{count}++ if $item->{$hbranch};
2106
                $onloan_items->{$key}->{branchname}     = $item->{branchname};
2107
                $onloan_items->{$key}->{location}       = $shelflocations->{ $item->{location} };
2105
                $onloan_items->{$key}->{location}       = $shelflocations->{ $item->{location} };
2108
                $onloan_items->{$key}->{itemcallnumber} = $item->{itemcallnumber};
2109
                $onloan_items->{$key}->{description}    = $item->{description};
2110
                $onloan_items->{$key}->{imageurl} =
2106
                $onloan_items->{$key}->{imageurl} =
2111
                  getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2107
                  getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2112
2108
Lines 2192-2216 sub searchResults { Link Here
2192
                    $other_count++;
2188
                    $other_count++;
2193
2189
2194
                    my $key = $prefix . $item->{status};
2190
                    my $key = $prefix . $item->{status};
2195
                    foreach (qw(withdrawn itemlost damaged branchname itemcallnumber)) {
2191
                    $other_items->{$key} = { %$item };
2196
                        $other_items->{$key}->{$_} = $item->{$_};
2197
                    }
2198
                    $other_items->{$key}->{intransit} = ( $transfertwhen ne '' ) ? 1 : 0;
2192
                    $other_items->{$key}->{intransit} = ( $transfertwhen ne '' ) ? 1 : 0;
2199
                    $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0;
2193
                    $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0;
2200
                    $other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value and $item->{notforloan};
2194
                    $other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value and $item->{notforloan};
2201
					$other_items->{$key}->{count}++ if $item->{$hbranch};
2195
					$other_items->{$key}->{count}++ if $item->{$hbranch};
2202
					$other_items->{$key}->{location} = $shelflocations->{ $item->{location} };
2196
					$other_items->{$key}->{location} = $shelflocations->{ $item->{location} };
2203
					$other_items->{$key}->{description} = $item->{description};
2204
					$other_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2197
					$other_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2205
                }
2198
                }
2206
                # item is available
2199
                # item is available
2207
                else {
2200
                else {
2208
                    $can_place_holds = 1;
2201
                    $can_place_holds = 1;
2209
                    $available_count++;
2202
                    $available_count++;
2203
                    $available_items->{$prefix} = { %$item };
2210
					$available_items->{$prefix}->{count}++ if $item->{$hbranch};
2204
					$available_items->{$prefix}->{count}++ if $item->{$hbranch};
2211
					foreach (qw(branchname itemcallnumber description)) {
2212
                    	$available_items->{$prefix}->{$_} = $item->{$_};
2213
					}
2214
					$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} };
2205
					$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} };
2215
					$available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2206
					$available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2216
                }
2207
                }
Lines 2239-2245 sub searchResults { Link Here
2239
        # XSLT processing of some stuff
2230
        # XSLT processing of some stuff
2240
        # we fetched the sysprefs already before the loop through all retrieved record!
2231
        # we fetched the sysprefs already before the loop through all retrieved record!
2241
        if (!$scan && $xslfile) {
2232
        if (!$scan && $xslfile) {
2242
            $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, 1, \@hiddenitems, $sysxml, $xslfile, $lang);
2233
            $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, [@available_items_loop, @onloan_items_loop, @other_items_loop], 1, $sysxml, $xslfile, $lang);
2243
        # the last parameter tells Koha to clean up the problematic ampersand entities that Zebra outputs
2234
        # the last parameter tells Koha to clean up the problematic ampersand entities that Zebra outputs
2244
        }
2235
        }
2245
2236
(-)a/C4/XSLT.pm (-10 / +12 lines)
Lines 187-194 sub get_xslt_sysprefs { Link Here
187
    return $sysxml;
187
    return $sysxml;
188
}
188
}
189
189
190
=head2 XSLTParse4Display( $biblionumber, $orig_record, $xslsyspref, $items, $fixamps, $sysxml, $xslfilename, $lang )
191
192
  $items => an array of items rerords, as returned from eg. GetItemsInfo
193
194
Returns XSLT block
195
196
=cut
197
190
sub XSLTParse4Display {
198
sub XSLTParse4Display {
191
    my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $sysxml, $xslfilename, $lang ) = @_;
199
    my ( $biblionumber, $orig_record, $xslsyspref, $items, $fixamps, $sysxml, $xslfilename, $lang ) = @_;
192
200
193
    $sysxml ||= C4::Context->preference($xslsyspref);
201
    $sysxml ||= C4::Context->preference($xslsyspref);
194
    $xslfilename ||= C4::Context->preference($xslsyspref);
202
    $xslfilename ||= C4::Context->preference($xslsyspref);
Lines 240-246 sub XSLTParse4Display { Link Here
240
248
241
    # grab the XML, run it through our stylesheet, push it out to the browser
249
    # grab the XML, run it through our stylesheet, push it out to the browser
242
    my $record = transformMARCXML4XSLT($biblionumber, $orig_record);
250
    my $record = transformMARCXML4XSLT($biblionumber, $orig_record);
243
    my $itemsxml  = buildKohaItemsNamespace($biblionumber, $hidden_items);
251
    my $itemsxml  = $items ? buildKohaItemsNamespace($biblionumber, $items) : "";
244
    my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
252
    my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
245
253
246
    $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml\<\/record\>/;
254
    $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml\<\/record\>/;
Lines 266-278 Is only used in this module currently. Link Here
266
=cut
274
=cut
267
275
268
sub buildKohaItemsNamespace {
276
sub buildKohaItemsNamespace {
269
    my ($biblionumber, $hidden_items) = @_;
277
    my ($biblionumber, $items) = @_;
270
271
    my @items = C4::Items::GetItemsInfo($biblionumber);
272
    if ($hidden_items && @$hidden_items) {
273
        my %hi = map {$_ => 1} @$hidden_items;
274
        @items = grep { !$hi{$_->{itemnumber}} } @items;
275
    }
276
278
277
    my $shelflocations =
279
    my $shelflocations =
278
      { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => GetFrameworkCode($biblionumber), kohafield => 'items.location' } ) };
280
      { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => GetFrameworkCode($biblionumber), kohafield => 'items.location' } ) };
Lines 285-291 sub buildKohaItemsNamespace { Link Here
285
    my $location = "";
287
    my $location = "";
286
    my $ccode = "";
288
    my $ccode = "";
287
    my $xml = '';
289
    my $xml = '';
288
    for my $item (@items) {
290
    for my $item (@$items) {
289
        my $status;
291
        my $status;
290
292
291
        my ( $transfertwhen, $transfertfrom, $transfertto ) = C4::Circulation::GetTransfers($item->{itemnumber});
293
        my ( $transfertwhen, $transfertfrom, $transfertto ) = C4::Circulation::GetTransfers($item->{itemnumber});
(-)a/catalogue/detail.pl (-15 / +15 lines)
Lines 88-108 my $fw = GetFrameworkCode($biblionumber); Link Here
88
my $showallitems = $query->param('showallitems');
88
my $showallitems = $query->param('showallitems');
89
my $marcflavour  = C4::Context->preference("marcflavour");
89
my $marcflavour  = C4::Context->preference("marcflavour");
90
90
91
# XSLT processing of some stuff
92
my $xslfile = C4::Context->preference('XSLTDetailsDisplay');
93
my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
94
my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
95
96
if ( $xslfile ) {
97
    $template->param(
98
        XSLTDetailsDisplay => '1',
99
        XSLTBloc => XSLTParse4Display(
100
                        $biblionumber, $record, "XSLTDetailsDisplay",
101
                        1, undef, $sysxml, $xslfile, $lang
102
                    )
103
    );
104
}
105
106
$template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
91
$template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
107
$template->param( ocoins => GetCOinSBiblio($record) );
92
$template->param( ocoins => GetCOinSBiblio($record) );
108
93
Lines 150-155 if (@hostitems){ Link Here
150
	push (@items,@hostitems);
135
	push (@items,@hostitems);
151
}
136
}
152
137
138
# XSLT processing of some stuff
139
my $xslfile = C4::Context->preference('XSLTDetailsDisplay');
140
my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
141
my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
142
143
if ( $xslfile ) {
144
    $template->param(
145
        XSLTDetailsDisplay => '1',
146
        XSLTBloc => XSLTParse4Display(
147
                        $biblionumber, $record, "XSLTDetailsDisplay", \@all_items,
148
                        1, $sysxml, $xslfile, $lang
149
                    )
150
    );
151
}
152
153
my $dat = &GetBiblioData($biblionumber);
153
my $dat = &GetBiblioData($biblionumber);
154
154
155
#coping with subscriptions
155
#coping with subscriptions
(-)a/opac/opac-detail.pl (-15 / +14 lines)
Lines 155-174 SetUTF8Flag($record); Link Here
155
my $marcflavour      = C4::Context->preference("marcflavour");
155
my $marcflavour      = C4::Context->preference("marcflavour");
156
my $ean = GetNormalizedEAN( $record, $marcflavour );
156
my $ean = GetNormalizedEAN( $record, $marcflavour );
157
157
158
# XSLT processing of some stuff
159
my $xslfile = C4::Context->preference('OPACXSLTDetailsDisplay');
160
my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
161
my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
162
163
if ( $xslfile ) {
164
    $template->param(
165
        XSLTBloc => XSLTParse4Display(
166
                        $biblionumber, $record, "OPACXSLTDetailsDisplay",
167
                        1, undef, $sysxml, $xslfile, $lang
168
                    )
169
    );
170
}
171
172
my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
158
my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
173
$template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
159
$template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
174
160
Lines 502-507 if ($hideitems) { Link Here
502
    @items = @all_items;
488
    @items = @all_items;
503
}
489
}
504
490
491
# XSLT processing of some stuff
492
my $xslfile = C4::Context->preference('OPACXSLTDetailsDisplay');
493
my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
494
my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
495
496
if ( $xslfile ) {
497
    $template->param(
498
        XSLTBloc => XSLTParse4Display(
499
                        $biblionumber, $record, "OPACXSLTDetailsDisplay", \@items,
500
                        1, $sysxml, $xslfile, $lang
501
                    )
502
    );
503
}
504
505
my $branch = '';
505
my $branch = '';
506
if (C4::Context->userenv){
506
if (C4::Context->userenv){
507
    $branch = C4::Context->userenv->{branch};
507
    $branch = C4::Context->userenv->{branch};
508
- 

Return to bug 11213