From 2e2606a5abc94f888c1d6142798af6491f00242c Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Fri, 26 Apr 2019 01:47:13 +0000 Subject: [PATCH] Bug 8628: Digital signs - opac interface To test: 1. Apply this patch and the database updates patch 2. Run updatedatabase.pl 3. In staff client, go to Tools/Additional Tools/Digital signs 4. You should be warned about OPACDigitalSigns not being enabled, you can ignore this for now. 5. Add a new sign by clicking the "+ New sign" button 6. Enter a name and optionally numbers for automatic page turing 7. Your new sign should appear in the Signs list 8. Add a new stream by clicking the "+ New stream" button 9. Unless you already have reports in the report group with code SIGN, you should be warned that there are no reports in the group with code SIGN and given a link for creating a new report. Follow the link and create a new report with report group code SIGN. En example SQL command for the report could be: SELECT * FROM biblio WHERE timestamp > DATE_SUB(NOW(), INTERVAL 7 DAY) or if you are testing the parameters feature of the digital signs, an example report could be: SELECT * FROM biblio WHERE biblionumber < placeholder. 10. Go back to the "new stream" page, and reload. You should no longer see a warning message, and your newly created report should appear in the list of reports. 11. Select the report and click Submit. Your newly created stream should now appear in the list of streams. 12. In the list of signs, press "edit streams" for the sign you previously created. 13. Choose a stream to attach and click Submit. If you have attached a report with a parameter placeholder, edit the parameters so that the placeholder gets substituted with a value. For example, in the edit parameters box, you can have: placeholder = 10000 When you submit, you'll see the SQL replaces the placeholder with your value and completes the query. Your sign is now ready for OPAC. 14. In OPAC, visit /cgi-bin/koha/opac-signs.pl 15. You should be told that Digital signs are not enabled. Enable with new system preference OPACDigitalSigns and reload the page. 15. You should see a list of available signs, click on a sign that you wish to display. 16. You should now see a list of all books matching the SQL query in the report that you attached to your stream. 17. If you have OPACLocalCoverImages enabled, all books with local covers attached should be presented using this cover. If no local cover is available and the book has a ISBN with a cover in openlibrary.org, the cover image from openlibrary.org should be shown. If all of the above fails, a cover matching the theme of the page should be seen, showing the book title and author. 18. Clicking a book should bring you to a detailed view of the book where you can see the books availability. You should also see the two next books and the two previous books in the stream (unless you're at the beginning or end of the stream) 19. Swiping (if no touch screen, click and hold left mouse button and drag) left/right should bring you to next/previous book. Clicking on the next/previous books (right/left of the active one) should bring you to the detailed view of the clicked book. 20. Leaving the page idle (i.e no user interaction) for the amount of time specified in step 6. should result in the page automatically switching to the next book in the stream. Sponsored-by: Regionbibliotek Halland / County library of Halland Signed-off-by: Lisette Scheer --- koha-tmpl/opac-tmpl/bootstrap/css/signs.css | 100 ++++ .../opac-tmpl/bootstrap/en/modules/opac-signs.tt | 564 +++++++++++++++++++++ opac/opac-signs.pl | 113 +++++ tools/signs.pl | 1 + 4 files changed, 778 insertions(+) create mode 100644 koha-tmpl/opac-tmpl/bootstrap/css/signs.css create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-signs.tt create mode 100755 opac/opac-signs.pl diff --git a/koha-tmpl/opac-tmpl/bootstrap/css/signs.css b/koha-tmpl/opac-tmpl/bootstrap/css/signs.css new file mode 100644 index 0000000000..f481d47cd3 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/css/signs.css @@ -0,0 +1,100 @@ +.carousel-container { + height: 225px; + position: relative; + margin: 0 auto 40px; + -webkit-perspective: 1100px; + -moz-perspective: 1100px; + -o-perspective: 1100px; + -ms-perspective: 1100px; + perspective: 1100px; +} + +.carousel { + width: 100%; + height: 100%; + -webkit-transform-style: preserve-3d; + -moz-transform-style: preserve-3d; + -o-transform-style: preserve-3d; + -ms-transform-style: preserve-3d; + transform-style: preserve-3d; +} + +.unicorn { + display: inline; + position: relative; + width: 150px; + height: 225px; + left: 10px; + top: 10px; + -webkit-box-reflect: below 0 -webkit-gradient(linear, left bottom, left top, color-stop(0.05, rgba(255, 255, 255, 0.12)), color-stop(0.2, transparent)); +} + +.ui-li { + padding-top: 0px !important; + padding-bottom: 0px !important; + margin-bottom: -7px !important; +} + +.ui-li h4 { + margin-top: 2px !important; + margin-bottom: 2px !important; +} + +.ui-li-icon { + top: 15% !important; +} + +.vspace { + margin-top: 2em; +} + +.content { + text-align: center; +} + +.btn-record { + margin: 10px; +} + +.cover { + border: none; + display: inline-block; + height: 225px; + width: 150px; + background-size: 100%; + background-repeat: round; +} + +.cover.cover-blank { +} + +.cover.placeholder { +} + +.cover .cover-inner { + display: table-cell; + vertical-align: middle; + padding: 25px; + border: 2px solid #fff; + height: 171px; + max-height: 171px; + width: inherit; +} + +.cover-text { + text-align: center; + position: relative; + font-family: Georgia, "Palatino Linotype", "Book Antiqua", Palatino, "Times New Roman", serif; + font-size: 1em; + max-height: inherit; + overflow: hidden; +} + +.cover-text .title { + font-weight: bold; +} + +.cover-text .author { + font-style: italic; + margin-top: 1em; +} diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-signs.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-signs.tt new file mode 100644 index 0000000000..6990d3bad4 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-signs.tt @@ -0,0 +1,564 @@ +[% USE Koha %] +[% USE KohaDates %] +[% USE Branches %] +[% USE JSON.Escape %] + +[%- BLOCK item_status -%] + [%- SET itemavailable = 1 -%] + [%- IF ( item.itemlost ) -%] + [%- SET itemavailable = 0 -%] + [%-%]Item lost + [%- END -%] + [%- IF ( item.datedue || issue.date_due ) -%] + [%- SET itemavailable = 0 -%] + [%- IF item.onsite_checkout -%] + [%-%]Currently in local use + [%- ELSE -%] + [%-%]Checked out + [%- END -%] + [%- END -%] + [%- IF ( item.transfertwhen ) %] + [%- SET itemavailable = 0 -%] + [%-%]In transit from [%- item.transfertfrom %] to [%- item.transfertto %] since [%- item.transfertwhen | $KohaDates %] + [%- END %] + [%- IF ( item.waiting ) -%] + [%- SET itemavailable = 0 -%] + [%-%]On hold + [%- END -%] + [%- IF ( item.withdrawn ) -%] + [%- SET itemavailable = 0 -%] + [%-%]Item withdrawn + [%- END -%] + [%- IF ( item.itemnotforloan ) -%] + [%- SET itemavailable = 0 -%] + [%- IF ( item.notforloanvalueopac ) -%] + [%- item.notforloanvalueopac -%] [%- IF ( item.restrictedopac ) -%] ([%- item.restrictedopac -%])[%- END -%] + [%- ELSE -%] + [%-%]Not for loan [%- IF ( item.restrictedopac ) -%] ([%- item.restrictedopac -%])[%- END -%] + [%- END -%] + [%- ELSIF ( item.notforloan_per_itemtype ) -%] + [%- SET itemavailable = 0 -%] + [%-%]Not for loan [%- IF ( item.restrictedopac ) -%] ([%- item.restrictedopac -%])[%- END -%] + [%- END -%] + [%- IF ( item.damaged ) -%] + [%- SET itemavailable = 0 -%] + [%-%]Item damaged + [%- END -%] + [%- IF item.on_order -%] + [%- SET itemavailable = 0 -%] + [%-%]On order + [%- END -%] + [%- IF ( itemavailable ) -%] + [%-%]Available [%- IF ( item.restrictedopac ) -%] ([%- item.restrictedopac -%])[%- END -%] + [%- END -%] +[%- END -%] + +[% INCLUDE 'doc-head-open.inc' %] +[% IF ( sign ) %][% sign.name %] - Koha[% ELSE %]Koha digital signs[% END %] +[%- IF ( sign.webapp ) %] + + +[% END -%] +[% BLOCK cssinclude %] + [%- IF Koha.Preference( 'OPACDigitalSignsCSS' ) != '' -%] + + + [%- ELSE -%] + + + [%- END -%] +[% END # BLOCK cssinclude %] +[% INCLUDE 'doc-head-close.inc' %] + +[% INCLUDE 'bodytag.inc' bodyid='opac-signs' %] + +[%- UNLESS Koha.Preference( 'OPACDigitalSigns' ) -%] +

Digital signs are not enabled!

+[%- ELSE -%] + [%# Display a sign, all its streams and all records %] + [%- IF ( sign ) -%] + [%- IF ( streams.0 ) -%] + [%# Iterate through the streams, creating one front page for each %] + [%- FOREACH s IN streams -%] +
+
+
+ [%# The header has a list of buttons for all the streams %] + [%- SET localstreams = streams -%] + [%- FOREACH stream IN localstreams -%] + [% IF s.sign_stream_id == stream.sign_stream_id %] + [% stream.name %] + [% ELSE %] + [% stream.name %] + [% END %] + [% END -%] +
+
+
+

[% s.name %]

+
+
+ + [% END # FOREACH s IN streams %] + [% ELSE %] +

No streams attached to this sign.

+ [% END # IF ( streams.0 ) %] + [% END # IF ( sign ) %] + + [%# Display a list of all signs, as a default. Links use data-ajax="false" so signs will replace the first page, not be AJAXed in. %] + [%# This page is not meant to be viewed by non-librarians, so it can not be themed. %] + [% IF ( signs ) %] +
+
+

All signs

+
+
+ +
+
+ [% END # IF ( signs ) %] +[% END # UNLESS Koha.Preference( 'OPACDigitalSigns' ) %] + +[% INCLUDE 'opac-bottom.inc' is_popup=1 %] +[% BLOCK jsinclude %] + [% IF sign && Koha.Preference( 'OPACDigitalSigns') %] + + [% END # IF ( sign ) %] + +[% END # BLOCK jsinclude %] + + + diff --git a/opac/opac-signs.pl b/opac/opac-signs.pl new file mode 100755 index 0000000000..48904689b3 --- /dev/null +++ b/opac/opac-signs.pl @@ -0,0 +1,113 @@ +#!/usr/bin/perl + +# Copyright 2012 Magnus Enger Libriotech +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use CGI; +use C4::Auth; +use C4::Output; +use C4::Biblio; +use C4::Reports::Guided; +use C4::Context; +use C4::Koha; +use C4::Items; +use Koha::AuthorisedValues; +use Koha::Signs; +use Koha::SignStreams; +use Koha::SignsToStreams; +use Koha::Reports; +use Modern::Perl; + +binmode STDOUT, ':encoding(UTF-8)'; # FIXME Non-ASCII is broken without this + +my $query = CGI->new; +my $sign_id = $query->param('sign') || ''; + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user({ + 'template_name' => 'opac-signs.tt', + 'query' => $query, + 'type' => 'opac', + 'authnotrequired' => ( C4::Context->preference('OpacPublic') ? 1 : 0 ), + 'flagsrequired' => { borrowers => 1 }, +}); + +if ( C4::Context->preference('OPACDigitalSigns') ) { + if ( $sign_id ne '' ) { # Display a sign with streams + $template->{VARS}->{'sign'} = Koha::Signs->find( $sign_id ); + + # Getting sign streams attached to sign with records + my $schema = Koha::Database->new()->schema(); + my @signstostreams = $schema->resultset('SignsToStream')->search({ 'me.sign_id' => $sign_id }, { prefetch => 'sign_stream' }); + my @changedstreams; + my %record_cache = (); + foreach my $s ( @signstostreams ) { + my $stream = Koha::SignStreams->find( $s->sign_stream_id ); + my $sql = Koha::Reports->find($stream->saved_sql_id); + my $params = Koha::SignsToStreams->find({ sign_to_stream_id => $s->sign_to_stream_id }); + + # Generate SQL with added params + my $newsql = $sql->savedsql; + foreach my $param ( split /&/, $params->params ) { + $param =~ tr/ //ds; # replace any whitespace with nothing, strip the spaces out so the query works + my ( $key, $value ) = split /=|<|>/, $param; # The < and > in the split are just to prevent software errors, the sign in the query must be changed in the report itself + $newsql =~ s/$key/$value/g; + } + + # Run query with new sql + my ( $records, $error ) = execute_query( $newsql, 0, 999999 ); + if ( ! $error ) { + $records = $records->fetchall_arrayref({}); + } + # Include marc + my @processed_records; + foreach my $rec ( @{$records} ) { + unless (defined $record_cache{$rec->{'biblionumber'}}) { + my $marc = GetMarcBiblio({ biblionumber => $rec->{'biblionumber'} }); + if ( ! $marc ) { + next; + } + + my $isbn = GetNormalizedISBN( undef, $marc, C4::Context->preference("marcflavor") ) || ''; + $rec->{'isbn'} = $isbn; + + my $dat = GetBiblioData($rec->{'biblionumber'}); + my @items = GetItemsInfo($rec->{'biblionumber'}); + foreach my $item ( @items ) { + my $shelflocations = { map { $_->authorised_value => $_->opac_description } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) }; + if ( defined $item->{'location'} ) { + $item->{'location_description'} = $shelflocations->{ $item->{'location'} }; + } + } + $rec->{'items'} = \@items; + foreach ( keys %{$dat} ) { + $rec->{"$_"} = defined $dat->{$_} ? $dat->{$_} : ''; + } + $rec->{'marc'} = $marc; + $record_cache{$rec->{'biblionumber'}} = $rec; + } + push @processed_records, $record_cache{$rec->{'biblionumber'}}; + } + $s->{'records'} = \@processed_records; + push @changedstreams, $s; + } + $template->{VARS}->{'streams'} = \@changedstreams; + } else { # Display a list of all available signs + $template->{VARS}->{'signs'} = Koha::Signs->search({}); + } +} + +output_html_with_http_headers $query, $cookie, $template->output; diff --git a/tools/signs.pl b/tools/signs.pl index 01c70bc4de..eff2784a35 100755 --- a/tools/signs.pl +++ b/tools/signs.pl @@ -188,6 +188,7 @@ if ( $op eq 'add_stream' ) { # Generate SQL with added params my $newsql = $sql->savedsql; foreach my $param ( split /&/, $params->params ) { + $param =~ tr/ //ds; # replace any whitespace with nothing, strip the spaces out so the query works my ( $key, $value ) = split /=|<|>/, $param; # The < and > in the split are just to prevent software errors, the sign in the query must be changed in the report itself $newsql =~ s/$key/$value/g; } -- 2.11.0