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

(-)a/C4/Reserves.pm (-3 / +10 lines)
Lines 743-755 sub GetReserveStatus { Link Here
743
743
744
    my $dbh = C4::Context->dbh;
744
    my $dbh = C4::Context->dbh;
745
745
746
    my ($sth, $found, $priority);
746
    my ($sth, $found, $priority, $pending);
747
    if ( $itemnumber ) {
747
    if ( $itemnumber ) {
748
        $sth = $dbh->prepare("SELECT found, priority FROM reserves WHERE itemnumber = ? order by priority LIMIT 1");
748
        $sth = $dbh->prepare(q{
749
                SELECT found, priority, IF( tmp_holdsqueue.itemnumber IS NULL, 0, 1) AS pending
750
                FROM reserves
751
                LEFT JOIN tmp_holdsqueue USING (itemnumber)
752
                WHERE itemnumber = ? order by priority LIMIT 1
753
        });
749
        $sth->execute($itemnumber);
754
        $sth->execute($itemnumber);
750
        ($found, $priority) = $sth->fetchrow_array;
755
        ($found, $priority, $pending) = $sth->fetchrow_array;
751
    }
756
    }
752
757
758
    return 'Pending' if $pending;
759
753
    if(defined $found) {
760
    if(defined $found) {
754
        return 'Waiting'  if $found eq 'W' and $priority == 0;
761
        return 'Waiting'  if $found eq 'W' and $priority == 0;
755
        return 'Processing'  if $found eq 'P';
762
        return 'Processing'  if $found eq 'P';
(-)a/C4/Search.pm (-9 / +19 lines)
Lines 1608-1622 sub searchResults { Link Here
1608
    #Build branchnames hash
1608
    #Build branchnames hash
1609
    my %branches = map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' });
1609
    my %branches = map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' });
1610
1610
1611
# FIXME - We build an authorised values hash here, using the default framework
1611
    my $description = $is_opac ? 'opac_description' : 'lib';
1612
# though it is possible to have different authvals for different fws.
1613
1614
    my $shelflocations =
1612
    my $shelflocations =
1615
      { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' } ) };
1613
      { map { $_->{authorised_value} => $_->{$description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' } ) };
1614
    my $ccodes = { map { $_->{authorised_value} => $_->{$description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => "", kohafield => 'items.ccode' } ) };
1616
1615
1617
    # get notforloan authorised value list (see $shelflocations  FIXME)
1616
    # get notforloan authorised value list (see $shelflocations  FIXME)
1618
    my $av = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.notforloan', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
1617
    my $av = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.notforloan', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
1619
    my $notforloan_authorised_value = $av->count ? $av->next->authorised_value : undef;
1618
    my $notforloan_authorised_value = $av->count ? $av->next->authorised_value : undef;
1619
    my $notforloan_descriptions = { map { $_->{authorised_value} => $_->{$description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { kohafield => 'items.notforloan' } ) };
1620
1620
1621
1621
    #Get itemtype hash
1622
    #Get itemtype hash
1622
    my $itemtypes = Koha::ItemTypes->search_with_localization;
1623
    my $itemtypes = Koha::ItemTypes->search_with_localization;
Lines 1814-1819 sub searchResults { Link Here
1814
        my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref
1815
        my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref
1815
1816
1816
        # loop through every item
1817
        # loop through every item
1818
        my @items = ();
1817
        foreach my $field (@fields) {
1819
        foreach my $field (@fields) {
1818
            my $item;
1820
            my $item;
1819
1821
Lines 1849-1854 sub searchResults { Link Here
1849
            elsif ($item->{$otherbranch}) {	# Last resort
1851
            elsif ($item->{$otherbranch}) {	# Last resort
1850
                $item->{'branchname'} = $branches{$item->{$otherbranch}};
1852
                $item->{'branchname'} = $branches{$item->{$otherbranch}};
1851
            }
1853
            }
1854
            $item->{homebranch} = $branches{ $item->{homebranch} } if defined $item->{homebranch};
1855
            $item->{holdingbranch} = $branches{ $item->{holdingbranch} } if defined $item->{holdingbranch};
1852
1856
1853
            my $prefix =
1857
            my $prefix =
1854
                ( $item->{$hbranch} ? $item->{$hbranch} . '--' : q{} )
1858
                ( $item->{$hbranch} ? $item->{$hbranch} . '--' : q{} )
Lines 1856-1861 sub searchResults { Link Here
1856
              . ( $item->{itype}    ? $item->{itype}    : q{} )
1860
              . ( $item->{itype}    ? $item->{itype}    : q{} )
1857
              . ( $item->{itemcallnumber} ? $item->{itemcallnumber} : q{} );
1861
              . ( $item->{itemcallnumber} ? $item->{itemcallnumber} : q{} );
1858
# For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item
1862
# For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item
1863
            my $itemtype = C4::Context->preference("item-level_itypes")? $item->{itype}: $oldbiblio->{itemtype};
1864
            $item->{itemtype} = $itemtype;
1865
            $item->{location} = $item->{location} && exists $shelflocations->{$item->{location}} ? $shelflocations->{$item->{location}} : $item->{location} ;
1866
            $item->{notforloan_description} = exists $notforloan_descriptions->{ $item->{notforloan} } ? $notforloan_descriptions->{ $item->{notforloan} } : "Not for loan";
1867
            $item->{ccode_description} = defined $item->{ccode} && exists $ccodes->{ $item->{ccode} } ? $ccodes->{ $item->{ccode} } :  $item->{ccode};
1868
            $item->{notforloan_itemtype} = defined $itemtype && exists $itemtypes{ $itemtype } ? $itemtypes{ $itemtype }->{notforloan} : undef;
1859
            if ( $item->{onloan}
1869
            if ( $item->{onloan}
1860
                and $logged_in_user
1870
                and $logged_in_user
1861
                and !( $patron_category_hide_lost_items and $item->{itemlost} ) )
1871
                and !( $patron_category_hide_lost_items and $item->{itemlost} ) )
Lines 1865-1871 sub searchResults { Link Here
1865
                $onloan_items->{$key}->{due_date} = $item->{onloan};
1875
                $onloan_items->{$key}->{due_date} = $item->{onloan};
1866
                $onloan_items->{$key}->{count}++ if $item->{$hbranch};
1876
                $onloan_items->{$key}->{count}++ if $item->{$hbranch};
1867
                $onloan_items->{$key}->{branchname}     = $item->{branchname};
1877
                $onloan_items->{$key}->{branchname}     = $item->{branchname};
1868
                $onloan_items->{$key}->{location}       = $shelflocations->{ $item->{location} } if $item->{location};
1878
                $onloan_items->{$key}->{location}       = $item->{location} if $item->{location};
1869
                $onloan_items->{$key}->{itemcallnumber} = $item->{itemcallnumber};
1879
                $onloan_items->{$key}->{itemcallnumber} = $item->{itemcallnumber};
1870
                $onloan_items->{$key}->{description}    = $item->{description};
1880
                $onloan_items->{$key}->{description}    = $item->{description};
1871
                $onloan_items->{$key}->{imageurl} =
1881
                $onloan_items->{$key}->{imageurl} =
Lines 1884-1890 sub searchResults { Link Here
1884
         # items not on loan, but still unavailable ( lost, withdrawn, damaged )
1894
         # items not on loan, but still unavailable ( lost, withdrawn, damaged )
1885
            else {
1895
            else {
1886
1896
1887
                my $itemtype = C4::Context->preference("item-level_itypes")? $item->{itype}: $oldbiblio->{itemtype};
1888
                $item->{notforloan} = 1 if !$item->{notforloan} &&
1897
                $item->{notforloan} = 1 if !$item->{notforloan} &&
1889
                    $itemtype && $itemtypes{ $itemtype }->{notforloan};
1898
                    $itemtype && $itemtypes{ $itemtype }->{notforloan};
1890
1899
Lines 1962-1968 sub searchResults { Link Here
1962
                    $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0;
1971
                    $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0;
1963
                    $other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value and $item->{notforloan};
1972
                    $other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value and $item->{notforloan};
1964
                    $other_items->{$key}->{count}++ if $item->{$hbranch};
1973
                    $other_items->{$key}->{count}++ if $item->{$hbranch};
1965
                    $other_items->{$key}->{location} = $shelflocations->{ $item->{location} } if $item->{location};
1974
                    $other_items->{$key}->{location} = $item->{location} if $item->{location};
1966
                    $other_items->{$key}->{description} = $item->{description};
1975
                    $other_items->{$key}->{description} = $item->{description};
1967
                    $other_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context->{'interface'}, $itemtypes{ $item->{itype}//q{} }->{imageurl} );
1976
                    $other_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context->{'interface'}, $itemtypes{ $item->{itype}//q{} }->{imageurl} );
1968
                }
1977
                }
Lines 1974-1983 sub searchResults { Link Here
1974
                    foreach (qw(branchname itemcallnumber description)) {
1983
                    foreach (qw(branchname itemcallnumber description)) {
1975
                        $available_items->{$prefix}->{$_} = $item->{$_};
1984
                        $available_items->{$prefix}->{$_} = $item->{$_};
1976
                    }
1985
                    }
1977
                    $available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} } if $item->{location};
1986
                    $available_items->{$prefix}->{location} = $item->{location} if $item->{location};
1978
                    $available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context->{'interface'}, $itemtypes{ $item->{itype}//q{} }->{imageurl} );
1987
                    $available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context->{'interface'}, $itemtypes{ $item->{itype}//q{} }->{imageurl} );
1979
                }
1988
                }
1980
            }
1989
            }
1990
            push @items, $item;
1981
        }    # notforloan, item level and biblioitem level
1991
        }    # notforloan, item level and biblioitem level
1982
1992
1983
        # if all items are hidden, do not show the record
1993
        # if all items are hidden, do not show the record
Lines 2008-2014 sub searchResults { Link Here
2008
            });
2018
            });
2009
2019
2010
            $record_processor->process($marcrecord);
2020
            $record_processor->process($marcrecord);
2011
            $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, 1, \@hiddenitems, $sysxml, $xslfile, $lang, $xslt_variables);
2021
            $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, 1, \@hiddenitems, $sysxml, $xslfile, $lang, $xslt_variables, \@items );
2012
        }
2022
        }
2013
2023
2014
        # if biblio level itypes are used and itemtype is notforloan, it can't be reserved either
2024
        # if biblio level itypes are used and itemtype is notforloan, it can't be reserved either
(-)a/C4/XSLT.pm (-52 / +27 lines)
Lines 190-196 sub get_xslt_sysprefs { Link Here
190
}
190
}
191
191
192
sub XSLTParse4Display {
192
sub XSLTParse4Display {
193
    my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $sysxml, $xslfilename, $lang, $variables, $items_rs ) = @_;
193
    my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $sysxml, $xslfilename, $lang, $variables, $items ) = @_;
194
194
195
    $sysxml ||= C4::Context->preference($xslsyspref);
195
    $sysxml ||= C4::Context->preference($xslsyspref);
196
    $xslfilename ||= C4::Context->preference($xslsyspref);
196
    $xslfilename ||= C4::Context->preference($xslsyspref);
Lines 246-252 sub XSLTParse4Display { Link Here
246
    if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" || $xslsyspref eq "XSLTResultsDisplay" ) {
246
    if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" || $xslsyspref eq "XSLTResultsDisplay" ) {
247
        $itemsxml = ""; #We don't use XSLT for items display on these pages
247
        $itemsxml = ""; #We don't use XSLT for items display on these pages
248
    } else {
248
    } else {
249
        $itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items, $items_rs);
249
        $itemsxml = buildKohaItemsNamespace($items);
250
    }
250
    }
251
    my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
251
    my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
252
252
Lines 289-369 sub XSLTParse4Display { Link Here
289
289
290
=head2 buildKohaItemsNamespace
290
=head2 buildKohaItemsNamespace
291
291
292
    my $items_xml = buildKohaItemsNamespace( $biblionumber, [ $hidden_items, $items ] );
292
    my $items_xml = buildKohaItemsNamespace( $items );
293
293
294
Returns XML for items. It accepts two optional parameters:
294
Returns XML for items. It requires one parameter:
295
- I<$hidden_items>: An arrayref of itemnumber values, for items that should be hidden
295
- I<$items>: An arrayref of item hashes, for the items to be returned, hidden items should be filtered before calling this routine
296
- I<$items>: A Koha::Items resultset, for the items to be returned
297
298
If both parameters are passed, I<$items> is used as the basis resultset, and I<$hidden_items>
299
are filtered out of it.
300
296
301
Is only used in this module currently.
297
Is only used in this module currently.
302
298
303
=cut
299
=cut
304
300
305
sub buildKohaItemsNamespace {
301
sub buildKohaItemsNamespace {
306
    my ($biblionumber, $hidden_items, $items_rs) = @_;
302
    my ($items) = @_;
307
308
    $hidden_items ||= [];
309
310
    my $query = {};
311
    $query = { 'me.itemnumber' => { not_in => $hidden_items } }
312
      if $hidden_items;
313
314
    unless ( $items_rs && ref($items_rs) eq 'Koha::Items' ) {
315
        $query->{'me.biblionumber'} = $biblionumber;
316
        $items_rs = Koha::Items->new;
317
    }
318
303
319
    my $items = $items_rs->search( $query, { prefetch => [ 'branchtransfers', 'reserves' ] } );
320
321
    my $shelflocations =
322
      { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => "", kohafield => 'items.location' } ) };
323
    my $ccodes =
324
      { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => "", kohafield => 'items.ccode' } ) };
325
326
    my %branches = map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' });
327
328
    my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } };
329
    my $xml = '';
304
    my $xml = '';
330
    my %descs = map { $_->{authorised_value} => $_ } Koha::AuthorisedValues->get_descriptions_by_koha_field( { kohafield => 'items.notforloan' } );
331
    my $ref_status = C4::Context->preference('Reference_NFL_Statuses') || '1|2';
305
    my $ref_status = C4::Context->preference('Reference_NFL_Statuses') || '1|2';
332
306
333
    while ( my $item = $items->next ) {
307
    for my $item ( @$items ) {
334
        my $status;
308
        my $status;
335
        my $substatus = '';
309
        my $substatus = '';
336
310
337
        if ($item->has_pending_hold) {
311
        my $reservestatus = C4::Reserves::GetReserveStatus( $item->{itemnumber} );
312
        my $transfer = C4::Circulation::GetTransfers($item->{itemnumber});
313
314
        if ($reservestatus eq 'Pending' ) {
338
            $status = 'Pending hold';
315
            $status = 'Pending hold';
339
        }
316
        }
340
        elsif ( $item->holds->waiting->count ) {
317
        elsif ( $reservestatus eq 'Waiting' ) {
341
            $status = 'Waiting';
318
            $status = 'Waiting';
342
        }
319
        }
343
        elsif ($item->get_transfer) {
320
        elsif ($transfer) {
344
            $status = 'In transit';
321
            $status = 'In transit';
345
        }
322
        }
346
        elsif ($item->damaged) {
323
        elsif ($item->{damaged}) {
347
            $status = "Damaged";
324
            $status = "Damaged";
348
        }
325
        }
349
        elsif ($item->itemlost) {
326
        elsif ($item->{itemlost}) {
350
            $status = "Lost";
327
            $status = "Lost";
351
        }
328
        }
352
        elsif ( $item->withdrawn) {
329
        elsif ( $item->{withdrawn}) {
353
            $status = "Withdrawn";
330
            $status = "Withdrawn";
354
        }
331
        }
355
        elsif ($item->onloan) {
332
        elsif ($item->{onloan}) {
356
            $status = "Checked out";
333
            $status = "Checked out";
357
        }
334
        }
358
        elsif ( $item->notforloan ) {
335
        elsif ( $item->{notforloan} ) {
359
            $status = $item->notforloan =~ /^($ref_status)$/
336
            $status = $item->{notforloan} =~ /^($ref_status)$/
360
                ? "reference"
337
                ? "reference"
361
                : "reallynotforloan";
338
                : "reallynotforloan";
362
            $substatus = exists $descs{$item->notforloan} ? $descs{$item->notforloan}->{opac_description} : "Not for loan";
339
            $substatus = $item->{notforloan_description};
363
        }
340
        }
364
        elsif ( exists $itemtypes->{ $item->effective_itemtype }
341
        elsif ( defined $item->{notforloan_itemtype} && $item->{notforloan_itemtype} == 1 )
365
            && $itemtypes->{ $item->effective_itemtype }->{notforloan}
366
            && $itemtypes->{ $item->effective_itemtype }->{notforloan} == 1 )
367
        {
342
        {
368
            $status = "1" =~ /^($ref_status)$/
343
            $status = "1" =~ /^($ref_status)$/
369
                ? "reference"
344
                ? "reference"
Lines 373-384 sub buildKohaItemsNamespace { Link Here
373
        else {
348
        else {
374
            $status = "available";
349
            $status = "available";
375
        }
350
        }
376
        my $homebranch     = xml_escape($branches{$item->homebranch});
351
        my $homebranch     = xml_escape( $item->{homebranch} );
377
        my $holdingbranch  = xml_escape($branches{$item->holdingbranch});
352
        my $holdingbranch  = xml_escape( $item->{holdingbranch} );
378
        my $location       = xml_escape($item->location && exists $shelflocations->{$item->location} ? $shelflocations->{$item->location} : $item->location);
353
        my $location       = xml_escape( $item->{location} );
379
        my $ccode          = xml_escape($item->ccode    && exists $ccodes->{$item->ccode}            ? $ccodes->{$item->ccode}            : $item->ccode);
354
        my $ccode          = xml_escape( $item->{ccode} );
380
        my $itemcallnumber = xml_escape($item->itemcallnumber);
355
        my $itemcallnumber = xml_escape($item->{itemcallnumber});
381
        my $stocknumber    = xml_escape($item->stocknumber);
356
        my $stocknumber    = xml_escape($item->{stocknumber});
382
        $xml .=
357
        $xml .=
383
            "<item>"
358
            "<item>"
384
          . "<homebranch>$homebranch</homebranch>"
359
          . "<homebranch>$homebranch</homebranch>"
(-)a/opac/opac-shelves.pl (-1 / +19 lines)
Lines 307-312 if ( $op eq 'view' ) { Link Here
307
                $art_req_itypes = Koha::CirculationRules->guess_article_requestable_itemtypes({ $patron ? ( categorycode => $patron->categorycode ) : () });
307
                $art_req_itypes = Koha::CirculationRules->guess_article_requestable_itemtypes({ $patron ? ( categorycode => $patron->categorycode ) : () });
308
            }
308
            }
309
309
310
            # Build lookup tables now to avoid fetching later
311
            my %branches = map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' });
312
            my $shelflocations = { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' } ) };
313
            my $notforloan_descriptions = { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { kohafield => 'items.notforloan' } ) };
314
            my $ccodes = { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => "", kohafield => 'items.ccode' } ) };
315
            my $itemtypes = Koha::ItemTypes->search_with_localization;
316
            my %itemtypes = map { $_->{itemtype} => $_ } @{ $itemtypes->unblessed };
317
310
            my @items_info;
318
            my @items_info;
311
            while ( my $content = $contents->next ) {
319
            while ( my $content = $contents->next ) {
312
                my $biblionumber = $content->biblionumber;
320
                my $biblionumber = $content->biblionumber;
Lines 351-361 if ( $op eq 'view' ) { Link Here
351
359
352
                my $items = $biblio->items->filter_by_visible_in_opac({ patron => $patron });
360
                my $items = $biblio->items->filter_by_visible_in_opac({ patron => $patron });
353
                my $allow_onshelf_holds;
361
                my $allow_onshelf_holds;
362
                my @items;
354
                while ( my $item = $items->next ) {
363
                while ( my $item = $items->next ) {
355
364
356
                    # This method must take a Koha::Items rs
365
                    # This method must take a Koha::Items rs
357
                    $allow_onshelf_holds ||= Koha::CirculationRules->get_onshelfholds_policy(
366
                    $allow_onshelf_holds ||= Koha::CirculationRules->get_onshelfholds_policy(
358
                        { item => $item, patron => $patron } );
367
                        { item => $item, patron => $patron } );
368
                    my $item_hash = $item->unblessed;
369
                    $item_hash->{itemtype} = $item->effective_itemtype;
370
                    $item_hash->{homebranch} = $branches{ $item->homebranch };
371
                    $item_hash->{holdingbranch} = $branches{ $item->holdingbranch };
372
                    $item_hash->{notforloan_description} = $item->notforloan && exists $notforloan_descriptions->{ $item->notforloan } ? $notforloan_descriptions->{ $item->notforloan } : "Not for loan";
373
                    $item_hash->{location} = $item->{location} && exists $shelflocations->{$item->location} ? $shelflocations->{$item->location} : $item->location ;
374
                    $item_hash->{ccode_description} = $item->{ccode} && exists $ccodes->{$item->ccode} ? $ccodes->{$item->ccode} : $item->ccode ;
375
                    $item_hash->{notforloan_itemtype} = $itemtypes{ $itemtype }->{notforloan};
376
                    push @items, $item_hash;
359
377
360
                }
378
                }
361
379
Lines 371-377 if ( $op eq 'view' ) { Link Here
371
                        "OPACXSLTListsDisplay", 1,
389
                        "OPACXSLTListsDisplay", 1,
372
                        undef,                 $sysxml,
390
                        undef,                 $sysxml,
373
                        $xslfile,              $lang,
391
                        $xslfile,              $lang,
374
                        $variables,            $items->reset
392
                        $variables,            \@items
375
                    );
393
                    );
376
                }
394
                }
377
395
(-)a/t/db_dependent/XSLT.t (-116 / +32 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use MARC::Record;
20
use MARC::Record;
21
use Test::More tests => 4;
21
use Test::More tests => 3;
22
use Test::Warn;
22
use Test::Warn;
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
24
use t::lib::Mocks;
Lines 46-208 subtest 'transformMARCXML4XSLT tests' => sub { Link Here
46
};
46
};
47
47
48
subtest 'buildKohaItemsNamespace status tests' => sub {
48
subtest 'buildKohaItemsNamespace status tests' => sub {
49
    plan tests => 14;
49
    plan tests => 12;
50
50
51
    t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2');
51
    t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2');
52
52
53
    my $itype = $builder->build_object({ class => 'Koha::ItemTypes' });
53
    my $item  = $builder->build_sample_item({})->unblessed;
54
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
55
    my $item  = $builder->build_sample_item({ itype => $itype->itemtype });
56
    $item->biblioitem->itemtype($itemtype->itemtype)->store;
57
54
58
    my $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
55
56
    my $xml = C4::XSLT::buildKohaItemsNamespace([$item]);
59
    like($xml,qr{<status>available</status>},"Item is available when no other status applied");
57
    like($xml,qr{<status>available</status>},"Item is available when no other status applied");
60
58
61
    # notforloan
59
    # notforloan
62
    {
60
    {
63
        t::lib::Mocks::mock_preference('item-level_itypes', 0);
61
64
        $item->notforloan(0)->store;
62
        $item->{notforloan} = 1;
65
        Koha::ItemTypes->find($item->itype)->notforloan(0)->store;
63
        $xml = C4::XSLT::buildKohaItemsNamespace([$item]);
66
        Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(1)->store;
64
        like($xml,qr{<status>reference</status>},"reference if itemtype notforloan value in Reference_NFL_Statuses");
67
        $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
65
68
        like($xml,qr{<status>reference</status>},"reference if positive itype notforloan value");
66
        $item->{notforloan} = -1;
69
67
        $item->{notforloan_description} = 'nopenope';
70
        t::lib::Mocks::mock_preference('item-level_itypes', 1);
68
        $xml = C4::XSLT::buildKohaItemsNamespace( [$item]);
71
        Koha::ItemTypes->find($item->itype)->notforloan(1)->store;
69
        like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan if notforloan value not in Reference_NFL_Statuses");
72
        Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(0)->store;
70
        like($xml,qr{<substatus>nopenope</substatus>},"substatus set if notforloan value not in Reference_NFL_Statuses");
73
        $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
74
        like($xml,qr{<status>reference</status>},"reference if positive itemtype notforloan value");
75
        Koha::ItemTypes->find($item->itype)->notforloan(0)->store;
76
77
        my $substatus = Koha::AuthorisedValues->search({ category => 'NOT_LOAN', authorised_value => -1 })->next->lib;
78
        $item->notforloan(-1)->store;
79
        $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
80
        like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan if negative notforloan value");
81
        like($xml,qr{<substatus>$substatus</substatus>},"substatus set if negative notforloan value");
82
83
        $item->notforloan(1)->store;
84
        $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
85
        like($xml,qr{<status>reference</status>},"reference if positive notforloan value");
86
71
87
        # But now make status notforloan==1 count under Not available
72
        # But now make status notforloan==1 count under Not available
73
        $item->{notforloan} = 1;
88
        t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '2');
74
        t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '2');
89
        $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
75
        $xml = C4::XSLT::buildKohaItemsNamespace( [$item]);
90
        like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan when we change Reference_NFL_Statuses");
76
        like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan when we change Reference_NFL_Statuses");
91
        t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2');
77
        t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2');
92
    }
78
    }
93
79
94
    $item->onloan('2001-01-01')->store;
80
    $item->{onloan} = '2001-01-01';
95
    $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
81
    $xml = C4::XSLT::buildKohaItemsNamespace( [$item]);
96
    like($xml,qr{<status>Checked out</status>},"Checked out status takes precedence over Not for loan");
82
    like($xml,qr{<status>Checked out</status>},"Checked out status takes precedence over Not for loan");
97
83
98
    $item->withdrawn(1)->store;
84
    $item->{withdrawn} = 1;
99
    $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
85
    $xml = C4::XSLT::buildKohaItemsNamespace( [$item]);
100
    like($xml,qr{<status>Withdrawn</status>},"Withdrawn status takes precedence over Checked out");
86
    like($xml,qr{<status>Withdrawn</status>},"Withdrawn status takes precedence over Checked out");
101
87
102
    $item->itemlost(1)->store;
88
    $item->{itemlost} = 1;
103
    $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
89
    $xml = C4::XSLT::buildKohaItemsNamespace( [$item]);
104
    like($xml,qr{<status>Lost</status>},"Lost status takes precedence over Withdrawn");
90
    like($xml,qr{<status>Lost</status>},"Lost status takes precedence over Withdrawn");
105
91
106
    $item->damaged(1)->store;
92
    $item->{damaged} = 1;
107
    $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
93
    $xml = C4::XSLT::buildKohaItemsNamespace( [$item]);
108
    like($xml,qr{<status>Damaged</status>},"Damaged status takes precedence over Lost");
94
    like($xml,qr{<status>Damaged</status>},"Damaged status takes precedence over Lost");
109
95
110
    $builder->build({ source => "Branchtransfer", value => {
96
    $builder->build({ source => "Branchtransfer", value => {
111
        itemnumber  => $item->itemnumber,
97
        itemnumber  => $item->{itemnumber},
112
        datearrived => undef,
98
        datearrived => undef,
113
        datecancelled => undef,
99
        datecancelled => undef,
114
        }
100
        }
115
    });
101
    });
116
    $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
102
    $xml = C4::XSLT::buildKohaItemsNamespace( [$item]);
117
    like($xml,qr{<status>In transit</status>},"In-transit status takes precedence over Damaged");
103
    like($xml,qr{<status>In transit</status>},"In-transit status takes precedence over Damaged");
118
104
119
    my $hold = $builder->build_object({ class => 'Koha::Holds', value => {
105
    my $hold = $builder->build_object({ class => 'Koha::Holds', value => {
120
        biblionumber => $item->biblionumber,
106
        biblionumber => $item->{biblionumber},
121
        itemnumber   => $item->itemnumber,
107
        itemnumber   => $item->{itemnumber},
122
        found        => 'W',
108
        found        => 'W',
123
        priority     => 0,
109
        priority     => 0,
124
        }
110
        }
125
    });
111
    });
126
    $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
112
    $xml = C4::XSLT::buildKohaItemsNamespace( [$item]);
127
    like($xml,qr{<status>Waiting</status>},"Waiting status takes precedence over In transit");
113
    like($xml,qr{<status>Waiting</status>},"Waiting status takes precedence over In transit");
128
114
129
    $builder->build({ source => "TmpHoldsqueue", value => {
115
    $builder->build({ source => "TmpHoldsqueue", value => {
130
        itemnumber => $item->itemnumber
116
        itemnumber => $item->{itemnumber}
131
        }
117
        }
132
    });
118
    });
133
    $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
119
    $xml = C4::XSLT::buildKohaItemsNamespace( [$item]);
134
    like($xml,qr{<status>Pending hold</status>},"Pending status takes precedence over all");
120
    like($xml,qr{<status>Pending hold</status>},"Pending status takes precedence over all");
135
121
136
122
137
};
123
};
138
124
139
$schema->storage->txn_rollback;
125
$schema->storage->txn_rollback;
140
141
subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub {
142
143
    plan tests => 20;
144
145
    $schema->storage->txn_begin;
146
147
    my $biblio = $builder->build_sample_biblio;
148
149
    # Have two known libraries for testing purposes
150
    my $library_1 = $builder->build_object({ class => 'Koha::Libraries' });
151
    my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
152
    my $library_3 = $builder->build_object({ class => 'Koha::Libraries' });
153
154
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library_1->id });
155
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library_2->id });
156
    my $item_3 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library_3->id });
