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

(-)a/C4/Items.pm (-69 / +22 lines)
Lines 69-75 BEGIN { Link Here
69
        GetItemInfosOf
69
        GetItemInfosOf
70
        GetItemsByBiblioitemnumber
70
        GetItemsByBiblioitemnumber
71
        GetItemsInfo
71
        GetItemsInfo
72
	GetItemsLocationInfo
73
	GetHostItemsInfo
72
	GetHostItemsInfo
74
        GetItemnumbersForBiblio
73
        GetItemnumbersForBiblio
75
        get_itemnumbers_of
74
        get_itemnumbers_of
Lines 1258-1267 sub GetItemsByBiblioitemnumber { Link Here
1258
1257
1259
=head2 GetItemsInfo
1258
=head2 GetItemsInfo
1260
1259
1261
  @results = GetItemsInfo($biblionumber);
1260
  @results = GetItemsInfo($biblionumber, $order_by);
1262
1261
1263
Returns information about items with the given biblionumber.
1262
Returns information about items with the given biblionumber.
1264
1263
1264
The list is ordered by home branch name and some complex criteria
1265
within it (see the code), unless $order_by is specified.
1266
Currently only "cn_sort" is supported.
1267
1265
C<GetItemsInfo> returns a list of references-to-hash. Each element
1268
C<GetItemsInfo> returns a list of references-to-hash. Each element
1266
contains a number of keys. Most of them are attributes from the
1269
contains a number of keys. Most of them are attributes from the
1267
C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
1270
C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
Lines 1299-1305 If this is set, it is set to C<One Order>. Link Here
1299
=cut
1302
=cut
1300
1303
1301
sub GetItemsInfo {
1304
sub GetItemsInfo {
1302
    my ( $biblionumber ) = @_;
1305
    my ( $biblionumber, $order_by ) = @_;
1306
1303
    my $dbh   = C4::Context->dbh;
1307
    my $dbh   = C4::Context->dbh;
1304
    # note biblioitems.* must be avoided to prevent large marc and marcxml fields from killing performance.
1308
    # note biblioitems.* must be avoided to prevent large marc and marcxml fields from killing performance.
1305
    require C4::Languages;
1309
    require C4::Languages;
Lines 1354-1360 sub GetItemsInfo { Link Here
1354
        AND localization.lang = ?
1358
        AND localization.lang = ?
1355
    |;
1359
    |;
1356
1360
1357
    $query .= " WHERE items.biblionumber = ? ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
1361
    $query .= " WHERE items.biblionumber = ? ORDER BY ";
1362
    my $order_by_cause = "home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
1363
    if ($order_by) {
1364
        if ($order_by eq 'cn_sort') {
1365
            $order_by_cause = "cn_sort ASC";
1366
        }
1367
        else {
1368
            warn qq{Unsupported order by "$order_by"};
1369
        }
1370
    }
1371
    $query .= $order_by_cause;
1372
1358
    my $sth = $dbh->prepare($query);
1373
    my $sth = $dbh->prepare($query);
1359
    $sth->execute($language, $biblionumber);
1374
    $sth->execute($language, $biblionumber);
1360
    my $i = 0;
1375
    my $i = 0;
Lines 1387-1392 sub GetItemsInfo { Link Here
1387
            $data->{stack}          = C4::Koha::GetKohaAuthorisedValueLib( $code, $data->{stack} );
1402
            $data->{stack}          = C4::Koha::GetKohaAuthorisedValueLib( $code, $data->{stack} );
1388
        }
1403
        }
1389
1404
1405
        $data->{location_intranet} = GetKohaAuthorisedValueLib('LOC', $data->{location});
1406
        $data->{location_opac}     = GetKohaAuthorisedValueLib('LOC', $data->{location}, 1);
1407
1390
        # Find the last 3 people who borrowed this item.
1408
        # Find the last 3 people who borrowed this item.
1391
        my $sth2 = $dbh->prepare("SELECT * FROM old_issues,borrowers
1409
        my $sth2 = $dbh->prepare("SELECT * FROM old_issues,borrowers
1392
                                    WHERE itemnumber = ?
1410
                                    WHERE itemnumber = ?
Lines 1411-1481 sub GetItemsInfo { Link Here
1411
        : @results;
1429
        : @results;
1412
}
1430
}
1413
1431
1414
=head2 GetItemsLocationInfo
1415
1416
  my @itemlocinfo = GetItemsLocationInfo($biblionumber);
1417
1418
Returns the branch names, shelving location and itemcallnumber for each item attached to the biblio in question
1419
1420
C<GetItemsInfo> returns a list of references-to-hash. Data returned:
1421
1422
=over 2
1423
1424
=item C<$data-E<gt>{homebranch}>
1425
1426
Branch Name of the item's homebranch
1427
1428
=item C<$data-E<gt>{holdingbranch}>
1429
1430
Branch Name of the item's holdingbranch
1431
1432
=item C<$data-E<gt>{location}>
1433
1434
Item's shelving location code
1435
1436
=item C<$data-E<gt>{location_intranet}>
1437
1438
The intranet description for the Shelving Location as set in authorised_values 'LOC'
1439
1440
=item C<$data-E<gt>{location_opac}>
1441
1442
The OPAC description for the Shelving Location as set in authorised_values 'LOC'.  Falls back to intranet description if no OPAC 
1443
description is set.
1444
1445
=item C<$data-E<gt>{itemcallnumber}>
1446
1447
Item's itemcallnumber
1448
1449
=item C<$data-E<gt>{cn_sort}>
1450
1451
Item's call number normalized for sorting
1452
1453
=back
1454
  
1455
=cut
1456
1457
sub GetItemsLocationInfo {
1458
        my $biblionumber = shift;
1459
        my @results;
1460
1461
	my $dbh = C4::Context->dbh;
1462
	my $query = "SELECT a.branchname as homebranch, b.branchname as holdingbranch, 
1463
			    location, itemcallnumber, cn_sort
1464
		     FROM items, branches as a, branches as b
1465
		     WHERE homebranch = a.branchcode AND holdingbranch = b.branchcode 
1466
		     AND biblionumber = ?
1467
		     ORDER BY cn_sort ASC";
1468
	my $sth = $dbh->prepare($query);
1469
        $sth->execute($biblionumber);
1470
1471
        while ( my $data = $sth->fetchrow_hashref ) {
1472
             $data->{location_intranet} = GetKohaAuthorisedValueLib('LOC', $data->{location});
1473
             $data->{location_opac}= GetKohaAuthorisedValueLib('LOC', $data->{location}, 1);
1474
	     push @results, $data;
1475
	}
1476
	return @results;
1477
}
1478
1479
=head2 GetHostItemsInfo
1432
=head2 GetHostItemsInfo
1480
1433
1481
	$hostiteminfo = GetHostItemsInfo($hostfield);
1434
	$hostiteminfo = GetHostItemsInfo($hostfield);
(-)a/C4/Search.pm (-14 / +5 lines)
Lines 2007-2013 sub searchResults { Link Here
2007
        my $items_count           = scalar(@fields);
2007
        my $items_count           = scalar(@fields);
2008
        my $maxitems_pref = C4::Context->preference('maxItemsinSearchResults');
2008
        my $maxitems_pref = C4::Context->preference('maxItemsinSearchResults');
2009
        my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1;
2009
        my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1;
2010
        my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref
2011
2010
2012
        # loop through every item
2011
        # loop through every item
2013
        foreach my $field (@fields) {
2012
        foreach my $field (@fields) {
Lines 2029-2035 sub searchResults { Link Here
2029
                # hidden based on OpacHiddenItems syspref
2028
                # hidden based on OpacHiddenItems syspref
2030
                my @hi = C4::Items::GetHiddenItemnumbers($item);
2029
                my @hi = C4::Items::GetHiddenItemnumbers($item);
2031
                if (scalar @hi) {
2030
                if (scalar @hi) {
2032
                    push @hiddenitems, @hi;
2033
                    $hideatopac_count++;
2031
                    $hideatopac_count++;
2034
                    next;
2032
                    next;
2035
                }
2033
                }
Lines 2046-2052 sub searchResults { Link Here
2046
                $item->{'branchname'} = $branches{$item->{$otherbranch}};
2044
                $item->{'branchname'} = $branches{$item->{$otherbranch}};
2047
            }
2045
            }
2048
2046
2049
			my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber};
2047
            my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber};
2050
# For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item
2048
# For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item
2051
            my $userenv = C4::Context->userenv;
2049
            my $userenv = C4::Context->userenv;
2052
            if ( $item->{onloan}
2050
            if ( $item->{onloan}
Lines 2054-2065 sub searchResults { Link Here
2054
            {
2052
            {
2055
                $onloan_count++;
2053
                $onloan_count++;
2056
                my $key = $prefix . $item->{onloan} . $item->{barcode};
2054
                my $key = $prefix . $item->{onloan} . $item->{barcode};
2055
                $onloan_items->{$key} = { %$item };
2057
                $onloan_items->{$key}->{due_date} = output_pref( { dt => dt_from_string( $item->{onloan} ), dateonly => 1 } );
2056
                $onloan_items->{$key}->{due_date} = output_pref( { dt => dt_from_string( $item->{onloan} ), dateonly => 1 } );
2058
                $onloan_items->{$key}->{count}++ if $item->{$hbranch};
2057
                $onloan_items->{$key}->{count}++ if $item->{$hbranch};
2059
                $onloan_items->{$key}->{branchname}     = $item->{branchname};
2060
                $onloan_items->{$key}->{location}       = $shelflocations->{ $item->{location} };
2058
                $onloan_items->{$key}->{location}       = $shelflocations->{ $item->{location} };
2061
                $onloan_items->{$key}->{itemcallnumber} = $item->{itemcallnumber};
2062
                $onloan_items->{$key}->{description}    = $item->{description};
2063
                $onloan_items->{$key}->{imageurl} =
2059
                $onloan_items->{$key}->{imageurl} =
2064
                  getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2060
                  getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2065
2061
Lines 2145-2169 sub searchResults { Link Here
2145
                    $other_count++;
2141
                    $other_count++;
2146
2142
2147
                    my $key = $prefix . $item->{status};
2143
                    my $key = $prefix . $item->{status};
2148
                    foreach (qw(withdrawn itemlost damaged branchname itemcallnumber)) {
2144
                    $other_items->{$key} = { %$item };
2149
                        $other_items->{$key}->{$_} = $item->{$_};
2150
                    }
2151
                    $other_items->{$key}->{intransit} = ( $transfertwhen ne '' ) ? 1 : 0;
2145
                    $other_items->{$key}->{intransit} = ( $transfertwhen ne '' ) ? 1 : 0;
2152
                    $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0;
2146
                    $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0;
2153
                    $other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value and $item->{notforloan};
2147
                    $other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value and $item->{notforloan};
2154
					$other_items->{$key}->{count}++ if $item->{$hbranch};
2148
					$other_items->{$key}->{count}++ if $item->{$hbranch};
2155
					$other_items->{$key}->{location} = $shelflocations->{ $item->{location} };
2149
					$other_items->{$key}->{location} = $shelflocations->{ $item->{location} };
2156
					$other_items->{$key}->{description} = $item->{description};
2157
					$other_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2150
					$other_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2158
                }
2151
                }
2159
                # item is available
2152
                # item is available
2160
                else {
2153
                else {
2161
                    $can_place_holds = 1;
2154
                    $can_place_holds = 1;
2162
                    $available_count++;
2155
                    $available_count++;
2156
                    $available_items->{$prefix} = { %$item };
2163
					$available_items->{$prefix}->{count}++ if $item->{$hbranch};
2157
					$available_items->{$prefix}->{count}++ if $item->{$hbranch};
2164
					foreach (qw(branchname itemcallnumber description)) {
2165
                    	$available_items->{$prefix}->{$_} = $item->{$_};
2166
					}
2167
					$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} };
2158
					$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} };
2168
					$available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2159
					$available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
2169
                }
2160
                }
Lines 2192-2198 sub searchResults { Link Here
2192
        # XSLT processing of some stuff
2183
        # XSLT processing of some stuff
2193
        my $interface = $search_context eq 'opac' ? 'OPAC' : '';
2184
        my $interface = $search_context eq 'opac' ? 'OPAC' : '';
2194
        if (!$scan && C4::Context->preference($interface . "XSLTResultsDisplay")) {
2185
        if (!$scan && C4::Context->preference($interface . "XSLTResultsDisplay")) {
2195
            $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $interface."XSLTResultsDisplay", 1, \@hiddenitems);
2186
            $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $interface."XSLTResultsDisplay", [@available_items_loop, @onloan_items_loop, @other_items_loop], 1);
2196
        # the last parameter tells Koha to clean up the problematic ampersand entities that Zebra outputs
2187
        # the last parameter tells Koha to clean up the problematic ampersand entities that Zebra outputs
2197
        }
2188
        }
2198
2189
(-)a/C4/XSLT.pm (-10 / +13 lines)
Lines 156-163 sub _get_best_default_xslt_filename { Link Here
156
    return $xslfilename;
156
    return $xslfilename;
157
}
157
}
158
158
159
=head2 XSLTParse4Display( $biblionumber, $orig_record, $xslsyspref, $items, $fixamps )
160
161
  $items => an array of items rerords, as returned from eg. GetItemsInfo
162
163
Returns XSLT block
164
165
=cut
166
159
sub XSLTParse4Display {
167
sub XSLTParse4Display {
160
    my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items ) = @_;
168
    my ( $biblionumber, $orig_record, $xslsyspref, $items, $fixamps ) = @_;
169
161
    my $xslfilename = C4::Context->preference($xslsyspref);
170
    my $xslfilename = C4::Context->preference($xslsyspref);
162
    if ( $xslfilename =~ /^\s*"?default"?\s*$/i ) {
171
    if ( $xslfilename =~ /^\s*"?default"?\s*$/i ) {
163
        my $htdocs;
172
        my $htdocs;
Lines 195-201 sub XSLTParse4Display { Link Here
195
204
196
    # grab the XML, run it through our stylesheet, push it out to the browser
205
    # grab the XML, run it through our stylesheet, push it out to the browser
197
    my $record = transformMARCXML4XSLT($biblionumber, $orig_record);
206
    my $record = transformMARCXML4XSLT($biblionumber, $orig_record);
198
    my $itemsxml  = buildKohaItemsNamespace($biblionumber, $hidden_items);
207
    my $itemsxml  = $items ? buildKohaItemsNamespace($biblionumber, $items) : "";
199
    my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
208
    my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
200
    my $sysxml = "<sysprefs>\n";
209
    my $sysxml = "<sysprefs>\n";
201
    foreach my $syspref ( qw/ hidelostitems OPACURLOpenInNewWindow
210
    foreach my $syspref ( qw/ hidelostitems OPACURLOpenInNewWindow
Lines 242-254 Is only used in this module currently. Link Here
242
=cut
251
=cut
243
252
244
sub buildKohaItemsNamespace {
253
sub buildKohaItemsNamespace {
245
    my ($biblionumber, $hidden_items) = @_;
254
    my ($biblionumber, $items) = @_;
246
247
    my @items = C4::Items::GetItemsInfo($biblionumber);
248
    if ($hidden_items && @$hidden_items) {
249
        my %hi = map {$_ => 1} @$hidden_items;
250
        @items = grep { !$hi{$_->{itemnumber}} } @items;
251
    }
252
255
253
    my $shelflocations = GetKohaAuthorisedValues('items.location',GetFrameworkCode($biblionumber), 'opac');
256
    my $shelflocations = GetKohaAuthorisedValues('items.location',GetFrameworkCode($biblionumber), 'opac');
254
    my $ccodes         = GetKohaAuthorisedValues('items.ccode',GetFrameworkCode($biblionumber), 'opac');
257
    my $ccodes         = GetKohaAuthorisedValues('items.ccode',GetFrameworkCode($biblionumber), 'opac');
Lines 258-264 sub buildKohaItemsNamespace { Link Here
258
    my $location = "";
261
    my $location = "";
259
    my $ccode = "";
262
    my $ccode = "";
260
    my $xml = '';
263
    my $xml = '';
261
    for my $item (@items) {
264
    for my $item (@$items) {
262
        my $status;
265
        my $status;
263
266
264
        my ( $transfertwhen, $transfertfrom, $transfertto ) = C4::Circulation::GetTransfers($item->{itemnumber});
267
        my ( $transfertwhen, $transfertfrom, $transfertto ) = C4::Circulation::GetTransfers($item->{itemnumber});
(-)a/catalogue/detail.pl (-6 / +6 lines)
Lines 83-94 my $fw = GetFrameworkCode($biblionumber); Link Here
83
my $showallitems = $query->param('showallitems');
83
my $showallitems = $query->param('showallitems');
84
my $marcflavour  = C4::Context->preference("marcflavour");
84
my $marcflavour  = C4::Context->preference("marcflavour");
85
85
86
# XSLT processing of some stuff
87
if (C4::Context->preference("XSLTDetailsDisplay") ) {
88
    $template->param('XSLTDetailsDisplay' =>'1',
89
        'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "XSLTDetailsDisplay") );
90
}
91
92
$template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
86
$template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
93
$template->param( ocoins => GetCOinSBiblio($record) );
87
$template->param( ocoins => GetCOinSBiblio($record) );
94
88
Lines 136-141 if (@hostitems){ Link Here
136
	push (@items,@hostitems);
130
	push (@items,@hostitems);
137
}
131
}
138
132
133
# XSLT processing of some stuff
134
if (C4::Context->preference("XSLTDetailsDisplay") ) {
135
    $template->param('XSLTDetailsDisplay' =>'1',
136
        'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "XSLTDetailsDisplay", \@all_items) );
137
}
138
139
my $dat = &GetBiblioData($biblionumber);
139
my $dat = &GetBiblioData($biblionumber);
140
140
141
#coping with subscriptions
141
#coping with subscriptions
(-)a/opac/opac-detail.pl (-6 / +5 lines)
Lines 140-150 SetUTF8Flag($record); Link Here
140
my $marcflavour      = C4::Context->preference("marcflavour");
140
my $marcflavour      = C4::Context->preference("marcflavour");
141
my $ean = GetNormalizedEAN( $record, $marcflavour );
141
my $ean = GetNormalizedEAN( $record, $marcflavour );
142
142
143
# XSLT processing of some stuff
144
if (C4::Context->preference("OPACXSLTDetailsDisplay") ) {
145
    $template->param( 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "OPACXSLTDetailsDisplay" ) );
146
}
147
148
my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
143
my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
149
$template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
144
$template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
150
145
Lines 480-485 if ($hideitems) { Link Here
480
    @items = @all_items;
475
    @items = @all_items;
481
}
476
}
482
477
478
# XSLT processing of some stuff
479
if (C4::Context->preference("OPACXSLTDetailsDisplay") ) {
480
    $template->param( 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "OPACXSLTDetailsDisplay", \@items) );
481
}
482
483
my $branches = GetBranches();
483
my $branches = GetBranches();
484
my $branch = '';
484
my $branch = '';
485
if (C4::Context->userenv){
485
if (C4::Context->userenv){
486
- 

Return to bug 11213