Lines 38-46
use DateTime::Format::MySQL;
Link Here
|
38 |
use DateTime::Duration; |
38 |
use DateTime::Duration; |
39 |
|
39 |
|
40 |
use constant DURATION_BEFORE_REFRESH => DateTime::Duration->new( months => 3 ); |
40 |
use constant DURATION_BEFORE_REFRESH => DateTime::Duration->new( months => 3 ); |
41 |
|
|
|
42 |
use C4::Output qw( output_with_http_headers ); |
41 |
use C4::Output qw( output_with_http_headers ); |
43 |
my $input = new CGI; |
42 |
my $input = CGI->new; |
44 |
binmode STDOUT, ":encoding(UTF-8)"; |
43 |
binmode STDOUT, ":encoding(UTF-8)"; |
45 |
|
44 |
|
46 |
|
45 |
|
Lines 70-75
eval {
Link Here
|
70 |
$temp = $now - $timestamp; |
69 |
$temp = $now - $timestamp; |
71 |
}; |
70 |
}; |
72 |
my @biblios; |
71 |
my @biblios; |
|
|
72 |
my @biblios_blessed; |
73 |
if ( $local_suggestions and DateTime::Duration->compare( ($now - $timestamp), DURATION_BEFORE_REFRESH ) == -1 ){ |
73 |
if ( $local_suggestions and DateTime::Duration->compare( ($now - $timestamp), DURATION_BEFORE_REFRESH ) == -1 ){ |
74 |
delete $local_suggestions->{timestamp}; |
74 |
delete $local_suggestions->{timestamp}; |
75 |
delete $local_suggestions->{biblionumber}; |
75 |
delete $local_suggestions->{biblionumber}; |
Lines 86-92
else{
Link Here
|
86 |
my $notnormalizeddocumentid; |
86 |
my $notnormalizeddocumentid; |
87 |
if ( $biblioitem->isbn ){ |
87 |
if ( $biblioitem->isbn ){ |
88 |
$idtype= "isbn"; |
88 |
$idtype= "isbn"; |
89 |
$documentid= NormalizeISBN({ isbn => $biblioitem->isbn, format => 'ISBN-13', strip_hyphens => 1 }); |
89 |
$documentid= C4::Koha::NormalizeISBN({ isbn => $biblioitem->isbn, format => 'ISBN-13', strip_hyphens => 1 }); |
90 |
} |
90 |
} |
91 |
elsif ( $biblioitem->issn ){ |
91 |
elsif ( $biblioitem->issn ){ |
92 |
$idtype= "issn"; |
92 |
$idtype= "issn"; |
Lines 110-116
else{
Link Here
|
110 |
my $url = "$mana_ip/getsuggestion/$notnormalizeddocumentid/$idtype?offset=$offset&length=$length"; |
110 |
my $url = "$mana_ip/getsuggestion/$notnormalizeddocumentid/$idtype?offset=$offset&length=$length"; |
111 |
my $request = HTTP::Request->new( GET => $url ); |
111 |
my $request = HTTP::Request->new( GET => $url ); |
112 |
$request->content_type('aplication/json'); |
112 |
$request->content_type('aplication/json'); |
113 |
my $response = Koha::SharedContent::manaRequest( $request ); |
113 |
my $response = Koha::SharedContent::process_request( $request ); |
114 |
|
114 |
|
115 |
#error handling |
115 |
#error handling |
116 |
my $resources = $response->{data}; |
116 |
my $resources = $response->{data}; |
Lines 139-160
else{
Link Here
|
139 |
foreach my $resource ( @{ $resources } ){ |
139 |
foreach my $resource ( @{ $resources } ){ |
140 |
# isbn processsing |
140 |
# isbn processsing |
141 |
if ( $resource->{idtype} eq "isbn" ){ |
141 |
if ( $resource->{idtype} eq "isbn" ){ |
142 |
$documentid= NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 1 }); |
142 |
$documentid= C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 1 }); |
143 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; |
143 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; |
144 |
|
144 |
|
145 |
#if we don't have such a biblioitem, we try to format else the isbn |
145 |
#if we don't have such a biblioitem, we try to format else the isbn |
146 |
unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ |
146 |
unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ |
147 |
$documentid = NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 1 }); |
147 |
$documentid = C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 1 }); |
148 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; |
148 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; |
149 |
} |
149 |
} |
150 |
|
150 |
|
151 |
unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ |
151 |
unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ |
152 |
$documentid = NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 0 }); |
152 |
$documentid = C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 0 }); |
153 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; |
153 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; |
154 |
} |
154 |
} |
155 |
|
155 |
|
156 |
unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ |
156 |
unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ |
157 |
$documentid = NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 0 }); |
157 |
$documentid = C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 0 }); |
158 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; |
158 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; |
159 |
} |
159 |
} |
160 |
|
160 |
|
Lines 165-175
else{
Link Here
|
165 |
} |
165 |
} |
166 |
if (scalar @{ $ownedbiblioitem->unblessed() } ){ |
166 |
if (scalar @{ $ownedbiblioitem->unblessed() } ){ |
167 |
my $ownedbiblio = Koha::Biblios->find( @{ $ownedbiblioitem->unblessed() }[0]->{biblionumber} ); |
167 |
my $ownedbiblio = Koha::Biblios->find( @{ $ownedbiblioitem->unblessed() }[0]->{biblionumber} ); |
168 |
push @biblios, $ownedbiblio; |
168 |
push @biblios_blessed, $ownedbiblio; |
|
|
169 |
push @biblios, $ownedbiblio->unblessed(); |
169 |
} |
170 |
} |
170 |
} |
171 |
} |
171 |
#the number of requested resource is inversely proportionnal to the found_items/returned_items ratio, +1 is here just to avoid 0 |
172 |
#the number of requested resource is inversely proportionnal to the found_items/returned_items ratio, +1 is here just to avoid 0 |
172 |
my $newlength = int( ( 10*( $length + $offset ) - $length ) / (scalar @biblios + 1 )); |
173 |
my $newlength = int( ( 10*( $length + $offset ) - $length ) / (scalar @biblios_blessed + 1 )); |
173 |
if ( $newlength > 500 ){ |
174 |
if ( $newlength > 500 ){ |
174 |
$newlength = 500; |
175 |
$newlength = 500; |
175 |
} |
176 |
} |
Lines 177-192
else{
Link Here
|
177 |
$length = $newlength; |
178 |
$length = $newlength; |
178 |
|
179 |
|
179 |
|
180 |
|
180 |
} while( (scalar @biblios < 10 ) and $mananotover ); |
181 |
} while( (scalar @biblios_blessed < 10 ) and $mananotover ); |
181 |
|
182 |
|
182 |
#preparing new suggestion |
183 |
#preparing new suggestion |
183 |
my $newSuggestion; |
184 |
my $newSuggestion; |
184 |
my $cter = scalar @biblios; |
185 |
my $cter = scalar @biblios_blessed; |
185 |
$cter = 10 unless ($cter < 10); |
186 |
$cter = 10 unless ($cter < 10); |
186 |
$newSuggestion->{ biblionumber } = $biblionumber; |
187 |
$newSuggestion->{ biblionumber } = $biblionumber; |
187 |
while ( $cter > 0 ){ |
188 |
while ( $cter > 0 ){ |
188 |
if ( $biblios[ $cter-1 ] and $biblios[ $cter-1 ]->biblionumber){ |
189 |
if ( $biblios_blessed[ $cter-1 ] and $biblios_blessed[ $cter-1 ]->biblionumber){ |
189 |
$newSuggestion->{ "biblionumber".$cter }=$biblios[ $cter-1 ]->biblionumber; |
190 |
$newSuggestion->{ "biblionumber".$cter }=$biblios_blessed[ $cter-1 ]->biblionumber; |
190 |
} |
191 |
} |
191 |
$cter--; |
192 |
$cter--; |
192 |
} |
193 |
} |
Lines 205-211
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Link Here
|
205 |
debug => 1, |
206 |
debug => 1, |
206 |
} |
207 |
} |
207 |
); |
208 |
); |
208 |
|
|
|
209 |
$template->param( JacketImage => 1); |
209 |
$template->param( JacketImage => 1); |
210 |
$template->param( suggestions => \@biblios ); |
210 |
$template->param( suggestions => \@biblios ); |
211 |
|
211 |
|
212 |
- |
|
|