Bugzilla – Attachment 65068 Details for
Bug 18618
Mana - Add reading suggestions (crontab and scripts for Koha)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18618: Mana - Add reading suggestion
Bug-18618-Mana---Add-reading-suggestion.patch (text/plain), 16.44 KB, created by
Brendan Gallagher
on 2017-07-14 19:57:31 UTC
(
hide
)
Description:
Bug 18618: Mana - Add reading suggestion
Filename:
MIME Type:
Creator:
Brendan Gallagher
Created:
2017-07-14 19:57:31 UTC
Size:
16.44 KB
patch
obsolete
>From 64865b6ee5fb61a6d9d1c6279adbe7cd3c7e618a Mon Sep 17 00:00:00 2001 >From: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com> >Date: Mon, 15 May 2017 13:58:58 +0000 >Subject: [PATCH] Bug 18618: Mana - Add reading suggestion > >There is now a module to get suggestions from Mana. > >- It is activated by default on Mana. >- When you browse on a notice, there is now a tab called "Suggestions" >- On click on the tab, it will check in the database if it has suggestions. >- Else, it will ask to Mana for suggestions and will store in the database. > >- The suggestions are stored in the NEW table reading_pairs >- Implement new dbix objets: Reading_suggestion and Reading_suggestions > >Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com> >--- > Koha/Biblio.pm | 14 ++ > Koha/Reading_suggestion.pm | 50 ++++++ > Koha/Reading_suggestions.pm | 58 +++++++ > .../atomicupdate/mana_add_table_reading_pairs.sql | 16 ++ > .../bootstrap/en/modules/mana/mana_suggestions.tt | 40 +++++ > .../opac-tmpl/bootstrap/en/modules/opac-detail.tt | 30 ++++ > opac/svc/mana/getSuggestion | 178 +++++++++++++++++++++ > 7 files changed, 386 insertions(+) > create mode 100644 Koha/Reading_suggestion.pm > create mode 100644 Koha/Reading_suggestions.pm > create mode 100644 installer/data/mysql/atomicupdate/mana_add_table_reading_pairs.sql > create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/modules/mana/mana_suggestions.tt > create mode 100755 opac/svc/mana/getSuggestion > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index aad4343..8841b57 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -22,6 +22,7 @@ use Modern::Perl; > use Carp; > > use C4::Biblio qw(); >+use C4::Koha qw(NormalizeISBN); > > use Koha::Database; > use Koha::DateUtils qw( dt_from_string ); >@@ -319,6 +320,19 @@ sub subscriptions { > > =cut > >+=head3 normalized_isbn >+ >+my $normalized_isbn = $biblio->normalizedisbn(); >+ >+Return the normalized isbn of the biblio ( isbn-10 without hyphens ) >+ >+=cut >+ >+sub normalized_isbn { >+ my $self = shift; >+ return NormalizeISBN({ isbn => $self->biblioitem->isbn, format => 'ISBN-10', strip_hyphens => 1 }); >+} >+ > sub _type { > return 'Biblio'; > } >diff --git a/Koha/Reading_suggestion.pm b/Koha/Reading_suggestion.pm >new file mode 100644 >index 0000000..485cdce >--- /dev/null >+++ b/Koha/Reading_suggestion.pm >@@ -0,0 +1,50 @@ >+package Koha::Reading_suggestion; >+ >+# Copyright Biblibre 2017 - Baptiste Wojtkowski >+# >+# 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 Modern::Perl; >+ >+use Carp; >+ >+use Koha::Database; >+use Koha::DateUtils qw( dt_from_string ); >+ >+use base qw(Koha::Object); >+ >+ >+=head1 NAME >+ >+Koha::Biblio - Koha Biblio Object class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+sub _type { >+ return 'ReadingSuggestion'; >+} >+ >+=head1 AUTHOR >+ >+Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com> >+ >+=cut >+ >+1; >diff --git a/Koha/Reading_suggestions.pm b/Koha/Reading_suggestions.pm >new file mode 100644 >index 0000000..93c7c14 >--- /dev/null >+++ b/Koha/Reading_suggestions.pm >@@ -0,0 +1,58 @@ >+package Koha::Reading_suggestions; >+ >+# Copiright Biblibre 2017 - Baptiste Wojtkowski >+# >+# 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 Modern::Perl; >+use Carp; >+use Koha::Database; >+use Koha::Reading_suggestion; >+use base qw(Koha::Objects); >+ >+=head1 NAME >+ >+Koha::Reading_suggestions - Koha Reading_suggestion object set class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 type >+ >+=cut >+ >+sub _type { >+ return 'ReadingSuggestion'; >+} >+ >+=head3 object_class >+ >+=cut >+ >+sub object_class { >+ return 'Koha::Reading_suggestion'; >+} >+ >+=head1 AUTHOR >+ >+Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com> >+ >+=cut >+ >+1 >diff --git a/installer/data/mysql/atomicupdate/mana_add_table_reading_pairs.sql b/installer/data/mysql/atomicupdate/mana_add_table_reading_pairs.sql >new file mode 100644 >index 0000000..eea656d >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/mana_add_table_reading_pairs.sql >@@ -0,0 +1,16 @@ >+-- biblionumber1 not null otherwise the data is useless >+CREATE TABLE `reading_suggestion` ( >+ `biblionumber` int(11) NOT NULL, >+ `biblionumber1` int(11) NOT NULL, >+ `biblionumber2` int(11) DEFAULT NULL, >+ `biblionumber3` int(11) DEFAULT NULL, >+ `biblionumber4` int(11) DEFAULT NULL, >+ `biblionumber5` int(11) DEFAULT NULL, >+ `biblionumber6` int(11) DEFAULT NULL, >+ `biblionumber7` int(11) DEFAULT NULL, >+ `biblionumber8` int(11) DEFAULT NULL, >+ `biblionumber9` int(11) DEFAULT NULL, >+ `biblionumber10` int(11) DEFAULT NULL, >+ `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, >+ PRIMARY KEY (`biblionumber`) >+); >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/mana/mana_suggestions.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/mana/mana_suggestions.tt >new file mode 100644 >index 0000000..5033a50 >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/mana/mana_suggestions.tt >@@ -0,0 +1,40 @@ >+[% USE Koha %] >+[% IF suggestions %] >+ <table id="suggestions_tab" class="table table-bordered table-striped"> >+ <caption>[% issues_count %] Item(s) you should try</caption> >+ <thead> >+ <tr> >+ <th class="nosort">Cover Image</th> >+ <th class="anti-the">Title</th> >+ <th>Author</th> >+ <th>Publisher</th> >+ </tr> >+ </thead> >+ <tbody> >+ [% FOREACH suggestion IN suggestions %] >+ <tr> >+ <td class="jacketcell"> >+ [% IF ( Koha.Preference('OPACAmazonCoverImages') ) %] >+ >+ [% IF ( suggestion.normalized_isbn() ) %] >+ <a href="http://www.amazon.com/gp/reader/[% suggestion.normalized_isbn() %]/ref=sib_dp_pt/002-7879865-0184864#reader-link" title="View on Amazon.com"><img src="https://images-na.ssl-images-amazon.com/images/P/[% suggestion.normalized_isbn() %].01.THUMBZZZ.jpg" alt="View on Amazon.com" class="item-thumbnail"/></a> >+ [% ELSE %] >+ <a href="#"><span class="no-image">No cover image available</span></a> >+ [% END %] >+ [% END %] >+ </td> >+ <td class="title"> >+ <a class="title" href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% suggestion.biblionumber %]">[% suggestion.title |html %] [% FOREACH subtitl IN suggestion.subtitles %] [% subtitl.subfield %][% END %]</a> >+ </td> >+ <td class="author">[% suggestion.author %]</td> >+ </td> >+ <td class="publisher"> >+ <span class="publisher">[% suggestion.biblioitem.publishercode %]</td> >+ </td> >+ </tr> >+ [% END # /FOREACH suggestions %] >+ </tbody> >+ </table> >+[% ELSE %] >+ <h1> There are no available suggestions on mana KB </h1> >+[% END # IF suggestions %] >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >index d95dc8c..4c51b5c 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt >@@ -623,6 +623,10 @@ > [% IF ( IDreamBooksReviews ) %] > <li id='tab_idb_critic_reviews' style="display:none;"><a href='#idb_critic_reviews'>Book reviews by critics ( XXX )</a></li> > [% END %] >+ >+ [% IF Koha.Preference( 'Mana' ) == 1 %] >+ <li id="tab_suggestions"><a href="#reading_suggestions">Suggestion </a></li> >+ [% END %] > </ul> > > [% IF ( serialcollection ) %] >@@ -899,6 +903,11 @@ > </div> > [% END # / IF LibraryThingForLibrariesID && LibraryThingForLibrariesTabbedView %] > >+ [% IF Koha.Preference( 'Mana' ) == 1 %] >+ <div id="reading_suggestions"> >+ </div> >+ [% END # / IF Koha.Preference( 'Mana') ==1 %] >+ > [% IF Koha.Preference( 'reviewson' ) == 1 %] > <div id="comments"> > <div id="newcomment"></div> >@@ -1926,4 +1935,25 @@ > //]]> > </script> > [% END # / IF OPACPopupAuthorsSearch %] >+ >+[% IF Koha.Preference('Mana') %] >+ <script> >+ $("#reading_suggestions").html(""); >+ $(document).ready( function(){ >+ $( "#tab_suggestions" ).one( "click", function(){ >+ $.ajax({ >+ type: "POST", >+ url: "/cgi-bin/koha/svc/mana/getSuggestion", >+ data: { biblionumber : [% biblionumber %] }, >+ dataType: "html", >+ } ).done( function( data ) { >+ $( "#reading_suggestions" ).html(data) >+ } ).fail( function( error, msg, longmsg ) { >+ $( "#reading_suggestions" ).html( "<h1> An error occured: unknown error </h1>" ) >+ } ); >+ }); >+ }); >+ </script> >+[% END %] >+ > [% END %] >diff --git a/opac/svc/mana/getSuggestion b/opac/svc/mana/getSuggestion >new file mode 100755 >index 0000000..3760451 >--- /dev/null >+++ b/opac/svc/mana/getSuggestion >@@ -0,0 +1,178 @@ >+#!/usr/bin/perl >+ >+# Copyright 2017 BibLibre Baptiste Wojtkowski >+# >+# 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, see <http://www.gnu.org/licenses>. >+# >+ >+use Modern::Perl; >+use Koha::SharedContent; >+use Koha::Biblioitems; >+use Koha::Biblioitem; >+use Koha::Reading_suggestions; >+use Koha::Reading_suggestion; >+ >+use Koha; >+use C4::Koha; >+ >+use C4::Auth qw(check_cookie_auth), qw(get_template_and_user); >+ >+use CGI; >+use JSON; >+ >+use DateTime; >+use DateTime::Format::MySQL; >+use DateTime::Duration; >+ >+use constant DURATION_BEFORE_REFRESH => DateTime::Duration->new( months => 3 ); >+ >+use C4::Output qw( output_with_http_headers ); >+my $input = new CGI; >+binmode STDOUT, ":encoding(UTF-8)"; >+my $biblionumber = $input->param( "biblionumber" ); >+my $biblioitem = Koha::Biblioitems->find( $biblionumber ); >+ >+my $local_suggestions; >+ >+my $now; >+my $timestamp; >+my $temp; >+#check it doesn't already have the informations localy stored >+eval { >+ $local_suggestions = Koha::Reading_suggestions->find( $biblionumber )->unblessed(); >+ $now = DateTime->now(); >+ $timestamp = DateTime::Format::MySQL->parse_timestamp( $local_suggestions->{timestamp} ); >+ $temp = $now - $timestamp; >+}; >+my @biblios; >+if ( $local_suggestions and DateTime::Duration->compare( ($now - $timestamp), DURATION_BEFORE_REFRESH ) == -1 ){ >+ delete $local_suggestions->{timestamp}; >+ delete $local_suggestions->{biblionumber}; >+ foreach my $key ( sort keys %{ $local_suggestions }){ >+ push @biblios, Koha::Biblios->find( $local_suggestions->{ $key } ); >+ } >+} >+else{ >+ # get all informations to ask mana >+ my $idtype; >+ my $documentid; >+ if ( $biblioitem->isbn ){ >+ $idtype= "isbn"; >+ $documentid= NormalizeISBN({ isbn => $biblioitem->isbn, format => 'ISBN-13', strip_hyphens => 1 }); >+ } >+ elsif ( $biblioitem->issn ){ >+ $idtype= "issn"; >+ $documentid= $biblioitem->issn; >+ } >+ elsif ( $biblioitem->ean ){ >+ $idtype= "ean"; >+ $documentid= $biblioitem->ean; >+ } >+ else{ >+ die "error: no propper identifier"; >+ } >+ >+ #request mana >+ my $mana_ip = C4::Context->config('mana_config'); >+ my $url = "$mana_ip/getsuggestion/$documentid/$idtype"; >+ my $request = HTTP::Request->new( GET => $url ); >+ $request->content_type('aplication/json'); >+ my $response = Koha::SharedContent::manaRequest( $request ); >+ >+ #error handling >+ my $resources = $response->{data}; >+ unless ( $resources ){ >+ my $msg; >+ $msg = $response->{msg}; >+ if ( $msg ){ >+ die $msg; >+ } >+ else{ >+ die "Unknown error"; >+ } >+ } >+ #create the list of owned suggested resources >+ my $ownedbiblioitem; >+ my $ownedbiblio; >+ foreach my $resource ( @{ $resources } ){ >+ >+ >+ # Â isbn processsing >+ if ( $resource->{idtype} eq "isbn" ){ >+ $documentid= NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 1 }); >+ $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}); >+ >+ #if we don't have such a biblioitem, we try to format else the isbn >+ unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ >+ $documentid = NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 1 }); >+ $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}); >+ } >+ >+ unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ >+ $documentid = NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 0 }); >+ $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}); >+ } >+ >+ unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ >+ $documentid = NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 0 }); >+ $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}); >+ } >+ >+ } >+ #others ids do not need any processing >+ else{ >+ $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}); >+ } >+ if (scalar @{ $ownedbiblioitem->unblessed() } ){ >+ $ownedbiblio = Koha::Biblios->find( @{ $ownedbiblioitem->unblessed() }[0]->{biblionumber} ); >+ push @biblios, $ownedbiblio; >+ } >+ } >+ >+ #preparing new suggestion >+ my $newSuggestion; >+ my $cter = scalar @biblios; >+ $cter = 10 unless ($cter < 10); >+ $newSuggestion->{ biblionumber } = $biblionumber; >+ if ( scalar @biblios < 11 ){ >+ while ( $cter > 1 ){ >+ $cter--; >+ $newSuggestion->{ "biblionumber".$cter }=$biblios[ $cter ]->biblionumber; >+ } >+ } >+ if ( $local_suggestions ){ >+ Koha::Reading_suggestions->find( $biblionumber )->delete(); >+ } >+ Koha::Reading_suggestion->new( $newSuggestion )->store; >+ >+} >+ >+my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >+ { >+ template_name => "mana/mana_suggestions.tt", >+ query => $input, >+ type => "opac", >+ authnotrequired => 1, >+ debug => 1, >+ } >+); >+ >+ >+$template->param( JacketImage => 1); >+$template->param( suggestions => \@biblios ); >+ >+ >+output_with_http_headers $input, $cookie, $template->output, 'json'; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18618
:
63496
|
63497
|
64531
|
64960
|
65066
|
65067
|
65068
|
65069
|
65070
|
130706
|
130707
|
130708
|
130709
|
130710
|
130711
|
130712
|
130713
|
130714
|
130715
|
130735
|
130736
|
130737
|
130738
|
130739
|
130740
|
130741
|
130742
|
130743
|
130744
|
132690
|
132691