View | Details | Raw Unified | Return to bug 18618
Collapse All | Expand All

(-)a/Koha/Biblio.pm (+14 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Carp;
22
use Carp;
23
23
24
use C4::Biblio qw();
24
use C4::Biblio qw();
25
use C4::Koha qw(NormalizeISBN);
25
26
26
use Koha::Database;
27
use Koha::Database;
27
use Koha::DateUtils qw( dt_from_string );
28
use Koha::DateUtils qw( dt_from_string );
Lines 319-324 sub subscriptions { Link Here
319
320
320
=cut
321
=cut
321
322
323
=head3 normalized_isbn
324
325
my $normalized_isbn = $biblio->normalizedisbn();
326
327
Return the normalized isbn of the biblio ( isbn-10 without hyphens )
328
329
=cut
330
331
sub normalized_isbn {
332
    my $self = shift;
333
    return NormalizeISBN({ isbn => $self->biblioitem->isbn, format => 'ISBN-10', strip_hyphens => 1 });
334
}
335
322
sub _type {
336
sub _type {
323
    return 'Biblio';
337
    return 'Biblio';
324
}
338
}
(-)a/Koha/Reading_suggestion.pm (+50 lines)
Line 0 Link Here
1
package Koha::Reading_suggestion;
2
3
# Copyright Biblibre 2017 - Baptiste Wojtkowski
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
use Koha::DateUtils qw( dt_from_string );
26
27
use base qw(Koha::Object);
28
29
30
=head1 NAME
31
32
Koha::Biblio - Koha Biblio Object class
33
34
=head1 API
35
36
=head2 Class Methods
37
38
=cut
39
40
sub _type {
41
    return 'ReadingSuggestion';
42
}
43
44
=head1 AUTHOR
45
46
Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com>
47
48
=cut
49
50
1;
(-)a/Koha/Reading_suggestions.pm (+58 lines)
Line 0 Link Here
1
package Koha::Reading_suggestions;
2
3
# Copiright Biblibre 2017 - Baptiste Wojtkowski
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
use Carp;
22
use Koha::Database;
23
use Koha::Reading_suggestion;
24
use base qw(Koha::Objects);
25
26
=head1 NAME
27
28
Koha::Reading_suggestions - Koha Reading_suggestion object set class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 type
37
38
=cut
39
40
sub _type {
41
    return 'ReadingSuggestion';
42
}
43
44
=head3 object_class
45
46
=cut
47
48
sub object_class {
49
    return 'Koha::Reading_suggestion';
50
}
51
52
=head1 AUTHOR
53
54
Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com>
55
56
=cut
57
58
1
(-)a/installer/data/mysql/atomicupdate/mana_add_table_reading_pairs.sql (+16 lines)
Line 0 Link Here
1
-- biblionumber1 not null otherwise the data is useless
2
CREATE TABLE `reading_suggestion` (
3
  `biblionumber` int(11) NOT NULL,
4
  `biblionumber1` int(11) NOT NULL,
5
  `biblionumber2` int(11) DEFAULT NULL,
6
  `biblionumber3` int(11) DEFAULT NULL,
7
  `biblionumber4` int(11) DEFAULT NULL,
8
  `biblionumber5` int(11) DEFAULT NULL,
9
  `biblionumber6` int(11) DEFAULT NULL,
10
  `biblionumber7` int(11) DEFAULT NULL,
11
  `biblionumber8` int(11) DEFAULT NULL,
12
  `biblionumber9` int(11) DEFAULT NULL,
13
  `biblionumber10` int(11) DEFAULT NULL,
14
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
15
  PRIMARY KEY (`biblionumber`)
16
);
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/mana/mana_suggestions.tt (+40 lines)
Line 0 Link Here
1
[% USE Koha %]
2
[% IF suggestions %]
3
    <table id="suggestions_tab" class="table table-bordered table-striped">
4
        <caption>[% issues_count %] Item(s) you should try</caption>
5
        <thead>
6
            <tr>
7
                <th class="nosort">Cover Image</th>
8
                <th class="anti-the">Title</th>
9
                <th>Author</th>
10
                <th>Publisher</th>
11
            </tr>
12
        </thead>
13
        <tbody>
14
            [% FOREACH suggestion IN suggestions %]
15
            <tr>
16
               <td class="jacketcell">
17
                [% IF ( Koha.Preference('OPACAmazonCoverImages') ) %]
18
19
                [% IF ( suggestion.normalized_isbn() ) %]
20
                    <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>
21
                [% ELSE %]
22
                    <a href="#"><span class="no-image">No cover image available</span></a>
23
                [% END %]
24
                [% END %]
25
                </td>
26
                <td class="title">
27
                    <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>
28
                </td>
29
                <td class="author">[% suggestion.author %]</td>
30
                </td>
31
                <td class="publisher">
32
                    <span class="publisher">[% suggestion.biblioitem.publishercode %]</td>
33
                </td>
34
            </tr>
35
            [% END # /FOREACH suggestions %]
36
        </tbody>
37
    </table>
38
[% ELSE %]
39
    <h1> There are no available suggestions on mana KB </h1>
40
[% END # IF suggestions %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt (+30 lines)
Lines 611-616 Link Here
611
                        [% IF ( IDreamBooksReviews ) %]
611
                        [% IF ( IDreamBooksReviews ) %]
612
                            <li id='tab_idb_critic_reviews' style="display:none;"><a href='#idb_critic_reviews'>Book reviews by critics ( XXX )</a></li>
612
                            <li id='tab_idb_critic_reviews' style="display:none;"><a href='#idb_critic_reviews'>Book reviews by critics ( XXX )</a></li>
613
                        [% END %]
613
                        [% END %]
614
615
                        [% IF Koha.Preference( 'Mana' ) == 1 %]
616
                            <li id="tab_suggestions"><a href="#reading_suggestions">Suggestion </a></li>
617
                        [% END %]
614
                    </ul>
618
                    </ul>
615
619
616
                    [% IF ( serialcollection ) %]
620
                    [% IF ( serialcollection ) %]
Lines 877-882 Link Here
877
                                </div>
881
                                </div>
878
                    [% END # / IF LibraryThingForLibrariesID && LibraryThingForLibrariesTabbedView %]
882
                    [% END # / IF LibraryThingForLibrariesID && LibraryThingForLibrariesTabbedView %]
879
883
884
                    [% IF Koha.Preference( 'Mana' ) == 1 %]
885
                        <div id="reading_suggestions">
886
                        </div>
887
                    [% END # / IF Koha.Preference( 'Mana') ==1 %]
888
880
                    [% IF Koha.Preference( 'reviewson' ) == 1 %]
889
                    [% IF Koha.Preference( 'reviewson' ) == 1 %]
881
                        <div id="comments">
890
                        <div id="comments">
882
                            <div id="newcomment"></div>
891
                            <div id="newcomment"></div>
Lines 1904-1907 Link Here
1904
    //]]>
1913
    //]]>
1905
    </script>
1914
    </script>
1906
[% END # / IF OPACPopupAuthorsSearch  %]
1915
[% END # / IF OPACPopupAuthorsSearch  %]
1916
1917
[% IF Koha.Preference('Mana') %]
1918
    <script>
1919
        $("#reading_suggestions").html("");
1920
        $(document).ready( function(){
1921
            $( "#tab_suggestions" ).one( "click", function(){
1922
                $.ajax({
1923
                    type: "POST",
1924
                    url: "/cgi-bin/koha/svc/mana/getSuggestion",
1925
                    data: { biblionumber : [% biblionumber %] },
1926
                    dataType: "html",
1927
                } ).done( function( data ) {
1928
                    $( "#reading_suggestions" ).html(data)
1929
                } ).fail( function( error, msg, longmsg ) {
1930
                    $( "#reading_suggestions" ).html( "<h1> An error occured: unknown error </h1>" )
1931
                } );
1932
            });
1933
        });
1934
    </script>
1935
[% END %]
1936
1907
[% END %]
1937
[% END %]
(-)a/opac/svc/mana/getSuggestion (-1 / +178 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2017 BibLibre Baptiste Wojtkowski
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
#
20
21
use Modern::Perl;
22
use Koha::SharedContent;
23
use Koha::Biblioitems;
24
use Koha::Biblioitem;
25
use Koha::Reading_suggestions;
26
use Koha::Reading_suggestion;
27
28
use Koha;
29
use C4::Koha;
30
31
use C4::Auth qw(check_cookie_auth), qw(get_template_and_user);
32
33
use CGI;
34
use JSON;
35
36
use DateTime;
37
use DateTime::Format::MySQL;
38
use DateTime::Duration;
39
40
use constant DURATION_BEFORE_REFRESH => DateTime::Duration->new( months => 3 );
41
42
use C4::Output qw( output_with_http_headers );
43
my $input = new CGI;
44
binmode STDOUT, ":encoding(UTF-8)";
45
my $biblionumber = $input->param( "biblionumber" );
46
my $biblioitem = Koha::Biblioitems->find( $biblionumber );
47
48
my $local_suggestions;
49
50
my $now;
51
my $timestamp;
52
my $temp;
53
#check it doesn't already have the informations localy stored
54
eval {
55
    $local_suggestions = Koha::Reading_suggestions->find( $biblionumber )->unblessed();
56
    $now = DateTime->now();
57
    $timestamp = DateTime::Format::MySQL->parse_timestamp( $local_suggestions->{timestamp} );
58
    $temp = $now - $timestamp;
59
};
60
my @biblios;
61
if ( $local_suggestions and DateTime::Duration->compare( ($now - $timestamp), DURATION_BEFORE_REFRESH ) == -1 ){
62
        delete $local_suggestions->{timestamp};
63
        delete $local_suggestions->{biblionumber};
64
        foreach my $key ( sort keys %{ $local_suggestions }){
65
            push @biblios, Koha::Biblios->find( $local_suggestions->{ $key } );
66
        }
67
}
68
else{
69
    # get all informations to ask mana
70
    my $idtype;
71
    my $documentid;
72
    if ( $biblioitem->isbn ){
73
        $idtype= "isbn";
74
        $documentid= NormalizeISBN({ isbn => $biblioitem->isbn, format => 'ISBN-13', strip_hyphens => 1 });
75
    }
76
    elsif ( $biblioitem->issn ){
77
        $idtype= "issn";
78
        $documentid= $biblioitem->issn;
79
    }
80
    elsif ( $biblioitem->ean ){
81
        $idtype= "ean";
82
        $documentid= $biblioitem->ean;
83
    }
84
    else{
85
        die "error: no propper identifier";
86
    }
87
88
    #request mana
89
    my $mana_ip = C4::Context->config('mana_config');
90
    my $url = "$mana_ip/getsuggestion/$documentid/$idtype";
91
    my $request = HTTP::Request->new( GET => $url );
92
    $request->content_type('aplication/json');
93
    my $response = Koha::SharedContent::manaRequest( $request );
94
95
    #error handling
96
    my $resources = $response->{data};
97
    unless ( $resources ){
98
        my $msg;
99
        $msg = $response->{msg};
100
        if ( $msg ){
101
            die $msg;
102
        }
103
        else{
104
            die "Unknown error";
105
        }
106
    }
107
    #create the list of owned suggested resources
108
    my $ownedbiblioitem;
109
    my $ownedbiblio;
110
    foreach my $resource ( @{ $resources } ){
111
112
113
    #   isbn processsing
114
        if ( $resource->{idtype} eq "isbn" ){
115
            $documentid= NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 1 });
116
            $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid});
117
118
        #if we don't have such a biblioitem, we try to format else the isbn
119
            unless ( scalar @{ $ownedbiblioitem->unblessed() } ){
120
                $documentid = NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 1 });
121
                $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid});
122
            }
123
124
            unless ( scalar @{ $ownedbiblioitem->unblessed() } ){
125
                $documentid = NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 0 });
126
                $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid});
127
            }
128
129
            unless ( scalar @{ $ownedbiblioitem->unblessed() } ){
130
                $documentid = NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 0 });
