From a3c7bb103808f7c0118b0ef04f6289eb938d6dad Mon Sep 17 00:00:00 2001 From: Gabriel DeCarufel Date: Thu, 12 Mar 2020 16:23:42 -0400 Subject: [PATCH] Bug 17385: Added download option in list --- .../prog/en/includes/cat-toolbar.inc | 2 +- .../en/modules/admin/preferences/opac.pref | 2 +- .../prog/en/modules/catalogue/detail.tt | 2 +- .../en/includes/opac-detail-sidebar.inc | 2 +- opac/opac-downloadshelf.pl | 8 +++- t/db_dependent/XSLT.t | 45 +++++++++++++------ 6 files changed, 41 insertions(+), 20 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc index a12f95abb0..9ba3d01b85 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc @@ -97,7 +97,7 @@ CAN_user_serials_create_subscription ) %]
  • MODS (XML)
  • RIS
  • [% FOREACH filesOption IN filesOptions %] -
  • [% filesOption.filename | html %]
  • +
  • XSL - [% filesOption.filename | html %]
  • [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 40ecfae5f1..ab5c39bbc9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -321,7 +321,7 @@ OPAC: mods: MODS ris: RIS isbd: ISBD - custom: Custom + custom: XSL - Simple Export - - pref: OpacSeparateHoldings choices: diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index c67377b59f..9965d859ed 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -781,7 +781,7 @@ Note that permanent location is a code, and location may be an authval. [% FOREACH filesOption IN filesOptions %] - + [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc index da7d4f7bb3..7843aff2d9 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc @@ -80,7 +80,7 @@ [% ELSE %] [% FOREACH filesOption IN filesOptions %] -
  • [% filesOption.filename | html %]
  • +
  • XSL - [% filesOption.filename | html %]
  • [% END %] [% END %] [% END %] diff --git a/opac/opac-downloadshelf.pl b/opac/opac-downloadshelf.pl index ac6e910ebd..72964fb362 100755 --- a/opac/opac-downloadshelf.pl +++ b/opac/opac-downloadshelf.pl @@ -28,6 +28,7 @@ use C4::Items; use C4::Output; use C4::Record; use C4::Ris; +use C4::XSLT; use Koha::CsvProfiles; use Koha::RecordProcessor; use Koha::Virtualshelves; @@ -118,13 +119,15 @@ if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { }); $extension = "txt"; $type = "text/plain"; - } + }elsif ($format =~ /^xsl\.(.*)$/){ + $output .= XSLTParse4Display($biblionumber, $record, 'XSLTCustomExport', 1, undef, undef, $1, '', 1); + } } } # If it was a CSV export we change the format after the export so the file extension is fine $format = "csv" if ($format =~ m/^\d+$/); - + $format = "html" if ($format =~ /^xsl\./); print $query->header( -type => ($type) ? $type : 'application/octet-stream', -'Content-Transfer-Encoding' => 'binary', @@ -140,6 +143,7 @@ if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { } else { $template->param(fullpage => 1); } + $template->param(xsl_exports => CustomXSLTExportList()); $template->param(csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }) ]); $template->param( shelf => $shelf ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/t/db_dependent/XSLT.t b/t/db_dependent/XSLT.t index d933cf80a4..4a50bfac16 100644 --- a/t/db_dependent/XSLT.t +++ b/t/db_dependent/XSLT.t @@ -1,28 +1,23 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 4; use t::lib::Mocks; use C4::XSLT; -use Koha::Caches; use Koha::Database; +use Test::Warn; +use t::lib::TestBuilder; +use Koha::ItemTypes; +use Koha::Caches; our $schema = Koha::Database->new->schema; our $cache = Koha::Caches->get_instance; +BEGIN { + use_ok('C4::XSLT'); +} +my $builder = t::lib::TestBuilder->new; # Here we go $schema->storage->txn_begin; -subtest 'CustomXSLTExportList: Caching' => sub { - plan tests => 1; - t::lib::Mocks::mock_preference('OpacExportOptions', 'custom'); - $cache->clear_from_cache('CustomXSLTExportListOPAC'); - my $list = C4::XSLT::CustomXSLTExportList(1); - push @$list, { nonsense => 1 }; - $cache->set_in_cache( 'CustomXSLTExportListOPAC', $list ); - my $n = @$list; - $list = C4::XSLT::CustomXSLTExportList(1); - is( @$list, $n, 'This list comes from the cache and that is fine' ); - $cache->clear_from_cache('CustomXSLTExportListOPAC'); -}; subtest 'buildKohaItemsNamespace status tests' => sub { plan tests => 13; my $item = $builder->build_sample_item({}); @@ -99,4 +94,26 @@ subtest 'buildKohaItemsNamespace status tests' => sub { $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); like($xml,qr{Pending hold},"Pending status takes precedence over all"); }; +subtest 'CustomXSLTExportList: Caching' => sub { + plan tests => 1; + t::lib::Mocks::mock_preference('OpacExportOptions', 'custom'); + $cache->clear_from_cache('CustomXSLTExportListOPAC'); + my $list = C4::XSLT::CustomXSLTExportList(1); + push @$list, { nonsense => 1 }; + $cache->set_in_cache('CustomXSLTExportListOPAC', $list ); + my $n = @$list; + $list = C4::XSLT::CustomXSLTExportList(1); + is( @$list, $n, 'This list comes from the cache and that is fine' ); + $cache->clear_from_cache('CustomXSLTExportListOPAC'); +}; +subtest 'CustomXSLTExportList: Check export options' => sub { + plan tests => 2; + t::lib::Mocks::mock_preference('OpacExportOptions', 'custom'); + my $list = C4::XSLT::CustomXSLTExportList(1); + is( $list>0, 1, 'We expect at least one result: simple export' ); + $cache->clear_from_cache('CustomXSLTExportListOPAC'); + t::lib::Mocks::mock_preference('OpacExportOptions', 'dc'); + $list = C4::XSLT::CustomXSLTExportList(1); + is( @$list, 0, 'We expect an empty list now' ); +}; $schema->storage->txn_rollback; -- 2.17.1