157
158
    my $items_rs = $biblio->items->search({ "me.itemnumber" => { '!=' => $item_3->itemnumber } });
159
160
    ## Test passing items_rs only
161
    my $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, undef, $items_rs );
162
163
    my $library_1_name = $library_1->branchname;
164
    my $library_2_name = $library_2->branchname;
165
    my $library_3_name = $library_3->branchname;
166
167
    like(   $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 present in the XML' );
168
    like(   $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' );
169
    unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' );
170
    ## Test passing one item in hidden_items and items_rs
171
    $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ], $items_rs->reset );
172
173
    unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' );
174
    like(   $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' );
175
    unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' );
176
177
    ## Test passing both items in hidden_items and items_rs
178
    $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber ], $items_rs->reset );
179
180
    unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' );
181
    unlike( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 not present in the XML' );
182
    unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' );
183
    is( $xml, '<items xmlns="http://www.koha-community.org/items"></items>', 'Empty XML' );
184
185
    ## Test passing both items in hidden_items and no items_rs
186
    $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber, $item_2->itemnumber, $item_3->itemnumber ] );
187
188
    unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' );
189
    unlike( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 not present in the XML' );
190
    unlike( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 not present in the XML' );
191
    is( $xml, '<items xmlns="http://www.koha-community.org/items"></items>', 'Empty XML' );
192
193
    ## Test passing one item in hidden_items and items_rs
194
    $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber, [ $item_1->itemnumber ] );
195
196
    unlike( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 not present in the XML' );
197
    like(   $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' );
198
    like(   $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 present in the XML' );
199
200
    ## Test not passing any param
201
    $xml = C4::XSLT::buildKohaItemsNamespace( $biblio->biblionumber );
202
203
    like( $xml, qr{<homebranch>$library_1_name</homebranch>}, '$item_1 present in the XML' );
204
    like( $xml, qr{<homebranch>$library_2_name</homebranch>}, '$item_2 present in the XML' );
205
    like( $xml, qr{<homebranch>$library_3_name</homebranch>}, '$item_3 present in the XML' );
206
207
    $schema->storage->txn_rollback;
208
};
209
- 

Return to bug 28702