131
                $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid});
132
            }
133
134
        }
135
    #others ids do not need any processing
136
        else{
137
            $ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid});
138
        }
139
        if (scalar @{ $ownedbiblioitem->unblessed() } ){
140
            $ownedbiblio = Koha::Biblios->find(  @{ $ownedbiblioitem->unblessed() }[0]->{biblionumber} );
141
            push @biblios, $ownedbiblio;
142
        }
143
    }
144
145
    #preparing new suggestion
146
    my $newSuggestion;
147
    my $cter = scalar @biblios;
148
    $cter = 10 unless ($cter < 10);
149
    $newSuggestion->{ biblionumber } = $biblionumber;
150
    if ( scalar @biblios < 11 ){
151
    while ( $cter > 1 ){
152
            $cter--;
153
            $newSuggestion->{ "biblionumber".$cter }=$biblios[ $cter ]->biblionumber;
154
        }
155
    }
156
    if ( $local_suggestions ){
157
        Koha::Reading_suggestions->find( $biblionumber )->delete();
158
    }
159
    Koha::Reading_suggestion->new( $newSuggestion )->store;
160
161
}
162
163
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
164
    {
165
        template_name   => "mana/mana_suggestions.tt",
166
        query           => $input,
167
        type            => "opac",
168
        authnotrequired => 1,
169
        debug           => 1,
170
    }
171
);
172
173
174
$template->param( JacketImage => 1);
175
$template->param( suggestions => \@biblios );
176
177
178
output_with_http_headers $input, $cookie, $template->output, 'json';

Return to bug 18618