Lines 24-35
use Koha::Biblioitems;
Link Here
|
24 |
use Koha::Biblioitem; |
24 |
use Koha::Biblioitem; |
25 |
use Koha::Reading_suggestions; |
25 |
use Koha::Reading_suggestions; |
26 |
use Koha::Reading_suggestion; |
26 |
use Koha::Reading_suggestion; |
|
|
27 |
use Koha::Util::Normalize q/NormalizeISMN/; |
27 |
|
28 |
|
28 |
use Koha; |
29 |
use Koha; |
29 |
use C4::Koha; |
30 |
use C4::Koha; |
30 |
|
31 |
use C4::Context; |
31 |
use C4::Auth qw(check_cookie_auth), qw(get_template_and_user); |
32 |
use C4::Auth qw(check_cookie_auth), qw(get_template_and_user); |
32 |
|
33 |
|
|
|
34 |
use List::MoreUtils qw(uniq); |
35 |
|
33 |
use CGI; |
36 |
use CGI; |
34 |
use JSON; |
37 |
use JSON; |
35 |
|
38 |
|
Lines 70-75
eval {
Link Here
|
70 |
}; |
73 |
}; |
71 |
my @biblios; |
74 |
my @biblios; |
72 |
my @biblios_blessed; |
75 |
my @biblios_blessed; |
|
|
76 |
my $bibliosnumbers; |
73 |
if ( $local_suggestions and DateTime::Duration->compare( $duration, DURATION_BEFORE_REFRESH ) == -1 ){ |
77 |
if ( $local_suggestions and DateTime::Duration->compare( $duration, DURATION_BEFORE_REFRESH ) == -1 ){ |
74 |
delete $local_suggestions->{timestamp}; |
78 |
delete $local_suggestions->{timestamp}; |
75 |
delete $local_suggestions->{biblionumber}; |
79 |
delete $local_suggestions->{biblionumber}; |
Lines 83-104
else{
Link Here
|
83 |
# get all informations to ask mana |
87 |
# get all informations to ask mana |
84 |
my $idtype; |
88 |
my $idtype; |
85 |
my $documentid; |
89 |
my $documentid; |
|
|
90 |
my $documentids; |
86 |
my $notnormalizeddocumentid; |
91 |
my $notnormalizeddocumentid; |
87 |
my $found = 0; |
92 |
my $found = 0; |
88 |
|
93 |
|
89 |
if ( $biblioitem && $biblioitem->isbn ){ |
94 |
if ( $biblioitem && $biblioitem->isbn ){ |
90 |
$idtype= "isbn"; |
95 |
$idtype = "isbn"; |
91 |
$documentid= C4::Koha::NormalizeISBN({ isbn => $biblioitem->isbn, format => 'ISBN-13', strip_hyphens => 1 }); |
96 |
$documentids = Koha::Util::Normalize::NormalizeISBNs({ isbns => $biblioitem->isbn, pattern => ' \| ', format => 'ISBN-13', strip_hyphens => 1 }); |
92 |
if ($documentids) { $found = 1; }; |
97 |
if ($documentids) { $found = 1; }; |
93 |
} |
98 |
} |
94 |
elsif ( $biblioitem && $biblioitem->issn ){ |
99 |
elsif ( $biblioitem && $biblioitem->issn ){ |
95 |
$idtype= "issn"; |
100 |
$idtype = "issn"; |
96 |
$documentid= $biblioitem->issn; |
101 |
$documentids = Koha::Util::Normalize::NormalizeISSNs({ issns => $biblioitem->issn, pattern => ' \| ', strip_hyphens => 0 }); |
97 |
if ($documentids) { $found = 1; }; |
102 |
if ($documentids) { $found = 1; }; |
98 |
} |
103 |
} |
99 |
elsif ( $biblioitem && $biblioitem->ean ){ |
104 |
elsif ( $biblioitem && $biblioitem->ean ){ |
100 |
$idtype= "ean"; |
105 |
$idtype = "ean"; |
101 |
$documentid= $biblioitem->ean; |
106 |
$documentid = $biblioitem->ean; |
|
|
107 |
$documentids =~ s/ \| / /; |
102 |
if ($documentids) { $found = 1; }; |
108 |
if ($documentids) { $found = 1; }; |
103 |
} |
109 |
} |
104 |
if ($found == 0){ |
110 |
if ($found == 0){ |
Lines 122-157
else{
Link Here
|
122 |
|
128 |
|
123 |
if ($row->{isbn}){ |
129 |
if ($row->{isbn}){ |
124 |
$idtype = "isbn"; |
130 |
$idtype = "isbn"; |
125 |
$documentid = C4::Koha::NormalizeISBN({ isbn => $row->{isbn}, format => 'ISBN-13', strip_hyphens => 1 }); |
131 |
$documentid = Koha::Util::Normalize::NormalizeISBNs({ isbn => $row->{isbn}, pattern => ' ', format => 'ISBN-13', strip_hyphens => 1 }); |
126 |
} |
132 |
} |
127 |
elsif ($row->{issn}){ |
133 |
elsif ($row->{issn}){ |
128 |
$idtype = "issn"; |
134 |
$idtype = "issn"; |
129 |
$documentid = $row->{issn}; |
135 |
$documentid = Koha::Util::Normalize::NormalizeISSNs({ ismn => $row->{issn}, pattern => ' ', strip_hyphens => 1 }); |
130 |
} |
136 |
} |
131 |
elsif ($row->{ismn}){ |
137 |
elsif ($row->{ismn}){ |
132 |
$idtype = "ismn"; |
138 |
$idtype = "ismn"; |
133 |
$documentid = $row->{ismn}; |
139 |
$documentids = Koha::Util::Normalize::NormalizeISMNs({ ismns => $row->{ismn}, pattern => ' ', format => 'ISMN-13', strip_hyphens => 1 }); |
134 |
} |
140 |
} |
135 |
elsif ($row->{isrn}){ |
141 |
elsif ($row->{isrn}){ |
136 |
$idtype = "isrn"; |
142 |
$idtype = "isrn"; |
137 |
$documentid = $row->{isrn}; |
143 |
$documentids = Koha::Util::Normalize::NormalizeISRNs({isrns => $row->{isrn}, pattern => ' ', convert_slash => 1, drop_local_suffix => 1 }); |
138 |
} |
144 |
} |
139 |
elsif ($row->{isrc}){ |
145 |
elsif ($row->{isrc}){ |
140 |
$idtype = "isrc"; |
146 |
$idtype = "isrc"; |
141 |
$documentid = $row->{isrc}; |
147 |
$documentids = Koha::Util::Normalize::NormalizeISRCs({ isrcs => $row->{isrc}, pattern => ' ', strip_hyphens => 1 }) |
142 |
} |
148 |
} |
143 |
elsif ($row->{upc}){ |
149 |
elsif ($row->{upc}){ |
144 |
$idtype = "upc"; |
150 |
$idtype = "upc"; |
145 |
$documentid = $row->{upc}; |
151 |
$documentids = $row->{upc}; |
146 |
} |
152 |
} |
147 |
elsif ($row->{ean}){ |
153 |
elsif ($row->{ean}){ |
148 |
$idtype = "ean"; |
154 |
$idtype = "ean"; |
149 |
$documentid = $row->{ean}; |
155 |
$documentids = $row->{ean}; |
150 |
} |
156 |
} |
151 |
else{ |
157 |
else{ |
152 |
die "error: no propper identifier"; |
158 |
die "error: no propper identifier"; |
153 |
} |
159 |
} |
154 |
} |
160 |
} |
|
|
161 |
|
162 |
$documentid=(split(/ /, $documentids, 2))[0]; |
155 |
$notnormalizeddocumentid = $documentid; |
163 |
$notnormalizeddocumentid = $documentid; |
156 |
my $offset = 1; |
164 |
my $offset = 1; |
157 |
my $length = 10; |
165 |
my $length = 10; |
Lines 190-225
else{
Link Here
|
190 |
#create the list of owned suggested resources |
198 |
#create the list of owned suggested resources |
191 |
my $ownedbiblioitem; |
199 |
my $ownedbiblioitem; |
192 |
foreach my $resource ( @{ $resources } ){ |
200 |
foreach my $resource ( @{ $resources } ){ |
193 |
# isbn processsing |
201 |
my $found = 0; |
194 |
if ( $resource->{idtype} eq "isbn" ){ |
|
|
195 |
$documentid= C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 1 }); |
196 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; |
197 |
|
198 |
#if we don't have such a biblioitem, we try to format else the isbn |
199 |
unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ |
200 |
$documentid = C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 1 }); |
201 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; |
202 |
} |
203 |
|
202 |
|
204 |
unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ |
203 |
#isbn, issn and ean can be search for with Koha::Biblioitems->search |
205 |
$documentid = C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 0 }); |
204 |
if ($resource->{idtype} eq "isbn" || $resource->{idtype} eq "issn" || $resource->{idtype} eq "ean"){ |
|
|
205 |
#isbn processsing |
206 |
if ( $resource->{idtype} eq "isbn" ){ |
207 |
$documentid= C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 1 }); |
206 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; |
208 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; |
|
|
209 |
|
210 |
#if we don't have such a biblioitem, we try to format else the isbn |
211 |
unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ |
212 |
$documentid = C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 1 }); |
213 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; |
214 |
} |
215 |
|
216 |
unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ |
217 |
$documentid = C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-10', strip_hyphens => 0 }); |
218 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; |
219 |
} |
220 |
|
221 |
unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ |
222 |
$documentid = C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 0 }); |
223 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; |
224 |
} |
207 |
} |
225 |
} |
208 |
|
226 |
|
209 |
unless ( scalar @{ $ownedbiblioitem->unblessed() } ){ |
227 |
#issn and ean don't need special processing |
210 |
$documentid = C4::Koha::NormalizeISBN({ isbn => $resource->{documentid}, format => 'ISBN-13', strip_hyphens => 0 }); |
228 |
elsif ($resource->{idtype} eq "issn" or $resource->{idtype} eq "ean"){ |
211 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $documentid}) if $documentid; |
229 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $resource->{documentid} }); |
212 |
} |
230 |
} |
213 |
|
231 |
|
|
|
232 |
#construct the tables with biblionumber |
233 |
if (scalar @{ $ownedbiblioitem->unblessed() } ){ |
234 |
$found = 1; |
235 |
my $ownedbiblio = Koha::Biblios->find( @{ $ownedbiblioitem->unblessed() }[0]->{biblionumber} ); |
236 |
#add the biblio if not already present |
237 |
if ( not(exists($bibliosnumbers->{@{ $ownedbiblioitem->unblessed() }[0]->{biblionumber}})) ){ |
238 |
push @biblios_blessed, $ownedbiblio; |
239 |
push @biblios, $ownedbiblio->unblessed(); |
240 |
$bibliosnumbers->{@{ $ownedbiblioitem->unblessed() }[0]->{biblionumber}}=1; |
241 |
} |
242 |
} |
214 |
} |
243 |
} |
215 |
#others ids do not need any processing |
244 |
# if we don't have such a biblioitem, we try to look directly in metadata |
216 |
else{ |
245 |
# because if the document has multiple isbn they are store in biblioitem table like this |
217 |
$ownedbiblioitem = Koha::Biblioitems->search({ $resource->{idtype} => $resource->{documentid} }); |
246 |
# "isbn1 | isbn2" and can't be found by biblioitems->seach |
218 |
} |
247 |
# other id need to be search with sql |
219 |
if (scalar @{ $ownedbiblioitem->unblessed() } ){ |
248 |
if ($found != 1) { |
220 |
my $ownedbiblio = Koha::Biblios->find( @{ $ownedbiblioitem->unblessed() }[0]->{biblionumber} ); |
249 |
my @params; |
221 |
push @biblios_blessed, $ownedbiblio; |
250 |
my %field=("isbn" => "010", "issn" => "011", "ismn" => "013", "isrn" => "015", "isrc" => "016", "upc" => "072", "ean" => "073"); |
222 |
push @biblios, $ownedbiblio->unblessed(); |
251 |
|
|
|
252 |
#pattern to be tolerent on the hyphens |
253 |
my $pattern=""; |
254 |
foreach my $p (split('', $resource->{documentid})){ |
255 |
$pattern .= "$p-*"; |
256 |
} |
257 |
|
258 |
my $dbh = C4::Context->dbh; |
259 |
my $query = q{ |
260 |
SELECT biblioitems.biblionumber as biblionumber |
261 |
FROM biblioitems |
262 |
LEFT JOIN biblio_metadata ON biblioitems.biblionumber=biblio_metadata.biblionumber |
263 |
WHERE ExtractValue(biblio_metadata.metadata, '//datafield[@tag="}.$field{$resource->{idtype}}.q{"]/subfield[@code="a"]') REGEXP "}.$pattern.q{" |
264 |
AND biblio_metadata.format="marcxml" |
265 |
}; |
266 |
my $sth = $dbh->prepare( $query ); |
267 |
$ownedbiblioitem = $sth->execute; |
268 |
|
269 |
#construct the tables with biblionumber |
270 |
my $row = $sth->fetchrow_hashref; |
271 |
if ( $row ){ |
272 |
my $ownedbiblio = Koha::Biblios->find( $row->{biblionumber} ); |
273 |
#add the biblio if not already present |
274 |
if ( not(exists($bibliosnumbers->{$row->{biblionumber}})) ){ |
275 |
push @biblios_blessed, $ownedbiblio; |
276 |
push @biblios, $ownedbiblio->unblessed(); |
277 |
$bibliosnumbers->{$row->{biblionumber}}=1; |
278 |
} |
279 |
} |
223 |
} |
280 |
} |
224 |
} |
281 |
} |
225 |
#the number of requested resource is inversely proportionnal to the found_items/returned_items ratio, +1 is here just to avoid 0 |
282 |
#the number of requested resource is inversely proportionnal to the found_items/returned_items ratio, +1 is here just to avoid 0 |
226 |
- |
|
|