From 2e53a13a798f0d42f70f1b1bafd47c3dfbbd1378 Mon Sep 17 00:00:00 2001 From: Srdjan Date: Mon, 31 Mar 2014 16:50:34 +1300 Subject: [PATCH] bug_11213: C4::VirtualShelves::Page::shelf_contents() * Extracted shelf items processing from shelfpage() into a separate sub shelf_contents() in order to be able to test it * Added tests for shelf_contents() with XSLT --- C4/VirtualShelves/Page.pm | 113 +++++++++++++++++++++-------------- t/db_dependent/VirtualShelves_Page.t | 43 ++++++++++++- 2 files changed, 110 insertions(+), 46 deletions(-) diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm index 506e9d4..eb0f498 100644 --- a/C4/VirtualShelves/Page.pm +++ b/C4/VirtualShelves/Page.pm @@ -74,7 +74,6 @@ sub shelfpage { my $itemoff = ( $query->param('itemoff') ? $query->param('itemoff') : 1 ); my $displaymode = ( $query->param('display') ? $query->param('display') : 'publicshelves' ); my ( $shelflimit, $shelfoffset, $shelveslimit, $shelvesoffset ); - my $marcflavour = C4::Context->preference("marcflavour"); $shelflimit = ( $type eq 'opac' ? C4::Context->preference('OPACnumSearchResults') : C4::Context->preference('numSearchResults') ); $shelflimit = $shelflimit || ShelvesMax('MGRPAGE'); @@ -238,7 +237,6 @@ sub shelfpage { #check that the user can view the shelf if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) { my $items; - my $tag_quantity; my $sortfield = ( $sorton ? $sorton : 'title' ); $sortfield = $query->param('sort') || $sortfield; ## Passed in sorting overrides default sorting my $direction = $query->param('direction') || 'asc'; @@ -246,8 +244,6 @@ sub shelfpage { sort => $sortfield, direction => $direction, ); - ( $items, $totitems ) = GetShelfContents( $shelfnumber, $shelflimit, $shelfoffset, $sortfield, $direction ); - # get biblionumbers stored in the cart # Note that it's not use at the intranet my @cart_list; @@ -257,47 +253,16 @@ sub shelfpage { @cart_list = split(/\//, $cart_list); } - my $borrower = GetMember( 'borrowernumber' => $loggedinuser ); - - for my $this_item (@$items) { - my $biblionumber = $this_item->{'biblionumber'}; - # Getting items infos for location display - my @items_infos = &GetItemsInfo( $this_item->{'biblionumber'}, "cn_sort" ); - my $record = GetMarcBiblio($biblionumber); - if (C4::Context->preference("OPACXSLTResultsDisplay") && $type eq 'opac') { - $this_item->{XSLTBloc} = XSLTParse4Display($biblionumber, $record, "OPACXSLTResultsDisplay", \@items_infos); - } elsif (C4::Context->preference("XSLTResultsDisplay") && $type eq 'intranet') { - $this_item->{XSLTBloc} = XSLTParse4Display($biblionumber, $record, "XSLTResultsDisplay", \@items_infos); - } - - # the virtualshelfcontents table does not store these columns nor are they retrieved from the items - # and itemtypes tables, so I'm commenting them out for now to quiet the log -crn - #$this_item->{imageurl} = $imgdir."/".$itemtypes->{ $this_item->{itemtype} }->{'imageurl'}; - #$this_item->{'description'} = $itemtypes->{ $this_item->{itemtype} }->{'description'}; - $this_item->{'dateadded'} = format_date( $this_item->{'dateadded'} ); - $this_item->{'imageurl'} = getitemtypeinfo( $this_item->{'itemtype'}, $type )->{'imageurl'}; - $this_item->{'coins'} = GetCOinSBiblio( $record ); - $this_item->{'subtitle'} = GetRecordValue('subtitle', $record, GetFrameworkCode($this_item->{'biblionumber'})); - $this_item->{'normalized_upc'} = GetNormalizedUPC( $record,$marcflavour); - $this_item->{'normalized_ean'} = GetNormalizedEAN( $record,$marcflavour); - $this_item->{'normalized_oclc'} = GetNormalizedOCLCNumber($record,$marcflavour); - $this_item->{'normalized_isbn'} = GetNormalizedISBN(undef,$record,$marcflavour); - if(!defined($this_item->{'size'})) { $this_item->{'size'} = "" }; #TT has problems with size - $this_item->{'itemsissued'} = CountItemsIssued( $this_item->{'biblionumber'} ); - $this_item->{'ITEM_RESULTS'} = \@items_infos; - if ( grep {$_ eq $biblionumber} @cart_list) { - $this_item->{'incart'} = 1; - } - - if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnList')) { - $this_item->{'TagLoop'} = get_tags({ - biblionumber=>$this_item->{'biblionumber'}, approved=>1, 'sort'=>'-weight', - limit=>$tag_quantity - }); - } - - $this_item->{'allow_onshelf_holds'} = C4::Reserves::OnShelfHoldsAllowed($this_item, $borrower); - } + ( $items, $totitems ) = shelf_contents({ + borrower => GetMember( 'borrowernumber' => $loggedinuser ), + shelfnumber => $shelfnumber, + shelflimit => $shelflimit, + shelfoffset => $shelfoffset, + sortfield => $sortfield, + direction => $direction, + type => $type, + cart_list => \@cart_list, + }); if($type eq 'intranet'){ # Build drop-down list for 'Add To:' menu... my ($totalref, $pubshelves, $barshelves)= @@ -501,6 +466,64 @@ sub shelfpage { output_html_with_http_headers $query, $cookie, $template->output; } +sub shelf_contents { + my ( $params ) = @_; + my $borrower = $params->{borrower}; + my $shelfnumber = $params->{shelfnumber}; + my $shelflimit = $params->{shelflimit}; + my $shelfoffset = $params->{shelfoffset}; + my $sortfield = $params->{sortfield}; + my $direction = $params->{direction}; + my $type = $params->{type}; + my $cart_list = $params->{cart_list}; + + my $marcflavour = C4::Context->preference("marcflavour"); + my $tag_quantity = C4::Context->preference('TagsEnabled') + ? C4::Context->preference('TagsShowOnList') + : undef; + my ( $items, $totitems ) = GetShelfContents( $shelfnumber, $shelflimit, $shelfoffset, $sortfield, $direction ); + for my $this_item (@$items) { + my $biblionumber = $this_item->{'biblionumber'}; + # Getting items infos for location display + my @items_infos = &GetItemsInfo( $this_item->{'biblionumber'}, "cn_sort" ); + my $record = GetMarcBiblio($biblionumber); + if (C4::Context->preference("OPACXSLTResultsDisplay") && $type eq 'opac') { + $this_item->{XSLTBloc} = XSLTParse4Display($biblionumber, $record, "OPACXSLTResultsDisplay", \@items_infos); + } elsif (C4::Context->preference("XSLTResultsDisplay") && $type eq 'intranet') { + $this_item->{XSLTBloc} = XSLTParse4Display($biblionumber, $record, "XSLTResultsDisplay", \@items_infos); + } + + # the virtualshelfcontents table does not store these columns nor are they retrieved from the items + # and itemtypes tables, so I'm commenting them out for now to quiet the log -crn + #$this_item->{imageurl} = $imgdir."/".$itemtypes->{ $this_item->{itemtype} }->{'imageurl'}; + #$this_item->{'description'} = $itemtypes->{ $this_item->{itemtype} }->{'description'}; + $this_item->{'dateadded'} = format_date( $this_item->{'dateadded'} ); + $this_item->{'imageurl'} = getitemtypeinfo( $this_item->{'itemtype'}, $type )->{'imageurl'}; + $this_item->{'coins'} = GetCOinSBiblio( $record ); + $this_item->{'subtitle'} = GetRecordValue('subtitle', $record, GetFrameworkCode($this_item->{'biblionumber'})); + $this_item->{'normalized_upc'} = GetNormalizedUPC( $record,$marcflavour); + $this_item->{'normalized_ean'} = GetNormalizedEAN( $record,$marcflavour); + $this_item->{'normalized_oclc'} = GetNormalizedOCLCNumber($record,$marcflavour); + $this_item->{'normalized_isbn'} = GetNormalizedISBN(undef,$record,$marcflavour); + if(!defined($this_item->{'size'})) { $this_item->{'size'} = "" }; #TT has problems with size + $this_item->{'itemsissued'} = CountItemsIssued( $this_item->{'biblionumber'} ); + $this_item->{'ITEM_RESULTS'} = \@items_infos; + if ( $cart_list && grep {$_ eq $biblionumber} @$cart_list) { + $this_item->{'incart'} = 1; + } + + if ($tag_quantity) { + $this_item->{'TagLoop'} = get_tags({ + biblionumber=>$this_item->{'biblionumber'}, approved=>1, 'sort'=>'-weight', + limit=>$tag_quantity + }); + } + + $this_item->{'allow_onshelf_holds'} = C4::Reserves::OnShelfHoldsAllowed($this_item, $borrower); + } + return ( $items, $totitems ); +} + 1; __END__ diff --git a/t/db_dependent/VirtualShelves_Page.t b/t/db_dependent/VirtualShelves_Page.t index 236d147..dfe4b62 100755 --- a/t/db_dependent/VirtualShelves_Page.t +++ b/t/db_dependent/VirtualShelves_Page.t @@ -6,9 +6,50 @@ use strict; use warnings; -use Test::More tests => 1; +use Test::More tests => 3; + +use C4::Context; BEGIN { use_ok('C4::VirtualShelves::Page'); } +my $dbh = C4::Context->dbh; +# Start transaction +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; + +C4::Context->set_preference('XSLTResultsDisplay', 'default'); +C4::Context->set_preference('OPACXSLTResultsDisplay', 'default'); +C4::Context->clear_syspref_cache(); + +my $query = qq{ + SELECT vs.shelfnumber, vs.shelfname,vs.owner, + bo.surname,bo.firstname,vs.category,vs.sortfield, + count(vc.biblionumber) as count + FROM virtualshelves vs + JOIN borrowers bo ON vs.owner=bo.borrowernumber + JOIN virtualshelfcontents vc USING (shelfnumber) + GROUP BY vs.shelfnumber + LIMIT 1 +}; +my $shelf = $dbh->selectrow_hashref($query); + +my %params = ( + shelfnumber => $shelf->{shelfnumber}, + shelflimit => 1, + shelfoffset => 0, + sortfield => $shelf->{sortfield}, + direction => 'asc', + type => 'opac', + cart_list => [], +); +my ( $items, $totitems ) = C4::VirtualShelves::Page::shelf_contents(\%params); +ok( $items->[0]{XSLTBloc}, "opac items XSLT"); + +$params{type} = 'intranet'; +( $items, $totitems ) = C4::VirtualShelves::Page::shelf_contents(\%params); +ok( $items->[0]{XSLTBloc}, "intranet items XSLT"); + +# Cleanup +$dbh->rollback; -- 1.9.1