From srdjan at catalyst.net.nz Tue Apr 1 02:25:22 2014 From: srdjan at catalyst.net.nz (Srdjan) Date: Tue, 1 Apr 2014 13:25:22 +1300 Subject: [Koha-patches] [PATCH] bug_11213: C4::VirtualShelves::Page::shelf_contents() Message-ID: <1396311922-25934-1-git-send-email-srdjan@catalyst.net.nz> * 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 | 105 +++++++++++++++++++++-------------- t/db_dependent/VirtualShelves_Page.t | 43 +++++++++++++- 2 files changed, 106 insertions(+), 42 deletions(-) diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm index 823248f..e211d80 100644 --- a/C4/VirtualShelves/Page.pm +++ b/C4/VirtualShelves/Page.pm @@ -73,7 +73,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"); # get biblionumbers stored in the cart my @cart_list; @@ -250,7 +249,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'; @@ -258,45 +256,15 @@ sub shelfpage { sort => $sortfield, direction => $direction, ); - ( $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 ( 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 - }); - } - - } + ( $items, $totitems ) = shelf_contents({ + 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)= @@ -487,6 +455,61 @@ sub shelfpage { output_html_with_http_headers $query, $cookie, $template->output; } +sub shelf_contents { + my ( $params ) = @_; + 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 ( 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 + }); + } + } + 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.8.3.2 From srdjan at catalyst.net.nz Tue Apr 1 07:48:35 2014 From: srdjan at catalyst.net.nz (Srdjan) Date: Tue, 1 Apr 2014 18:48:35 +1300 Subject: [Koha-patches] [PATCH] bug_11213: Use branch codes from the database rather than hardcoded CPL and MPL Message-ID: <1396331315-18720-1-git-send-email-srdjan@catalyst.net.nz> --- t/db_dependent/Items.t | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index 5ec8d34..bec6d9d 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -20,6 +20,7 @@ use Modern::Perl; use MARC::Record; use C4::Biblio; +use C4::Branch; use Test::More tests => 3; @@ -28,6 +29,8 @@ BEGIN { } my $dbh = C4::Context->dbh; +my $branches = GetBranches; +my ($branch1, $branch2) = keys %$branches; subtest 'General Add, Get and Del tests' => sub { @@ -42,7 +45,7 @@ subtest 'General Add, Get and Del tests' => sub { my ($bibnum, $bibitemnum) = get_biblio(); # Add an item. - my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum); + my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch1, holdingbranch => $branch1 } , $bibnum); cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber."); cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber."); @@ -79,14 +82,14 @@ subtest 'GetHiddenItemnumbers tests' => sub { # Add two items my ($item1_bibnum, $item1_bibitemnum, $item1_itemnumber) = AddItem( - { homebranch => 'CPL', - holdingbranch => 'CPL', + { homebranch => $branch1, + holdingbranch => $branch1, withdrawn => 1 }, $biblionumber ); my ($item2_bibnum, $item2_bibitemnum, $item2_itemnumber) = AddItem( - { homebranch => 'MPL', - holdingbranch => 'MPL', + { homebranch => $branch2, + holdingbranch => $branch2, withdrawn => 0 }, $biblionumber ); @@ -127,7 +130,7 @@ subtest 'GetHiddenItemnumbers tests' => sub { # Two variables, a value each $opachiddenitems = " withdrawn: [1] - homebranch: [MPL] + homebranch: [$branch2] "; C4::Context->set_preference( 'OpacHiddenItems', $opachiddenitems ); @hidden = GetHiddenItemnumbers( @items ); -- 1.8.3.2 From srdjan at catalyst.net.nz Tue Apr 1 07:48:45 2014 From: srdjan at catalyst.net.nz (Srdjan) Date: Tue, 1 Apr 2014 18:48:45 +1300 Subject: [Koha-patches] [PATCH] bug_11213: GetItemsInfo() test Message-ID: <1396331325-18782-1-git-send-email-srdjan@catalyst.net.nz> --- t/db_dependent/Items.t | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index bec6d9d..8c7cdf7 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -34,7 +34,7 @@ my ($branch1, $branch2) = keys %$branches; subtest 'General Add, Get and Del tests' => sub { - plan tests => 6; + plan tests => 8; # Start transaction $dbh->{AutoCommit} = 0; @@ -49,6 +49,11 @@ subtest 'General Add, Get and Del tests' => sub { cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber."); cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber."); + # Get items. + my @items_infos = GetItemsInfo( $bibnum, "cn_sort" ); + cmp_ok(scalar(@items_infos), '==', 1, "One item for biblionumber."); + cmp_ok($items_infos[0]{biblionumber}, '==', $bibnum, "Item has correct biblionumber."); + # Get item. my $getitem = GetItem($itemnumber); cmp_ok($getitem->{'itemnumber'}, '==', $itemnumber, "Retrieved item has correct itemnumber."); -- 1.8.3.2 From srdjan at catalyst.net.nz Tue Apr 1 08:17:40 2014 From: srdjan at catalyst.net.nz (Srdjan) Date: Tue, 1 Apr 2014 19:17:40 +1300 Subject: [Koha-patches] [PATCH] bug_11213: Added XSLTParse4Display() to Items test Message-ID: <1396333060-21347-1-git-send-email-srdjan@catalyst.net.nz> --- t/db_dependent/Items.t | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index 8c7cdf7..196219d 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -21,6 +21,7 @@ use Modern::Perl; use MARC::Record; use C4::Biblio; use C4::Branch; +use C4::XSLT; use Test::More tests => 3; @@ -34,7 +35,7 @@ my ($branch1, $branch2) = keys %$branches; subtest 'General Add, Get and Del tests' => sub { - plan tests => 8; + plan tests => 10; # Start transaction $dbh->{AutoCommit} = 0; @@ -54,6 +55,16 @@ subtest 'General Add, Get and Del tests' => sub { cmp_ok(scalar(@items_infos), '==', 1, "One item for biblionumber."); cmp_ok($items_infos[0]{biblionumber}, '==', $bibnum, "Item has correct biblionumber."); + C4::Context->set_preference('XSLTResultsDisplay', 'default'); + C4::Context->set_preference('OPACXSLTResultsDisplay', 'default'); + C4::Context->clear_syspref_cache(); + my $record = GetMarcBiblio($bibnum); + my $html = XSLTParse4Display($bibnum, $record, "OPACXSLTResultsDisplay", \@items_infos); + ok($html, "XSLTParse4Display( OPACXSLTResultsDisplay )"); + $html = XSLTParse4Display($bibnum, $record, "XSLTResultsDisplay", \@items_infos); + ok($html, "XSLTParse4Display( XSLTResultsDisplay )"); + + # Get item. my $getitem = GetItem($itemnumber); cmp_ok($getitem->{'itemnumber'}, '==', $itemnumber, "Retrieved item has correct itemnumber."); -- 1.8.3.2 From srdjan at catalyst.net.nz Tue Apr 1 08:19:17 2014 From: srdjan at catalyst.net.nz (Srdjan) Date: Tue, 1 Apr 2014 19:19:17 +1300 Subject: [Koha-patches] [PATCH] bug_11213: Check for $item->{itype} presence to avoid warning Message-ID: <1396333157-21559-1-git-send-email-srdjan@catalyst.net.nz> --- C4/XSLT.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 28b42b2..d56b21a 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -270,8 +270,16 @@ sub buildKohaItemsNamespace { my $reservestatus = C4::Reserves::GetReserveStatus( $item->{itemnumber} ); - if ( $itemtypes->{ $item->{itype} }->{notforloan} || $item->{notforloan} || $item->{onloan} || $item->{withdrawn} || $item->{itemlost} || $item->{damaged} || - (defined $transfertwhen && $transfertwhen ne '') || $item->{itemnotforloan} || (defined $reservestatus && $reservestatus eq "Waiting") ){ + if ( ($item->{itype} && $itemtypes->{ $item->{itype} }->{notforloan}) + || $item->{notforloan} + || $item->{onloan} + || $item->{withdrawn} + || $item->{itemlost} + || $item->{damaged} + || (defined $transfertwhen && $transfertwhen ne '') + || $item->{itemnotforloan} + || (defined $reservestatus && $reservestatus eq "Waiting") + ){ if ( $item->{notforloan} < 0) { $status = "On order"; } -- 1.8.3.2 From oleonard at myacpl.org Wed Apr 2 16:47:06 2014 From: oleonard at myacpl.org (Owen Leonard) Date: Wed, 2 Apr 2014 10:47:06 -0400 Subject: [Koha-patches] [PATCH] Bug 12018 - add table sorting to patron card batches Message-ID: <1396450026-5984-1-git-send-email-oleonard@myacpl.org> When viewing batches of patrons in the patron card creator module the table is not sortable. This patch adds table sorting. The patch also makes some corrections of invalid markup and moves informational/error messages to the top of the page rather than in a sidebar. This change lets the table and sorting controls expand into a wider space. This patch also corrects a translation issue with table headers identical to that addressed by Bug 11505. To test, go to Tools -> Patron card creator -> Manage batches. View an existing batch or create a new batch and populate it with patrons. Table sorting controls should work correctly. Batch management operations should work correctly. --- .../prog/en/modules/patroncards/edit-batch.tt | 92 ++++++++++++-------- 1 file changed, 56 insertions(+), 36 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt index ac4e051..60806f1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-batch.tt @@ -2,6 +2,8 @@ Koha › Tools › Patron card creator › Manage patron card batches [% INCLUDE 'doc-head-close.inc' %] [% INCLUDE 'greybox.inc' %] + + [% INCLUDE 'datatables.inc' %] @@ -115,9 +115,9 @@ Item types administration