1 package C4::SocialData;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
26 Get social data from a biblio
29 $isbn = isbn of the biblio (it must be the same in your database, isbn given to babelio)
32 this function returns an hashref with keys
35 num_critics = number of critics
36 num_critics_pro = number of profesionnal critics
37 num_quotations = number of quotations
38 num_videos = number of videos
39 score_avg = average score
40 num_scores = number of score
44 my $dbh = C4::Context->dbh;
45 my $sth = $dbh->prepare( qq{SELECT * FROM social_data WHERE isbn = ? LIMIT 1} );
46 $sth->execute( $isbn );
47 my $results = $sth->fetchrow_hashref;
57 $url = url containing csv file with data
59 data separator : ; (semicolon)
60 data order : isbn ; active ; critics number , critics pro number ; quotations number ; videos number ; average score ; scores number
64 my ( $output_filepath ) = @_;
66 my $dbh = C4::Context->dbh;
67 my $sth = $dbh->prepare( qq{INSERT INTO social_data (
68 `isbn`, `num_critics`, `num_critics_pro`, `num_quotations`, `num_videos`, `score_avg`, `num_scores`
69 ) VALUES ( ?, ?, ?, ?, ?, ?, ? )
70 ON DUPLICATE KEY UPDATE `num_critics`=?, `num_critics_pro`=?, `num_quotations`=?, `num_videos`=?, `score_avg`=?, `num_scores`=?
73 open my $file, '<', $output_filepath or die "File $output_filepath can not be read";
77 while ( my $line = <$file> ) {
78 my ( $isbn, $active, $num_critics, $num_critics_pro, $num_quotations, $num_videos, $score_avg, $num_scores ) = split $sep, $line;
81 $sth->execute( $isbn, $num_critics, $num_critics_pro, $num_quotations, $num_videos, $score_avg, $num_scores,
82 $num_critics, $num_critics_pro, $num_quotations, $num_videos, $score_avg, $num_scores
86 warn "Can't insert $isbn ($@)";
91 say "$i data insered or updated";
96 Get social data report
100 my $dbh = C4::Context->dbh;
102 my $sth = $dbh->prepare( qq{
103 SELECT biblionumber, isbn FROM biblioitems
107 while ( my ( $biblionumber, $isbn ) = $sth->fetchrow() ) {
108 push @{ $results{no_isbn} }, { biblionumber => $biblionumber } and next if not $isbn;
109 my $original_isbn = $isbn;
110 $isbn =~ s/^\s*(\S*)\s*$/$1/;
111 $isbn = GetNormalizedISBN( $isbn, undef, undef );
112 $isbn = Business::ISBN->new( $isbn );
115 $isbn = $isbn->as_isbn13->as_string;
119 my $social_datas = C4::SocialData::get_data( $isbn );
120 if ( $social_datas ) {
121 push @{ $results{with} }, { biblionumber => $biblionumber, isbn => $isbn, original => $original_isbn };
123 push @{ $results{without} }, { biblionumber => $biblionumber, isbn => $isbn, original => $original_isbn };