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

(-)a/C4/Items.pm (-3 / +22 lines)
Lines 1261-1270 sub GetItemsByBiblioitemnumber { Link Here
1261
1261
1262
=head2 GetItemsInfo
1262
=head2 GetItemsInfo
1263
1263
1264
  @results = GetItemsInfo($biblionumber);
1264
  @results = GetItemsInfo($biblionumber, $order_by);
1265
1265
1266
Returns information about items with the given biblionumber.
1266
Returns information about items with the given biblionumber.
1267
1267
1268
The list is ordered by home branch name and some complex criteria
1269
within it (see the code), unless $order_by is specified.
1270
Currently only "cn_sort" is supported.
1271
1268
C<GetItemsInfo> returns a list of references-to-hash. Each element
1272
C<GetItemsInfo> returns a list of references-to-hash. Each element
1269
contains a number of keys. Most of them are attributes from the
1273
contains a number of keys. Most of them are attributes from the
1270
C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
1274
C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
Lines 1302-1308 If this is set, it is set to C<One Order>. Link Here
1302
=cut
1306
=cut
1303
1307
1304
sub GetItemsInfo {
1308
sub GetItemsInfo {
1305
    my ( $biblionumber ) = @_;
1309
    my ( $biblionumber, $order_by ) = @_;
1310
1306
    my $dbh   = C4::Context->dbh;
1311
    my $dbh   = C4::Context->dbh;
1307
    # note biblioitems.* must be avoided to prevent large marc and marcxml fields from killing performance.
1312
    # note biblioitems.* must be avoided to prevent large marc and marcxml fields from killing performance.
1308
    require C4::Languages;
1313
    require C4::Languages;
Lines 1358-1364 sub GetItemsInfo { Link Here
1358
        AND localization.lang = ?
1363
        AND localization.lang = ?
1359
    |;
1364
    |;
1360
1365
1361
    $query .= " WHERE items.biblionumber = ? ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
1366
    $query .= " WHERE items.biblionumber = ? ORDER BY ";
1367
    my $order_by_cause = "home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
1368
    if ($order_by) {
1369
        if ($order_by eq 'cn_sort') {
1370
            $order_by_cause = "cn_sort ASC";
1371
        }
1372
        else {
1373
            warn qq{Unsupported order by "$order_by"};
1374
        }
1375
    }
1376
    $query .= $order_by_cause;
1377
1362
    my $sth = $dbh->prepare($query);
1378
    my $sth = $dbh->prepare($query);
1363
    $sth->execute($language, $biblionumber);
1379
    $sth->execute($language, $biblionumber);
1364
    my $i = 0;
1380
    my $i = 0;
Lines 1391-1396 sub GetItemsInfo { Link Here
1391
        $av = Koha::AuthorisedValues->search_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.stack', authorised_value => $data->{stack} });
1407
        $av = Koha::AuthorisedValues->search_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.stack', authorised_value => $data->{stack} });
1392
        $data->{stack}          = $av->count ? $av->next->lib : '';
1408
        $data->{stack}          = $av->count ? $av->next->lib : '';
1393
1409
1410
        $data->{location_intranet} = GetKohaAuthorisedValueLib('LOC', $data->{location});
1411
        $data->{location_opac}     = GetKohaAuthorisedValueLib('LOC', $data->{location}, 1);
1412
1394
        # Find the last 3 people who borrowed this item.
1413
        # Find the last 3 people who borrowed this item.
1395
        my $sth2 = $dbh->prepare("SELECT * FROM old_issues,borrowers
1414
        my $sth2 = $dbh->prepare("SELECT * FROM old_issues,borrowers
1396
                                    WHERE itemnumber = ?
1415
                                    WHERE itemnumber = ?
(-)a/C4/Search.pm (-14 / +5 lines)
Lines 2037-2043 sub searchResults { Link Here
2037
        my $items_count           = scalar(@fields);
2037
        my $items_count           = scalar(@fields);
2038
        my $maxitems_pref = C4::Context->preference('maxItemsinSearchResults');
2038
        my $maxitems_pref = C4::Context->preference('maxItemsinSearchResults');
2039
        my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1;
2039
        my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1;
2040
        my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref
2041
2040
2042
        # loop through every item
2041
        # loop through every item
2043
        foreach my $field (@fields) {
2042
        foreach my $field (@fields) {
Lines 2059-2065 sub searchResults { Link Here
2059
                # hidden based on OpacHiddenItems syspref
2058
                # hidden based on OpacHiddenItems syspref
2060
                my @hi = C4::Items::GetHiddenItemnumbers($item);
2059
                my @hi = C4::Items::GetHiddenItemnumbers($item);
2061
                if (scalar @hi) {
2060
                if (scalar @hi) {
2062
                    push @hiddenitems, @hi;
2063
                    $hideatopac_count++;
2061
                    $hideatopac_count++;
2064
                    next;
2062
                    next;
2065
                }
2063
                }
Lines 2076-2082 sub searchResults { Link Here
2076
                $item->{'branchname'} = $branches{$item->{$otherbranch}};
2074
                $item->{'branchname'} = $branches{$item->{$otherbranch}};
2077
            }
2075
            }
2078
2076
2079
			my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber};
2077
            my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber};
2080
# For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item
2078
# For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item
2081
            my $userenv = C4::Context->userenv;
2079
            my $userenv = C4::Context->userenv;
2082
            if ( $item->{onloan}
2080
            if ( $item->{onloan}
Lines 2084-2095 sub searchResults { Link Here
2084
            {
2082
            {
2085
                $onloan_count++;
2083
                $onloan_count++;
2086
                my $key = $prefix . $item->{onloan} . $item->{barcode};
2084
                my $key = $prefix . $item->{onloan} . $item->{barcode};
2085
                $onloan_items->{$key} = { %$item };
2087
                $onloan_items->{$key}->{due_date} = output_pref( { dt => dt_from_string( $item->{onloan} ), dateonly => 1 } );
2086
                $onloan_items->{$key}->{due_date} = output_pref( { dt => dt_from_string( $item->{onloan} ), dateonly => 1 } );
2088
                $onloan_items->{$key}->{count}++ if $item->{$hbranch};
2087
                $onloan_items->{$key}->{count}++ if $item->{$hbranch};
2089
                $onloan_items->{$key}->{branchname}     = $item->{branchname};
2090
                $onloan_items->{$key}->{location}       = $shelflocations->{ $item->{location} };
2088
                $onloan_items->{$key}->{location}       = $shelflocations->{ $item->{location} };
2091
                $onloan_items->{$key}->{itemcallnumber} = $item->{itemcallnumber};
2092
                $onloan_items->{$key}->{description}    = $item->{description};
2093
                $onloan_items->{$key}->{imageurl} =
2089
                $onloan_items->{$key}->{imageurl} =
2094
                  getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2090
                  getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2095
2091
Lines 2175-2199 sub searchResults { Link Here
2175
                    $other_count++;
2171
                    $other_count++;
2176
2172
2177
                    my $key = $prefix . $item->{status};
2173
                    my $key = $prefix . $item->{status};
2178
                    foreach (qw(withdrawn itemlost damaged branchname itemcallnumber)) {
2174
                    $other_items->{$key} = { %$item };
2179
                        $other_items->{$key}->{$_} = $item->{$_};
2180
                    }
2181
                    $other_items->{$key}->{intransit} = ( $transfertwhen ne '' ) ? 1 : 0;
2175
                    $other_items->{$key}->{intransit} = ( $transfertwhen ne '' ) ? 1 : 0;
2182
                    $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0;
2176
                    $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0;
2183
                    $other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value and $item->{notforloan};
2177
                    $other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value and $item->{notforloan};
2184
					$other_items->{$key}->{count}++ if $item->{$hbranch};
2178
					$other_items->{$key}->{count}++ if $item->{$hbranch};
2185
					$other_items->{$key}->{location} = $shelflocations->{ $item->{location} };
2179
					$other_items->{$key}->{location} = $shelflocations->{ $item->{location} };
2186
					$other_items->{$key}->{description} = $item->{description};
2187
					$other_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2180
					$other_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2188
                }
2181
                }
2189
                # item is available
2182
                # item is available
2190
                else {
2183
                else {
2191
                    $can_place_holds = 1;
2184
                    $can_place_holds = 1;
2192
                    $available_count++;
2185
                    $available_count++;
2186
                    $available_items->{$prefix} = { %$item };
2193
					$available_items->{$prefix}->{count}++ if $item->{$hbranch};
2187
					$available_items->{$prefix}->{count}++ if $item->{$hbranch};
2194
					foreach (qw(branchname itemcallnumber description)) {
2195
                    	$available_items->{$prefix}->{$_} = $item->{$_};
2196
					}
2197
					$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} };
2188
					$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} };
2198
					$available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2189
					$available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2199
                }
2190
                }
Lines 2222-2228 sub searchResults { Link Here
2222
        # XSLT processing of some stuff
2213
        # XSLT processing of some stuff
2223
        # we fetched the sysprefs already before the loop through all retrieved record!
2214
        # we fetched the sysprefs already before the loop through all retrieved record!
2224
        if (!$scan && $xslfile) {
2215
        if (!$scan && $xslfile) {
2225
            $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, 1, \@hiddenitems, $sysxml, $xslfile, $lang);
2216
            $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, [@available_items_loop, @onloan_items_loop, @other_items_loop], 1, $sysxml, $xslfile, $lang);
2226
        # the last parameter tells Koha to clean up the problematic ampersand entities that Zebra outputs
2217
        # the last parameter tells Koha to clean up the problematic ampersand entities that Zebra outputs
2227
        }
2218
        }
2228
2219
(-)a/C4/XSLT.pm (-10 / +12 lines)
Lines 186-193 sub get_xslt_sysprefs { Link Here
186
    return $sysxml;
186
    return $sysxml;
187
}
187
}
188
188
189
=head2 XSLTParse4Display( $biblionumber, $orig_record, $xslsyspref, $items, $fixamps, $sysxml, $xslfilename, $lang )
190
191
  $items => an array of items rerords, as returned from eg. GetItemsInfo
192
193
Returns XSLT block
194
195
=cut
196
189
sub XSLTParse4Display {
197
sub XSLTParse4Display {
190
    my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $sysxml, $xslfilename, $lang ) = @_;
198
    my ( $biblionumber, $orig_record, $xslsyspref, $items, $fixamps, $sysxml, $xslfilename, $lang ) = @_;
191
199
192
    $sysxml ||= C4::Context->preference($xslsyspref);
200
    $sysxml ||= C4::Context->preference($xslsyspref);
193
    $xslfilename ||= C4::Context->preference($xslsyspref);
201
    $xslfilename ||= C4::Context->preference($xslsyspref);
Lines 239-245 sub XSLTParse4Display { Link Here
239
247
240
    # grab the XML, run it through our stylesheet, push it out to the browser
248
    # grab the XML, run it through our stylesheet, push it out to the browser
241
    my $record = transformMARCXML4XSLT($biblionumber, $orig_record);
249
    my $record = transformMARCXML4XSLT($biblionumber, $orig_record);
242
    my $itemsxml  = buildKohaItemsNamespace($biblionumber, $hidden_items);
250
    my $itemsxml  = $items ? buildKohaItemsNamespace($biblionumber, $items) : "";
243
    my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
251
    my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
244
252
245
    $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml\<\/record\>/;
253
    $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml\<\/record\>/;
Lines 265-277 Is only used in this module currently. Link Here
265
=cut
273
=cut
266
274
267
sub buildKohaItemsNamespace {
275
sub buildKohaItemsNamespace {
268
    my ($biblionumber, $hidden_items) = @_;
276
    my ($biblionumber, $items) = @_;
269
270
    my @items = C4::Items::GetItemsInfo($biblionumber);
271
    if ($hidden_items && @$hidden_items) {
272
        my %hi = map {$_ => 1} @$hidden_items;
273
        @items = grep { !$hi{$_->{itemnumber}} } @items;
274
    }
275
277
276
    my $shelflocations =
278
    my $shelflocations =
277
      { map { $_->authorised_value => $_->opac_description } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => GetFrameworkCode($biblionumber), kohafield => 'items.location' } ) };
279
      { map { $_->authorised_value => $_->opac_description } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => GetFrameworkCode($biblionumber), kohafield => 'items.location' } ) };
Lines 284-290 sub buildKohaItemsNamespace { Link Here
284
    my $location = "";
286
    my $location = "";
285
    my $ccode = "";
287
    my $ccode = "";
286
    my $xml = '';
288
    my $xml = '';
287
    for my $item (@items) {
289
    for my $item (@$items) {
288
        my $status;
290
        my $status;
289
291
290
        my ( $transfertwhen, $transfertfrom, $transfertto ) = C4::Circulation::GetTransfers($item->{itemnumber});
292
        my ( $transfertwhen, $transfertfrom, $transfertto ) = C4::Circulation::GetTransfers($item->{itemnumber});
(-)a/catalogue/detail.pl (-15 / +15 lines)
Lines 84-104 my $fw = GetFrameworkCode($biblionumber); Link Here
84
my $showallitems = $query->param('showallitems');
84
my $showallitems = $query->param('showallitems');
85
my $marcflavour  = C4::Context->preference("marcflavour");
85
my $marcflavour  = C4::Context->preference("marcflavour");
86
86
87
# XSLT processing of some stuff
88
my $xslfile = C4::Context->preference('XSLTDetailsDisplay');
89
my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
90
my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
91
92
if ( $xslfile ) {
93
    $template->param(
94
        XSLTDetailsDisplay => '1',
95
        XSLTBloc => XSLTParse4Display(
96
                        $biblionumber, $record, "XSLTDetailsDisplay",
97
                        1, undef, $sysxml, $xslfile, $lang
98
                    )
99
    );
100
}
101
102
$template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
87
$template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
103
$template->param( ocoins => GetCOinSBiblio($record) );
88
$template->param( ocoins => GetCOinSBiblio($record) );
104
89
Lines 145-150 if (@hostitems){ Link Here
145
	push (@items,@hostitems);
130
	push (@items,@hostitems);
146
}
131
}
147
132
133
# XSLT processing of some stuff
134
my $xslfile = C4::Context->preference('XSLTDetailsDisplay');
135
my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
136
my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
137
138
if ( $xslfile ) {
139
    $template->param(
140
        XSLTDetailsDisplay => '1',
141
        XSLTBloc => XSLTParse4Display(
142
                        $biblionumber, $record, "XSLTDetailsDisplay", \@all_items,
143
                        1, $sysxml, $xslfile, $lang
144
                    )
145
    );
146
}
147
148
my $dat = &GetBiblioData($biblionumber);
148
my $dat = &GetBiblioData($biblionumber);
149
149
150
#coping with subscriptions
150
#coping with subscriptions
(-)a/opac/opac-detail.pl (-15 / +14 lines)
Lines 148-167 SetUTF8Flag($record); Link Here
148
my $marcflavour      = C4::Context->preference("marcflavour");
148
my $marcflavour      = C4::Context->preference("marcflavour");
149
my $ean = GetNormalizedEAN( $record, $marcflavour );
149
my $ean = GetNormalizedEAN( $record, $marcflavour );
150
150
151
# XSLT processing of some stuff
152
my $xslfile = C4::Context->preference('OPACXSLTDetailsDisplay');
153
my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
154
my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
155
156
if ( $xslfile ) {
157
    $template->param(
158
        XSLTBloc => XSLTParse4Display(
159
                        $biblionumber, $record, "OPACXSLTDetailsDisplay",
160
                        1, undef, $sysxml, $xslfile, $lang
161
                    )
162
    );
163
}
164
165
my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
151
my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
166
$template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
152
$template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
167
153
Lines 496-501 if ($hideitems) { Link Here
496
    @items = @all_items;
482
    @items = @all_items;
497
}
483
}
498
484
485
# XSLT processing of some stuff
486
my $xslfile = C4::Context->preference('OPACXSLTDetailsDisplay');
487
my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
488
my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
489
490
if ( $xslfile ) {
491
    $template->param(
492
        XSLTBloc => XSLTParse4Display(
493
                        $biblionumber, $record, "OPACXSLTDetailsDisplay", \@items,
494
                        1, $sysxml, $xslfile, $lang
495
                    )
496
    );
497
}
498
499
my $branch = '';
499
my $branch = '';
500
if (C4::Context->userenv){
500
if (C4::Context->userenv){
501
    $branch = C4::Context->userenv->{branch};
501
    $branch = C4::Context->userenv->{branch};
502
- 

Return to bug 11213