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 C4::SocialData - Koha functions for dealing with social datas
27 For now used by babeltheque, a french company providing, for books, comments, upload of videos, scoring (star)...
28 the social_data table could be used and improved by other provides.
36 The functions in this module deal with social datas
42 Get social data from a biblio
45 $isbn = isbn of the biblio (it must be the same in your database, isbn given to babelio)
48 this function returns an hashref with keys
51 num_critics = number of critics
52 num_critics_pro = number of profesionnal critics
53 num_quotations = number of quotations
54 num_videos = number of videos
55 score_avg = average score
56 num_scores = number of score
61 my $dbh = C4
::Context
->dbh;
62 my $sth = $dbh->prepare( qq{SELECT
* FROM social_data WHERE isbn
= ? LIMIT
1} );
63 $sth->execute( $isbn );
64 my $results = $sth->fetchrow_hashref;
74 $url = url containing csv file with data
76 data separator : ; (semicolon)
77 data order : isbn ; active ; critics number , critics pro number ; quotations number ; videos number ; average score ; scores number
82 my ( $output_filepath ) = @_;
84 my $dbh = C4
::Context
->dbh;
85 my $sth = $dbh->prepare( qq{INSERT INTO social_data
(
86 `isbn`, `num_critics`, `num_critics_pro`, `num_quotations`, `num_videos`, `score_avg`, `num_scores`
87 ) VALUES
( ?
, ?
, ?
, ?
, ?
, ?
, ?
)
88 ON DUPLICATE KEY UPDATE
`num_critics`=?
, `num_critics_pro`=?
, `num_quotations`=?
, `num_videos`=?
, `score_avg`=?
, `num_scores`=?
91 open my $file, '<', $output_filepath or die "File $output_filepath can not be read";
95 while ( my $line = <$file> ) {
96 my ( $isbn, $active, $num_critics, $num_critics_pro, $num_quotations, $num_videos, $score_avg, $num_scores ) = split $sep, $line;
99 $sth->execute( $isbn, $num_critics, $num_critics_pro, $num_quotations, $num_videos, $score_avg, $num_scores,
100 $num_critics, $num_critics_pro, $num_quotations, $num_videos, $score_avg, $num_scores
104 warn "Can't insert $isbn ($@)";
109 say "$i data insered or updated";
114 Get social data report
119 my $dbh = C4
::Context
->dbh;
121 my $sth = $dbh->prepare( qq{
122 SELECT biblionumber
, isbn FROM biblioitems
126 while ( my ( $biblionumber, $isbn ) = $sth->fetchrow() ) {
127 push @
{ $results{no_isbn
} }, { biblionumber
=> $biblionumber } and next if not $isbn;
128 my $original_isbn = $isbn;
129 $isbn =~ s/^\s*(\S*)\s*$/$1/;
130 $isbn = GetNormalizedISBN
( $isbn, undef, undef );
131 $isbn = Business
::ISBN
->new( $isbn );
134 $isbn = $isbn->as_isbn13->as_string;
138 my $social_datas = C4
::SocialData
::get_data
( $isbn );
139 if ( $social_datas ) {
140 push @
{ $results{with
} }, { biblionumber
=> $biblionumber, isbn
=> $isbn, original
=> $original_isbn };
142 push @
{ $results{without
} }, { biblionumber
=> $biblionumber, isbn
=> $isbn, original
=> $original_isbn };